android7.1 针对某个apk静默安装升级

该方式在rk3288 7.1平台实现,针对某个apk实现静默安装升级等操作,其他的第三方apk仍然实行手动授权安装。

packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java

private void initiateInstall() {
        String pkgName = mPkgInfo.packageName;
        // Check if there is already a package on the device with this name
        // but it has been renamed to something else.
        String[] oldName = mPm.canonicalToCurrentPackageNames(new String[] { pkgName });
        if (oldName != null && oldName.length > 0 && oldName[0] != null) {
            pkgName = oldName[0];
            mPkgInfo.packageName = pkgName;
            mPkgInfo.applicationInfo.packageName = pkgName;
        }
        // Check if package is already installed. display confirmation dialog if replacing pkg
        try {
            // This is a little convoluted because we want to get all uninstalled
            // apps, but this may include apps with just data, and if it is just
            // data we still want to count it as "installed".
            mAppInfo = mPm.getApplicationInfo(pkgName,
                    PackageManager.GET_UNINSTALLED_PACKAGES);
            if ((mAppInfo.flags&ApplicationInfo.FLAG_INSTALLED) == 0) {
                mAppInfo = null;
            }
        } catch (NameNotFoundException e) {
            mAppInfo = null;
        }

-
-        startInstallConfirm();
+                               if(pkgName.equals("com.android.test")){/*这句替换成要静默安装的apk的包名就可以了*/
+                                               Log.i("==test==", "application upgrade sliently");
+                                               startInstall();
+                               }else{
+                                               startInstallConfirm();
+                               }
+        
     }

你可能感兴趣的:(rk3288)