Android 11? Fast! Help me up and continue learning

Preface

The Android update is very fast. The timeline of the update before 5.0 is a bit unreadable, but the update after 5.0 is still relatively stable. It is updated about once a year. The naming of each version of Android by Google engineers is also a bit interesting, such as Lollipop , Marshmallows, Oreos, pies (the name should also be a foodie), and, starting from 1.5, the subsequent versions are arranged in alphabetical order, starting from C, and reaching the current row 11 to R .

On May 8, 2019, Google officially announced the Android 10 system at the Google I/O 2019 Developer Conference. After months of beta testing, Google released the official version of Android 10 on September 4, 2019.

It’s been almost a year since Google launched Android 10. Many applications have not yet been adapted, but now the developer preview version of Android 11 has come out. The official version of Android 11 should have been released at this year’s I/O conference. However, due to the impact of the epidemic, the news was released on March 21. Due to the impact of the new crown pneumonia epidemic, Google announced on Friday that it would completely cancel the annual I/O developer conference. The company announced on March 3 that due to the new crown The impact of the virus epidemic will change the I/O conference to only be held online, but now the online conference has also been cancelled.

Although the I/O conference will not open this year, Android 11 will definitely be released, so developers don’t even want to run, they also need to adapt!

Ready to work

"Brother, where are you talking about the adaptation of Android 11 for a long time?"

"Don't worry, don't we have to talk about it next!"

"Say it quickly, it will be cleared no matter how wasteful it is!"

"This is here, hey! If you have a Pixel, then congratulations, you can directly experience and adapt Android 11 in advance by swiping OTA."

"No? Let's use the simulator like me!"

"What? I don't know how to configure it? Really, let me tell you about it, and remember it."

  1. In Android Studio, click Tools> SDK Manager .

  2. Under the SDK Platforms tab, select Show Package Details at the bottom of the window .

  3. Under Android 11 Developer Preview , select the system image (for example, Google APIs Intel x86 Atom System Image ).

  4. In the SDK Tools tab, select the latest version of the Android emulator and click OK to start the installation.

  5. After the installation is complete, select Tools> AVD Manager and follow the instructions to create a new AVD .

    Be sure to select the Pixel device and select R for the system image .

  6. Return to the virtual device list of the AVD manager, double-click the new virtual device to start the device.

"Everything is ready, I just need to adapt!"

The specific steps to flash OTA are not written here, you can download and flash by yourself if you need it .

text

"Come here, let's start, stop talking, be quiet!!!"

Partition storage

Remember to set requestLegacyExternalStorage to true to modify the external storage view model (true for Legacy View, false for Filtered View) when adapting to Android 10? This is the key: When you apply the update to Android 11 as the target platform, will not be used requestLegacyExternalStorageto disable the partition storage.

"Brother, this is all disabled, how should I adapt?"

"This child is anxious, so I'm not talking about it!"

Data is migrated to the directory visible when using partition storage:

Before using Android 11 as the target platform, data should be migrated to a directory compatible with partitioned storage. In most cases, data can be migrated to the application-specific directory of the application .

If there is data to be migrated, when users upgrade to a new version of the application with Android 11 as the target platform, the old storage model can be retained. In this way, the user can retain access to the application data stored in the directory that the application previously used to save the data. To enable legacy storage model for upgrade, select it in the list of application preserveLegacyExternalStorageattributes set true.

There are two points to note here:

  • Most applications do not need to use it preserveLegacyExternalStorage. This flag only applies to a situation where you migrate your application data to a location compatible with partitioned storage, and you want users to retain access to the data when updating your application. Using this flag makes it more difficult to test how partitioned storage affects users of the app, because when users update the app, it will continue to use the old storage model.
  • If used preserveLegacyExternalStorage, the old storage model will only remain valid until the user uninstalls the application. If the user is equipped to install or reinstall the application on the device Android 11's, regardless preserveLegacyExternalStorageof what value is that applications can not disable the partition storage model.

Test partition storage

If you want to enable partition storage in your application regardless of the target SDK version and manifest tag value of the application, please enable the following application compatibility flags:

To disable partition storage and use the old storage model, unset these two flags.

Manage device storage space

If your application is a file manager application and it runs on Android 11, it can no longer delete cache files of other applications, even if your application has all file access permissions (applications that clean files need special attention, such as certain Butler, guard or something). Instead, you should do the following:

  1. ACTION_MANAGE_STORAGECheck the available space by calling the intent operation.
  2. If there is not enough free space on the device, prompt the user to agree to let your app clear all caches. To do this, call the ACTION_CLEAR_APP_CACHEintent operation.

Note here: the ACTION_CLEAR_APP_CACHEintent operation will seriously affect the battery life of the device and may remove a large number of files from the device .

Media file access permissions

This is great. Android 11 adds the following media access functions.

Perform bulk operations

In order to achieve consistency between various devices and increase user convenience, Android 11 MediaStoreadds a variety of methods to the API. These methods are especially useful for applications that want to simplify the process of changing specific media files, such as editing photos in the original location.

