Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What's new in Android 14 - IO Extended George Town 2023

What's new in Android 14 - IO Extended George Town 2023

Somkiat Khitwongwattana

June 28, 2023
Tweet

More Decks by Somkiat Khitwongwattana

Other Decks in Technology

Transcript

  1. New features and APIs that are available in Android 14

    System changes that might affect your app when it's running on Android 14 New Feature All Apps Targeting 14 Behavior Changes
  2. Sharesheet improvement 1. Add custom actions 2. Updated preview UI

    3. Improve ranking quality with Direct Share targets New Feature User Experience
  3. Sharesheet improvement Add custom actions val actions: Array<ChooserAction> = /*

    ... */ val intent = Intent(/* ... */).apply { /* ... */ putExtra(Intent.EXTRA_CHOOSER_CUSTOM_ACTIONS, actions) } Intent.createChooser(intent, "Chooser title") New Feature User Experience
  4. Predictive Back Built-in and custom animations Multiple improvements and new

    guidance for Predictive Back New Feature User Experience
  5. Predictive Back Per activity opt-in <manifest> <application> <activity android:name=" MainActivity"

    android:enableOnBackInvokedCallback="true" /> <activity android:name=" SecondActivity" android:enableOnBackInvokedCallback="false" /> </application> </manifest> New Feature User Experience
  6. Predictive Back Custom in-app transitions and animations override fun onCreate(savedInstanceState:

    Bundle?) { /* ... */ val callback = object : OnBackPressedCallback(enabled = true) { override fun handleOnBackProgressed(backEvent: BackEvent) { // Transform animation } override fun handleOnBackPressed() { /* ... */ } override fun handleOnBackCancelled() { /* ... */ } } this.onBackPressedDispatcher.addCallback(callback) } New Feature User Experience
  7. Detecting Screenshots Lets apps register callbacks on a per-activity basis.

    And the user is notified, when the user takes a screenshot while that activity is visible. New Feature User Experience
  8. Detecting Screenshots // Activity val screenCaptureCallback = Activity.ScreenCaptureCallback { //

    Add logic to take action in your app. } override fun onStart() { registerScreenCaptureCallback(mainExecutor, screenCaptureCallback) } override fun onStop() { unregisterScreenCaptureCallback(screenCaptureCallback) } New Feature User Experience
  9. Grant partial access to photos and videos User can grant

    partial access to their photos and videos when an app requests any visual media permissions that were introduced in Android 13. Behavior Changes: All Apps User Experience
  10. Grant partial access to photos and videos Consider declaring the

    new READ_MEDIA_VISUAL_USER_SELECTED permission, or use the photo picker in AndroidX Activity library. Behavior Changes: All Apps User Experience
  11. Secure full-screen Intent notifications Behavior Changes: All Apps Apps allowed

    to use USE_FULL_SCREEN_INTENT permission are limited to those that provide calling or alarms only. And users can turn this permission on and off. To support this changes • Use NotificationManager.canUseFullScreenIntent to check the permission. • Use ACTION_MANAGE_APP_USE_FULL_SCREEN_INTENT to launch the settings page. User Experience
  12. Changes to how users experience non-dismissable notifications The notification that

    set • Notification.Builder#setOngoing(true) • NotificationCompat.Builder#setOngoing(true) to prevent users dismissing foreground notification will be dismissable by the user. Behavior Changes: All Apps User Experience
  13. Changes to how users experience non-dismissable notifications Except: • When

    the phone is locked • User selects a Clear all notification action • Notifications tied to real calls using CallStyle • Notifications created using MediaStyle Behavior Changes: All Apps User Experience
  14. Data safety information is more visible The system runtime permission

    dialog now includes a clickable section that highlights your app's data sharing practices for some permission. Behavior Changes: All Apps User Experience
  15. Data safety information is more visible Behavior Changes: All Apps

    System notification that appears when some installed apps change their data sharing to the third party or ads-related purpose. User Experience
  16. Per-app language preferences Automatic per-app language preferences // Android Studio

    Giraffe Canary 7 or higher // AGP 8.1.0-alpha07 or higher android { androidResource { generateLocaleConfig true } } New Feature Internationalization
  17. Per-app language preferences Dynamic updates for different language sets val

    localeManager = context.getSystemService(LocaleManager::class.java) localeManager.overrideLocaleConfig = LocaleConfig( LocaleList.forLanguageTags(regional_locales) ) New Feature Internationalization
  18. Grammatical Inflection API Lets you add support for grammatical gender

    without refactoring your app. • feminine • masculine • neuter New Feature Internationalization
  19. Regional preferences Enable users to personalize temperature units, the first

    day of the week, and numbering systems. New Feature Internationalization
  20. Regional preferences // androidx.core:core-ktx:1.12.0-alpha01 or higher val temperatureUnit = LocalePreferences.getTemperatureUnit()

    // LocalePreferences.TemperatureUnit.CELSIUS // ... val firstDayOfWeek = LocalePreferences.getFirstDayOfWeek() // FirstDayOfWeek.SUNDAY // ... New Feature Internationalization
  21. Minimum installable target API level Behavior Changes: All Apps Apps

    with a targetSdkVersion lower than 23 can't be installed. Requiring apps to meet these minimum target API level requirements improves security and privacy for users. // build.gradle (module) android { defaultConfig { targetSdk 22 } } Security
  22. Media owner package names might be redacted The value of

    OWN_PACKAGE_NAME column in media store is redacted unless at least one of the following condition is true: • App that stored the media file has a package name that is always visible to other apps. • App that queries the media store requests the QUERY_ALL_PACKAGES permission. Behavior Changes: All Apps Security
  23. Restrictions to implicit and pending intents Behavior Changes: Targeting 34

    Restricts apps from sending implicit intents to internal app components in the following ways: • Implicit intents are only delivered to exported components. • Mutable pending intent that doesn't specify a component or package Security
  24. Restrictions to implicit and pending intents <activity android:name=".AppActivity" android:exported="false"> <intent-filter>

    <action android:name="com.example.action.APP_ACTION" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> Behavior Changes: Targeting 34 Security
  25. Restrictions to implicit and pending intents // Throws an exception

    when targeting Android 14. context.startActivity(Intent("com.example.action.APP_ACTION")) // This makes the intent explicit. val intent = Intent("com.example.action.APP_ACTION").apply { setPackage(context.packageName) } context.startActivity(intent) Behavior Changes: Targeting 34 Security
  26. Runtime-registered broadcasts receivers must specify export behavior val broadcastReceiver: BroadcastReceiver

    = /* ... */ val intentFilter: IntentFilter = /* ... */ context.registerReceiver( broadcastReceiver, intentFilter, Context.RECEIVER_EXPORTED // or Context.RECEIVER_NOT_EXPORTED ) Behavior Changes: Targeting 34 Security
  27. Safer dynamic code loading All dynamically-loaded files must be marked

    as read-only. val jar = File("DYNAMICALLY_LOADED_FILE.jar") FileOutputStream(jar).use { // Set the file to read-only first to prevent race conditions jar.setReadOnly() // Then write the actual file content } val pathClassLoader = PathClassLoader(jar, parentClassLoader) Behavior Changes: Targeting 34 Security
  28. Safer dynamic code loading Deleting and recreating the files before

    you try to dynamically load them again in your app. Alternatively, verify the integrity of the files and re-label the existing files as read-only Behavior Changes: Targeting 34 Security
  29. Using ZipFile(String) and ZipInputStream.getNextEntry() with zip file entry names containing

    .. or start with / will throw a ZipException . Or calling dalvik.system.ZipPathValidator.clearCallback() to opt-out from this validation. Zip path traversal Behavior Changes: Targeting 34 Security
  30. Additional restrictions on starting activities from the background The system

    further restricts when apps are allowed to start activities from the background. • Sends a PendingIntent using PendingIntent#send() and wants to grant its own privileges to start the pending intent. • A visible app binds a service of another app that's in the background using the bindService() method and want to grant its own privileges to the bound service. Behavior Changes: Targeting 34 Security
  31. Paths are now queryable and interpolatable New Feature val path

    = Path().apply { moveTo(1.0f, 1.0f) lineTo(2.0f, 2.0f) close() } val pathIterator = path.pathIterator for (segment in pathIterator) { println("segment: ${segment.verb}, ${segment.points}") } Graphic
  32. Paths are now queryable and interpolatable val interpolatedResult = Path()

    if (path.isInterpolatable(otherPath)) { path.interpolate(otherPath, .5f, interpolatedResult) } New Feature Graphic
  33. Non-linear font scaling to 200% To prevent large text elements

    on screen from scaling too large, the system applies a non-linear scaling curve New Feature Behavior Changes: All Apps Accessibility
  34. Non-linear font scaling to 200% New Feature Behavior Changes: All

    Apps • Test your app with non-linear font scaling • Open the Settings app and navigate to Accessibility > Display size and text • Use scaled pixel (sp) units for text-sizes • Convert scaled pixel (sp) units • Use TypedValue.applyDimension() to convert from sp units to pixels • Use TypedValue.deriveDimension() to convert pixels to sp Accessibility
  35. Schedule exact alarms are denied by default Behavior Changes: All

    Apps The SCHEDULE_EXACT_ALARM permission is no longer being pre-granted, the permission is denied by default. • Targets Android 13 (API level 33) or higher • Declares the SCHEDULE_EXACT_ALARM permission in the manifest • Isn't a calendar or alarm clock app • Doesn't fall under an exemption or pre-grant scenario Core Functionality
  36. Schedule exact alarms are denied by default Behavior Changes: All

    Apps val manager: AlarmManager = context.getSystemService(AlarmManager::class.java) when { manager.canScheduleExactAlarms() -> { // If permission is granted, proceed with scheduling exact alarms manager.setExact(...) } else -> { // Ask users to go to exact alarm page in system settings startActivity(Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM)) } } Core Functionality
  37. Apps can kill only their own background processes Behavior Changes:

    All Apps ActivityManager#killBackgroundProcesses method can kill only the background processes of your own app Core Functionality
  38. Foreground service types are required Behavior Changes: Targeting 34 Specify

    at least one foreground service type for each foreground service within your app <manifest ...> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" /> <application ...> <service android:name=".LocationTrackingService" android:exported="false" android:foregroundServiceType="location" /> </application> </manifest> Core Functionality
  39. Foreground service types are required Behavior Changes: Targeting 34 •

    FOREGROUND_SERVICE_CAMERA • FOREGROUND_SERVICE_LOCATION • FOREGROUND_SERVICE_MEDIA_PLAYBACK • FOREGROUND_SERVICE_MICROPHONE • FOREGROUND_SERVICE_PHONE_CALL • etc. Core Functionality
  40. Enforcement of BLUETOOTH_CONNECT permission Enforces the BLUETOOTH_CONNECT permission when calling

    the getProfileConnectionState() method in BluetoothAdapter for apps targeting Android 14 <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> Behavior Changes: Targeting 34 Core Functionality
  41. OpenJDK 17 updates • Updated ~300 java.base classes • Text

    Blocks • Pattern Matching for instanceOf • Sealed classes Behavior Changes: Targeting 34 New Feature • Changes to regular expressions • UUID handling Core Functionality
  42. Thank You! Somkiat Khitwongwattana Android GDE @akexorcist More about Android

    14 https://developer.android.com/about/versions/14