preface

Android update very quickly, before version 5.0 update time line is a little look not to understand, but still more stable after the 5.0 update, updated once a year, about Google engineer for each version of the android named also interesting, such as lollipops, cotton candy, oreo, pie? What should be also a version (name), and, since 1.5, Subsequent editions were arranged alphabetically, starting with C and now 11 and moving up to R.

On May 8, 2019, Google officially unveiled Android 10 at its 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, and many apps have yet to be released, but now the developer preview of Android 11 is out, and the official version of Android 11 was supposed to be released at this year’s I/O conference, but due to the impact of COVID-19, it was announced on March 21, Google on Friday announced the complete cancellation of its annual I/O Developer conference, following the announcement on March 3 that it was moving to an online-only event due to the Novel Coronavirus outbreak, which has now also been canceled.

Although I/O conference will not be held this year, android 11 will definitely be released, so developers will not want to run, but also need to adapt!

The preparatory work

“Big brother, you said this half day android 11 adaptation where?”

“Don’t worry, the following is not about to say!”

“Say quickly, another white life will be shut down!”

“Coming, coming, coming! If you have the Pixel, you’ll be able to play with android 11 by tapping otAs. “

“No? Use the simulator like I did! “

“What? Don’t know how to configure it? It really is. Tell you, remember.”

  1. In Android Studio, go to 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. On 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, choose Tools > AVD Manager and follow the instructions to create a new AVD.

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

  6. Returns the virtual device list of AVD Manager. Double-click a new virtual device to start it.

“Everything is ready except adaptation!”

The specific steps of brushing OTA are not written here. You can download and brush by yourself if necessary.

The body of the

“Come on, come on, start, stop talking, be quiet!!”

Partition storage

Remember when the adapter android 10 set requestLegacyExternalStorage to true to modify the external storage space View model (true Legacy for the View, false for Filtered View)? This is important: when you will be applied after the update for the target platform for Android 11, will not be able to use requestLegacyExternalStorage to disable partition storage.

“Hey, big brother, how do I fit in when this is out of service?”

“This child, monkey anxious monkey anxious, this is about to say!”

Migrate data to a directory visible when using partitioned storage:

Before targeting Android 11, migrate your data to a directory compatible with partitioned storage. In most cases, data can be migrated to the application’s application-specific directory.

If there is data to migrate, users can retain the old storage model when upgrading to a new version of the application targeting Android 11. In this way, users can retain access to application data stored in the directory where the application was previously stored. To enable the old storage model in order to upgrade, please the list in the application preserveLegacyExternalStorage attribute set to true.

Here are two points to note:

  • Most apps don’t need itpreserveLegacyExternalStorage. This flag only applies if you have migrated your application data to a location compatible with partitioned storage and want users to retain access to the data when updating your application. Using this tag makes it more difficult to test how partitioned storage affects the application’s users, because when the user updates the application, it will continue to use the old storage model.
  • If you are usingpreserveLegacyExternalStorage, the old storage model remains valid only until the user uninstalls the application. If the user installs or reinstalls the app on an Android 11 device, no matterpreserveLegacyExternalStorageThe application cannot disable the partitioned storage model.

Test partitioned storage

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

  • DEFAULT_SCOPED_STORAGE (enabled for all applications by default)
  • FORCE_ENABLE_SCOPED_STORAGE (disabled for all applications by default)

To disable partitioned storage in favor of the older storage model, unset these two flags.

Manage device storage space

If your app is a file manager app running on Android 11, it will no longer be able to delete other apps’ cached files, even if your app has full file access (especially file-cleaning apps, such as butler, guard, etc.). Instead, do the following:

  1. Check the available space by calling the ACTION_MANAGE_STORAGE Intent action.
  2. If there is not enough free space on the device, ask the user to agree to let your application clear all caches. To do this, callACTION_CLEAR_APP_CACHEThe intent.

Note that ACTION_CLEAR_APP_CACHE Intent actions can seriously affect the battery life of a device and can remove a large number of files from the device.

Media file access permission

This is awesome. Android 11 adds the following media access features.

Performing batch operations

To achieve consistency across devices and increase user convenience, Android 11 adds a variety of methods to the MediaStore API. These methods are especially useful for applications that want to simplify the process of changing a particular media file, such as editing a photo in its original location.

