Android 9.0 is an Android operating system developed by Google. It was first published on Google’s official website on January 25, 2018. In February 2018, Android 9.0 was initially code-named Pistachio Ice Cream. After Android 8.0, Android 9.0 features further improved, Android 9.0 mainly added Google push upgrade, deep integration of Project Treble mode, more closed, native support for voice recording and other features, let’s take a look.

Android 9 adds platform support for the IEEE 802.11MC Wi-Fi protocol (also known as Wi-Fi round-trip-time (RTT)) to enable your applications to take advantage of indoor location.

On devices running Android 9 with hardware support, apps can use the RTT API to measure the distance to nearby RTT-enabled Wi-Fi access points (aps). The device must have Location services enabled and Wi-Fi scanning enabled (under Settings > Location), and your application must have ACCESS_FINE_LOCATION permission.

Devices can use RTT without connecting to the access point. To protect privacy, only the phone can determine the distance from the access point; The access point does not have this information.

If your device measures distances from three or more access points, you can use a multipoint positioning algorithm to predict the location of the device that best matches those measurements. The results are usually accurate to 1 to 2 meters.

With this precision, you can build new experiences such as in-building navigation, fine-location-based services such as unambiguous voice controls (” Turn on this light “, for example), and location-based information such as “Does this product have a special offer? ).

Screen notch support

Android 9 supports the latest full screen, which includes a screen gap to make room for the camera and speakers. The DisplayCutout class allows you to determine the position and shape of non-functional areas that should not display content. To determine whether these screen notch regions exist and where they are, use the getDisplayCutout() function.

New window layout attribute layoutInDisplayCutoutMode lets your application for the equipment layout screen gap around the content. You can set this property to one of the following values:

LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER
Copy the code

You can simulate the screen gap on any device or emulator running Android 9 by: Enabling the developer option. In the Developer Options screen, scroll down to the Drawing section and select Simulate a Display with a Cutout. Select the screen notch size. Note: We recommend that you test the display of content around the screen gap using a device or emulator running Android 9.

notice

Android 9 introduces several notification enhancements for developers targeting API level 28 and above.

SMS notification

Starting with Android 7.0 (API level 24), you can add an action to reply to a text message or enter additional text directly from the notification. Android 9 improves this functionality with the following enhancements:

  • Simplified support for conversation participants: The Person class can be used to identify people participating in a conversation, including their avatars and URIs. Many other apis, such as addMessage(), now make use of the [Person] class instead of the CharSequence. The Person class also supports the builder design pattern.
  • Image support: Android 9 now displays images in SMS notifications on your phone. You can display images using setData() for SMS messages. The following code snippet demonstrates how to create a Person and a text message containing an image.

For example, MessagingStyle with photos

// Create new Person.
Person sender = new Person()
        .setName(name)
        .setUri(uri)
        .setIcon(null)
        .build();
// Create image message.
Message message = new Message("Picture", time, sender)
        .setData("image/", imageUri);
Notification.MessagingStyle style = new Notification.MessagingStyle(getUser())
        .addMessage("Check this out!", 0, sender)
        .addMessage(message);
Copy the code

  • Save replies as drafts: Your application can retrieve EXTRA_REMOTE_INPUT_DRAFT sent by the system when a user inadvertently turns off an SMS notification. You can use this Extra to pre-populate text fields in your application so that users can complete their responses.
  • Determine whether the conversation is a group conversation. You can use setGroupConversation() to explicitly determine whether the conversation is a group conversation.
  • Set semantic actions for Intents: The setSemanticAction() function allows you to provide semantic meanings for actions such as “mark as read,” “delete,” and “reply.”
  • SmartReply: Android 9 supports providing the same suggested responses in your messaging app. Use remoteInput.setchoices () to provide the user with a standard set of responses.

Channel Settings, broadcast, and Do not Disturb

Android 8.0 introduces notification channels, allowing you to create customizable channels for each notification type you want to display. Android 9 simplifies notification channel Settings with the following changes:

  • Blocking channel Groups: Users can now block entire channel groups in notification Settings for an application. You can use the isBlocked() function to determine when to block a channel group so that no notifications are sent to the channels in that group.

In addition, your application can use the new getNotificationChannelGroup () function queries the current channel group Settings.

  • New types of broadcast Intents: Android now sends broadcast intents when the blocking status of a notification channel or channel group changes. Applications with blocked channels or channel groups can listen for these intents and respond accordingly. For more information about these Intent operations and extra, see the updated list of constants in the NotificationManager reference.
  • NotificationManager. The Policy has three new “do not disturb” priority categories:
