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

更多相关文章

  1. MediaStore.ACTION_IMAGE_CAPTURE注意事项
  2. android 日记log保存到本地简单方法
  3. android缺少权限为什么报NullPointerException
  4. Android(安卓)7.0的新特性
  5. android修改或添加SettingsProvider的默认值
  6. android权限大全整理
  7. Android(安卓)如何关闭Navigation Bar
  8. Android(安卓)为apk文件签名,增加修改系统时间等权限
  9. OpenGLES 2.0 在 NDK-r15b上的编译问题

随机推荐

  1. 利用android studio LinearLayout线性布
  2. Android中进行单元测试
  3. android中用jsonObject解析json数据
  4. 微软和亚马逊在Android方面的最新消息
  5. Android的strings.xml不在代码显示转html
  6. android画图——颜色过滤
  7. Android SQLite公用结果处理
  8. android studio 奇怪问题收集(gradle问题
  9. android 开发环境之JDK+eclipse+ADT
  10. android 机器人:应用程序Manifest介绍