Android 系统第三方应用系统修改权限及在应用上层显示权限默认打开

在android手机系统开发中,可能会遇到将第三方应用的修改系统设置及在其他应用上层显示的权限默认打开的问题。

我习惯的做法:
在framework层中,DatabaseHelper.java 中添加

    private void loadSettings(SQLiteDatabase db) {
        loadSystemSettings(db);
        loadSecureSettings(db);
        // The global table only exists for the 'owner' user
        if (mUserHandle == UserHandle.USER_OWNER) {
            loadGlobalSettings(db);
        }

        /*SUN:jicong.wang add for appops permission app */
        loadAppOpsPermission();
        /*SUN:jicong.wang add appops permission app */
    }


    /*SUN:jicong.wang add appops permission disable app */
    private void loadAppOpsPermission(){
       AppOpsManager appOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
       PackageManager pm = mContext.getPackageManager();

        final String []itemString = mContext.getResources()
            .getStringArray(com.android.internal.R.array.system_alert_window_permission_disable_custom_packagename);

        for (int i = 0; i < itemString.length; i++) {
            try {
                 PackageInfo packageInfo = pm.getPackageInfo(itemString[i],
                     PackageManager.GET_DISABLED_COMPONENTS |
                     PackageManager.GET_UNINSTALLED_PACKAGES |
                     PackageManager.GET_SIGNATURES);

                    appOpsManager.setMode(AppOpsManager.OP_SYSTEM_ALERT_WINDOW,
                            packageInfo.applicationInfo.uid, itemString[i], AppOpsManager.MODE_ERRORED);                     
            } catch (Exception e) {
                Log.e(TAG, "Exception when retrieving package:", e);
            }    
        }

        final String []itemStringExt = mContext.getResources()
            .getStringArray(com.android.internal.R.array.system_alert_window_permission_custom_packagename);

        for (int i = 0; i < itemStringExt.length; i++) {
            try {
                 PackageInfo packageInfo = pm.getPackageInfo(itemStringExt[i],
                     PackageManager.GET_DISABLED_COMPONENTS |
                     PackageManager.GET_UNINSTALLED_PACKAGES |
                     PackageManager.GET_SIGNATURES);

                    appOpsManager.setMode(AppOpsManager.OP_SYSTEM_ALERT_WINDOW,
                            packageInfo.applicationInfo.uid, itemStringExt[i], AppOpsManager.MODE_ALLOWED);                     
            } catch (Exception e) {
                Log.e(TAG, "Exception when retrieving package:", e);
            }    
        }

    final String []itemStringExt1 = mContext.getResources()
        .getStringArray(com.android.internal.R.array.write_settings_permission_custom_packagename);

    for (int i = 0; i < itemStringExt1.length; i++) {
        try {
             PackageInfo packageInfo = pm.getPackageInfo(itemStringExt1[i],
                 PackageManager.GET_DISABLED_COMPONENTS |
                 PackageManager.GET_UNINSTALLED_PACKAGES |
                 PackageManager.GET_SIGNATURES);

                appOpsManager.setMode(AppOpsManager.OP_WRITE_SETTINGS,
                        packageInfo.applicationInfo.uid, itemStringExt1[i], AppOpsManager.MODE_ALLOWED);                     
        } catch (Exception e) {
            Log.e(TAG, "Exception when retrieving package:", e);
        }    
    }


    }

你可能感兴趣的:(Android,android系统)