Android System permissions and signatures2015-03-23 19:13:33CSDN-chen52671-Number of Hits:
- Android Permissions and Signature Primer
Phenomenon: A custom service in the system, services are open to the outside, using the system signature
LOCAL_CERTIFICATE := platform
The application layer invokes this system service to get some information at the bottom . If development in the IDE, ordinary signature, cannot call to the service, changed to compile in the system compilation environment, and add the following statement in ANDROID.MK:
LOCAL_CERTIFICATE := platformandroid:sharedUserId="android.uid.system“android:process="com.android.phone"
will be able to obtain the system services smoothly. What is the intrinsic reason?
Linux Permissions
Speaking of the rights and signatures of Android, it is necessary to start with the Linux permissions, we know that the Linux file system is restricted, for each file or directory, we execute the ls-l command will see similar to the following display:-rw-r–r–1 xxxxx xxxxx 681 2013-05-24 09:16 android.mk respectively represent: types and permissions of files, number of hard links, user;group; size; last access/modification time; File/directory Name file permissions represent whether to open read or write permissions to the corresponding user, user group, or other user. User;group, for example, represents who the file belongs to, such as a file created by user ABC, which is ABC. Linux is guaranteed to be secure through file permissions and user groups. and file permissions are reflected through the process, the user access to a file, always through the process to access, that is, to open a terminal interface, but also opened a bash process to view the file. As shown: Figure 1
For Android, starting a application, it's also common to start a separate process to run, like this:
drwxr-x--x u0_a49 u0_a49 radio radio 2013-01-03 06:35 com.android.phone
The test app above launches a separate process, and its user group is u0_a49. This way, if there is no accident, it can only access the app's own data. The question comes, what if I want to access other files and directories that are not appropriate to my data ? The first thing to think about is whether you can change the user group of your custom application to be the same as any other application. For example, user changed to radio.
The
answer is yes. However, Android to ensure the security of the system, there is a rule: must be androidmanifest.xml with the same signature + the same Shareuserid attribute of two apps, you can assign the same user ID. Because Com.android.phone is a system application, its signature is local_certificate: = Platform system signature, so I must also use local_certificate: = Platform System signature, and android:shareduserid= "Android.uid". radio "Allows this custom app and phone app to have the same UID. (Of course, if you just want to access, Android:shareduserid can be set to a higher-privileged user can also be implemented).
The
Androidmanifest.xml also has a label android:process, such as: android:process= "Com.android.phone", It can be applied to an activity or service alone, or directly to Appli< Span style= "Width:auto; Height:auto; Color: #0000ff; font-size:14px; Float:none; " >cat Ion. The function is to put the corresponding activity or service in the process of Com.android.phone to run. The premise of using this tag is that the previous paragraph says: With the same signature + same Shareuserid attribute. The role of a label android:process such as a dynamic library running in the phone app or a singleton object that is held if another app would like to use or invoke, it is not available, or get another singleton-because it is another process. This time through android:process will be for the activity to let it run in the phone process. This makes it easy to use the resources in the phone app. Figure 2
The relationship between the signature and the APK: usually the APK is for user and process in Linux. The APK runs on behalf of a unique process, and the process belongs to a user. Two apk with the same signature and the same Shareuserid attribute will only belong to the same user. (apk installation, Packagemanagerservice checks) the relationship between signatures and permissions: The signature is for the system to identify whether the same author, In addition to the system signatures mentioned earlier, each author can customize his or her own signature. Permissions for the signature level, such as an author's app, define a permission. and set the android:protectionlevel of the permission to "signature". That permission can only be used if the author uses another app with the same signature.
What about the phone after root?
Why is root allowed to ignore those permissions? Take a root to get the phone, execute the following code:
Process process = Runtime.getRuntime().exec("su");os = new DataOutputStream(process.getOutputStream());
The permissions for the SU program are as follows:
The key is the EXECUTE permission flag bit S, which represents the owner's permission-–root when any user executes the file. Of course, this is relatively brief, in fact, in the application of the root permission operation, to superuser.apk request the Superuser, superuser.apk exploit the system vulnerability, perform a similar operation as follows. Let the SU program actually these functions.
cp /data/tmp/su /system/bin/chown root:root su chmod 4775 /system/bin/su
So the statement above to modify the CPU frequency can be executed smoothly.
Q&a
The relationship between Q:android:shareduserid and android:process? A:shareduserid is for the whole apk, android:process is to a certain activity or SERVICCE, many times Shareduserid is android:process premise q:android : Shareduserid and Android:process, respectively, have an effect on the application. A:shareduserid can make the UID of the application become similar to the system,phone, although not the root user privilege is high, but also can do a lot of things, depends on its needs. Have the UID of the phone before you can set the Android:process property of the activity within the app. There are many reasons for using android:process: a) such as STK application, want to use Catservice (singleton mode), so it calls Catservice.getinstance (), The Catservice instance is returned correctly when called, and the instance has not been established and is not available. And this catservice is in the phone app, using the Commandsinterface object (Ril) as a parameter. This is the need to put the Stk app in the phone process before you can get the Catservice instance. b) or want to Design A system application that wants to call phone phone = Phonefactory.getdefaultphone () to get the phone object, but this call can only be run in the phone process (see the function source ). This requires that the activity that invokes the statement be set to android:process= "Com.android.phone"-such as icclocksettings in setting.
Android System permissions and signatures