In our last Article on Android Permissions, we covered some of the permissions and outlined the permissions changes that the new Android M brings. How do we deal with these changes? Is the burning question before us. Now the targetSdkVersion of our business is less than 23. If we need to upgrade to 23 one day, how can we ensure that the business can function normally as before? For us, after the upgrade to 23, when the business needs to use a certain permission, the window will pop up and let the user choose. When the user rejects the permission, if our business is not handled normally, it is very likely to lead to abnormalities in the program, such as various crash, abnormal page display, no operation response and so on. In view of the above questions, we have done the following work: mainly divided into three parts: sorting out the corresponding relationship between permissions and functions, shielding the impact of permissions testing, and checking the model permissions, as shown in the figure below. View the picture and introduce the content of three parts respectively:

I. Sorting out service rights

1.1 List all Service Permissions You can use the following methods to list all service permissions: (1) to obtain business itself its own jurisdiction Can through the PackageManager. GetPackageInfo. (pkgName, PackageManager. GET_PERMISSIONS). RequestedPermissions is available. (2) The permission to obtain other services can be obtained by parsing the Androidmanifest.xml file using the Android XmlResourceParser.

1.2 To find out the corresponding relationship between permissions and functions can be determined through communication with the development of corresponding functions. If you are not sure, you need to check the corresponding function code to find out the key API that triggers permissions, refer to this document: dx.doi.org/10.1145/204… This is the API and permission mapping relationship summarized by foreigners, Google does not provide this relationship.

Two, using Xposed shielding permission to test

2.1 Install Xposed framework installer

Prerequisite: The mobile phone must be authenticated by root.

View the picture Xposed framework needs to use the installer for installation, so we need to install the Xposed framework installer, open the installation after the completion of the click on the framework (in the red box position), the installation of the framework. View the picture and click to enter the frame installation and upgrade interface. Click “Install/Update” and the ROOT authorization prompt will appear. Xposed framework after the completion of the installation to restart the phone to activate, can be directly click to restart can also manually restart.

Install Permission Master Permission modifier, which can be downloaded from the Internet.

2.3 Select modules to view pictures

Check the box and the module comes into play.

2.4 Select the application, enable/disable the permission and test the image

After a permission is disabled or allowed, test the function corresponding to the permission to see whether the function is normal.

3, permission check For Android permission mechanism, do a simple permission check DEMO, the main functions are as follows: according to the input permission, check the mobile phone whether the permission is available. If the permission is unavailable, try applying for the permission.

3.1 targetSdkVersion and compileSdkVersion You can specify targetSdkVersion and compileSdkVersion in build.gradle. Set them to 23. For example, set them to 6.0 or lower according to the actual project.

3.2 Checking input We put all the permissions to be checked into a list array, such as viewing images and then checking the input source.

3.3 check CheckSelfPermission 23 version, if it is used for inspection, otherwise use checkCallingOrSelfPermission for inspection, , of course, also can use the v4 directly compatible with library ContextCompat. CheckSelfPermission (), so you don’t need to distinguish between versions. When no permissions, we try to use the v4 compatible library ActivityCompat. RequestPermissions to apply for permission, according to the result of onRequestPermissionsResult returns to write the result file. Note: The permission dialog box may pop up when demo version 23 is running. Attached is a simple flow chart: View pictures

3.4 Result Output Based on the permission list, the actual permission results for a certain model can be given. For example, after the permission check, the following results are obtained on model A: Model: A Firmware version: *** Permission check: View pictures

According to the above permissions and functions, we get the popover and shortcut corresponding functions to view pictures

In combination with Xposed shielding permissions after the test results to view the picture

Combined with the above, it is basically possible to evaluate the performance results of the business on this model. The ~ of this chapter

Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please indicate the source.