Android禁止安装三方应用(屏蔽所有安装应用的方式)

android系统安装应用有四种方式

1.系统应用安装――开机时完成,没有安装界面

2.网络下载应用安装――通过market应用完成,没有安装界面

3.ADB工具安装――没有安装界面。

4.第三方应用安装――通过现有的APK文件安装,有安装界面,由packageinstaller.apk应用处理安装及卸载过程的界面。

1.禁止ADB和应用商店安装由“frameworks\base\services\core\java\com\android\server\pm\PackageManagerService.java”来控制安装

需要屏蔽的话,只需要修改这个文件里边的代码。

  //禁止第三方应用安装的标志
private boolean APK_INSTALL_FINISH = SystemProperties.getBoolean("persist.sys.horion.apk.install", false);
 class PackageHandler extends Handler{
                    .......
 void doHandleMessage(Message msg) {
            switch (msg.what) {
                case INIT_COPY: {
         ++++       if(APK_INSTALL_FINISH){
         ++++               return ;
         ++++           }
                    HandlerParams params = (HandlerParams) msg.obj;
                    int idx = mPendingInstalls.size();
                    if (DEBUG_INSTALL) Slog.i(TAG, "init_copy idx=" + idx + ": " + params);
                    ........
            }
        }
    }
}

 

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;
            // 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
}

在构造函数中这个位置将APK_INSTALL_FINISH设置为true,此时系统内置应用完成了安装。PackageManagerService.java  PackageHandler中做处理,如果APK_INSTALL_FINISH为true 禁止安装。至此,就完成了禁止禁止ADB和应用商店安装的屏蔽

2.禁止手动安装

手动安装由\packages\apps\PackageInstaller完成,禁止手动安装只需要在这里边处理,在InstallStart.java中

//禁止第三方应用安装的标志
    private boolean APK_INSTALL_FINISH = SystemProperties.getBoolean("persist.sys.horion.apk.install", false);
public class InstallStart extends Activity {
                ........

        if (nextActivity != null) {
++++            if(!APK_INSTALL_FINISH) {
//          startActivity(nextActivity);
++++            Toast.makeText(InstallStart.this, android.R.string.prohibit_install_message, 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();
    }
.......
}

完成对手动安装apk的屏蔽

你可能感兴趣的:(android)