Android Q Adaptation Guide

The official document: developer.android.com/about/versi…

In the first version of Android 10, the official changes are quite large, and the corresponding developer adaptation costs are still quite high. Following the Google Android Q Workshop 2019.11.11, here is a general description of android Q adaptation needs to pay attention to. Although it is about the introduction, but should be the most complete adaptation strategy…

  • The SDK interface
  • Device ID
  • External storage
  • permissions
  • New feature – Night mode

First, non-SDK interface

Official documentation: Restrictions for non-SDK interfaces

Starting with Android 9 (API level 28), apps can use non-SDK interfaces. These restrictions come into play if your APP references a non-SDK interface or tries to use reflection or JNI to get handles. The official explanation is to improve the user experience and reduce the risk of app crashes.

1.1 Non-SDK interface detection tools

A test tool is available for download at Veridex

Veridex usage:

appcompat.sh --dex-file=apk.apk

Copy the code
Insert a picture description here

1.2 blacklist, greylist, greylist-max-o, and greylist-max-p

In the preceding screenshot, blacklist, greylist, greylist-max-o, and greylist-max-p are described as follows:

  • Blacklist: non-SDK interfaces that are forbidden to be used and Crash when running (therefore must be resolved)
  • Greylist: Non-SDK interfaces that are still available in the current version but may become restricted in the next version
  • Greylist-max-o: non-SDK interface that can be used in targetSDK<= o but is disabled in targetSDK>=P
  • Greylist-max -p: non-SDK interface that can be used in targetSDK<= p, but is disabled in targetSDK>=Q

If you think I am not clear, please see the following screenshot of Google Android Q Workshop PPT on November 11, 2019

Insert a picture description here


Insert a picture description here


Insert a picture description here

1.3 Android Q Hardening and hot fixes

There are apis for hardening and hotfix

  • strengthening

    Insert a picture description here
  • Hot repair

    Insert a picture description here

Note: For an application that is not adapted to Android Q, if the interface related to the Blacklist is used, it will Crash when opened on Android Q. If an application that is not adapted to Android Q uses the interface related to the Blacklist, it will Crash when it is opened on Android Q. If an application that is not adapted to Android Q uses the interface related to the Blacklist, it will Crash when it is opened on Android Q.

2. Device ID

From Android 10, it is impossible to completely identify a device. The methods used to identify a device with MAC address, IMEI and other device information are invalid from Android 10. And it doesn’t matter if your APP is shipped with Android 10 or not.

2.1 Device information such as IMEI

As of Android10, common applications are no longer allowed to request permission android.permission.READ_PHONE_STATE. In addition, no matter whether your App is compatible with Android Q (targetSdkVersion is greater than or equal to 29), you can no longer obtain device information such as IMEI.

The affected apis are as follows:

Build.getSerial(a);

TelephonyManager.getImei(a);

TelephonyManager.getMeid(a)

TelephonyManager.getDeviceId(a);

TelephonyManager.getSubscriberId(a);

TelephonyManager.getSimSerialNumber(a);

Copy the code
Insert a picture description here

An application whose targetSdkVersion<29 returns a null targetSdkVersion>=29 when it obtains the device ID, and runs a SecurityException when it obtains the device ID

Insert a picture description here

If your App still wants to obtain the IMEI and other information from devices with Android 10 or lower, you can adapt the App as follows:

Insert a picture description here

2.2. Mac Addresses are randomly assigned

Starting with Android10, randomly assigned MAC addresses are transmitted by default on devices running Android10 or higher. (Starting from Android 10, common applications cannot obtain the real MAC address of the device, indicating that the device cannot use the MAC address.)

2.3. How to mark the uniqueness of equipment?

Insert a picture description here


Insert a picture description here

Google’s solution: If your app needs to track reinstalls of non-logged-in users, use ANDROID_ID to identify the device.

  • ANDROID_ID is generated as follows:Signature + Device information + Device user
  • ANDROID_ID Reset rule:ANDROID_ID will be reset when the device is restored to factory Settings
String androidId = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);

Copy the code

In other words, a device cannot be completely identified from Android 10. The methods used to identify a device with MAC address, IMEI and other device information are invalid from Android 10. And it doesn’t matter if your APP is shipped with Android 10 or not.

On the Android 10 system, I have not found the identification device unique way, if we have a way to hope to inform the message!!

External storage

Official documents:

Manage scoped external storage access Only application files and media

Insert a picture description here

To address the problem in the screenshot, starting with Android Q, external storage has been officially limited.

To give users more control over their files and to limit file clutter, apps targeting Android 10 (API level 29) and higher are given scoped access into an external storage device, or scoped storage, By default. To apps can see only their app – specific directory – accessed using Context. GetExternalFilesDir () – the and specific types of media. It’s a best practice to use scoped storage unless your app needs access to a file that doesn’t reside in either the app-specific directory or the MediaStore.

In order to change the user management Sdcard file, solve the problem of file chaos. Starting with Android 10 (API Level 29), Android will have some restrictions on external storage. By default, the external storage, the App can only through the Context. GetExternalFilesDir () access to their specific file directory; And directories for system-specific file types (e.g., photos, screenshots, videos, and so on).

Insert a picture description here

3.1 APP exclusive path

The READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions are no longer required for App exclusive internal and external storage paths:

  • Internal storage path/ data/data / < package name > /
  • External storage path/ storage/Android/data / < package name > /

For details about how to obtain Android Q storage directories, see the following documents: Android Sdcard Storage directory Android Q storage directory Android Sdcard storage directory

3.2 Mobile phone sharing path

To read shared files created by other apps, such as photo albums and screen snapshots, you need to apply for the READ_EXTERNAL_STORAGE permission:

  • Images: Photos, Screenshots are accessed using the MediaStore.Images API
  • The Video is accessed using the Mediastore.video API
  • Use audioMediaStore.AudioAPI access

3.2 Mobile phone sharing path

To read shared files created by other apps, such as photo albums and screen snapshots, you need to apply for the READ_EXTERNAL_STORAGE permission:

  • Images: Photos, Screenshots are accessed using the MediaStore.Images API
  • The Video is accessed using the Mediastore.video API
  • Audio is accessed using the Mediastore.audio API

3.3. Downloads folder

You don’t need any permissions to read the Downloads folder for your phone. You need to use the API Storage Access Framework

Four, authority related

Mainly include:

  • Access device location information while in the background
  • Restrictions on starting the Activity from the background
  • Screen recording
  • Camera and microphone

4.1 Access device location information while running in the background

Android 10 introduced the ACCESS_BACKGROUND_LOCATION permission. If the application needs to dynamically apply for the permission to access the mobile phone location when the application is running in the background, the user can choose to reject the permission.

According to official data, most users are sensitive to location information. And most users don’t allow apps to use location information in the background.

Insert a picture description here
Insert a picture description here
Insert a picture description here

4.2 Restrictions on starting the Activity from the background

Please refer to the official document for details

4.3 Screen recording

You do not need to apply for permission manually, but the official API will pop up to the user to apply for permission

Insert a picture description here

4.4 Camera and Microphone

Android 9 camera and microphone background permissions have been removed

4.5 Activity detection — new permissions

Insert a picture description here

5. New feature — night mode

For those of you who are interested in night mode, check out my other document:

Android Q has a dark theme

6. Refer to the article

Android 10 Scoped Storage