Android Permissions - Protection Levels

段劲
2023-12-01

Android Permissions - Protection Levels

Android applications declare the permissions they are likely to require in their manifest (a short file that describes the contents of the 'package'). This allows the system to sandbox them from critical resources and gives the user some indication of what havoc they might reap. That's the theory at least, but the first time I installed an application and read the permissions page I had no idea what they were on about! Clearly this system needs to be changed, but that is not what I want to talk about today.

As an application writer I need to know the protection level of these permissions, i.e. which of these permissions are normal(can cause the user no real harm), dangerous (might require a greater level of trust, such as the ability to read SMS messages), signature (only granted to applications that are signed by the people who built the OS), signatureOrSystem (like signature, but also allowed if they have been pre-installed in a system folder). I was surprised to find no easy reference for thisin the documentation, but I did find the relevant information in the source.

You can of course probe the android package itself for this information, which is useful if you don't have access to the particular version of Android you are running. Here is some code that does just that:

// Get the permissions for the core android package
PackageInfo packageInfo = getPackageManager().getPackageInfo("android", PackageManager.GET_PERMISSIONS);
if (packageInfo.permissions != null) {
  // For each defined permission
  for (PermissionInfo permission : packageInfo.permissions) {
    // Dump permission info
    String protectionLevel;
    switch(permission.protectionLevel) {
    case PermissionInfo.PROTECTION_NORMAL : protectionLevel = "normal"break;
    case PermissionInfo.PROTECTION_DANGEROUS : protectionLevel = "dangerous"break;
    case PermissionInfo.PROTECTION_SIGNATURE : protectionLevel = "signature"break;
    case PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM : protectionLevel = "signatureOrSystem"break;
    default : protectionLevel = "<unknown>"break;
    }
    Log.i("PermissionCheck", permission.name + " " + protectionLevel);
  }
}

...and here are the results in case you need to know them at a glance...

