Android安全機制--四大組件安全

來源:互聯網
上載者:User

Android安全機制--四大組件安全

組件有Public和Private的概念,是否能被其他方調用。通過android:exported欄位來確定,android:exported=true表示能,反之不行。

預設情況下,組件在AndroidMainfest聲明中沒有 interfliter 那麼exported為false,有了interfliter為true.當然我們可以直接輸入android:exported來自己控制。以下就設定為false

[html]  
  1. android:name=.LoginActivity
  2. android:label=@string/app_name
  3. android:screenOrientation=portrait
  4. android:exported=false>

    我們可以通過自訂permission來限制四大組件的安全

    Activity中

    在service

    在contentprovider中分為寫與讀的兩個許可權

    在broastreceiver中發送時

    接收時

    怎麼自訂?在androidmainfest中

     

    [html] 
    1. android:label=test
    2. android:name=com.test.custempermission
    3. android:protectionLevel=normal>

    4.  

      下面通過指定一個BroadcastReceiver的許可權來實驗
      首先建立了兩個app,app A ,app B ;
      app A中註冊了一個BroadcastReceiver ,app B 發送訊息
      app A的menifest檔案:

      Xml代碼
      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. app B 的menifest 檔案內容
        Xml代碼
        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. 這樣app B 給app A 發送訊息,A就可以收到了,若未在app B的menifest檔案中聲明使用相應的許可權,app B發送的訊息,A是收不到的。


           

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.