summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSuchi Amalapurapu <asuchitra@google.com>2010-03-17 18:50:29 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-03-17 18:50:29 -0700
commitd3dd518baf87f06a571e56d9a127b043cf719e23 (patch)
treea268fe0a59afe5c4615423d9dd27ea13280cfb8f /tests
parentf43eab142df7d3096f299d34c9e5713200332392 (diff)
parent14b6abda1309631d49d4bebbb0317a7e1dfc0a50 (diff)
downloadframeworks_base-d3dd518baf87f06a571e56d9a127b043cf719e23.zip
frameworks_base-d3dd518baf87f06a571e56d9a127b043cf719e23.tar.gz
frameworks_base-d3dd518baf87f06a571e56d9a127b043cf719e23.tar.bz2
Merge "Add new install flag to install on internal flash only Change default install location policy for new flag. New error code for media unavailable."
Diffstat (limited to 'tests')
-rwxr-xr-xtests/AndroidTests/src/com/android/unit_tests/PackageManagerTests.java676
1 files changed, 623 insertions, 53 deletions
diff --git a/tests/AndroidTests/src/com/android/unit_tests/PackageManagerTests.java b/tests/AndroidTests/src/com/android/unit_tests/PackageManagerTests.java
index a06a13b..b988920 100755
--- a/tests/AndroidTests/src/com/android/unit_tests/PackageManagerTests.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/PackageManagerTests.java
@@ -78,6 +78,7 @@ public class PackageManagerTests extends AndroidTestCase {
private static final int APP_INSTALL_AUTO = PackageHelper.APP_INSTALL_AUTO;
private static final int APP_INSTALL_DEVICE = PackageHelper.APP_INSTALL_INTERNAL;
private static final int APP_INSTALL_SDCARD = PackageHelper.APP_INSTALL_EXTERNAL;
+ private boolean mOrigState;
void failStr(String errMsg) {
Log.w(TAG, "errMsg="+errMsg);
@@ -91,6 +92,21 @@ public class PackageManagerTests extends AndroidTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
+ mOrigState = getMediaState();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ // Restore media state.
+ boolean newState = getMediaState();
+ if (newState != mOrigState) {
+ if (mOrigState) {
+ getMs().mountVolume(Environment.getExternalStorageDirectory().getPath());
+ } else {
+ getMs().unmountVolume(Environment.getExternalStorageDirectory().getPath(), true);
+ }
+ }
+ super.tearDown();
}
private class PackageInstallObserver extends IPackageInstallObserver.Stub {
@@ -254,21 +270,70 @@ public class PackageManagerTests extends AndroidTestCase {
packageParser = null;
return pkg;
}
- private boolean getInstallLoc(int flags, int expInstallLocation) {
+ private boolean checkSd(long pkgLen) {
+ String status = Environment.getExternalStorageState();
+ if (!status.equals(Environment.MEDIA_MOUNTED)) {
+ return false;
+ }
+ long sdSize = -1;
+ StatFs sdStats = new StatFs(
+ Environment.getExternalStorageDirectory().getPath());
+ sdSize = (long)sdStats.getAvailableBlocks() *
+ (long)sdStats.getBlockSize();
+ // TODO check for thesholds here
+ return pkgLen <= sdSize;
+
+ }
+ private boolean checkInt(long pkgLen) {
+ StatFs intStats = new StatFs(Environment.getDataDirectory().getPath());
+ long intSize = (long)intStats.getBlockCount() *
+ (long)intStats.getBlockSize();
+ long iSize = (long)intStats.getAvailableBlocks() *
+ (long)intStats.getBlockSize();
+ // TODO check for thresholds here?
+ return pkgLen <= iSize;
+ }
+ private static final int INSTALL_LOC_INT = 1;
+ private static final int INSTALL_LOC_SD = 2;
+ private static final int INSTALL_LOC_ERR = -1;
+ private int getInstallLoc(int flags, int expInstallLocation, long pkgLen) {
// Flags explicitly over ride everything else.
if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0 ) {
- return false;
+ return INSTALL_LOC_INT;
} else if ((flags & PackageManager.INSTALL_EXTERNAL) != 0 ) {
- return true;
+ return INSTALL_LOC_SD;
+ } else if ((flags & PackageManager.INSTALL_INTERNAL) != 0) {
+ return INSTALL_LOC_INT;
}
// Manifest option takes precedence next
if (expInstallLocation == PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL) {
- return true;
+ // TODO fitsonSd check
+ if (checkSd(pkgLen)) {
+ return INSTALL_LOC_SD;
+ }
+ if (checkInt(pkgLen)) {
+ return INSTALL_LOC_INT;
+ }
+ return INSTALL_LOC_ERR;
}
if (expInstallLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) {
- return false;
+ if (checkInt(pkgLen)) {
+ return INSTALL_LOC_INT;
+ }
+ return INSTALL_LOC_ERR;
}
- // TODO Out of memory checks here.
+ if (expInstallLocation == PackageInfo.INSTALL_LOCATION_AUTO) {
+ // Check for free memory internally
+ if (checkInt(pkgLen)) {
+ return INSTALL_LOC_INT;
+ }
+ // Check for free memory externally
+ if (checkSd(pkgLen)) {
+ return INSTALL_LOC_SD;
+ }
+ return INSTALL_LOC_ERR;
+ }
+ // Check for settings preference.
boolean checkSd = false;
int setLoc = 0;
try {
@@ -284,46 +349,63 @@ public class PackageManagerTests extends AndroidTestCase {
failStr(e);
}
if (userPref == APP_INSTALL_DEVICE) {
- checkSd = false;
+ if (checkInt(pkgLen)) {
+ return INSTALL_LOC_INT;
+ }
+ return INSTALL_LOC_ERR;
} else if (userPref == APP_INSTALL_SDCARD) {
- checkSd = true;
+ if (checkSd(pkgLen)) {
+ return INSTALL_LOC_SD;
+ }
+ return INSTALL_LOC_ERR;
} else if (userPref == APP_INSTALL_AUTO) {
- // Might be determined dynamically. TODO fix this
- checkSd = false;
+ if (checkInt(pkgLen)) {
+ return INSTALL_LOC_INT;
+ }
+ // Check for free memory externally
+ if (checkSd(pkgLen)) {
+ return INSTALL_LOC_SD;
+ }
+ return INSTALL_LOC_ERR;
+
}
- }
- return checkSd;
+ }
+ return INSTALL_LOC_ERR;
}
private void assertInstall(PackageParser.Package pkg, int flags, int expInstallLocation) {
try {
String pkgName = pkg.packageName;
- ApplicationInfo info = getPm().getApplicationInfo(pkgName, 0);
- assertNotNull(info);
- assertEquals(pkgName, info.packageName);
- File dataDir = Environment.getDataDirectory();
- String appInstallPath = new File(dataDir, "app").getPath();
- String drmInstallPath = new File(dataDir, "app-private").getPath();
- File srcDir = new File(info.sourceDir);
- String srcPath = srcDir.getParent();
- File publicSrcDir = new File(info.publicSourceDir);
- String publicSrcPath = publicSrcDir.getParent();
-
- if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) {
- assertTrue((info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0);
- assertEquals(srcPath, drmInstallPath);
- assertEquals(publicSrcPath, appInstallPath);
- } else {
- assertFalse((info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0);
- if (!getInstallLoc(flags, expInstallLocation)) {
- assertEquals(srcPath, appInstallPath);
+ ApplicationInfo info = getPm().getApplicationInfo(pkgName, 0);
+ assertNotNull(info);
+ assertEquals(pkgName, info.packageName);
+ File dataDir = Environment.getDataDirectory();
+ String appInstallPath = new File(dataDir, "app").getPath();
+ String drmInstallPath = new File(dataDir, "app-private").getPath();
+ File srcDir = new File(info.sourceDir);
+ String srcPath = srcDir.getParent();
+ File publicSrcDir = new File(info.publicSourceDir);
+ String publicSrcPath = publicSrcDir.getParent();
+ long pkgLen = new File(info.sourceDir).length();
+
+ if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) {
+ assertTrue((info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0);
+ assertEquals(srcPath, drmInstallPath);
assertEquals(publicSrcPath, appInstallPath);
- assertFalse((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0);
} else {
- assertTrue((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0);
- assertTrue(srcPath.startsWith(SECURE_CONTAINERS_PREFIX));
- assertTrue(publicSrcPath.startsWith(SECURE_CONTAINERS_PREFIX));
+ assertFalse((info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0);
+ int rLoc = getInstallLoc(flags, expInstallLocation, pkgLen);
+ if (rLoc == INSTALL_LOC_INT) {
+ assertEquals(srcPath, appInstallPath);
+ assertEquals(publicSrcPath, appInstallPath);
+ assertFalse((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0);
+ } else if (rLoc == INSTALL_LOC_SD){
+ assertTrue((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0);
+ assertTrue(srcPath.startsWith(SECURE_CONTAINERS_PREFIX));
+ assertTrue(publicSrcPath.startsWith(SECURE_CONTAINERS_PREFIX));
+ } else {
+ // TODO handle error. Install should have failed.
+ }
}
- }
} catch (NameNotFoundException e) {
failStr("failed with exception : " + e);
}
@@ -396,8 +478,6 @@ public class PackageManagerTests extends AndroidTestCase {
} catch (Exception e) {
failStr(e);
}
- // Clean up the containers as well
- clearSecureContainersForPkg(pkg.packageName);
}
InstallParams ip = null;
try {
@@ -1047,19 +1127,6 @@ public class PackageManagerTests extends AndroidTestCase {
}
}
- public void xxxtestClearAllSecureContainers() {
- IMountService ms = getMs();
- try {
- String list[] = ms.getSecureContainerList();
- if (list != null) {
- for (String cid : list) {
- Log.i(TAG, "Destroying container " + cid);
- ms.destroySecureContainer(cid, false);
- }
- }
- } catch (RemoteException e) {}
- }
-
class MoveReceiver extends GenericReceiver {
String pkgName;
final static int INVALID = -1;
@@ -1185,7 +1252,7 @@ public class PackageManagerTests extends AndroidTestCase {
public void moveFromRawResource(int installFlags, int moveFlags,
int expRetCode) {
int origDefaultLoc = getInstallLoc();
- setInstallLoc(PackageInfo.INSTALL_LOCATION_AUTO);
+ setInstallLoc(PackageHelper.APP_INSTALL_AUTO);
// Install first
InstallParams ip = sampleInstallFromRawResource(installFlags, false);
ApplicationInfo oldAppInfo = null;
@@ -1255,7 +1322,7 @@ public class PackageManagerTests extends AndroidTestCase {
// Try to install and make sure an error code is returned.
assertNull(installFromRawResource("install.apk", R.raw.install,
PackageManager.INSTALL_EXTERNAL, false,
- true, PackageManager.INSTALL_FAILED_CONTAINER_ERROR,
+ true, PackageManager.INSTALL_FAILED_MEDIA_UNAVAILABLE,
PackageInfo.INSTALL_LOCATION_AUTO));
} finally {
// Restore original media state
@@ -1292,6 +1359,509 @@ public class PackageManagerTests extends AndroidTestCase {
}
/*---------- Recommended install location tests ----*/
+ /* Precedence: FlagManifestExistingUser
+ * PrecedenceSuffixes:
+ * Flag : FlagI, FlagE, FlagF
+ * I - internal, E - external, F - forward locked, Flag suffix absent if not using any option.
+ * Manifest: ManifestI, ManifestE, ManifestA, Manifest suffix absent if not using any option.
+ * Existing: Existing suffix absent if not existing.
+ * User: UserI, UserE, UserA, User suffix absent if not existing.
+ *
+ */
+ /*
+ * Install an app on internal flash
+ */
+ public void testFlagI() {
+ sampleInstallFromRawResource(PackageManager.INSTALL_INTERNAL, true);
+ }
+ /*
+ * Install an app on sdcard.
+ */
+ public void testFlagE() {
+ sampleInstallFromRawResource(PackageManager.INSTALL_EXTERNAL, true);
+ }
+
+ /*
+ * Install an app on sdcard.
+ */
+ public void testFlagF() {
+ sampleInstallFromRawResource(PackageManager.INSTALL_FORWARD_LOCK, true);
+ }
+ /*
+ * Install an app with both internal and external flags set. should fail
+ */
+ public void testFlagIE() {
+ installFromRawResource("install.apk", R.raw.install,
+ PackageManager.INSTALL_EXTERNAL | PackageManager.INSTALL_INTERNAL,
+ false,
+ true, PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION,
+ PackageInfo.INSTALL_LOCATION_AUTO);
+ }
+
+ /*
+ * Install an app with both internal and external flags set. should fail
+ */
+ public void testFlagIF() {
+ sampleInstallFromRawResource(PackageManager.INSTALL_FORWARD_LOCK |
+ PackageManager.INSTALL_INTERNAL, true);
+ }
+ /*
+ * Install an app with both internal and external flags set. should fail
+ */
+ public void testFlagEF() {
+ installFromRawResource("install.apk", R.raw.install,
+ PackageManager.INSTALL_FORWARD_LOCK | PackageManager.INSTALL_EXTERNAL,
+ false,
+ true, PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION,
+ PackageInfo.INSTALL_LOCATION_AUTO);
+ }
+ /*
+ * Install an app with both internal and external flags set. should fail
+ */
+ public void testFlagIEF() {
+ installFromRawResource("install.apk", R.raw.install,
+ PackageManager.INSTALL_FORWARD_LOCK | PackageManager.INSTALL_INTERNAL |
+ PackageManager.INSTALL_EXTERNAL,
+ false,
+ true, PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION,
+ PackageInfo.INSTALL_LOCATION_AUTO);
+ }
+ /*
+ * Install an app with both internal and manifest option set.
+ * should install on internal.
+ */
+ public void testFlagIManifestI() {
+ installFromRawResource("install.apk", R.raw.install_loc_internal,
+ PackageManager.INSTALL_INTERNAL,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY);
+ }
+ /*
+ * Install an app with both internal and manifest preference for
+ * preferExternal. Should install on internal.
+ */
+ public void testFlagIManifestE() {
+ installFromRawResource("install.apk", R.raw.install_loc_sdcard,
+ PackageManager.INSTALL_INTERNAL,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY);
+ }
+ /*
+ * Install an app with both internal and manifest preference for
+ * auto. should install internal.
+ */
+ public void testFlagIManifestA() {
+ installFromRawResource("install.apk", R.raw.install_loc_auto,
+ PackageManager.INSTALL_INTERNAL,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY);
+ }
+ /*
+ * Install an app with both external and manifest option set.
+ * should install externally.
+ */
+ public void testFlagEManifestI() {
+ installFromRawResource("install.apk", R.raw.install_loc_internal,
+ PackageManager.INSTALL_EXTERNAL,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL);
+ }
+ /*
+ * Install an app with both external and manifest preference for
+ * preferExternal. Should install externally.
+ */
+ public void testFlagEManifestE() {
+ installFromRawResource("install.apk", R.raw.install_loc_sdcard,
+ PackageManager.INSTALL_EXTERNAL,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL);
+ }
+ /*
+ * Install an app with both external and manifest preference for
+ * auto. should install on external media.
+ */
+ public void testFlagEManifestA() {
+ installFromRawResource("install.apk", R.raw.install_loc_auto,
+ PackageManager.INSTALL_EXTERNAL,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL);
+ }
+ /*
+ * Install an app with fwd locked flag set and install location set to
+ * internal. should install internally.
+ */
+ public void testFlagFManifestI() {
+ installFromRawResource("install.apk", R.raw.install_loc_internal,
+ PackageManager.INSTALL_EXTERNAL,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL);
+ }
+ /*
+ * Install an app with fwd locked flag set and install location set to
+ * preferExternal. should install internally.
+ */
+ public void testFlagFManifestE() {
+ installFromRawResource("install.apk", R.raw.install_loc_sdcard,
+ PackageManager.INSTALL_EXTERNAL,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL);
+ }
+ /*
+ * Install an app with fwd locked flag set and install location set to
+ * auto. should install internally.
+ */
+ public void testFlagFManifestA() {
+ installFromRawResource("install.apk", R.raw.install_loc_auto,
+ PackageManager.INSTALL_EXTERNAL,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL);
+ }
+ /* The following test functions verify install location for existing apps.
+ * ie existing app can be installed internally or externally. If install
+ * flag is explicitly set it should override current location. If manifest location
+ * is set, that should over ride current location too. if not the existing install
+ * location should be honoured.
+ * testFlagI/E/F/ExistingI/E -
+ */
+ public void testFlagIExistingI() {
+ int iFlags = PackageManager.INSTALL_INTERNAL;
+ int rFlags = PackageManager.INSTALL_INTERNAL | PackageManager.INSTALL_REPLACE_EXISTING;
+ // First install.
+ installFromRawResource("install.apk", R.raw.install,
+ iFlags,
+ false,
+ false, -1,
+ -1);
+ // Replace now
+ installFromRawResource("install.apk", R.raw.install,
+ rFlags,
+ true,
+ false, -1,
+ -1);
+ }
+ public void testFlagIExistingE() {
+ int iFlags = PackageManager.INSTALL_EXTERNAL;
+ int rFlags = PackageManager.INSTALL_INTERNAL | PackageManager.INSTALL_REPLACE_EXISTING;
+ // First install.
+ installFromRawResource("install.apk", R.raw.install,
+ iFlags,
+ false,
+ false, -1,
+ -1);
+ // Replace now
+ installFromRawResource("install.apk", R.raw.install,
+ rFlags,
+ true,
+ false, -1,
+ -1);
+ }
+ public void testFlagEExistingI() {
+ int iFlags = PackageManager.INSTALL_INTERNAL;
+ int rFlags = PackageManager.INSTALL_EXTERNAL | PackageManager.INSTALL_REPLACE_EXISTING;
+ // First install.
+ installFromRawResource("install.apk", R.raw.install,
+ iFlags,
+ false,
+ false, -1,
+ -1);
+ // Replace now
+ installFromRawResource("install.apk", R.raw.install,
+ rFlags,
+ true,
+ false, -1,
+ -1);
+ }
+ public void testFlagEExistingE() {
+ int iFlags = PackageManager.INSTALL_EXTERNAL;
+ int rFlags = PackageManager.INSTALL_EXTERNAL | PackageManager.INSTALL_REPLACE_EXISTING;
+ // First install.
+ installFromRawResource("install.apk", R.raw.install,
+ iFlags,
+ false,
+ false, -1,
+ -1);
+ // Replace now
+ installFromRawResource("install.apk", R.raw.install,
+ rFlags,
+ true,
+ false, -1,
+ -1);
+ }
+ public void testFlagFExistingI() {
+ int iFlags = PackageManager.INSTALL_INTERNAL;
+ int rFlags = PackageManager.INSTALL_FORWARD_LOCK | PackageManager.INSTALL_REPLACE_EXISTING;
+ // First install.
+ installFromRawResource("install.apk", R.raw.install,
+ iFlags,
+ false,
+ false, -1,
+ -1);
+ // Replace now
+ installFromRawResource("install.apk", R.raw.install,
+ rFlags,
+ true,
+ false, -1,
+ -1);
+ }
+ public void testFlagFExistingE() {
+ int iFlags = PackageManager.INSTALL_EXTERNAL;
+ int rFlags = PackageManager.INSTALL_FORWARD_LOCK | PackageManager.INSTALL_REPLACE_EXISTING;
+ // First install.
+ installFromRawResource("install.apk", R.raw.install,
+ iFlags,
+ false,
+ false, -1,
+ -1);
+ // Replace now
+ installFromRawResource("install.apk", R.raw.install,
+ rFlags,
+ true,
+ false, -1,
+ -1);
+ }
+ /*
+ * The following set of tests verify the installation of apps with
+ * install location attribute set to internalOnly, preferExternal and auto.
+ * The manifest option should dictate the install location.
+ * public void testManifestI/E/A
+ * TODO out of memory fall back behaviour.
+ */
+ public void testManifestI() {
+ installFromRawResource("install.apk", R.raw.install_loc_internal,
+ 0,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY);
+ }
+ public void testManifestE() {
+ installFromRawResource("install.apk", R.raw.install_loc_sdcard,
+ 0,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL);
+ }
+ public void testManifestA() {
+ installFromRawResource("install.apk", R.raw.install_loc_auto,
+ 0,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY);
+ }
+ /*
+ * The following set of tests verify the installation of apps
+ * with install location attribute set to internalOnly, preferExternal and auto
+ * for already existing apps. The manifest option should take precedence.
+ * TODO add out of memory fall back behaviour.
+ * testManifestI/E/AExistingI/E
+ */
+ public void testManifestIExistingI() {
+ int iFlags = PackageManager.INSTALL_INTERNAL;
+ int rFlags = PackageManager.INSTALL_REPLACE_EXISTING;
+ // First install.
+ installFromRawResource("install.apk", R.raw.install,
+ iFlags,
+ false,
+ false, -1,
+ -1);
+ // Replace now
+ installFromRawResource("install.apk", R.raw.install_loc_internal,
+ rFlags,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY);
+ }
+ public void testManifestIExistingE() {
+ int iFlags = PackageManager.INSTALL_EXTERNAL;
+ int rFlags = PackageManager.INSTALL_REPLACE_EXISTING;
+ // First install.
+ installFromRawResource("install.apk", R.raw.install,
+ iFlags,
+ false,
+ false, -1,
+ -1);
+ // Replace now
+ installFromRawResource("install.apk", R.raw.install_loc_internal,
+ rFlags,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY);
+ }
+ public void testManifestEExistingI() {
+ int iFlags = PackageManager.INSTALL_INTERNAL;
+ int rFlags = PackageManager.INSTALL_REPLACE_EXISTING;
+ // First install.
+ installFromRawResource("install.apk", R.raw.install,
+ iFlags,
+ false,
+ false, -1,
+ -1);
+ // Replace now
+ installFromRawResource("install.apk", R.raw.install_loc_sdcard,
+ rFlags,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL);
+ }
+ public void testManifestEExistingE() {
+ int iFlags = PackageManager.INSTALL_EXTERNAL;
+ int rFlags = PackageManager.INSTALL_REPLACE_EXISTING;
+ // First install.
+ installFromRawResource("install.apk", R.raw.install,
+ iFlags,
+ false,
+ false, -1,
+ -1);
+ // Replace now
+ installFromRawResource("install.apk", R.raw.install_loc_sdcard,
+ rFlags,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL);
+ }
+ public void testManifestAExistingI() {
+ int iFlags = PackageManager.INSTALL_INTERNAL;
+ int rFlags = PackageManager.INSTALL_REPLACE_EXISTING;
+ // First install.
+ installFromRawResource("install.apk", R.raw.install,
+ iFlags,
+ false,
+ false, -1,
+ -1);
+ // Replace now
+ installFromRawResource("install.apk", R.raw.install_loc_auto,
+ rFlags,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_AUTO);
+ }
+ public void testManifestAExistingE() {
+ int iFlags = PackageManager.INSTALL_EXTERNAL;
+ int rFlags = PackageManager.INSTALL_REPLACE_EXISTING;
+ // First install.
+ installFromRawResource("install.apk", R.raw.install,
+ iFlags,
+ false,
+ false, -1,
+ -1);
+ // Replace now
+ installFromRawResource("install.apk", R.raw.install_loc_auto,
+ rFlags,
+ true,
+ false, -1,
+ PackageInfo.INSTALL_LOCATION_AUTO);
+ }
+ /*
+ * The following set of tests check install location for existing
+ * application based on user setting.
+ */
+ private void setExistingXUserX(int userSetting, int iFlags) {
+ int rFlags = PackageManager.INSTALL_REPLACE_EXISTING;
+ // First install.
+ installFromRawResource("install.apk", R.raw.install,
+ iFlags,
+ false,
+ false, -1,
+ -1);
+ // Watch out for this.
+ int iloc = PackageInfo.INSTALL_LOCATION_AUTO;
+ if ((iFlags & PackageManager.INSTALL_INTERNAL) != 0) {
+ iloc = PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY;
+ } else if ((iFlags & PackageManager.INSTALL_EXTERNAL) != 0) {
+ iloc = PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL;
+ }
+ int origSetting = getInstallLoc();
+ try {
+ // Set user setting
+ setInstallLoc(userSetting);
+ // Replace now
+ installFromRawResource("install.apk", R.raw.install,
+ rFlags,
+ true,
+ false, -1,
+ iloc);
+ } finally {
+ setInstallLoc(origSetting);
+ }
+ }
+ public void testExistingIUserI() {
+ int userSetting = PackageHelper.APP_INSTALL_INTERNAL;
+ int iFlags = PackageManager.INSTALL_INTERNAL;
+ setExistingXUserX(userSetting, iFlags);
+ }
+ public void testExistingIUserE() {
+ int userSetting = PackageHelper.APP_INSTALL_EXTERNAL;
+ int iFlags = PackageManager.INSTALL_INTERNAL;
+ setExistingXUserX(userSetting, iFlags);
+ }
+ public void testExistingIUserA() {
+ int userSetting = PackageHelper.APP_INSTALL_AUTO;
+ int iFlags = PackageManager.INSTALL_INTERNAL;
+ setExistingXUserX(userSetting, iFlags);
+ }
+ public void testExistingEUserI() {
+ int userSetting = PackageHelper.APP_INSTALL_INTERNAL;
+ int iFlags = PackageManager.INSTALL_EXTERNAL;
+ setExistingXUserX(userSetting, iFlags);
+ }
+ public void testExistingEUserE() {
+ int userSetting = PackageHelper.APP_INSTALL_EXTERNAL;
+ int iFlags = PackageManager.INSTALL_EXTERNAL;
+ setExistingXUserX(userSetting, iFlags);
+ }
+ public void testExistingEUserA() {
+ int userSetting = PackageHelper.APP_INSTALL_AUTO;
+ int iFlags = PackageManager.INSTALL_EXTERNAL;
+ setExistingXUserX(userSetting, iFlags);
+ }
+ /*
+ * The following set of tests verify that the user setting defines
+ * the install location.
+ *
+ */
+ private void setUserX(int userSetting) {
+ int origSetting = getInstallLoc();
+ int iloc = PackageInfo.INSTALL_LOCATION_AUTO;
+ if (userSetting == PackageHelper.APP_INSTALL_AUTO) {
+ iloc = PackageInfo.INSTALL_LOCATION_AUTO;
+ } else if (userSetting == PackageHelper.APP_INSTALL_EXTERNAL) {
+ iloc = PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL;
+ } else if (userSetting == PackageHelper.APP_INSTALL_INTERNAL) {
+ iloc = PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY;
+ }
+ try {
+ // Set user setting
+ setInstallLoc(userSetting);
+ // Replace now
+ installFromRawResource("install.apk", R.raw.install,
+ 0,
+ true,
+ false, -1,
+ iloc);
+ } finally {
+ setInstallLoc(origSetting);
+ }
+ }
+ public void testUserI() {
+ int userSetting = PackageHelper.APP_INSTALL_INTERNAL;
+ setUserX(userSetting);
+ }
+ public void testUserE() {
+ int userSetting = PackageHelper.APP_INSTALL_EXTERNAL;
+ setUserX(userSetting);
+ }
+ public void testUserA() {
+ int userSetting = PackageHelper.APP_INSTALL_AUTO;
+ setUserX(userSetting);
+ }
/*
* TODO's
* check version numbers for upgrades