The method of adding is as follows:

  • [createWriteRequest()](https://developer.android.google.cn/reference/android/provider/MediaStore#createDeleteRequest(android.content.ContentResolver, java.util.Collection))

    The user grants a request to the application for write access to the specified media file group.

  • [createFavoriteRequest()](https://developer.android.google.cn/reference/android/provider/MediaStore#createFavoriteRequest(android.content.ContentResolver, java.util.Collection, boolean))

    A request for a user to mark a designated media file on the device as a "favorite". Any application that has read access to the file can see that the user has marked the file as a "favorite".

  • [createTrashRequest()](https://developer.android.google.cn/reference/android/provider/MediaStore#createTrashRequest(android.content.ContentResolver, java.util.Collection, boolean))

    A request by the user to put the specified media file into the device trash can. The contents of the trash can will be permanently deleted after a certain period of time (7 days by default).

  • [createDeleteRequest()](https://developer.android.google.cn/reference/android/provider/MediaStore#createWriteRequest(android.content.ContentResolver, java.util.Collection))

    The user immediately and permanently deletes the specified media file (instead of putting it in the trash can).

System after a method call any more, we will build an PendingIntentobject. After the application calls this intent, the user will see a dialog box asking the user to agree to the application update or delete the specified media file.

Use the original path to access the file

Starting Android 11, it has READ_EXTERNAL_STORAGEapplication permissions can use the direct file path and native libraries to read the media for your device. With this new feature, apps can use third-party media libraries more smoothly.

File and directory access restrictions

The following changes related to the Storage Access Framework (SAF) will only take effect when the application targets Android 11.

Access directory

The ACTION_OPEN_DOCUMENT_TREEintent operation can no longer be used to request access to the following directories:

  • Downloads Root directory.
  • The root directory of each SD card volume deemed reliable by the device manufacturer, regardless of whether the card is an analog card or a removable card.

Access file

Can no longer use ACTION_OPEN_DOCUMENT_TREEor ACTION_OPEN_DOCUMENTintent to operate the user to select individual files from the following directories:

  • Android/data/ The directory and all its subdirectories.
  • Android/obb/ The directory and all its subdirectories.

Authority

Regardless of the target SDK version of the app, the following changes will take effect in Android 11:

  • The storage runtime permissions have been renamed to files and media .
  • If the application is not deactivated partitioned memory and requests the READ_EXTERNAL_STORAGEpermission, the user will see a dialog box is different from the Android 10. The dialog box indicates that the app is requesting access to photos, videos, audio clips, and files.
  • Users can view which applications have in the system settings READ_EXTERNAL_STORAGEpermission. On the Settings> Privacy> Permission Manager> Files and Media page, each app with this permission is listed under Allow storage of all files .

Note here: If the application targets Android 11, remember that this access right to "all files" is read-only access. To use this app to read and write all files in the shared storage space , you need to have all file access permissions .

All file access permissions

The core use cases of certain applications require access to a large number of files, such as file management operations or backup and restore operations. These apps can get "all file access permissions" by doing the following:

  1. Statement MANAGE_EXTERNAL_STORAGEpermission.
  2. Use the ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSIONintent operation to direct the user to a system settings page, on this page, the user can enable the following option for the application: grant management permissions for all files .

"All file access permissions" can grant the following permissions:

Applications can access these files using the MediaStoreAPI or the original file path . If the application uses the storage access framework , it cannot be used to access other files and directories provided by "all file access permissions". An application with this permission still cannot access application-specific directories belonging to other applications . These directories appear as on the storage volume Android/data/subdirectory.

Custom message box view is blocked

For security reasons and to maintain a good user experience, if the message box containing a custom view is sent from the background by an application with the target platform of Android 11, the system will block these message boxes. Please note that still allows the use of text messaging box; the use of such a message box is Toast.makeText()created, do not call setView().

If your app still tries to publish a message box with a custom view from the background, the system will not display the corresponding message to the user, but will do the following:

  1. The following message box message is displayed:

    Background custom toast blocked for package package-name. See g.co/dev/toast.

  2. The following messages are logged in logcat:

    W/NotificationService: Blocking custom toast from package due to package not in the foreground

If you want to be notified when a message box (text message box or custom message box) appear or disappear, use the new addCallback()method.

It should be noted here that due to changes in platform behavior, applications targeting Android 11 will find that the text message box is negatively affected by the following:

  • getView()The method returns null.
  • The return value of the following methods does not reflect the actual value, so try not to use it:
  • The following methods are no-ops, so applications should not use them:
    • [setMargin()](https://developer.android.google.cn/reference/android/widget/Toast#setMargin(float, float))
    • [ setGravity()] (https://developer.android.google.cn/reference/android/widget/Toast#setGravity (int, int, int))

Front desk service type

Starting with Android 9, apps are limited to accessing the camera and microphone in the foreground . To further protect users, Android 11 changes the way the foreground service accesses camera and microphone related data. If the application to Android 11 as the target platform and access to these types of data in a particular front desk, you need to declare at the front desk of foregroundServiceTypeadding new attributes cameraand microphonetypes.

For example, if a foreground service in the application needs to access the location information of the device and the data related to the camera, please declare the service as shown in the following code snippet:

    <manifest>
        ...
        <service ... android:foregroundServiceType="location|camera" />
    </manifest>

MAC address

In applications targeting Android 10 (API level 29) and lower versions, the random allocation of MAC addresses is based on each SSID, because Passpoint can connect to different SSIDs of the same profile. In applications targeting Android 11 (API level "R") and higher, the random allocation of the MAC address of the Passpoint network will be changed to be allocated for each fully qualified domain name (FQDN).

For applications targeting API level "R" and higher, non-privileged applications will not be able to access the device's MAC address; only network interfaces with IPv4 addresses will be visible. Affects getifaddrs()and NetworkInterface.getHardwareAddress()methods, as well as RTM_GETLINKsend a netlink message.

Below is a list of the ways in which this change will affect the application:

  • NetworkInterface.getHardwareAddress() Will return null for each interface.
  • Applications can not NETLINK_ROUTEuse socket bind()functions.
  • IP The command does not return information about the interface.

These changes are mandatory not to use the guidance provided in the MAC address .

Please note that most developers should use higher-level ConnectivityManagerAPIs instead of lower-level NetworkInterface/ getifaddrs()APIs.

Network access control for each process

Starting with Android 11, applications that process sensitive user data can grant network access to each process. By explicitly specifying which processes are allowed to access the network, you can isolate all code that does not need to upload data.

Although there is no guarantee to prevent apps from accidentally uploading data, this feature can reduce the chance of data leakage caused by errors in the app.

An example of a manifest file using this new feature is shown below:

    <processes>
        <process />
        <deny-permission android:name="android.permission.INTERNET" />
        <process android:process=":withoutnet1" />
        <process android:process="com.android.cts.useprocess.withnet1">
            <allow-permission android:name="android.permission.INTERNET" />
        </process>
        <allow-permission android:name="android.permission.INTERNET" />
        <process android:process=":withoutnet2">
            <deny-permission android:name="android.permission.INTERNET" />
        </process>
        <process android:process="com.android.cts.useprocess.withnet2" />
    </processes>

One-time permission

In Android 11, whenever an app requests permission related to location information, microphone, or camera, the app will get a temporary one-time permission. This is actually a similar permission application in Apple.

Android 11 does not recommend repeated requests for permissions in a specific permission group. After your app is installed on the device, if the user taps Deny for a specific permission twice during use , this operation means that they want to "don't ask again" when requesting the permission in the corresponding permission group in the future.

The system also defines the response behavior for operations similar to tapping the reject option:

  • If the user presses the return button to close the permission dialog, this operation is not considered a "reject" operation.
  • If the user uses [ requestPermissions()](https://developer.android.google.cn/reference/androidx/core/app/ActivityCompat#requestPermissions(android.app.Activity, java.lang.String[], int)) from your The application goes to the system settings, and then press the back button, this operation is considered a "reject" operation.

The floating window intent will always bring the user to the system permissions screen

11 Starting Android, ACTION_MANAGE_OVERLAY_PERMISSIONthe Intent will always go to the top-level user settings screen, where the user can grant or revoke the application of SYSTEM_ALERT_WINDOWrights. any intent of package:data will be ignored.

In lower versions of Android, the ACTION_MANAGE_OVERLAY_PERMISSIONintent can specify a file package, which will redirect the user to the application-specific screen to manage permissions. Android 11 no longer supports this feature, but the user must first select the application to grant or revoke permissions for. This change can make the authorization of permissions more purposeful, so as to achieve the purpose of protecting users.

Restrict non-SDK interfaces

If the application is not targeting Android 11, some of these changes may not have an immediate impact. Although some non-SDK interfaces in the greylist can still be used (depending on the target API level of the application ), if any non-SDK methods or fields are used, the risk that the application will not run will eventually be higher.

If you are not sure whether your application uses a non-SDK interface, you can test the application to confirm. If your application relies on a non-SDK interface, you should start planning to migrate to an SDK alternative. If you cannot find an alternative to using a non-SDK interface for a function in your application, you should request a new public API .

Open Mobile API changes

Starting from Android 11, Open Mobile API (OMAPI) has additional features:

  • Analyze the rules of operator authority.
  • Use one or more of the following to customize embedded secure element (eSE) access permissions or configure eSE:
    • System privilege
    • Configurable access rules Application master data (ARA-M) Application identifier (AID)
    • System API to reset the OMAPI reader
  • Provide a clear indicator for the reader to apply filtering device functions.

Supports concurrent use of multiple cameras

Android 11 adds API to query support for using multiple cameras (including front camera and rear camera) at the same time.

To check support on the device running the app, use the following method:

to sum up

At this point, this article has come to an end. This article has basically finished the main content of the Android 11 update. You can prepare according to the actual situation of the application. It is not in a hurry to adapt. If it really needs to be adapted, it should be several months. Finally, let's put the official website address: https://developer.android.google.cn/preview If this article is helpful to you, remember to like and follow, thank you very much! ! !

Guess you like

Origin blog.csdn.net/haojiagou/article/details/105631020