PermissionProtection Level
android.intent.category.MASTER_CLEAR.permission.C2D_MESSAGEsignature
android.permission.ACCESS_CACHE_FILESYSTEMsignatureOrSystem
android.permission.ACCESS_CHECKIN_PROPERTIESsignatureOrSystem
android.permission.ACCESS_COARSE_LOCATIONdangerous
android.permission.ACCESS_FINE_LOCATIONdangerous
android.permission.ACCESS_LOCATION_EXTRA_COMMANDSnormal
android.permission.ACCESS_MOCK_LOCATIONdangerous
android.permission.ACCESS_NETWORK_STATEnormal
android.permission.ACCESS_SURFACE_FLINGERsignature
android.permission.ACCESS_WIFI_STATEnormal
android.permission.ACCOUNT_MANAGERsignature
android.permission.ASEC_ACCESSsignature
android.permission.ASEC_CREATEsignature
android.permission.ASEC_DESTROYsignature
android.permission.ASEC_MOUNT_UNMOUNTsignature
android.permission.ASEC_RENAMEsignature
android.permission.AUTHENTICATE_ACCOUNTSdangerous
android.permission.BACKUPsignatureOrSystem
android.permission.BATTERY_STATSnormal
android.permission.BIND_APPWIDGETsignatureOrSystem
android.permission.BIND_DEVICE_ADMINsignature
android.permission.BIND_INPUT_METHODsignature
android.permission.BIND_WALLPAPERsignatureOrSystem
android.permission.BLUETOOTHdangerous
android.permission.BLUETOOTH_ADMINdangerous
android.permission.BRICKsignature
android.permission.BROADCAST_PACKAGE_REMOVEDsignature
android.permission.BROADCAST_SMSsignature
android.permission.BROADCAST_STICKYnormal
android.permission.BROADCAST_WAP_PUSHsignature
android.permission.CALL_PHONEdangerous
android.permission.CALL_PRIVILEGEDsignatureOrSystem
android.permission.CAMERAdangerous
android.permission.CHANGE_BACKGROUND_DATA_SETTINGsignature
android.permission.CHANGE_COMPONENT_ENABLED_STATEsignature
android.permission.CHANGE_CONFIGURATIONdangerous
android.permission.CHANGE_NETWORK_STATEdangerous
android.permission.CHANGE_WIFI_MULTICAST_STATEdangerous
android.permission.CHANGE_WIFI_STATEdangerous
android.permission.CLEAR_APP_CACHEdangerous
android.permission.CLEAR_APP_USER_DATAsignature
android.permission.CONTROL_LOCATION_UPDATESsignatureOrSystem
android.permission.COPY_PROTECTED_DATAsignature
android.permission.DELETE_CACHE_FILESsignatureOrSystem
android.permission.DELETE_PACKAGESsignatureOrSystem
android.permission.DEVICE_POWERsignature
android.permission.DIAGNOSTICsignature
android.permission.DISABLE_KEYGUARDnormal
android.permission.DUMPdangerous
android.permission.EXPAND_STATUS_BARnormal
android.permission.FACTORY_TESTsignature
android.permission.FLASHLIGHTnormal
android.permission.FORCE_BACKsignature
android.permission.FORCE_STOP_PACKAGESsignature
android.permission.GET_ACCOUNTSnormal
android.permission.GET_PACKAGE_SIZEnormal
android.permission.GET_TASKSdangerous
android.permission.GLOBAL_SEARCHsignatureOrSystem
android.permission.GLOBAL_SEARCH_CONTROLsignature
android.permission.HARDWARE_TESTsignature
android.permission.INJECT_EVENTSsignature
android.permission.INSTALL_LOCATION_PROVIDERsignatureOrSystem
android.permission.INSTALL_PACKAGESsignatureOrSystem
android.permission.INTERNAL_SYSTEM_WINDOWsignature
android.permission.INTERNETdangerous
android.permission.KILL_BACKGROUND_PROCESSESnormal
android.permission.MANAGE_ACCOUNTSdangerous
android.permission.MANAGE_APP_TOKENSsignature
android.permission.MASTER_CLEARsignatureOrSystem
android.permission.MODIFY_AUDIO_SETTINGSdangerous
android.permission.MODIFY_PHONE_STATEdangerous
android.permission.MOUNT_FORMAT_FILESYSTEMSdangerous
android.permission.MOUNT_UNMOUNT_FILESYSTEMSdangerous
android.permission.MOVE_PACKAGEsignatureOrSystem
android.permission.PACKAGE_USAGE_STATSsignature
android.permission.PERFORM_CDMA_PROVISIONINGsignatureOrSystem
android.permission.PERSISTENT_ACTIVITYdangerous
android.permission.PROCESS_OUTGOING_CALLSdangerous
android.permission.READ_CALENDARdangerous
android.permission.READ_CONTACTSdangerous
android.permission.READ_FRAME_BUFFERsignature
android.permission.READ_INPUT_STATEsignature
android.permission.READ_LOGSdangerous
android.permission.READ_OWNER_DATAdangerous
android.permission.READ_PHONE_STATEdangerous
android.permission.READ_SMSdangerous
android.permission.READ_SYNC_SETTINGSnormal
android.permission.READ_SYNC_STATSnormal
android.permission.READ_USER_DICTIONARYdangerous
android.permission.REBOOTsignatureOrSystem
android.permission.RECEIVE_BOOT_COMPLETEDnormal
android.permission.RECEIVE_MMSdangerous
android.permission.RECEIVE_SMSdangerous
android.permission.RECEIVE_WAP_PUSHdangerous
android.permission.RECORD_AUDIOdangerous
android.permission.REORDER_TASKSdangerous
android.permission.RESTART_PACKAGESnormal
android.permission.SEND_SMSdangerous
android.permission.SET_ACTIVITY_WATCHERsignature
android.permission.SET_ALWAYS_FINISHdangerous
android.permission.SET_ANIMATION_SCALEdangerous
android.permission.SET_DEBUG_APPdangerous
android.permission.SET_ORIENTATIONsignature
android.permission.SET_PREFERRED_APPLICATIONSsignature
android.permission.SET_PROCESS_LIMITdangerous
android.permission.SET_TIMEsignatureOrSystem
android.permission.SET_TIME_ZONEdangerous
android.permission.SET_WALLPAPERnormal
android.permission.SET_WALLPAPER_COMPONENTsignatureOrSystem
android.permission.SET_WALLPAPER_HINTSnormal
android.permission.SHUTDOWNsignature
android.permission.SIGNAL_PERSISTENT_PROCESSESdangerous
android.permission.STATUS_BARsignatureOrSystem
android.permission.STOP_APP_SWITCHESsignature
android.permission.SUBSCRIBED_FEEDS_READnormal
android.permission.SUBSCRIBED_FEEDS_WRITEdangerous
android.permission.SYSTEM_ALERT_WINDOWdangerous
android.permission.UPDATE_DEVICE_STATSsignature
android.permission.USE_CREDENTIALSdangerous
android.permission.VIBRATEnormal
android.permission.WAKE_LOCKdangerous
android.permission.WRITE_APN_SETTINGSdangerous
android.permission.WRITE_CALENDARdangerous
android.permission.WRITE_CONTACTSdangerous
android.permission.WRITE_EXTERNAL_STORAGEdangerous
android.permission.WRITE_GSERVICESsignatureOrSystem
android.permission.WRITE_OWNER_DATAdangerous
android.permission.WRITE_SECURE_SETTINGSsignatureOrSystem
android.permission.WRITE_SETTINGSdangerous
android.permission.WRITE_SMSdangerous
android.permission.WRITE_SYNC_SETTINGSdangerous
android.permission.WRITE_USER_DICTIONARYnormal
com.android.browser.permission.READ_HISTORY_BOOKMARKSdangerous
com.android.browser.permission.WRITE_HISTORY_BOOKMARKSdangerous
 类似资料:

相关阅读

相关文章

相关问答