首页 » Android » Android 系统第三方应用系统修改权限及在应用上层显示权限默

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

2017-05-11 12:23:30阅读(683)

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);
        }    
    }
    }

最新发布

CentOS专题

关于本站

5ibc.net旗下博客站精品博文小部分原创、大部分从互联网收集整理。尊重作者版权、传播精品博文,让更多编程爱好者知晓!

小提示

按 Ctrl+D 键,
把本文加入收藏夹