阅读:20256回复:1

Android系统Apk安装白名单和黑名单功能

楼主#
更多 发布于:2020-05-15 14:58
From c4862e3f9844c448ea436b134c1e0221782b0261 Mon Sep 17 00:00:00 2001
From: yu <yu@ubuntu.com>
Date: Fri, 15 May 2020 14:38:04 +0800
Subject: [PATCH] 1.App install white list and black list API 2.Set system time
 and set Date API


---
 core/java/android/provider/Settings.java           |  5 ++
 .../android/server/pm/PackageManagerService.java   | 37 +++++++++-
 .../android/server/policy/PhoneWindowManager.java  | 79 ++++++++++++++++++++++
 3 files changed, 119 insertions(+), 2 deletions(-)


diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index a7b8eaf..28a79ec 100755
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -3366,6 +3366,11 @@ public final class Settings {
  public static final String LAST_BOOT_TIME="last_boot_time";
  /** @hide */
  public static final String INIT_HISTORY_UPTIME="init_history_uptime";//Add by jackly 2020.5.14
+ /** @hide */
+ public static final String BLOCK_INSTALL_PACKAGE_LIST = "block_install_package_list";//Add by jackly 2020.5.15
+ /** @hide */
+ public static final String BLOCK_INSTALL_PACKAGE_MODE = "block_install_package_mode";//Add by jackly 2020.5.15
+
         /**
          * Whether the phone vibrates when it is ringing due to an incoming call. This will
          * be used by Phone and Setting apps; it shouldn't affect other apps.
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 1afefcb..f343e15 100755
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -311,6 +311,7 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
+import android.provider.Settings.SettingNotFoundException;
 
 /**
  * Keep track of all those APKs everywhere.
@@ -346,7 +347,7 @@ import java.util.concurrent.atomic.AtomicInteger;
  * </pre>
  */
 public class PackageManagerService extends IPackageManager.Stub {
-    static final String TAG = "PackageManager";
+    static final String TAG = "yu_PackageManager";
     static final boolean DEBUG_SETTINGS = false;
     static final boolean DEBUG_PREFERRED = false;
     static final boolean DEBUG_UPGRADE = false;
@@ -13106,7 +13107,39 @@ public class PackageManagerService extends IPackageManager.Stub {
             } else {
                 pkgLite = mContainerService.getMinimalPackageInfo(origin.resolvedPath, installFlags,
                         packageAbiOverride);
-
+ //add by jackly 2020-5-15 For Install Whitelist or Blacklist
+ int blockMode = 0;
+ String blockPacakges = null;
+ try{
+ blockMode = android.provider.Settings.System.getInt(mContext.getContentResolver(), android.provider.Settings.System.BLOCK_INSTALL_PACKAGE_MODE);
+ blockPacakges = android.provider.Settings.System.getString(mContext.getContentResolver(), android.provider.Settings.System.BLOCK_INSTALL_PACKAGE_LIST);
+ }catch(SettingNotFoundException e){
+ Slog.v(TAG,"======SettingNotFoundException=====" + e.toString());
+ }
+ if(blockMode == 1 && blockPacakges != null && !blockPacakges.equals("")){
+ Slog.v(TAG,"******Install Whitelist Mode******");
+ List<String>packageWhiteList = Arrays.asList(blockPacakges.split(";"));
+ if(!packageWhiteList.contains(pkgLite.packageName)){
+ Slog.v(TAG,"======Install Block!=====" + pkgLite.packageName);
+ ret = PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE;
+ }
+ for (int i = 0; i < packageWhiteList.size(); i++) {
+ Slog.v(TAG,"=====Whitelist Package:" + packageWhiteList.get(i) + "\n");
+ }
+ }else if(blockMode == 2 && blockPacakges != null && !blockPacakges.equals("")){
+ Slog.v(TAG,"******Install Blacklist Mode******");
+ List<String>packageBlackList = Arrays.asList(blockPacakges.split(";"));
+ if(packageBlackList.contains(pkgLite.packageName)){
+ Slog.v(TAG,"======Install Block!=====" + pkgLite.packageName);
+ ret = PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE;
+ }
+ for (int i = 0; i < packageBlackList.size(); i++) {
+ Slog.v(TAG,"=====Blacklist Package:" + packageBlackList.get(i) + "\n");
+ }
+ }else{
+ Slog.v(TAG,"******Install Block Disabled Mode*********");
+ }
+ //add end by jackly 2020-5-15
                 if (DEBUG_EPHEMERAL && ephemeral) {
                     Slog.v(TAG, "pkgLite for install: " + pkgLite);
                 }
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index 0b882c1..fece749 100755
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -1898,6 +1898,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
  filter.addAction("ads.android.setreboot.action");
  filter.addAction("rk.android.realsleepmode.action");
  filter.addAction("android.intent.action.ACTION_SHUTDOWN");
+ filter.addAction("rk.android.setinstallpackage.action");
         context.registerReceiver(mDreamReceiver, filter);
 
         filter = new IntentFilter();
@@ -6825,9 +6828,85 @@ public class PhoneWindowManager implements WindowManagerPolicy {
  CatKmsgHelper mCatKmsgHelper = CatKmsgHelper.getInstance(mContext,null);
  mCatKmsgHelper.destroyThread();
  mCatKmsgHelper.start(true);
+ }else if("rk.android.setinstallpackage.action".equals(intent.getAction())){
+ ContentResolver contentResolver = mContext.getContentResolver();
+ Bundle bundle = intent.getBundleExtra("intallBlock");
+ if(bundle != null){
+ int mode = bundle.getInt("intallBlockMode");
+ String packages = bundle.getString("intallBlockPackages");
+ if(packages != null && !packages.equals("")){
+ Settings.System.putString(contentResolver, Settings.System.BLOCK_INSTALL_PACKAGE_LIST, packages);
+ }else{
+ mode = 0;
+ Settings.System.putString(contentResolver, Settings.System.BLOCK_INSTALL_PACKAGE_LIST, null);
+ }
+ Settings.System.putInt(contentResolver, Settings.System.BLOCK_INSTALL_PACKAGE_MODE, mode);
+ Log.d(TAG,"-----intallBlock------mode:" + mode + "-------packages:" + packages);
+ }else{
+ Log.d(TAG,"-----intallBlock disabled-----");
+ Settings.System.putInt(contentResolver, Settings.System.BLOCK_INSTALL_PACKAGE_MODE, 0);
+ Settings.System.putString(contentResolver, Settings.System.BLOCK_INSTALL_PACKAGE_LIST, null);
+ }
  }
         }
     };
  //add by Winston
  private String set_alarm_mode_path = "/sys/bus/i2c/drivers/rtc_hym8563/set_alarm_mode";
  public boolean setRtcTime(int week,int h,int m) {
--
1.9.1


附件名称/大小 下载次数 最后更新
App-install-white-list-and-black-list-API.rar (3KB)  6 2020-05-15 15:00
[url]http://190.lsal.cn/195/1329.gif?0728100424873[/url]
沙发#
发布于:2020-12-30 10:35
用户被禁言,该主题自动屏蔽!
游客

返回顶部