Sep 24, 2018

Preparing Your Apps for the Android 9 (Pie)

HTEC photo placeholder

This version represents the effort to make phones more personal, efficient and overall easier to use. Some of the main buzzwords attached to this release are artificial intelligence (AI), well-being, simplicity, media, and privacy. There are multiple challenges for developers to adapt their current Android apps to support the changes that Android 9 brings, so the app users with Android Pie can benefit from the platform’s latest security updates, performance improvements, and stability features.

Aleksandra Vojinovic, Android developer at HTEC

Migration to Android 9

Android developers should pay close attention to all the behavior and API changes that Android 9 brought with itself. It is advised for developers to update their app version targetSdkVersion to 28 as soon as possible. All apps that are running on the Android 9 fall under the certain behavior changes, regardless of the API level they are targeting. The changes were made to the power management, privacy, restrictions on the use of non-SDK interfaces, security and cryptographic changes, ICU libraries updates, test framework library changes, Java UTF decoder, hostname verification using certificate, screen rotation changes, enforced usage of the FLAG_ACTIVITY_NEW_TASK, enumerated cameras, etc.

The behavior changes for the apps that are targeting API level 28 include: addition of FOREGROUND_SERVICE permission, connectivity changes and Apache HTTP client deprecation, privacy changes related to build serial number deprecation and DNS privacy, framework security changes, and some minor UI changes.

Migration to Android 9

Among all these changes, a special highlight is placed on those that can significantly affect the way an app behaves, like power management and privacy.

Power Management

Android 9 has introduced the new features to help improve device power management: app standby buckets and battery saver improvements. App Standby Buckets help the system to prioritize the app’s requests for resources based on how often the apps are used. Priority buckets are designed to allow the system to be smarter about how resources are distributed between applications. To further explain, if a rarely used app is working in the background while some other app is currently being used by the user (and is used frequently, in general), its processes will be blocked and not disrupt the active app.

The apps are dynamically assigned to some of the following priority groups: active, working set, frequent, rare and never. When the app is in an active bucket priority group, the system does not place any restrictions on the app’s jobs, alarms, network or Firebase Cloud Messaging (FCM) notifications. Otherwise, the system can impose some very severe restrictions.

Power Management Priority Buckets Standby Buckets

If an existing app already follows the best practices for Doze and app standby, which were introduced in Android 6, supporting the new power management changes should not require much effort. However, it is important to follow some of the official guidelines such as: not to try to manipulate the system into putting the app in some of the buckets, to add the launcher activity if the app does not already have one, to make the notifications more interactive especially if the app receives the high priority FCM message, because that can trigger the app promotion to the active bucket.


Android Pie brings some very important privacy changes, including the limiting of the background apps the access to device sensors and new permission rules related to the phone calls, phone state, and Wi-Fi scans.

The new dangerous permission group CALL_LOG is introduced. The READ_CALL_LOG permission was moved to this group, and the app must prompt the user to grant it at runtime in order to read the phone numbers from phone state.

The background apps running on Android 9 cannot access the microphone and the camera. The camera will not send the images, and any access to the camera, from a background app, will throw an error. The microphone audio will be empty when the app is in the background.

Sensors such as gyroscopes and accelerometers do not receive events anymore. It is advised to use the foreground service in order to be able to continue the detection of sensor events. Since the foreground service is bound to a notification, the user will be able to know exactly which app is accessing the data.

Android 9 also brings per-network randomization of associated MAC addresses to the platform, which means that it will not be quite so easy to track devices across the public access Wi-Fi.

Features Implementation

Some of the most important new features available in Android Pie, from a developer’s point of view, are Indoor positioning with Wi-Fi RTT, support for display cutouts, improved notifications, multi-camera support, neural networks API 1.1, security enhancements, text and magnifier changes, etc.

Indoor Positioning with Wi-Fi RTT

Android 9 added the support for the indoor geolocation using Wi-Fi Round-Trip-Time (IEEE 802.11 mc Wi-Fi protocol). With the supported hardware, devices running Android Pie could use this feature to provide the user location inside a building with an accuracy of 1-2 meters. An app would need ACCESS_COARSE_LOCATION permission and RTT APIs to measure the distance to the nearby Wi-Fi Access Points. The device does not need to connect to the Access Points to use the RTT, because the phone alone is able to determine the distance.

