Ramkumar D
IVYMobility TechBytes
9 min readNov 28, 2018

--

ANDROID PIE BEHAVIOUR CHANGES & FEATURES

Privacy Changes

  • Limiting background apps’ access to device sensors.

Your app cannot access the microphone or camera.

Sensors that use the continuous reporting mode, such as accelerometers and gyroscopes, don’t receive events.

Sensors that use the on-change or one-shot reporting modes don’t receive events.

  • New permission rules and permission groups related to phone calls, phone state, and Wi-Fi scans.

To read numbers from the PHONE_STATE intent action, you need both the READ_CALL_LOG permission and the READ_PHONE_STATE permission.

To read numbers from onCallStateChanged(), you need the READ_CALL_LOG permission only. You don’t need the READ_PHONE_STATE permission.

  • Restricting information retrieved from Wi-Fi scans

WifiManager.getScanResults() and WifiManager.startScan()

Android 8.0 and 8.1 — ACCESS_FINE_LOCATION Or ACCESS_COARSE_LOCATION Or CHANGE_WIFI_STATE

Android 9 and later — ACCESS_FINE_LOCATION Or ACCESS_COARSE_LOCATION And CHANGE_WIFI_STATE And Location services are enabled on the device (under Settings > Location)

  • Restrictions on use of non-sdk interfaces

Restrictions apply whether you attempt to access these methods and fields directly, via reflection, or using JNI.

App can continue to access these restricted interfaces; the platform uses toasts and log entries to bring them to your attention.

Power Management

The power management fall into two categories, App standby buckets and Battery saver improvements.

App Standby buckets — App Standby Buckets helps the system prioritize apps’ requests for resources based on how recently and how frequently the apps are used. Based on the app usage patterns, each app is placed in one of five priority buckets. The system limits apps’ access to device resources like the CPU or battery, based on the user’s usage patterns. The five buckets are Active, Working Set, Frequent, Rare and Never.

  • Active

The app has launched an activity

The app is running a foreground service

The app has a sync adapter associated with a content provider used by a foreground app

The user clicks on a notification from the app

If an app is in the active bucket, the system does not place any restrictions on the app’s jobs, alarms, or FCM messages.

  • Working Set

The app runs often but it is not currently active.

Apps are also promoted to the working set bucket if they’re used indirectly.

If an app is in the working set, the system imposes mild restrictions on its ability to run jobs and trigger alarms.

  • Frequent

The app used regularly, but not necessarily every day.

If an app is in the frequent bucket, the system imposes stronger restrictions on its ability to run jobs and trigger alarms, and also imposes a cap on high-priority FCM messages.

  • Rare

The app if it is not often used.

If an app is in the rare bucket, the system imposes strict restrictions on its ability to run jobs, trigger alarms, and receive high-priority FCM messages. The system also limits the app’s ability to connect to the internet.

  • Never

Apps that have been installed but never run are assigned to the never bucket.

The system imposes severe restrictions on these apps.

Battery saver improvements — When battery saver is turned on, the system places restrictions on all apps.

The system puts apps in app standby mode more aggressively, instead of waiting for the app to be idle.

Background execution limits apply to all apps, regardless of their target API level.

Location services may be disabled when the screen is off.

Background apps do not have network access.

“These changes apply to all apps, whether or not they target Android 9.”

Compatibility WAL (Write-Ahead Logging) for Apps

A special mode of SQLiteDatabase called Compatibility WAL (write-ahead logging) that allows a database to use journal_mode=WAL while preserving the behavior of keeping a maximum of one connection per database.

By default it is enabled in the application database unless the application has either:

Opted-in or out of write-ahead logging by calling SQLiteDatabase.enableWriteAheadLogging or disableWriteAheadLogging

Explicitly requested journal mode by calling SQLiteDatabase.OpenParams.setJournalMode(String mode)

Advantages

Parallel execution of queries from multiple threads on the same database.

Enable writes to proceed concurrently with reads.

Disadvantages

It is not possible for reads and writes to occur on the database at the same time.

Before modifying the database, the writer implicitly acquires an exclusive lock on the database which prevents readers from accessing the database until the write is completed.

Build Serial No Deprecation — Build.SERIAL is always set to “UNKNOWN” to protect users’ privacy. If your app needs to access a device’s hardware serial number, you should instead request the READ_PHONE_STATE permission, then call getSerial().

Apache HTTP client deprecation — With Android 6.0, we removed support for the Apache HTTP client. Beginning with Android 9, that library is removed from the bootclasspath and is not available to apps by default.

To continue using the Apache HTTP client, apps that target Android 9 and above can add the following to their AndroidManifest.xml:

// Put this in your buildtypes debug section:
manifestPlaceholders = [usesCleartextTraffic:”true”]
// Put this in your buildtypes release section
manifestPlaceholders = [usesCleartextTraffic:”false”]

In the application tag in AndroidManifest.xml

android:usesCleartextTraffic=”${usesCleartextTraffic}”<uses-library android:name=”org.apache.http.legacy” android:required=”false”/>

View focus — Views with 0 area (either a width or a height is 0) are no longer focusable. Additionally, activities no longer implicitly assign initial focus in touch-mode. Instead, it is up to you to explicitly request initial focus, if desired.

Example:

<LinearLayout

android:focusable=”true”

android:focusableInTouchMode=”true”

android:layout_width=”0px”

android:layout_height=”0px” >

<requestFocus />

</LinearLayout>

