Android Security Mechanism-four major component security

Source: Internet
Author: User

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]
  1. Android: name =. LoginActivity
  2. Android: label = @ string/app_name
  3. Android: screenOrientation = portrait
  4. 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]
    1. Android: label = test
    2. Android: name = com. test. custempermission
    3. Android: protectionLevel = normal>

    4.  

      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
      1. Package = com. example. testbutton
      2. Android: versionCode = 1
      3. Android: versionName = 1.0>
      4.  
      5. Android: minSdkVersion = 7
      6. Android: targetSdkVersion = 15/>
      7.  
      8. Android: icon = @ drawable/ic_launcher
      9. Android: label = @ string/app_name
      10. Android: theme = @ style/AppTheme>
      11. Android: name =. MainActivity
      12. LauncheMode = singleTask
      13. Android: configChanges = locale | orientation | keyboardHidden
      14. Android: screenOrientation = portrait
      15. Android: theme = @ style/android: style/Theme. NoTitleBar. Fullscreen>
      16.  
      17.  
      18.  
      19. Android: name = com. example. testbutton. TestButtonReceiver
      20. Android: permission = com. example. testbutton. RECEIVE>
      21.  
      22.  
      23.  
      24.  
      25. Menifest file content of app B
        Xml Code
        1. Package = com. example. testsender
        2. Android: versionCode = 1
        3. Android: versionName = 1.0>
        4.  
        5. Android: minSdkVersion = 7
        6. Android: targetSdkVersion = 15/>
        7.  
        8. Android: icon = @ drawable/ic_launcher
        9. Android: label = @ string/app_name
        10. Android: theme = @ style/AppTheme>
        11. Android: name =. MainActivity
        12. Android: label = @ string/title_activity_main>
        13.  
        14.  
        15.  
        16.  
        17.  
        18. 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.


           

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: info-contact@alibabacloud.com 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.