Android O 设备不允许安装第三方APP

  1. 屏蔽手动安装APK
    vendor/mediatek/proprietary/packages/apps/PackageInstaller/src/com/android/packageinstaller/InstallStart.java
public class InstallStart extends Activity {
         ......
         if (nextActivity != null) {
-            startActivity(nextActivity);
+            //startActivity(nextActivity);
+            Toast.makeText(InstallStart.this,R.string.not_allowed_install_apk,Toast.LENGTH_SHORT).show();
+            Intent result = new Intent();
+            result.putExtra(Intent.EXTRA_INSTALL_RESULT,
+                    PackageManager.INSTALL_FAILED_INVALID_URI);
+            setResult(RESULT_FIRST_USER, result);
         }
         finish();
     }

  1. 禁止ADB或第三方商店下载安装
    frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java
+    private  boolean APK_INSTALL_FINISH = false;
 class PackageHandler extends Handler {
	 	...
	 	 void doHandleMessage(Message msg) {
            switch (msg.what) {
                case INIT_COPY: {
					//add
                	if(APK_INSTALL_FINISH && getNvRam()){
                    	return;
                    }
					//end
                    HandlerParams params = (HandlerParams) msg.obj;
                    int idx = mPendingInstalls.size();
public PackageManagerService(Context context, Installer installer,
            boolean factoryTest, boolean onlyCore) {
            ......
             sMtkSystemServerIns.addBootEvent("Android:PMS_scan_END");
            Slog.i(TAG, "Time to scan packages: "
                    + ((SystemClock.uptimeMillis()-startTime)/1000f)
                    + " seconds");
             APK_INSTALL_FINISH = true;//add
            // 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

你可能感兴趣的:(Android O 设备不允许安装第三方APP)