Android Security Mechanism-four major component security
The component has the concept of Public and Private, and whether the component can be called by other parties. The android: exported field is used to determine. android: exported = true indicates yes, but not vice versa.
By default, if the AndroidMainfest statement does not contain interfliter, the value of exported is false, and the value of interfliter is true. Of course, you can directly enter android: exported for your control. Set the value to false as follows:
[Html]
- Android: name =. LoginActivity
- Android: label = @ string/app_name
- Android: screenOrientation = portrait
- Android: exported = false>
We can use custom permission to limit the security of the four major components.
Activity
In service
Contentprovider has two permissions: write and read.
When sending in broastreceiver
Receiving
How to customize it? In androidmainfest
[Html]
- Android: label = test
- Android: name = com. test. custempermission
- Android: protectionLevel = normal>
Next, we will experiment by specifying a BroadcastReceiver permission.
First, two apps, app A and app B, are created;
App A registers A BroadcastReceiver and app B sends messages.
Menifest file of app:
Xml Code
- Package = com. example. testbutton
- Android: versionCode = 1
- Android: versionName = 1.0>
-
- Android: minSdkVersion = 7
- Android: targetSdkVersion = 15/>
-
-
-
- Android: icon = @ drawable/ic_launcher
- Android: label = @ string/app_name
- Android: theme = @ style/AppTheme>
- Android: name =. MainActivity
- LauncheMode = singleTask
- Android: configChanges = locale | orientation | keyboardHidden
- Android: screenOrientation = portrait
- Android: theme = @ style/android: style/Theme. NoTitleBar. Fullscreen>
-
-
-
-
-
-
-
- Android: name = com. example. testbutton. TestButtonReceiver
- Android: permission = com. example. testbutton. RECEIVE>
-
-
-
-
-
-
- Menifest file content of app B
Xml Code
- Package = com. example. testsender
- Android: versionCode = 1
- Android: versionName = 1.0>
-
- Android: minSdkVersion = 7
- Android: targetSdkVersion = 15/>
-
-
-
- Android: icon = @ drawable/ic_launcher
- Android: label = @ string/app_name
- Android: theme = @ style/AppTheme>
- Android: name =. MainActivity
- Android: label = @ string/title_activity_main>
-
-
-
-
-
-
-
-
- In this way, app B sends A message to app A, and then A receives the message. If app B does not declare the corresponding permissions in the menifest file of app B, app B sends the message, A cannot.