PRIORITY_CATEGORY_ALARMS process alarms first. PRIORITY_CATEGORY_MEDIA prioritizes the sound of media sources, such as media and voice navigation. PRIORITY_CATEGORY_SYSTEM Processes system sounds first.Copy the code
  • NotificationManager. Policy and 7 kinds of new “do not disturb” constants, can be used to suppress the visual interruption:
SUPPRESSED_EFFECT_FULL_SCREEN_INTENT Prevents notifications from starting full-screen activities. SUPPRESSED_EFFECT_LIGHTS Suppress the notification light. SUPPRESSED_EFFECT_PEEK Prevents notifications from briefly entering the view (" slide out "). SUPPRESSED_EFFECT_STATUS_BAR Prevents notifications from being displayed in the status bar of devices that support the status bar. SUPPRESSED_EFFECT_BADGE Shields the badge on devices that support the badge. For more information, see Modify Notification Flags. SUPPRESSED_EFFECT_AMBIENT blocks notifications on devices that support low light display. SUPPRESSED_EFFECT_NOTIFICATION_LIST Prevents notifications from being displayed in the list view of devices that support list views, such as notification bars or lock screens.Copy the code

Multi-camera support and camera updates

On devices running Android 9, you can access multiple video streams simultaneously with two or more physical cameras. On devices with dual front-facing or dual-rear-facing cameras, you can create innovative features, such as seamless zooming, background blurring, and stereoscopic imaging, that are not possible on devices with a single camera. Through the API, you can also invoke a logical or fused camera video stream that can automatically switch between two or more cameras. Other camera improvements include additional session parameters, which help reduce latency during the first photo, and Surface sharing, which allows the camera client to process a variety of use cases without stopping and starting the camera video stream. We have also added apis for display-based Flash support and OIS timestamp access for application-level image stabilization and effects.

In Android 9, the Multi-camera API supports monochrome cameras for devices with FULL or LIMITED capabilities. Monochromatic output is realized in YUV_420_888 format, Y is gray scale, U (Cb) is 128, V (Cr) is 128.

On supported devices, Android 9 also supports an external USB/UVC camera.

ImageDecoder

Android 9 introduces the ImageDecoder class, which provides modern methods for decoding images. Use this class to replace BitmapFactory and the BitmapFactory.options API.

ImageDecoder lets you create Drawable or Bitmap from byte buffers, files, or URIs. To decode the image, first call createSource() with the source of the encoded image as an argument. The Drawable() or decodeBitmap() is then called by passing the ImageDecoder.source object to create a Drawable] or Bitmap. To change the default Settings, pass OnHeaderDecodedListener to decodeDrawable() or decodeBitmap(). ImageDecoder calls onHeaderDecoded(), taking the default width and height (if known) of the image. If the encoded image is an animated GIF or WebP, decodeDrawable() returns Drawable, which is an instance of the AnimatedImageDrawable class.

You can set image properties in different ways:

  • To scale the decoded image to exact size, pass the target size to setTargetSize(). You can also scale the image using the sample size. Pass the sample size directly to setTargetSampleSize().
  • To crop the image within the scope of the scaled image, call setCrop().
  • To create a mutable bitmap, pass true to setMutableRequired().

ImageDecoder also allows you to add complex custom effects to images such as rounded corners or round masks. Use setPostProcessor() with an instance of the PostProcessor class as an argument to execute any drawing commands you need.

Note: When AnimatedImageDrawable is postprocessed, the effect appears in all frames of the animation.

animation

Android 9 introduces the AnimatedImageDrawable class for drawing and displaying GIF and WebP animated images. AnimatedImageDrawable works in much the same way as AnimatedVectorDrawable in that the renderer thread drives the AnimatedImageDrawable animation. The renderer thread also uses the worker thread for decoding, so decoding does not interfere with other operations of the renderer thread. This implementation mechanism allows your application to display animated images without managing their updates and without interfering with other events on the application interface threads.

AnimatedImageDrawable can be decoded using an instance of ImageDecoder. The following code snippet demonstrates how to use ImageDecoder to decode AnimatedImageDrawable:

