summaryrefslogtreecommitdiffstats
path: root/tests/AndroidTests/src
diff options
context:
space:
mode:
authorSuchi Amalapurapu <asuchitra@google.com>2010-02-09 03:45:40 -0800
committerSuchi Amalapurapu <asuchitra@google.com>2010-02-10 08:59:08 -0800
commit117818e4f171b1fd9daa05349c48f61388f04567 (patch)
tree2bb350a719caf06727a410ce662c46a28c45fb72 /tests/AndroidTests/src
parent596ce7fbfe5a81a4270949448c08dcb3a684cc3a (diff)
downloadframeworks_base-117818e4f171b1fd9daa05349c48f61388f04567.zip
frameworks_base-117818e4f171b1fd9daa05349c48f61388f04567.tar.gz
frameworks_base-117818e4f171b1fd9daa05349c48f61388f04567.tar.bz2
Add new manifest option for install location
Change recommendAppInstallLocation api add code to parse new attribute. Define flags in PackageInfo Add new settings attributes for enabling setting and value for install location Some tests The policy for install location: if explicitly set in manifest as internal only we try to install the app only on internal storage. if set to preferExternal, we try to install it on sdcard if possible. If not we fall back to internal. If the user enables setting SET_INSTALL_LOCATION(which will always be set to false in final release builds) and sets a prefered location, we try to honour it.
Diffstat (limited to 'tests/AndroidTests/src')
-rwxr-xr-xtests/AndroidTests/src/com/android/unit_tests/PackageManagerTests.java166
1 files changed, 166 insertions, 0 deletions
diff --git a/tests/AndroidTests/src/com/android/unit_tests/PackageManagerTests.java b/tests/AndroidTests/src/com/android/unit_tests/PackageManagerTests.java
index 3a4d38c..07bd489 100755
--- a/tests/AndroidTests/src/com/android/unit_tests/PackageManagerTests.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/PackageManagerTests.java
@@ -37,6 +37,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageDataObserver;
import android.content.pm.IPackageInstallObserver;
import android.content.pm.IPackageDeleteObserver;
+import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageParser;
import android.content.pm.PackageStats;
@@ -59,6 +60,7 @@ import android.os.storage.StorageResultCode;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.StatFs;
+import android.provider.Settings;
public class PackageManagerTests extends AndroidTestCase {
private static final boolean localLOGV = true;
@@ -761,6 +763,170 @@ public class PackageManagerTests extends AndroidTestCase {
outFile.delete();
}
}
+
+ public void invokeRecommendAppInstallLocation(String outFileName,
+ int fileResId, int expected) {
+ int origSetting = Settings.System.getInt(mContext.getContentResolver(),
+ Settings.System.SET_INSTALL_LOCATION, 0);
+ try {
+ // Make sure the set install location setting is diabled.
+ Settings.System.putInt(mContext.getContentResolver(),
+ Settings.System.SET_INSTALL_LOCATION, 0);
+ File filesDir = mContext.getFilesDir();
+ File outFile = new File(filesDir, outFileName);
+ Uri packageURI = getInstallablePackage(fileResId, outFile);
+ PackageParser.Package pkg = parsePackage(packageURI);
+ assertNotNull(pkg);
+ int installLoc = getPm().recommendAppInstallLocation(pkg);
+ Log.i(TAG, "expected=" + expected +", installLoc="+installLoc);
+ // Atleast one of the specified expected flags should be set.
+ boolean onFlash = (installLoc &
+ PackageManager.INSTALL_ON_INTERNAL_FLASH) != 0;
+ boolean onSd = (installLoc &
+ PackageManager.INSTALL_ON_SDCARD) != 0;
+ boolean expOnFlash = (expected &
+ PackageManager.INSTALL_ON_INTERNAL_FLASH) != 0;
+ boolean expOnSd = (expected &
+ PackageManager.INSTALL_ON_SDCARD) != 0;
+ assertTrue(expOnFlash == onFlash || expOnSd == onSd);
+ } finally {
+ // Restore original setting
+ Settings.System.putInt(mContext.getContentResolver(),
+ Settings.System.SET_INSTALL_LOCATION, origSetting);
+ }
+ }
+
+ /*
+ * Tests if an apk can be installed on internal flash by
+ * explicitly specifying in its manifest.
+ */
+ public void testInstallLocationInternal() {
+ invokeRecommendAppInstallLocation("install.apk",
+ R.raw.install_loc_internal, PackageManager.INSTALL_ON_INTERNAL_FLASH);
+ }
+
+ /*
+ * Tests if an apk can be installed on internal flash by
+ * explicitly specifying in its manifest and filling up
+ * internal flash. Should fail to install.
+ * TODO
+ */
+ public void xxxtestInstallLocationInternalFail() {
+ }
+
+ /*
+ * Tests if an apk can be installed on sdcard by
+ * explicitly specifying in its manifest.
+ */
+ public void testInstallLocationSdcard() {
+ // TODO No guarantee this will be on sdcard.
+ invokeRecommendAppInstallLocation("install.apk",
+ R.raw.install_loc_sdcard, PackageManager.INSTALL_ON_SDCARD
+ | PackageManager.INSTALL_ON_INTERNAL_FLASH);
+ }
+
+ /*
+ * Tests if an apk can be installed on sdcard by
+ * explicitly specifying in its manifest and filling up
+ * the sdcard. Should result in install failure
+ * TODO
+ */
+ public void xxxtestInstallLocationSdcardFail() {
+ }
+
+ /*
+ * Tests if an apk can be installed by specifying
+ * auto for install location
+ */
+ public void xxxtestInstallLocationAutoInternal() {
+ // TODO clear and make room on internal flash
+ invokeRecommendAppInstallLocation("install.apk",
+ R.raw.install_loc_auto, PackageManager.INSTALL_ON_INTERNAL_FLASH);
+ }
+
+ /*
+ * Tests if an apk can be installed by specifying
+ * auto for install location
+ */
+ public void testInstallLocationAutoSdcard() {
+ // TODO clear and make room on sdcard.
+ // Fill up internal
+ invokeRecommendAppInstallLocation("install.apk",
+ R.raw.install_loc_auto, PackageManager.INSTALL_ON_SDCARD |
+ PackageManager.INSTALL_ON_INTERNAL_FLASH);
+ }
+
+ /*
+ * Tests if an apk can be installed by specifying
+ * auto for install location
+ * fill up both internal and sdcard
+ * TODO
+ */
+ public void xxxtestInstallLocationAutoFail() {
+ }
+ /*
+ * Tests where an apk gets installed based
+ * on a not specifying anything in manifest.
+ */
+ public void testInstallLocationUnspecifiedInt() {
+ invokeRecommendAppInstallLocation("install.apk",
+ R.raw.install_loc_unspecified, PackageManager.INSTALL_ON_INTERNAL_FLASH);
+ }
+
+ public void xxxtestInstallLocationUnspecifiedStorage() {
+ // TODO Fill up internal storage
+ invokeRecommendAppInstallLocation("install.apk",
+ R.raw.install_loc_unspecified, PackageManager.INSTALL_ON_SDCARD
+ | PackageManager.INSTALL_ON_INTERNAL_FLASH);
+ }
+
+ /*
+ * Tests where an apk gets installed by expcitly setting
+ * the user specified install location
+ */
+ public void testInstallLocationUserSpecifiedInternal() {
+ // Enable user setting
+ Settings.System.putInt(mContext.getContentResolver(),
+ Settings.System.SET_INSTALL_LOCATION, 1);
+ Settings.System.putInt(mContext.getContentResolver(),
+ Settings.System.DEFAULT_INSTALL_LOCATION, 1);
+ invokeRecommendAppInstallLocation("install.apk",
+ R.raw.install_loc_unspecified, PackageManager.INSTALL_ON_INTERNAL_FLASH);
+ }
+
+ /*
+ * Tests where an apk gets installed by expcitly setting
+ * the user specified install location
+ */
+ public void testInstallLocationUserSpecifiedSdcard() {
+ // Enable user setting
+ Settings.System.putInt(mContext.getContentResolver(),
+ Settings.System.SET_INSTALL_LOCATION, 1);
+ Settings.System.putInt(mContext.getContentResolver(),
+ Settings.System.DEFAULT_INSTALL_LOCATION, 2);
+ int i = Settings.System.getInt(mContext.getContentResolver(),
+ Settings.System.DEFAULT_INSTALL_LOCATION, 0);
+ invokeRecommendAppInstallLocation("install.apk",
+ R.raw.install_loc_unspecified, PackageManager.INSTALL_ON_SDCARD);
+ Settings.System.putInt(mContext.getContentResolver(),
+ Settings.System.SET_INSTALL_LOCATION, 0);
+ }
+ /*
+ * Tests where an apk gets installed by expcitly setting
+ * the user specified install location
+ */
+ public void testInstallLocationUserSpecifiedAuto() {
+ // Enable user setting
+ Settings.System.putInt(mContext.getContentResolver(),
+ Settings.System.SET_INSTALL_LOCATION, 1);
+ Settings.System.putInt(mContext.getContentResolver(),
+ Settings.System.DEFAULT_INSTALL_LOCATION, 0);
+ invokeRecommendAppInstallLocation("install.apk",
+ R.raw.install_loc_unspecified, PackageManager.INSTALL_ON_INTERNAL_FLASH);
+ Settings.System.putInt(mContext.getContentResolver(),
+ Settings.System.SET_INSTALL_LOCATION, 0);
+ }
+
/*
* TODO's
* check version numbers for upgrades