關於system/priv-app和system/app目錄以及權限

        這篇文章將會說到有關android權限,android簽名,所以會分爲幾篇寫。

        最近有個項目遇到一個問題,我把客戶的apk預置到了system/priv-app下,怎麼預置的?

        在android.mk下加入一句LOCAL_PRIVILEGED_MODULE := true就行了。

        然後就出現了一個問題,因爲將usb屏蔽了所以客戶使用adb install 來安裝他們的apk,發現了一個問題,預置在裏面的apk版本1.0,他們在adb install完後的apk版本是1.1,但是——重啓之後版本又變回了1.0,想來想去極有可能是因爲我把apk預置到了system/priv-app下了,於是就查閱了一些相關資料,瞭解了一些相關東西(雖然後面發現其實是客戶自己寫的apk版本寫的有問題,具體可以參考https://developer.android.com/studio/publish/versioning)。

        先說明有關android權限的一些東西,android有4種權限:

        normal:低風險權限,只要申請了就可以使用(在AndroidManifest.xml中添加<uses-permission>標籤),安裝時不需要用戶確認;
        dangerous:高風險權限,安裝時需要用戶的確認纔可使用;
        signature:只有當申請權限的應用程序的數字簽名與聲明此權限的應用程序的數字簽名相同時(如果是申請系統權限,則需要與系統簽名相同),才能將權限授給它;
        signatureOrSystem:簽名相同,或者申請權限的應用爲系統應用(在system image中)。

        這些權限都在frameworks/base/core/res/AndroidManifest.xml裏面定義:

    <permission android:name="com.android.alarm.permission.SET_ALARM"
        android:label="@string/permlab_setAlarm"
        android:description="@string/permdesc_setAlarm"
        android:protectionLevel="normal" />

    <permission android:name="android.permission.READ_CONTACTS"
        android:permissionGroup="android.permission-group.CONTACTS"
        android:label="@string/permlab_readContacts"
        android:description="@string/permdesc_readContacts"
        android:protectionLevel="dangerous" />

    <permission android:name="android.permission.ACCESS_IMS_CALL_SERVICE"
        android:permissionGroup="android.permission-group.PHONE"
        android:label="@string/permlab_accessImsCallService"
        android:description="@string/permdesc_accessImsCallService"
        android:protectionLevel="signature|system" />

    <permission android:name="android.permission.RECEIVE_EMERGENCY_BROADCAST"
        android:protectionLevel="signature|privileged" />

        對於做應用開發的程序員來說,normal和dangerous級別的權限是他們需要關心的,但是對於做framework的程序員來說四種級別的權限都需要關注,因爲預置apk這個事情做android平臺二次開發的程序員怕是都沒少做。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章