private void decodeImage() throws IOException {
    Drawable decodedAnimation = ImageDecoder.decodeDrawable(
        ImageDecoder.createSource(getResources(), R.drawable.my_drawable));

    if(decodedAnimation instanceof AnimatedImageDrawable) { // Prior to start(), the first frame is displayed. ((AnimatedImageDrawable) decodedAnimation).start(); }}Copy the code

ImageDecoder has several functions that allow you to further modify the image. For example, you can use the setPostProcessor() function to modify the appearance of an image, such as applying a circular mask or rounded corners.

HDR VP9 video, HEIF image compression and Media API

Android 9 has added built-in support for High Dynamic Range (HDR) VP9 Profile 2, so, You can now offer users hDR-enabled Movies from YouTube, Play Movies, and other sources on HDR-enabled devices.

Android 9 adds support for HEIF (HEIC) image encoding to the platform. HEIF improves compression to save storage space and network data traffic. With platform support on Android 9 devices, sending and using HEIF images from back-end servers is a breeze. After ensuring that your application is compatible with this data format, which is easy to share and display, try using HEIF as an image storage format in your application. You can use ImageDecoder or BitmapFactory to convert jpeg to Heicto to get bitmaps through JPEG, And HeifWriter can be used to write HEIF static images from YUV byte buffers, surfaces, or bitmaps.

Media metrics can also be obtained from the AudioTrack, AudioRecord, and MediaDrm classes.

Android 9 adds functions to the MediaDRM class to get metrics, high bandwidth digital Content Protection (HDCP) levels, security levels, and number of sessions, as well as more control over security levels and security stops. For more details, see the API Differences Report.

In Android 9, the AAudio API contains the AAudioStream attribute for Usage, Content Type, and Input Preset. You can use these properties to create a stream of adjustments for VoIP or camera applications. You can also set the SessionID to associate the AAudio stream with a submix that can contain sound effects. Use the AudioEffect API to control sound effects.

Android 9 includes an AudioEffect API for DynamicsProcessing. With this class, you can build channel-based sound that consists of multiple stages of various types, including equalization, multiband compression, and limiter. The number of bands and active phases can be configured, and most parameters can be controlled in real time.

JobScheduler

Starting with Android 9, JobScheduler can use network status signals provided by carriers to improve the processing of network-related jobs.

Jobs can declare their estimated data size, signal preextraction, and specify specific network requirements. JobScheduler then manages work based on network state. For example, JobScheduler may delay large network requests when the network shows congestion. If you are on a network that does not charge by traffic, JobScheduler can run pre-fetch jobs to improve the user experience (for example, pre-fetch titles).

When adding jobs, be sure to use setEstimatedNetworkBytes(), setPrefetch(), and setRequiredNetwork(), if applicable, to help JobScheduler process the work correctly. When executing the job, be sure to use the Network object returned by jobparameters.getNetwork (). Otherwise, you will implicitly use the device’s default network, which may not meet your requirements, resulting in unexpected traffic consumption.

Neural Networks API 1.1

Android 8.1 (API level 27) introduced the Neural Networks API to speed up machine learning on Android devices. Android 9 extends and improves the API, adding support for nine new operations:

Element-level math

  • ANEURALNETWORKS_DIV
  • ANEURALNETWORKS_SUB

Array operation

  • ANEURALNETWORKS_BATCH_TO_SPACE_ND
  • ANEURALNETWORKS_SPACE_TO_BATCH_ND
  • ANEURALNETWORKS_SQUEEZE
  • ANEURALNETWORKS_STRIDED_SLICE
  • ANEURALNETWORKS_TRANSPOSE
  • ANEURALNETWORKS_PAD
  • ANEURALNETWORKS_MEAN

In addition, the API also introduced a new function, namely ANeuralNetworksModel_relaxComputationFloat32toFloat16 (), ANEURALNETWORKS_TENSOR_FLOAT32 allows you to specify whether to calculate the range and accuracy as low as IEEE 754 in the 16-bit ANEURALNETWORKS_TENSOR_FLOAT32 format.

Self-filling frame

Android 9 introduces several improvements that the auto-fill service can take advantage of to further enhance the user experience when filling out forms. For details on how to use autofill in your application, see the Autofill Framework guide.

Security enhancement

Android 9 introduces several security features, as summarized in the following sections:

Android Protected Confirmation

Supported devices running Android 9 or later give you the ability to use Android Protected Confirmation. When using this workflow, your application displays a prompt to the user asking them to approve a short statement. This declaration allows the application to reconfirm that the user really wants to complete a sensitive transaction, such as making a payment.

If the user accepts this declaration, the Android keystore receives and stores the encrypted signature protected by the key Hash Message Authentication code (HMAC). Android keystore after confirm the validity of the message, your application can use the trusted execution environment (TEE) signed by the key generated trustedConfirmationRequired users have accepted the message. This signature is highly reliable and indicates that the user has read the statement and agrees with its content.

Note: Android Protected Confirmation does not provide a security information channel for users. The application cannot assume any warranty other than that provided by the Android platform for confidentiality. In particular, do not use this workflow to display sensitive information that you would not normally display on a user’s device.

Unified biometric dialog box

In Android 9, the system provides a biometric authentication dialog box on behalf of your application. This feature creates a standardized look, style, and location of the dialog box to make users more confident that they are authenticating using a trusted biometric credential checker.

If your application uses FingerprintManager to display the fingerprint authentication dialog to the user, switch to BiometricPrompt instead. The BiometricPrompt relies on the system to display the authentication dialog. It also changes its behavior to suit the type of biometric authentication the user chooses.

Note: Before using BiometricPrompt in your application, you should use the hasSystemFeature() function to make sure your device supports FEATURE_FINGERPRINT, FEATURE_IRIS, or FEATURE_FACE.

If the device does not support biometric authentication, can use the fallback for createConfirmDeviceCredentialIntent () function to verify the user’s PIN number, design, or a password.

Hardware security module

Supported devices running Android 9 or later can have StrongBox Keymaster, which is an implementation of Keymaster HAL in the hardware security module. This module contains the following components:

  • Own CPU.
  • Secure storage space.
  • Real random number generator.
  • Additional mechanisms to resist software package tampering and unauthorized wire-brushing applications.

When checking the key stored in the StrongBox Keymaster, the system verifies the integrity of the key through the Trusted Execution Environment (TEE).

Protects key imports into key stores

Android 9 improves the security of key decryption by securely importing the encrypted key into the keystore using ASN.1‑ encoded key format. The Keymaster then decrypts the key in the keystore, so that the contents of the key never appear in clear text in the device’s host memory.

Note: Only devices shipped with Keymaster 4 or later support this feature.

APK signature scheme with key rotation

Android 9 has added support for APK Signature Scheme V3. The architecture provides the option to add a rotating evidence record for each signing certificate in its signature block. With this feature, an application can sign an application with a new signing certificate by linking the APK file’s past signing certificate to the certificate now used to sign the application.

Note: Devices running Android 8.1 (API level 27) or lower do not support changing the signing certificate. If the application has minSdkVersion 27 or lower, the application can be signed with the old signing certificate in addition to the new signature.

Key decryption is only allowed on unlocked devices

Android 9 introduces the unlockedDeviceRequired flag. This option determines whether the keystore requires screen unlocking before allowing decryption of any data being transmitted or stored using the specified key. These types of keys are ideal for encrypting sensitive data to be stored on disk, such as health or enterprise data. The flag provides users with a higher level of assurance that even if the phone is lost or stolen, the data cannot be decrypted while the device is locked.

Note: When the unlockedDeviceRequired flag is enabled, encryption and signature verification can still be performed at any time. This flag prevents “decrypt only” data when the device is unlocked.

When equipment lock to ensure that key security does not be decrypted, can pass true setUnlockedDeviceRequired () function enable this flag. After this step, any attempt to decrypt or sign data using this key will fail when the user’s screen is locked. Locking a device requires a PIN, password, fingerprint, or some other trusted factor before it can be accessed.

Older encryption support

Android 9 devices with Keymaster 4 support triple data encryption algorithms (triple DES for short). If your application interoperates with older systems that require triple DES, use this encryption to encrypt sensitive credentials.

Android backup

Android 9 has added features and developer options related to backup and restore. Details of these changes are shown in the following sections.

Client encryption backup

Android 9 has added support for encrypting Android backups using client keys. This function is automatically enabled when the following conditions are met:

  • The user has enabled backup using Android 9 or later.
  • The user has set a screen lock on their device and requires a PIN, pattern, or password to unlock it.

When this privacy measure is enabled, the device’s PIN, pattern, or password will be required to restore data from a backup made by the user’s device.

If your application data contains sensitive information or preferences, Android 9 lets you define device conditions (such as when client-side encryption is enabled or local device-to-device transfers are in progress) upon which the data will be included in the user’s backup.

Accessibility function

Android 9 introduces enhancements to the accessibility framework that make it easier for you to provide a better experience for your app’s users.

Navigation semantic

New properties in Android 9 make it easier to define how accessibility services, especially screen readers, navigate from one part of the screen to another. These properties help visually impaired users move quickly between text on the app interface and allow them to make choices.

For example, in a shopping application, a screen reader can help users navigate directly from one transaction category to the next, without having to read all the transactions in the current category before moving on to the next.

Accessibility pane title

In Android 8.1 (API level 27) and lower, accessibility services sometimes cannot determine when a pane of the screen was updated, such as when an Activity replaces one Fragment with another. Panes consist of visually related interface elements grouped logically, usually containing a Fragment.

In Android 9, these panes can be provided with barrier-free pane titles, individually identifiable titles. If a pane has a barrier-free feature pane title, the barrier-free service can receive more detailed information when the pane changes. With this capability, services can provide users with more detailed information about interface changes.

To specify the title of a pane, please use the android: accessibilityPaneTitle properties. You can also update at runtime using setAccessibilityPaneTitle () replace the title of the interface of a pane. For example, you can provide a title for the content area of a Fragment object.

Title-based navigation

If your application displays the text content contains logical headings, or added to the title of the View instance, please send the android: accessibilityHeading attribute set to true. By adding these headings, accessibility services help users navigate directly from one heading to the next. Any barrier-free service can use this functionality to improve the navigation experience of the user interface.

Group navigation and output

Traditionally, screen readers have used the Android :focusable property to determine when a ViewGroup or series of View objects should be read as a whole. In this way, users can understand that the views are logically related to each other.

In Android 8.1 and later, you need to mark each View object in a ViewGroup as unfocused and the ViewGroup itself as focatable. This arrangement causes some instances of the View to be marked as focusable, making keyboard navigation more cumbersome.

Starting from Android 9, if will View object marked can focus will produce negative consequences, then you can use the Android: screenReaderFocusable attributes instead of Android: focusable attribute. Screen readers focus on all the android: screenReaderFocusable or android: focusable element is set to true.

Convenient operation

Android 9 has added some new features to make it easier for users to perform operations:

Access Hints: A new feature in the accessibility framework allows you to access hints in the application interface. Use getTooltipText() to read the prompt text, and use ACTION_SHOW_TOOLTIP and ACTION_HIDE_TOOLTIP to instruct instances of the View to show or hide the prompt.

New global operations: Android 9 has introduced support for two additional device operations in the AccessibilityService class. Your Service can help users lock devices and take screenshots from screens with GLOBAL_ACTION_LOCK_SCREEN and global_action_take_screenshots, respectively.

Window change Details

Android 9 makes it easier to keep track of updates to your app Windows when your app redraws multiple Windows simultaneously. When a TYPE_WINDOWS_CHANGED event occurs, you can use the getWindowChanges() API to determine what has changed in the window. During multi-window updates, each window generates its own set of events. The getSource() function returns the root view of the window associated with each event.

If an application has defined accessibility pane titles for its View objects, your Service will be able to recognize when the application interface is updated. When the TYPE_WINDOW_STATE_CHANGED event occurs, the type returned by getContentChangeTypes() can be used to determine the window change. For example, the framework can detect when a pane has a new title or disappears.

rotating

To avoid unintentional rotation, we’ve added a mode that will stick to the current screen orientation even if the device’s position changes. The user can manually trigger the rotation by pressing a button on the system bar if necessary.

In most cases, the impact on application compatibility is negligible. However, if your application has any custom rotation behavior or uses any unconventional screen orientation Settings, you may experience problems that were previously ignored when the user rotation preference was always set to portrait. We encourage you to take a look at the rotation behavior in all of your app’s key activities and ensure that all of your screen orientation Settings still provide the best experience possible.

A new rotation mode allows the user to manually trigger the rotation if necessary using a button on the system bar.

The text

Android 9 provides the following text-related features for the platform:

  • Precompute text: The PrecomputedText class enables you to compute and cache the information you need ahead of time, improving text rendering performance. It also allows your application to perform text layout outside of the main thread.
  • Amplifiers: The Magnifier class is a widget that provides an amplifier API for a consistent amplifier functionality experience across all applications.
  • Smart Linkify: Android 9 has enhanced the TextClassifier class, which uses machine learning to identify entities in selected text and suggest actions accordingly. For example, TextClassifier lets your application detect that a user has selected a phone number. Your application can then suggest that the user use that number to make calls. The functionality in the TextClassifier replaces the functionality of the Linkify class.
  • Text layout: Interface design is made easier with several convenience functions and properties.

DEX file ART conversion ahead of time

On devices running Android 9 or later, the Android Runtime (ART) precompiler further optimizes the compressed Dalvik Executable format (DEX) file by converting the DEX file in the application package into a more compact representation. This change allows your application to start faster and consume less disk space and memory. This improvement is particularly beneficial for low-end devices with slower disk I/O speeds.

Device side system tracing

Android 9 allows you to track records through the device record system and then share reports of those records with your development team. The report supports multiple formats, including HTML.

By collecting these traces, you can capture timing data related to application processes and threads and view other types of globally significant device states.