Android手机中,有些permission并不是在应用程序的mainfest文件中声明就可以获得,它们还和是否是第三方签名及签名的类型有关系。
典型的android.permission.INSTALL_PACKAGES除了需要在mainfest文件中声明,还需要应用程序是系统的Platform签名。
今天特意写一测试程序来测试哪些permission是第三方签名的应用程序获得的。当然有些Android手机,如果把apk应用程序放到/system/app的目录下,即使是使用的第三方签名,也能获得相当于系统的Platform签名的权限。但是这个毕竟是非常规方法,故在这里不在我讨论的范围内。另外由于我的操作失误,可能应为某个permission没加入到mainfest文件,造成无法通过权限检查。因此测试结果仅供参考。
测试用例1
测试源码TestPermission.java
package edu.cdut.robin;import java.lang.reflect.Field;import android.content.Context;import android.content.pm.PackageManager;import android.util.Log;public class TestPermission extends Thread{final Context context;final static String TAG="robin";TestPermission(Context context){super();this.context=context;}public void run(){/* 使用getDeclaredFields获取属性*/Class<android.Manifest.permission> classType=android.Manifest.permission.class;Field[] fields =classType.getFields();for (Field f : fields) {Object o=null;try {o = f.get("");} catch (IllegalArgumentException e) {e.printStackTrace();} catch (IllegalAccessException e) {e.printStackTrace();}if(o!=null&& o instanceof String){String permission=(String)o;boolean res=(context.checkCallingOrSelfPermission(permission)== PackageManager.PERMISSION_GRANTED);if(!res){Log.w(TAG,permission);}}System.out.println(f);}}}
mainfest文件中
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/><uses-permission android:name="android.permission.ACCESS_CHECKIN_PROPERTIES"/><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/><uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/><uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/><uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER"/><uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/><uses-permission android:name="android.permission.ACCOUNT_MANAGER"/><uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/><uses-permission android:name="android.permission.BATTERY_STATS"/><uses-permission android:name="android.permission.BIND_APPWIDGET"/><uses-permission android:name="android.permission.BIND_DEVICE_ADMIN"/><uses-permission android:name="android.permission.BIND_INPUT_METHOD"/><uses-permission android:name="android.permission.BIND_WALLPAPER"/><uses-permission android:name="android.permission.BLUETOOTH"/><uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/><uses-permission android:name="android.permission.BRICK"/><uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED"/><uses-permission android:name="android.permission.BROADCAST_SMS"/><uses-permission android:name="android.permission.BROADCAST_STICKY"/><uses-permission android:name="android.permission.BROADCAST_WAP_PUSH"/><uses-permission android:name="android.permission.CALL_PHONE"/><uses-permission android:name="android.permission.CALL_PRIVILEGED"/><uses-permission android:name="android.permission.CAMERA"/><uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE"/><uses-permission android:name="android.permission.CHANGE_CONFIGURATION"/><uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/><uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/><uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/><uses-permission android:name="android.permission.CLEAR_APP_CACHE"/><uses-permission android:name="android.permission.CLEAR_APP_USER_DATA"/><uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES"/><uses-permission android:name="android.permission.DELETE_CACHE_FILES"/><uses-permission android:name="android.permission.DELETE_PACKAGES"/><uses-permission android:name="android.permission.DEVICE_POWER"/><uses-permission android:name="android.permission.DIAGNOSTIC"/><uses-permission android:name="android.permission.DISABLE_KEYGUARD"/><uses-permission android:name="android.permission.DUMP"/><uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/><uses-permission android:name="android.permission.FACTORY_TEST"/><uses-permission android:name="android.permission.FLASHLIGHT"/><uses-permission android:name="android.permission.FORCE_BACK"/><uses-permission android:name="android.permission.GET_ACCOUNTS"/><uses-permission android:name="android.permission.GET_PACKAGE_SIZE"/><uses-permission android:name="android.permission.GET_TASKS"/><uses-permission android:name="android.permission.GLOBAL_SEARCH"/><uses-permission android:name="android.permission.HARDWARE_TEST"/><uses-permission android:name="android.permission.INJECT_EVENTS"/><uses-permission android:name="android.permission.INSTALL_LOCATION_PROVIDER"/><uses-permission android:name="android.permission.INSTALL_PACKAGES"/><uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW"/><uses-permission android:name="android.permission.INTERNET"/><uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/><uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/><uses-permission android:name="android.permission.MANAGE_APP_TOKENS"/><uses-permission android:name="android.permission.MASTER_CLEAR"/><uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/><uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/><uses-permission android:name="android.permission.MOUNT_FORMAT_FILESYSTEMS"/><uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/><uses-permission android:name="android.permission.PERSISTENT_ACTIVITY"/><uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/><uses-permission android:name="android.permission.READ_CALENDAR"/><uses-permission android:name="android.permission.READ_CONTACTS"/><uses-permission android:name="android.permission.READ_FRAME_BUFFER"/><uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/><uses-permission android:name="android.permission.READ_INPUT_STATE"/><uses-permission android:name="android.permission.READ_LOGS"/><uses-permission android:name="android.permission.READ_OWNER_DATA"/><uses-permission android:name="android.permission.READ_PHONE_STATE"/><uses-permission android:name="android.permission.READ_SMS"/><uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/><uses-permission android:name="android.permission.READ_SYNC_STATS"/><uses-permission android:name="android.permission.REBOOT"/><uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/><uses-permission android:name="android.permission.RECEIVE_MMS"/><uses-permission android:name="android.permission.RECEIVE_SMS"/><uses-permission android:name="android.permission.RECEIVE_WAP_PUSH"/><uses-permission android:name="android.permission.RECORD_AUDIO"/><uses-permission android:name="android.permission.REORDER_TASKS"/><uses-permission android:name="android.permission.RESTART_PACKAGES"/><uses-permission android:name="android.permission.SEND_SMS"/><uses-permission android:name="android.permission.SET_ACTIVITY_WATCHER"/><uses-permission android:name="android.permission.SET_ALWAYS_FINISH"/><uses-permission android:name="android.permission.SET_ANIMATION_SCALE"/><uses-permission android:name="android.permission.SET_DEBUG_APP"/><uses-permission android:name="android.permission.SET_ORIENTATION"/><uses-permission android:name="android.permission.SET_PREFERRED_APPLICATIONS"/><uses-permission android:name="android.permission.SET_PROCESS_LIMIT"/><uses-permission android:name="android.permission.SET_TIME"/><uses-permission android:name="android.permission.SET_TIME_ZONE"/><uses-permission android:name="android.permission.SET_WALLPAPER"/><uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/><uses-permission android:name="android.permission.SIGNAL_PERSISTENT_PROCESSES"/><uses-permission android:name="android.permission.STATUS_BAR"/><uses-permission android:name="android.permission.SUBSCRIBED_FEEDS_READ"/><uses-permission android:name="android.permission.SUBSCRIBED_FEEDS_WRITE"/><uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/><uses-permission android:name="android.permission.UPDATE_DEVICE_STATS"/><uses-permission android:name="android.permission.USE_CREDENTIALS"/><uses-permission android:name="android.permission.VIBRATE"/><uses-permission android:name="android.permission.WAKE_LOCK"/><uses-permission android:name="android.permission.WRITE_APN_SETTINGS"/><uses-permission android:name="android.permission.WRITE_CALENDAR"/><uses-permission android:name="android.permission.WRITE_CONTACTS"/><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.WRITE_GSERVICES"/><uses-permission android:name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS"/><uses-permission android:name="android.permission.WRITE_OWNER_DATA"/><uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/><uses-permission android:name="android.permission.WRITE_SETTINGS"/><uses-permission android:name="android.permission.WRITE_SMS"/><uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
android.permission.ACCESS_4G_RADIO_DISABLEandroid.permission.ACCESS_4G_STATEandroid.permission.ACCESS_BLUETOOTH_PRINTERandroid.permission.ACCESS_CACHE_FILESYSTEMandroid.permission.ACCESS_CHECKIN_PROPERTIESandroid.permission.ACCESS_FM_RECEIVERandroid.permission.ACCESS_FM_TRANSMITTERandroid.permission.ACCESS_SURFACE_FLINGERandroid.permission.ACCESS_USBNET_STATEandroid.permission.ACCESS_WIMAX_STATEandroid.permission.ACCOUNT_MANAGERandroid.permission.ASEC_ACCESSandroid.permission.ASEC_CREATEandroid.permission.ASEC_DESTROYandroid.permission.ASEC_MOUNT_UNMOUNTandroid.permission.ASEC_RENAMEandroid.permission.BACKUPandroid.permission.BIND_APPWIDGETandroid.permission.BIND_DEVICE_ADMINandroid.permission.BIND_INPUT_METHODandroid.permission.BIND_WALLPAPERandroid.permission.BRICKandroid.permission.BROADCAST_PACKAGE_REMOVEDandroid.permission.BROADCAST_SMSandroid.permission.BROADCAST_WAP_PUSHandroid.intent.category.MASTER_CLEAR.permission.C2D_MESSAGEandroid.permission.CALL_PRIVILEGEDandroid.permission.CHANGE_4G_STATEandroid.permission.CHANGE_BACKGROUND_DATA_SETTINGandroid.permission.CHANGE_COMPONENT_ENABLED_STATEandroid.permission.CHANGE_USBNET_STATEandroid.permission.CHANGE_WIMAX_STATEandroid.permission.CLEAR_APP_USER_DATAandroid.permission.CONTROL_LOCATION_UPDATESandroid.permission.COPY_PROTECTED_DATAandroid.permission.DELETE_CACHE_FILESandroid.permission.DELETE_PACKAGESandroid.permission.DEVICE_POWERandroid.permission.DIAGNOSTICandroid.permission.DUMPandroid.permission.FACTORY_TESTti.permission.FMRXti.permission.FMRX_ADMINandroid.permission.FORCE_BACKandroid.permission.FORCE_STOP_PACKAGESandroid.permission.GLOBAL_SEARCHandroid.permission.GLOBAL_SEARCH_CONTROLandroid.permission.HARDWARE_TESTandroid.permission.INITIATE_4G_SCANandroid.permission.INITIATE_4G_SCAN_DATA_SERVICE_DISRUPTIVEandroid.permission.INJECT_EVENTSandroid.permission.INSTALL_LOCATION_PROVIDERandroid.permission.INSTALL_PACKAGESandroid.permission.INTERNAL_SYSTEM_WINDOWandroid.permission.MANAGE_APP_TOKENSandroid.permission.MANAGE_USBandroid.permission.MASTER_CLEARandroid.permission.MODIFY_PHONE_STATEandroid.permission.MOVE_PACKAGEandroid.permission.NET_ADMINandroid.permission.NET_RAWandroid.permission.NFCandroid.permission.PACKAGE_USAGE_STATSandroid.permission.PERFORM_CDMA_PROVISIONINGandroid.permission.READ_FRAME_BUFFERandroid.permission.READ_INPUT_STATEandroid.permission.READ_USER_DICTIONARYandroid.permission.REBOOTandroid.permission.RECEIVE_EMERGENCY_BROADCASTandroid.permission.SET_ACTIVITY_WATCHERcom.android.alarm.permission.SET_ALARMandroid.permission.SET_ORIENTATIONandroid.permission.SET_PREFERRED_APPLICATIONSandroid.permission.SET_TIMEandroid.permission.SET_WALLPAPER_COMPONENTandroid.permission.SHUTDOWNandroid.permission.STATUS_BARandroid.permission.STATUS_BAR_SERVICEandroid.permission.STOP_APP_SWITCHESandroid.permission.UPDATE_DEVICE_STATSandroid.permission.USE_SIPandroid.permission.VPNandroid.permission.WRITE_GSERVICESandroid.permission.WRITE_SECURE_SETTINGSandroid.permission.WRITE_USER_DICTIONARY
测试结果显示,在Lenovo A820(Android 4.1.2)中应用程序使用第三方签名无法获得以下的permission:
android.permission.ACCESS_CACHE_FILESYSTEMandroid.permission.ACCESS_CHECKIN_PROPERTIESandroid.permission.ACCESS_CONTENT_PROVIDERS_EXTERNALLYandroid.permission.ACCESS_MTK_MMHWandroid.permission.ACCESS_MTPandroid.permission.ACCESS_SURFACE_FLINGERandroid.permission.ACCESS_WIMAX_STATEandroid.permission.ACCOUNT_MANAGERcom.android.voicemail.permission.ADD_VOICEMAILandroid.permission.ALLOW_ANY_CODEC_FOR_PLAYBACKandroid.permission.ASEC_ACCESSandroid.permission.ASEC_CREATEandroid.permission.ASEC_DESTROYandroid.permission.ASEC_MOUNT_UNMOUNTandroid.permission.ASEC_RENAMEandroid.permission.BACKUPandroid.permission.BIND_ACCESSIBILITY_SERVICEandroid.permission.BIND_APPWIDGETandroid.permission.BIND_DEVICE_ADMINandroid.permission.BIND_INPUT_METHODandroid.permission.BIND_PACKAGE_VERIFIERandroid.permission.BIND_REMOTEVIEWSandroid.permission.BIND_TEXT_SERVICEandroid.permission.BIND_VPN_SERVICEandroid.permission.BIND_WALLPAPERandroid.permission.BRICKandroid.permission.BROADCAST_PACKAGE_REMOVEDandroid.permission.BROADCAST_SMSandroid.permission.BROADCAST_WAP_PUSHandroid.intent.category.MASTER_CLEAR.permission.C2D_MESSAGEandroid.permission.CALL_PRIVILEGEDandroid.permission.CHANGE_BACKGROUND_DATA_SETTINGandroid.permission.CHANGE_COMPONENT_ENABLED_STATEandroid.permission.CHANGE_WIMAX_STATEandroid.permission.CLEAR_APP_USER_DATAandroid.permission.CONFIRM_FULL_BACKUPandroid.permission.CONNECTIVITY_INTERNALandroid.permission.CONTROL_LOCATION_UPDATESandroid.permission.COPY_PROTECTED_DATAandroid.permission.CRYPT_KEEPERandroid.permission.DELETE_CACHE_FILESandroid.permission.DELETE_PACKAGESandroid.permission.DEVICE_POWERandroid.permission.DIAGNOSTICandroid.permission.DUMPandroid.permission.FACTORY_TESTandroid.permission.FORCE_BACKandroid.permission.FORCE_STOP_PACKAGESandroid.permission.GET_DETAILED_TASKSandroid.permission.GLOBAL_SEARCHandroid.permission.GLOBAL_SEARCH_CONTROLandroid.permission.GRANT_REVOKE_PERMISSIONSandroid.permission.HARDWARE_TESTandroid.permission.INJECT_EVENTSandroid.permission.INSTALL_LOCATION_PROVIDERandroid.permission.INSTALL_PACKAGESandroid.permission.INTERNAL_SYSTEM_WINDOWandroid.permission.MANAGE_APP_TOKENSandroid.permission.MANAGE_NETWORK_POLICYandroid.permission.MANAGE_USBandroid.permission.MASTER_CLEARandroid.permission.MODIFY_APPWIDGET_BIND_PERMISSIONSandroid.permission.MODIFY_NETWORK_ACCOUNTINGandroid.permission.MODIFY_PHONE_STATEandroid.permission.MOVE_PACKAGEandroid.permission.NET_ADMINandroid.permission.NFCandroid.permission.PACKAGE_USAGE_STATSandroid.permission.PACKAGE_VERIFICATION_AGENTandroid.permission.PERFORM_CDMA_PROVISIONINGandroid.permission.READ_CELL_BROADCASTSandroid.permission.READ_FRAME_BUFFERandroid.permission.READ_INPUT_STATEandroid.permission.READ_LOGSandroid.permission.READ_NETWORK_USAGE_HISTORYandroid.permission.READ_PRIVILEGED_PHONE_STATEandroid.permission.READ_PROFILEandroid.permission.READ_SOCIAL_STREAMandroid.permission.READ_USER_DICTIONARYandroid.permission.REBOOTandroid.permission.RECEIVE_EMERGENCY_BROADCASTandroid.permission.REMOTE_AUDIO_PLAYBACKandroid.permission.REMOVE_TASKSandroid.permission.RETRIEVE_WINDOW_CONTENTandroid.permission.SEND_SMS_NO_CONFIRMATIONandroid.permission.SERIAL_PORTandroid.permission.SET_ACTIVITY_WATCHERcom.android.alarm.permission.SET_ALARMandroid.permission.SET_ALWAYS_FINISHandroid.permission.SET_ANIMATION_SCALEandroid.permission.SET_DEBUG_APPandroid.permission.SET_KEYBOARD_LAYOUTandroid.permission.SET_ORIENTATIONandroid.permission.SET_POINTER_SPEEDandroid.permission.SET_PREFERRED_APPLICATIONSandroid.permission.SET_PROCESS_LIMITandroid.permission.SET_SCREEN_COMPATIBILITYandroid.permission.SET_TIMEandroid.permission.SET_WALLPAPER_COMPONENTandroid.permission.SHUTDOWNandroid.permission.SIGNAL_PERSISTENT_PROCESSESandroid.permission.START_ANY_ACTIVITYandroid.permission.STATUS_BARandroid.permission.STATUS_BAR_SERVICEandroid.permission.STOP_APP_SWITCHESandroid.permission.UPDATE_DEVICE_STATSandroid.permission.UPDATE_LOCKandroid.permission.USE_SIPandroid.permission.WRITE_APN_SETTINGSandroid.permission.WRITE_GSERVICESandroid.permission.WRITE_MEDIA_STORAGEandroid.permission.WRITE_PROFILEandroid.permission.WRITE_SECURE_SETTINGSandroid.permission.WRITE_SOCIAL_STREAMandroid.permission.WRITE_USER_DICTIONARY
结束!