1. 程式人生 > >Android O 裝置不允許安裝第三方APP

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