This document describes how to use the security line features provided by Android.
Android is an operating system with separated privileges. Each application running in the system has a System ID (Linux User ID and group ID ). The system part of the identity is also divided into different identities. Therefore, Linux can separate applications and systems.
In addition, more fine-grained security features are provided through the "permission" mechanism, which forcibly limits the specific operations that special processes can perform, in addition, each URI has the permission to specify the specific data segment.
Security Architecture
The core design of the Android security architecture is that, by default, no application is permitted to perform any operation that adversely affects other applications, operating systems, or users. This includes reading and writing users' private data (such as the address book or e-mail), reading and writing files from another application, executing network access, and keeping the device awake.
Because Android uses a sandbox to separate each application, the application must specify the resources and data to be shared. Applications use declarations to obtain additional capabilities that are not available in the basic sandbox they need. Applications declare their required permissions statically, And the Android system prompts the application to agree when installing the application. Android does not have a dynamic (at runtime) authorization mechanism, because security damages can bring complicated user experience to users.
The application sandbox does not rely on technologies used to build applications. Especially in the Dalvik virtual machine, there is no security boundary, and any application can run the local code. All types of applications, including Java, native, and hybrid applications, are put in the sandbox in the same way and have the same security degree to each other.
Application Signature
All androidapplication (.apk file) must be signed with a certificate. The private key of the certificate is held by the application developer. This certificate identifies the author of the application and does not need to be signed by the certificate authority. This is completely allowed and generally Android applications use self-signed certificates. The purpose of the certificate in Android is to differentiate the author of the application. In this way, the system is allowed to accept or deny the application's access to signature-level permissions, as well as to accept or reject the application's requests for the same Linux identity as the other application.
User ID and File Access
During installation, the Android system assigns a different Linux User ID to each package. This identity will remain unchanged for packets on the device during the running period. The same package may have different UID on different devices. This is not important. It is important that each package has a different UID on a device.
Because security is enforced at the process level, the code of any two packages is usually not run in the same process, so they need to be run by different Linux users. You can use the sharedUserId attribute in the <manifest> label in the Androidmanifest. xml file of each package to assign them the same user ID. In this way, packages with the same user ID are considered as the same application and have the same permissions. Note that only applications that use the same signature (and have applied for the same sharedUserId attribute) are assigned the same user ID to ensure security.
The User ID of an application is assigned to any data stored by the application, and other packages cannot access the application. When getSharedPreferences (String, int), openFileOutput (String, int), or openOrCreateDatabase (String, int, SQLiteDatabase. when creating a new file, you can use the MODE_WORLD_READABLE and (or) MODE_WORLD_WRITEABLE tags to allow other packages to read and write the file. When these tags are set, the file is still owned by the application that created it, but is configured with global read/write permissions so that other applications can access it.
Permission
A basic Android Application has no permission to associate with it, which means it cannot do anything that adversely affects the user experience or data on the device, to use the protected functions on the device, you must use the AndroidManifest in the application. the xml file contains one or more <uses-permission> labels to declare the permissions required by the application.
For example, the application that requires the monitor to receive SMS messages should specify the following settings:
<Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
Package = "com. android. app. myapp">
<Uses-permission android: name = "android. permission. RECEIVE_SMS"/>
...
</Manifest>
During application installation, the permissions applied for by the application are granted through the Android package installer. The package installer declares the permissions and (or) through the application) interact with the user to check whether the corresponding permissions should be granted to the application. When the application is running, it does not check permissions. That is to say, you must either grant the application the permissions it has applied for during the installation so that it can use the features limited by these permissions, or do not approve the permissions it has applied, so that the user cannot use the features limited by these permissions, and the user will not receive any prompt.
In many cases, a SecurityException exception is thrown to the application due to failure due to no permission. However, this exception does not occur anywhere you do not have the permission. For example, when the sendBroadcast (Intent) method sends data, it checks the permissions of each receiver. After this method is returned, if the permission fails, it will not receive an exception. However, in almost all cases, permission-related failure prints a system-level log ).
Permissions provided by the Android system can be found in the Manifest. permission class. Any application can also define and enforce its own permissions, so not all possible permissions listed in this class.
A special permission can be enforced in many places during program execution:
1. Prevent the application from executing certain functions during system calls;
2. When the Activity is started, the Activity of other applications is blocked to start the application;
3. When sending and receiving broadcasts, control who can receive your broadcasts or who can send broadcasts to you;
4. When accessing and operating a content provider;
5. When binding or starting a service.
From FireOfStar's column