Android P 添加应用白名单配置

需求:在白名单内的应用允许安装,不在白名单的应用禁止安装。

在PMS里面做判断,不在白名单内的应用直接return。

+++ b/services/core/java/com/android/server/pm/PackageManagerService.java

 /**
  * Keep track of all those APKs everywhere.
  * <p>
@@ -17346,6 +17350,27 @@ public class PackageManagerService extends IPackageManager.Stub
             return;
         }
 
+        if(!isWhiteListApp(pkg.packageName)){
+            Log.d("TAG","--isWhiteListApp--");
+            res.setError(PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE,
+                   "app is not in the whitelist. packageName:" + pkg.packageName);
+             return;
+        }
         if (instantApp && pkg.mSigningDetails.signatureSchemeVersion
                 < SignatureSchemeVersion.SIGNING_BLOCK_V2) {
             Slog.w(TAG, "Instant app package " + pkg.packageName
@@ -24913,6 +24938,65 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
 
         return mProtectedPackages.isPackageStateProtected(userId, packageName);
     }
+       private boolean isWhiteListApp(String packagename){
+        ArrayList<String> whiteListApp = new ArrayList<String>();
+        try{
+            BufferedReader br = new BufferedReader(new InputStreamReader(
+            new FileInputStream("/system/etc/WhiteListApp.conf")));
+            String line ="";
+            while ((line = br.readLine()) != null){
+                whiteListApp.add(line);
+            }
+            br.close();
+        }catch(java.io.FileNotFoundException ex){
+            return false;
+        }catch(java.io.IOException ex){
+            return false;
+        }
+        Iterator<String> it = whiteListApp.iterator();
+        while (it.hasNext()) {
+            String whitelistItem = it.next();
+            if (whitelistItem.equals(packagename)) {
+                return true;
+            }
+        }
+        return false;
+    }

创建WhiteListApp.conf。在device/项目/xxx/目录下的device.mk文件中将WhiteListApp.conf,copy到ystem/etc

PRODUCT_COPY_FILES += vendor/xxx/WhiteListApp.conf:system/etc/WhiteListApp.conf

WhiteListApp.conf内容如下:

com.xxx.xxx

com.xxx.xxx

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值