Android11.0禁止安装apk功能-创新互联

之前在做系统项目的时候遇到一个客户要求禁止掉安装apk的功能,就是不想让用户去安装任何第三方的app,其实apk的安装有好几个通道方法,如下两种都给禁止掉基本就能满足客户需求了

10年积累的成都网站设计、成都网站建设、外贸网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先做网站设计后付款的网站建设流程,更有木兰免费网站建设让你可以放心的选择与我们合作。

1. 禁掉机器中识别到的apk文件的安装 ,修改如下:

diff --git a/packages/PackageInstaller/src/com/android/packageinstaller/InstallStart.java b/packages/PackageInstaller/src/com/android/packageinstaller/InstallStart.java
old mode 100644
new mode 100755
index 0b8de6c..e45cb56
--- a/packages/PackageInstaller/src/com/android/packageinstaller/InstallStart.java
+++ b/packages/PackageInstaller/src/com/android/packageinstaller/InstallStart.java
@@ -38,6 +38,8 @@ import android.os.RemoteException;
 import android.os.UserManager;
 import android.permission.IPermissionManager;
 import android.util.Log;
+import android.widget.Toast;
+
 
 import java.util.List;
 
@@ -53,6 +55,7 @@ public class InstallStart extends Activity {
     private IPermissionManager mIPermissionManager;
     private UserManager mUserManager;
     private boolean mAbortInstall = false;
+	private boolean APK_INSTALL_FINISH = false;
 
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -150,7 +153,16 @@ public class InstallStart extends Activity {
         }
 
         if (nextActivity != null) {
-            startActivity(nextActivity);
+            if(!APK_INSTALL_FINISH) {
+	          	//startActivity(nextActivity);
+            	Toast.makeText(InstallStart.this, "禁止安装", Toast.LENGTH_LONG).show();
+            	Intent result = new Intent();
+           	 	result.putExtra(Intent.EXTRA_INSTALL_RESULT,
+                PackageManager.INSTALL_FAILED_INVALID_URI);
+            	setResult(RESULT_FIRST_USER, result);
+            } else{
+                startActivity(nextActivity);
+            }
         }
         finish();
     }

2. 禁掉adb命令安装apk,修改如下:

diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
old mode 100644
new mode 100755
index 31edaa0..4eaa570
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -495,6 +495,8 @@ public class PackageManagerService extends IPackageManager.Stub
     private static final boolean DEBUG_SHARED_LIBRARIES = false;
     public static final boolean DEBUG_COMPRESSION = Build.IS_DEBUGGABLE;
 
+	private boolean SYSTEM_APK_INSTALL_FINISH = false;
+
     // Debug output for dexopting. This is shared between PackageManagerService, OtaDexoptService
     // and PackageDexOptimizer. All these classes have their own flag to allow switching a single
     // user, but by default initialize to this.
@@ -1690,6 +1692,9 @@ public class PackageManagerService extends IPackageManager.Stub
         void doHandleMessage(Message msg) {
             switch (msg.what) {
                 case INIT_COPY: {
+					if(SYSTEM_APK_INSTALL_FINISH){
+                        return ;
+                    }
                     HandlerParams params = (HandlerParams) msg.obj;
                     if (params != null) {
                         if (DEBUG_INSTALL) Slog.i(TAG, "init_copy: " + params);
@@ -3444,6 +3449,7 @@ public class PackageManagerService extends IPackageManager.Stub
                     + ((SystemClock.uptimeMillis()-startTime)/1000f)
                     + " seconds");
 
+			SYSTEM_APK_INSTALL_FINISH = true;
             // If the platform SDK has changed since the last time we booted,
             // we need to re-grant app permission to catch any new ones that
             // appear.  This is really a hack, and means that apps can in some

以上两个通道给禁掉了,基本都能满足客户的需求了,一般用户也不会adb命令,但是我们还能尽所能去全面禁掉

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


文章标题:Android11.0禁止安装apk功能-创新互联
浏览路径:http://scjbc.cn/article/ecjhd.html

其他资讯