Loading core/tests/coretests/src/android/content/pm/PackageManagerTests.java +43 −0 Original line number Diff line number Diff line Loading @@ -2346,6 +2346,49 @@ public class PackageManagerTests extends AndroidTestCase { } } /* This test installs an application on sdcard and unmounts media. * The app is then re-installed on internal storage. The sdcard is mounted * and verified that the re-installation on internal storage takes precedence. */ @MediumTest public void testInstallSdcardStaleContainerReinstall() { boolean origMediaState = getMediaState(); try { // Mount media first mountMedia(); String outFileName = "install.apk"; int rawResId = R.raw.install; PackageManager pm = mContext.getPackageManager(); File filesDir = mContext.getFilesDir(); File outFile = new File(filesDir, outFileName); Uri packageURI = getInstallablePackage(rawResId, outFile); PackageParser.Package pkg = parsePackage(packageURI); assertNotNull(pkg); // Install an app on sdcard. installFromRawResource(outFileName, rawResId, PackageManager.INSTALL_EXTERNAL, false, false, -1, PackageInfo.INSTALL_LOCATION_UNSPECIFIED); // Unmount sdcard unmountMedia(); // Reinstall the app and make sure it gets installed on internal storage. installFromRawResource(outFileName, rawResId, PackageManager.INSTALL_REPLACE_EXISTING, false, false, -1, PackageInfo.INSTALL_LOCATION_UNSPECIFIED); mountMedia(); // Verify that the app installed is on internal storage. assertInstall(pkg, 0, PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY); } catch (Exception e) { failStr(e.getMessage()); } finally { if (origMediaState) { mountMedia(); } else { unmountMedia(); } } } /* * The following series of tests are related to upgrading apps with * different certificates. Loading services/java/com/android/server/PackageManagerService.java +6 −3 Original line number Diff line number Diff line Loading @@ -5340,13 +5340,13 @@ class PackageManagerService extends IPackageManager.Stub { } SdInstallArgs(String cid) { super(null, null, PackageManager.INSTALL_EXTERNAL, null); this.cid = cid; this((Uri)null, cid); } SdInstallArgs(Uri packageURI, String cid) { super(packageURI, null, PackageManager.INSTALL_EXTERNAL, null); this.cid = cid; cachePath = PackageHelper.getSdDir(cid); } void createCopyFile() { Loading Loading @@ -9608,7 +9608,10 @@ class PackageManagerService extends IPackageManager.Stub { } if (DEBUG_SD_INSTALL) Log.i(TAG, "Looking for pkg : " + pkgName); PackageSetting ps = mSettings.mPackages.get(pkgName); if (ps != null && ps.codePathString != null) { // The package status is changed only if the code path // matches between settings and the container id. if (ps != null && ps.codePathString != null && ps.codePathString.equals(args.getCodePath())) { if (DEBUG_SD_INSTALL) Log.i(TAG, "Container : " + cid + " corresponds to pkg : " + pkgName + " at code path: " + ps.codePathString); Loading Loading
core/tests/coretests/src/android/content/pm/PackageManagerTests.java +43 −0 Original line number Diff line number Diff line Loading @@ -2346,6 +2346,49 @@ public class PackageManagerTests extends AndroidTestCase { } } /* This test installs an application on sdcard and unmounts media. * The app is then re-installed on internal storage. The sdcard is mounted * and verified that the re-installation on internal storage takes precedence. */ @MediumTest public void testInstallSdcardStaleContainerReinstall() { boolean origMediaState = getMediaState(); try { // Mount media first mountMedia(); String outFileName = "install.apk"; int rawResId = R.raw.install; PackageManager pm = mContext.getPackageManager(); File filesDir = mContext.getFilesDir(); File outFile = new File(filesDir, outFileName); Uri packageURI = getInstallablePackage(rawResId, outFile); PackageParser.Package pkg = parsePackage(packageURI); assertNotNull(pkg); // Install an app on sdcard. installFromRawResource(outFileName, rawResId, PackageManager.INSTALL_EXTERNAL, false, false, -1, PackageInfo.INSTALL_LOCATION_UNSPECIFIED); // Unmount sdcard unmountMedia(); // Reinstall the app and make sure it gets installed on internal storage. installFromRawResource(outFileName, rawResId, PackageManager.INSTALL_REPLACE_EXISTING, false, false, -1, PackageInfo.INSTALL_LOCATION_UNSPECIFIED); mountMedia(); // Verify that the app installed is on internal storage. assertInstall(pkg, 0, PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY); } catch (Exception e) { failStr(e.getMessage()); } finally { if (origMediaState) { mountMedia(); } else { unmountMedia(); } } } /* * The following series of tests are related to upgrading apps with * different certificates. Loading
services/java/com/android/server/PackageManagerService.java +6 −3 Original line number Diff line number Diff line Loading @@ -5340,13 +5340,13 @@ class PackageManagerService extends IPackageManager.Stub { } SdInstallArgs(String cid) { super(null, null, PackageManager.INSTALL_EXTERNAL, null); this.cid = cid; this((Uri)null, cid); } SdInstallArgs(Uri packageURI, String cid) { super(packageURI, null, PackageManager.INSTALL_EXTERNAL, null); this.cid = cid; cachePath = PackageHelper.getSdDir(cid); } void createCopyFile() { Loading Loading @@ -9608,7 +9608,10 @@ class PackageManagerService extends IPackageManager.Stub { } if (DEBUG_SD_INSTALL) Log.i(TAG, "Looking for pkg : " + pkgName); PackageSetting ps = mSettings.mPackages.get(pkgName); if (ps != null && ps.codePathString != null) { // The package status is changed only if the code path // matches between settings and the container id. if (ps != null && ps.codePathString != null && ps.codePathString.equals(args.getCodePath())) { if (DEBUG_SD_INSTALL) Log.i(TAG, "Container : " + cid + " corresponds to pkg : " + pkgName + " at code path: " + ps.codePathString); Loading