这个修改是客制化的需求 没啥可说 需要的可以参考思路。
这个 修改主要在 Android 系统中添加了两个开关,一个用于控制 APK 的安装,另一个用于控制 APK 的下载。
修改的文件:
frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java
packages/providers/DownloadProvider/src/com/android/providers/downloads/DownloadProvider.java
文件修改说明:
PackageManagerService.java
: 在createDataDirsLI
方法中,添加了一个开关APK_install_finish_switch
。当此开关为 true 时,如果系统 APK 安装完成 (APK_install_finish
为 true),则禁止安装任何 APK。DownloadProvider.java
: 在insert
方法中,添加了一个开关DISABLE_DOWNLOAD_SWITCH
。当此开关为 true 时,禁止下载任何 APK 文件。
--- .../com/android/server/pm/PackageManagerService.java | 12 ++++++++---- .../providers/downloads/DownloadProvider.java | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java b/frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java index dfbb040..48fd384 100755 --- a/frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java @@ -256,6 +256,8 @@ public class PackageManagerService extends IPackageManager.Stub { private static boolean DEBUG_PERMISSION = false; //shh add private static boolean APK_install_finish = false; + //apk disable install switch + private static boolean APK_install_finish_switch= false; private static final int RADIO_UID = Process.PHONE_UID; private static final int LOG_UID = Process.LOG_UID; private static final int NFC_UID = Process.NFC_UID; @@ -5443,10 +5445,12 @@ public class PackageManagerService extends IPackageManager.Stub { private int createDataDirsLI(String packageName, int uid, String seinfo) { int[] users = sUserManager.getUserIds(); //如果系统APK安装完成,则禁止安装任何APK - if(APK_install_finish) - { - return PackageManager.INSTALL_FAILED_INVALID_APK; - } + if(APK_install_finish_switch){ + if(APK_install_finish) + { + return PackageManager.INSTALL_FAILED_INVALID_APK; + } + } int res = mInstaller.install(packageName, uid, uid, seinfo); if (res < 0) { return res; diff --git a/packages/providers/DownloadProvider/src/com/android/providers/downloads/DownloadProvider.java b/packages/providers/DownloadProvider/src/com/android/providers/downloads/DownloadProvider.java index 098961c..21dcd32 100755 --- a/packages/providers/DownloadProvider/src/com/android/providers/downloads/DownloadProvider.java +++ b/packages/providers/DownloadProvider/src/com/android/providers/downloads/DownloadProvider.java @@ -578,7 +578,7 @@ public final class DownloadProvider extends ContentProvider { } } } - + private static boolean DISABLE_DOWNLOAD_SWITCH = false; /** * Inserts a row in the database */ @@ -593,15 +593,15 @@ public final class DownloadProvider extends ContentProvider { Log.d(Constants.TAG, "calling insert on an unknown/invalid URI: " + uri); throw new IllegalArgumentException("Unknown/Invalid URI " + uri); } - - String mimeType = values.getAsString(Downloads.Impl.COLUMN_MIME_TYPE); - for (String str: APK_MIMETYPE){ - if(mimeType.equals(str)){ - Log.d(Constants.TAG, "do not download apk MIMETYPE "+ str); - return null; - } - } - + if(DISABLE_DOWNLOAD_SWITCH){ + String mimeType = values.getAsString(Downloads.Impl.COLUMN_MIME_TYPE); + for (String str: APK_MIMETYPE){ + if(mimeType.equals(str)){ + Log.d(Constants.TAG, "do not download apk MIMETYPE "+ str); + return null; + } + } + } // copy some of the input values as it ContentValues filteredValues = new ContentValues(); --