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


    }
  • 3
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值