Imagedecoder for drawables and bitmaps — ImageDecoder lets you create a Drawable or a Bitmap from a byte buffer, a file, or a URI. To decode an image, first call createSource() with the source of the encoded image. Then, call decodeDrawable() or decodeBitmap() by passing the ImageDecoder.Source object to create a Drawable] or a Bitmap.

Animation — AnimatedImageDrawable class for drawing and displaying GIF and WebP animated images.AnimatedImageDrawable works similarly to AnimatedVectorDrawable in that the render thread drives the animations of 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();

}

}

Indoor positioning with wifi RTT — IEEE 802.11mc Wi-Fi protocol — also known as Wi-Fi Round-Trip-Time (RTT). To measure the distance to nearby RTT-capable Wi-Fi access points (APs). The device must have location services enabled and Wi-Fi scanning turned on (under Settings > Location), and your app must have the ACCESS_FINE_LOCATION permission. The device doesn’t need to connect to the access points to use RTT. To maintain privacy, only the phone is able to determine the distance to the access point; the access points do not have this information. If your device got 3 or more access points then using multilateration algorithm to estimate the device position that best fits those measurements. The result is typically accurate within 1 to 2 meters.

Updates to the ICU libraries

What is ICU?

ICU is a mature, widely used set of C/C++ and Java libraries providing Unicode and Globalization support for software applications. ICU is widely portable and gives applications the same results on all platforms and between C/C++ and Java software.

Ex: java.util, java.text, and android.text.format.

The update to ICU 60 contains many small but useful changes, including Emoji 5.0 data support and improved date/time formats.

ICU now provides translated zone names for GMT and UTC. This change affects android.icu formatting and parsing behavior for zones like “GMT”, “Etc/GMT”, “UTC”, “Etc/UTC”, and “Zulu”.

java.text.SimpleDateFormat now uses ICU to provide display names for UTC /GMT, meaning:

Formatting zzzz generates a long localized string for many locales. Previously, it produced produced “UTC” for UTC and strings like “GMT+00:00” for GMT.

Parsing zzzz recognizes strings like “Universal Coordinated Time”, and “Greenwich Mean Time”.

Apps may encounter compatibility problems if they assume that “UTC” or “GMT+00:00” are output for zzzz in all languages.

The android.icu.text.NumberFormat.getInstance(ULocale, PLURALCURRENCYSTYLE).parse(String)method may throw a ParseException even when parsing legitimate currency text. Avoid this problem by using NumberFormat.parseCurrency, available since Android 7.0 (API level 24), for PLURALCURRENCYSTYLE-style currency text.

Rotation — To eliminate unintentional rotations, we’ve added a mode that pins the current orientation even if the device position changes. Users can trigger rotation manually when needed by pressing a button in the system bar.

The compatibility impacts for apps are minimal in most cases. However, if your app has any customized rotation behavior or uses any unusual screen orientation settings, you might run into issues that would have gone unnoticed before, when user rotation preference was always set to portrait.

Screen rotation changes

There are some changes done in portrait rotation mode. In Android 8.0 (API level 26), users could toggle between auto-rotate and portrait rotation modes using a Quicksettings tile or Display settings. The portrait mode has been renamed rotation lock and it is active when auto-rotate is toggled off.

When the device is in rotation lock mode, users can lock their screen to any rotation supported by the top, visible Activity. An Activity should not assume it will always be rendered in portrait. If the top Activity can be rendered in multiple rotations in auto-rotate mode, the same options should be available in rotation locked mode, with some exceptions based on the Activity’s screenOrientation setting (see the table below).

Screen Orientation and Behaviour

Unspecified — In auto-rotate and rotation lock the Activity can be rendered in portrait or landscape (and the reverse). Expect to support both portrait and landscape layouts.

Landscape — In auto-rotate and rotation lock the Activity can be rendered in either landscape or reverse landscape. Expect to support only landscape layouts.

Portrait — In auto-rotate and rotation lock the Activity can be rendered in either portrait or reverse portrait. Expect to support only portrait layouts.

Full — In auto-rotate and rotation lock the Activity can be rendered in portrait or landscape (and the reverse). Expect to support both portrait and landscape layouts. Rotation lock users will be given the option to lock to reverse portrait, often 180º.

Sensor, fullSensor, sensorPortrait, sensorLandscape — The rotation lock mode preference is ignored and is treated as if auto-rotate is active. Only use this in exceptional circumstances with very careful UX consideration.

Enumerating cameras

Android 9 devices can discover every available camera by calling getCameraIdList(). An app should not assume that the device has only a single back camera or only a single front camera. For example, if your app has a button to switch between the front and back cameras, there may be more than one front or back camera to choose from. You should walk the camera list, examine each camera’s characteristics, and decide which cameras to expose to the user.

Notifications from suspended apps

Prior to Android 9, notifications from suspended apps were canceled. Beginning with Android 9, notifications from suspended apps are hidden until the app is resumed.

Features

  • Notifications and Enhanced messaging experience
  • Data cost sensitivity in JobScheduler — Jobs can declare their estimated data size, signal prefetching, and specify detailed network requirements.
  • Autofill framework
  • Secure key import into Keystore — Android 9 provides additional key decryption security by adding the ability to import encrypted keys securely into the Keystore using an ASN.1‑encoded key format. The Keymaster then decrypts the keys in the Keystore, so the content of the keys never appears as plaintext in the device’s host memory.
  • Text — Magnifier, Smart Linkify
  • On-device system tracing

--

--