Support for Display Cutouts

There are a large number of new devices with the infinity display that have a small place at the top, reserved for the camera and sensors called the cutout or the notch. With the Android 9 cutout support, the apps can take the full advantage of the full-screen content. By calling getDisplayCutout() it can be checked whether the current device has the cutout, and with the DisplayCutout class, it is possible to determine the location and the shape of the non-functional screen areas where the content should not be displayed. A new window layout attribute, layoutInDisplayCutoutMode allows the app to lay out its content around the device’s cutouts. Android 9 enables the option, placed in Developer Options, to simulate a display with a cutout, and it is recommended to test the apps with this option enabled, to ensure that content is displayed properly.

Android 9 Display Cutouts

Improved Notifications

The notifications function and style have been improved in Android Pie. The new MessagingStyle class enables the possibility to preview the short history of the conversation messages, with the attached photos and stickers, but also to directly reply from the notification itself. Android Pie adds support to show the contact icon for the messages using the Notification.Person class and allows displaying the images that the user received right inside the notification.

Some additional features include: the possibility to save replies and drafts, the option to identify if the conversation is a group conversation, the set semantic meaning for an action (such as “mark as read”), the smart reply providing an array of standard responses to the user, the updated Notification Channels, three new Do-Not-Disturb priority categories in NotificationManager.Policy and also seven new Do-Not-Disturb constants that can be used to suppress visual interruptions.

Multi-Camera Support

With Android 9, developers can leverage the dual/front/rear device cameras in order to use them in their apps properly. It is possible to access streams simultaneously from multiple physical cameras on devices running Android Pie and also to call a logical or fused camera stream that automatically switches between two or more cameras.

Additionally, for the camera, there are new Session parameters that help reduce delays during the initial capture and Surface sharing that lets camera clients handle various use-cases without the need to stop and start the camera streaming.

In Android 9, the multi-camera API supports monochrome cameras for devices with FULL or LIMITED capability and enables support for external USB/UVC cameras on supported devices.

Neural Networks API 1.1

Neural Networks API (NNAPI) was previously introduced in Android 8.1 to advance the machine learning on Android devices. The NNAPI is designed to provide a base layer of functionality for higher-level machine learning frameworks (such as TensorFlow Lite, Caffe2, or others) that build and train neural networks.

In Android 9, the NNAPI is expanded and improved with the support for nine new operations: two element-wise mathematical operations, Div and Sub, and some array operations such as BatchToSpaceND, SpaceToBatchND, Squeeze, Strided Slice, Transpose, Pad, and Mean. These are the standard operations used to build Convolutional Neural Networks. Through the NNAPI, it is possible to abstract out these common machine learning operations to use the device’s hardware that will be most efficient for the corresponding operation, whether it’s a GPU or custom machine learning hardware. This should make the on-device machine learning and inference more power-efficient and could reduce reliance on server communication, improving the privacy and probably making lightweight machine learning applications feel faster.

Security Enhancements

A series of new security features have been introduced in Android Pie, like high-assurance user confirmation of sensitive transactions and unified fingerprint authentication dialog. Developers no longer need to build their own dialog, but instead, they should use the BiometricPrompt API to show the standard system dialog. The API also supports Face and Iris authentication. The hardware security module has been updated, and the additional key decryption security and APK Signature Scheme v3 have been added.

Text and magnifier

Android 9 brings the following text-related features to the platform:

  • Precomputed Text:  Improves text-rendering performance by enabling computation and caching of the required information ahead of time. It also enables performing text layout off the main thread.
  • Magnifier: The Magnifier class is a platform widget that provides the magnifier API and improves the user experience of selecting text. The magnifier helps users precisely position the cursor, or the text selection handles by viewing magnified text through a pane that can be dragged over the text. Furthermore, any view that is attached to a window can use the magnifier widget.
  • Smart Linkify: TextClassifier class has been updated in a way that leverages machine learning to identify some entities in the selected text and suggest the appropriate actions. The features in TextClassifier replace the functionality of the Linkify class.
  • Text Layout: Several convenience methods and attributes have been added to make the implementation of UI design easier.

Text and magnifier

A Fresh Look and Visual Changes