You can add it as follows:

  • [createWriteRequest ()] (developer. The android. Google. Cn/reference/a… (android.content.ContentResolver, java.util.Collection))

    A request by a user to grant an application write access to a specified media file group.

  • [createFavoriteRequest ()] (developer. The android. Google. Cn/reference/a… (android.content.ContentResolver, java.util.Collection, boolean))

    A request by the user to mark a specified media file on the device as favorites. Any application that has read access to the file can see that the user has marked the file as favorites.

  • [createTrashRequest ()] (developer. The android. Google. Cn/reference/a… (android.content.ContentResolver, java.util.Collection, boolean))

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

  • [createDeleteRequest ()] (developer. The android. Google. Cn/reference/a… (android.content.ContentResolver, java.util.Collection))

    A request by the user to delete the specified media file immediately and permanently, rather than putting it in the trash first.

After invoking any of the above methods, the system builds a PendingIntent object. After the intent is invoked, the user is presented with a dialog asking for permission to update or delete the specified media file.

Use the original path to access the file

Starting from Android 11, applications with the READ_EXTERNAL_STORAGE permission can read device media files using the direct file path and native library. 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 if the application is targeted at Android 11.

Access to the directory

The ACTION_OPEN_DOCUMENT_TREE Intent action is no longer available to request access to the following directories:

  • DownloadsThe root directory.
  • The root directory of each SD card volume that the device manufacturer considers reliable, whether the card is an analog or removable card.

Access to the file

You can no longer use ACTION_OPEN_DOCUMENT_TREE or ACTION_OPEN_DOCUMENT Intent operations to request the user to select a separate file from the following directory:

  • Android/data/Directory and all its subdirectories.
  • Android/obb/Directory and all its subdirectories.

permissions

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

  • Storage runtime permissions have been renamed to file and media.
  • If the application has not disabled partitioned storage and requests the READ_EXTERNAL_STORAGE permission, the user will see a different dialog box than Android 10. This dialog indicates that the application is requesting access to photos, videos, audio clips, and files.
  • Users can view which applications have them in system SettingsREAD_EXTERNAL_STORAGEPermissions. inSettings > Privacy > Rights Manager > Files and MediaOn the page, each application that has this permission is listed inAllows all files to be storedUnder.

A note of caution: if your app is targeting Android 11, remember that this access to “all files” is read-only. To use this application to read and write all files in a shared storage space, you need to have all file access rights.

All file access rights

The core use cases of some applications require access to a large number of files, such as file management operations or backup and restore operations. These applications obtain “all file access” by doing the following:

  1. Declare MANAGE_EXTERNAL_STORAGE permission.
  2. Use the ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION Intent to direct the user to a system Settings page, where the user can enable the following options for the application: Grant administrative permission to all files.

All File Access Rights grants the following permissions:

  • Read and write permission to all files in the shared storage space.
  • Access to the contents of the Mediastore.files table.

Applications can access these files using the MediaStore API or the original file path. If the application uses the storage access framework, it cannot be used to access other files and directories provided under All File Access rights. An application with this permission cannot access the application-specific directories of other applications. These directories appear on the storage volume as subdirectories of Android/data/.

The custom message box view is masked

For security reasons and to maintain a good user experience, message boxes containing custom views are blocked if they are sent in the background from Android 11 targeted applications. Note that text message boxes are still allowed; This type of message box is created using toast.maketext () without calling setView().

If your application still tries to publish a message box containing a custom view from the background, the system will not display the 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. Log the following message 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 or custom) appears or disappears, use the new addCallback() method.

Note that due to platform behavior changes, apps targeting Android 11 platforms will see the following negative effects on text message boxes:

  • getView()Method returnsnull.
  • The return value of the following methods does not reflect the actual value, so try not to use them:
    • getHorizontalMargin()
    • getVerticalMargin()
    • getGravity()
    • getXOffset()
    • getYOffset()
  • The following methods are null operations, so applications should not use them:
    • [setMargin()] (Developer. The android. Google. Cn/reference/a…(float, float))
    • [setGravity()] (Developer. The android. Google. Cn/reference/a…(int, int, int))

Front Desk Service Type

