Android custom access permission

Source: Internet
Author: User
Tags account security

Due to the relatively open design principles of Android, you may use intent or packagemanager to parse and process sub-classes that call other applications. Therefore, more security processing is required for some applications, ensures internal stability and security of the application.

Stability: If a classification has no numeric value, initialization may fail and force close may occur.

Security: when other applications call the SQL database of the program, unexpected losses may occur.

I. Security Protection for Android apps

To consider the security of some internal sensitive data processing, add class ACL access control, of course, more flexible, such as uid, Sid, PID and other methods.

1. you can use the sharedpreferences interface to handle some private configuration information or relatively lightweight content, and set it to private mode_private, however, you must note that this method can only be called by this process.

2. for SQLite security issues, the content provider's processing permissions can be directly displayed in Android, for example, in androidmanifest. in XML, the read or write permissions are declared. In the provider node, the Android: writepermission or Android: readpermission attributes are declared. Of course, other programs can also declare these permissions. In this case, we can use Android: the authorities attribute limits access to a class, such as Android: Authorities = " android. cwj ". Eventually similar

Android: name = "cwjProvider"
Android: authorities = " android. cwj"
Android: writePermission = " android. cwj. permission. WRITE_DATABASE"
Android: readPermission = " android. cwj. permission. READ_DATABASE"/>

The read/write operations of databases can handle multithreading, but data synchronization can be considered successively. You can set the android: multiprocess = "true" attribute to ensure data correctness, related questions are not covered in this article. We may discuss these issues in future.

3. You can directly use the android: permission attribute for permission declaration of Activity, Service, and referer. The specific method is the same as the above SQLite security. The Demo code is as follows:

Android: name = ". cwj"
Android: authorities = " android"
Android: permission = " android. cwj. permission. ACCESS"/>

Ii. Permission statement

Android: name = " android. cwj. permission. ACCESS"
Android: protectionLevel = "normal"
Android: label = "@ string/permission_aceess"
Android: description = "@ string/permission_aceess_detail"/>

Of course, there are optional attributes such as android: protectionLevel = "normal" to set protection permissions, and signatures must be signed. Of course, for permission groups, we can declare permissionGroup using permission methods, or directly use the system, such as android: permissionGroup = "android. permission-group.SYSTEM_TOOLS "is ultimately called in other applications and can be displayed in your own manifest. declaration in xml, similar to <uses-permission android: name = " android. cwj. permission. ACCESS "/>

Iii. Account Security Statement

Directly declare in the Application in androidmanifest. xml. For example, the standard user permission is similar

Android: sharedUserId = "android. uid. shared". Of course, if you are dealing with RIL, you can declare permissions similar to android. uid. phone to process more sensitive data.

Iv. Service Security

For the Service, in addition to the restricted access package, we can also directly bind the access with parameter judgment to avoid using the android: exported = "true" Export method, of course, you can use the extra method of intent for some simple verification through broadcast communication.

V. PID security problems

PID security issues, by limiting processID access, only allow access in the same process space.

6. Android permissionlevel

Android: protectionLevel is set when permissionLevel is defined. There are four optional values:
If we define the first two normal or dangerous types, our own applications only need to access the corresponding protected resources in androidmanifest. add the same uses-permission to the XML file. If it is signature, we can only add the permission to use it. It must have the same signature at the same time. For signatureorsystem, not only the same signature, but also the same shareduserid.

* @ Author Zhang xingye
* Email: xy-Zhang #
* Android Development Group: 278401545

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.