Android Pie rollout has already started. It is currently available on Google Pixel phones and on the Essential Phone. Good news awaits owners of newer Sony, Xiaomi, HMD Global, Oppo, Vivo, and OnePlus phones, as well as qualifying Android One devices. Google announced that these companies, which all participated in the Android Pie Beta, will issue the update by the end of the year. Many other manufacturers are expected to announce the launch dates over the course of the next several months and into the next year, as usual.

Reviewing the visual changes in Android Pie, on Google Pixel 2, the first impression is that the existing Material Design has received a significant visual refresh. The primary changes are related to the rounded corners, colored icons, and lots more white space. The text is sharper, and the menu has a lovely color, with smoother animations and a seamless transition. It is also a lot flatter, with even fewer drop shadows than before.

Some main notable changes are:

  • Navigation: Android 9 Pie introduced a new single-button gesture navigation system, which can be configured in the device settings.
  • Settings: The monochrome toggles in quick settings are now placed in colored circles, and in the main settings have a different color for each icon. The dark theme was also introduced.
  • Volume and Power Menus: Volume menu has been moved near to the physical volume buttons and contains the shortcuts for vibrate, mute and sound. In the power menu, the screenshot button has been added as well as a new feature called the Lockdown. It will disable fingerprint sensors and prevent notifications from appearing on-screen until the phone is unlocked with a pattern. Screenshots can be edited directly without requiring a third-party editing app.
  • Adaptive Brightness: It should not be confused with the old adaptive brightness because now it has the AI. Once enabled, Adaptive Brightness will automatically adjust to the ambiance of the user’s surrounding, as it always has, but it will also learn how the user modifies brightness in those conditions.
  • Adaptive Battery: AI has also entered the battery arena, prioritizing battery power for the apps and services that the user uses the most. The apps and services used infrequently will have their resources limited to extend the user phone’s battery life.
  • App Actions: App Actions suggests the things based on Google’s AI predictions of what the user would want to do – depending on the time of the day, where the user is and what they are doing – and highlight it in the app drawer just underneath the AI-curated app suggestions.
  • App Slices: Slices are snippets of some application content displayed outside of the application, for now only found within the Google Search app and will later be added in other places like the Google Assistant. They can display a range of content, including text, images, video, live data, scrolling content, and deep links, as well as interactive controls such as toggles and sliders. Slices can help users perform tasks faster by enabling the engagement outside of the fullscreen app experience.
  • Screen rotation: In the case when the screen rotation is disabled, and when the user rotates the device, a small icon will appear in the navigation bar asking the user if they want to change the orientation of the current activity if the app supports the change.
  • Digital Well-being: It is presented as an additional option in the phone’s settings menu, with the primary function to give the user an overview of the device usage – how many notifications were received, how often the device was unlocked and how much time was spent in various apps. App Timer enables the user to set time limits for particularly addictive apps, with the app icon being grayed out once the limit has been reached. Currently, the feature is available only as a Beta for Google Pixel owners.

Android 9 Pie

Wrap Up

With this release, Android is becoming even more user-friendly, intelligent and straight-forward, but also more concentrated on security and privacy.

This article mentions some of the key features and changes but does not include all the novelties Android Pie has to offer. The majority of mainstream users will see Android Pie as a less complex Android version. In some places, Pie has removed certain choices in favor of a possibly simpler single solution, with the intent of making Android more approachable. Beyond that, there are plenty of notable system-level improvements that give the platform room to grow in some important ways and make developers eager for an Android 9 update. Among other things, developers can expect better performance for apps written in Kotlin.

Android 9 Pie is a huge update and overall is a pleasure to use. It contains a lot of great features for users, new challenges for developers and phone manufacturers, and will only get better with some key features yet to be released in the upcoming period.

Related articles:

HTEC photo placeholder
December 6, 2018

GrowIT Conference Attended by HTEC Engineers

HTEC photo placeholder
August 6, 2018

HTEC Android Internship Welcomes High School Prodigies

HTEC Culture
September 10, 2018

HTEC Summer Internship: Tradition with Notable Results

How to block cookies?

You can change your cookie preferences at any time by clicking on the ‘Cookie preferences’ icon. You can then adjust the available sliders/checkboxes to ‘On’ or ‘Off’, then clicking ‘Save and close’. You may need to refresh your page for your settings to take effect.

essential cookies
preference cookies
statistic cookies
marketing cookies
Read more about these cookies