Starting with Android 9, apps are limited to foreground access to the camera and microphone. To further protect users, Android 11 changes the way foreground services access data related to cameras and microphones. If the application is targeting Android 11 and accesses these types of data in a foreground service, you need to add new Camera and microphone types to the foregroundServiceType property declared by the foreground service.

For example, if a foreground service in your application requires access to device location information and camera-related data, declare the service as follows:

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

The MAC address

In applications targeting Android 10 (API level 29) and lower, MAC addresses are randomly assigned based on each SSID because Passpoint can connect to different SSIDs of the same data. In applications targeting Android 11 (API level “R”) and higher, the RANDOM MAC address assignment for Passpoint networks will be changed to each fully qualified domain name (FQDN).

For applications whose API level is R or higher, non-privileged applications cannot access the MAC address of the device. Only network interfaces with IPv4 addresses are visible. Affect getifaddrs () and NetworkInterface. GetHardwareAddress () method, as well as RTM_GETLINK netlink message sent.

Here’s a list of how this change will affect the application:

  • NetworkInterface.getHardwareAddress()Null is returned for each interface.
  • Application fails to matchNETLINK_ROUTESocket usagebind()Function.
  • IPThe command does not return information about the interface.

These changes enforce do not use the instructions provided in MAC addresses.

Please note that most developers should use higher level ConnectivityManager API rather than low level NetworkInterface/getifaddrs () API.

Network access control for each process

Starting with Android 11, applications that handle 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.

While there is no guarantee that you will not accidentally upload data to your application, this feature can reduce the chance that errors in your application will result in data leakage.

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>
Copy the code

One-time permission

In Android 11, every time an app requests permission related to location information, microphone, or camera, it gets temporary, one-time access. This actually has a similar permission request in Apple.

Android 11 does not recommend repeating requests for permissions in a specific permission group. After your application is installed on the device, if a user clicks Reject twice for a specific permission, this operation indicates that the user wants to “ask no more” for the permission in the corresponding permission group in the future.

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

  • If the user presses the back button to close the permission dialog box, this action is not considered a “reject” action.
  • If the user uses [requestPermissions()] (Developer. The android. Google. Cn/reference/a…(Android.app.activity, java.lang.string [], int)) Go to system Settings from your app and press the back button, which counts as a “reject” action.

Hovering IntEnts always redirect the user to the system permissions screen

Starting with Android 11, ACTION_MANAGE_OVERLAY_PERMISSION Intent always directs the user to the top-level Settings screen, where the user can grant or revoke the application’s SYSTEM_ALERT_WINDOW permission. Any package: data in the intent is ignored.

On lower versions of Android, ACTION_MANAGE_OVERLAY_PERMISSION Intent can specify a file package that directs the user to an application-specific screen to manage permissions. Android 11 no longer supports this feature, but users must first choose which apps to grant or revoke permissions on. This change protects users by making permissions more purposeful.

Restrict non-SDK interfaces

Some of these changes may not have an immediate impact if the app is not targeted at Android 11. While it is still possible to use some of the non-SDK interfaces in the grey list (depending on the application’s target API level), if you use any non-SDK methods or fields, the risk of the application not running is always higher.

If you are not sure whether your application uses a non-SDK interface, you can test the application to make sure. If your application relies on non-SDK interfaces, 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 with Android 11, the Open Mobile API (OMAPI) has additional features:

  • Parses carrier permission rules.
  • Customize embedded Security Element (eSE) access or configure eSE with one or more of the following:
    • System permissions
    • Configurable Access rules Application Master Data (ARA-M) Application Identifier (AID)
    • System API for resetting the OMAPI reader
  • Provide clear indicators for readers to apply filter device functionality.

Supports concurrent use of multiple cameras

Android 11 added apis to query support for using multiple cameras at the same time, both front and rear.

To check support on the device where the application is running, use the following method:

  • getConcurrentStreamingCameraIds()Camera ID combination can be returnedSetThese combinations can be combined with guaranteed data streams for concurrent streaming (if they are configured by the same application process).
  • IsConcurrentSessionConfigurationSupported () query camera equipment support whether can develop the corresponding session configuration.

conclusion

That’s the end of this article, and it’s basically covered the android 11 update, so you can get ready for it based on your actual situation. Finally put the website address: developer. The android, Google. Cn/preview. If this article is helpful to you, please remember to click on it and pay attention to it. Thank you!!