/** * Installing encrypted apk on SDCard works. * * @throws Exception */ public void testEncryptedAppOnSdcard() throws Exception { if (mPMHostUtils.getIsExternalStorageEmulated()) { return; } PackageManagerHostTestUtils.InstallLocPreference preference = PackageManagerHostTestUtils.InstallLocPreference.EXTERNAL; PackageManagerHostTestUtils.InstallLocPreference savedPref = PackageManagerHostTestUtils.InstallLocPreference.AUTO; try { savedPref = mPMHostUtils.getDevicePreferredInstallLocation(); mPMHostUtils.setDevicePreferredInstallLocation(preference); mPMHostUtils.installEncryptedAppAndVerifyExists( getTestAppFilePath(SIMPLE_ENCRYPTED_APK), SIMPLE_PKG, true, ENCRYPTION_ALGO, ENCRYPTION_IV, ENCRYPTION_KEY, MAC_ALGO, MAC_KEY, MAC_TAG); assert (mPMHostUtils.appExistsAsEncrypted(SIMPLE_PKG, true)); } // cleanup test app finally { mPMHostUtils.setDevicePreferredInstallLocation(savedPref); mPMHostUtils.uninstallApp(SIMPLE_PKG); } }
/** * Regression test to verify that an app without installLocation in its manifest will install the * app to the device by default when the system default pref is to let the system decide. * * <p>Assumes adb is running as root in device under test. */ public void testInstallAppNoLocPrefIsAuto() throws Exception { Log.i(LOG_TAG, "Test an app with no installLocation gets installed on device"); PackageManagerHostTestUtils.InstallLocPreference savedPref = PackageManagerHostTestUtils.InstallLocPreference.AUTO; try { savedPref = mPMHostUtils.getDevicePreferredInstallLocation(); mPMHostUtils.setDevicePreferredInstallLocation( PackageManagerHostTestUtils.InstallLocPreference.AUTO); mPMHostUtils.installAppAndVerifyExistsOnDevice( getTestAppFilePath(NO_LOC_APK), NO_LOC_PKG, false); } // cleanup test app finally { mPMHostUtils.setDevicePreferredInstallLocation(savedPref); mPMHostUtils.uninstallApp(NO_LOC_PKG); } }
/** * Installs the Internal app using the preferred device install location specified, and verifies * it was installed to the location expected. * * <p>Assumes adb is running as root in device under test. * * @param preference the device's preferred location of where to install apps * @param expectedLocation the expected location of where the apk was installed */ public void installAppInternalLoc( PackageManagerHostTestUtils.InstallLocPreference preference, PackageManagerHostTestUtils.InstallLocation expectedLocation) throws Exception { PackageManagerHostTestUtils.InstallLocPreference savedPref = PackageManagerHostTestUtils.InstallLocPreference.AUTO; try { savedPref = mPMHostUtils.getDevicePreferredInstallLocation(); mPMHostUtils.setDevicePreferredInstallLocation(preference); doStandardInstall(INTERNAL_LOC_APK, INTERNAL_LOC_PKG, expectedLocation); } // cleanup test app finally { mPMHostUtils.setDevicePreferredInstallLocation(savedPref); mPMHostUtils.uninstallApp(INTERNAL_LOC_PKG); } }
/** * Installs the Auto app using the preferred device install location specified, and verifies it * was installed on the device. * * <p>Assumes adb is running as root in device under test. * * @param preference the device's preferred location of where to install apps * @param expectedLocation the expected location of where the apk was installed * @throws DeviceNotAvailableException */ public void installAppAutoLoc( PackageManagerHostTestUtils.InstallLocPreference preference, PackageManagerHostTestUtils.InstallLocation expectedLocation) throws IOException, InterruptedException, TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, InstallException, DeviceNotAvailableException { PackageManagerHostTestUtils.InstallLocPreference savedPref = PackageManagerHostTestUtils.InstallLocPreference.AUTO; try { savedPref = mPMHostUtils.getDevicePreferredInstallLocation(); mPMHostUtils.setDevicePreferredInstallLocation(preference); doStandardInstall(AUTO_LOC_APK, AUTO_LOC_PKG, expectedLocation); } // cleanup test app finally { mPMHostUtils.setDevicePreferredInstallLocation(savedPref); mPMHostUtils.uninstallApp(AUTO_LOC_PKG); } }
@Override protected void setUp() throws Exception { super.setUp(); // ensure apk path has been set before test is run assertNotNull("Missing --app-repository-path option", mAppRepositoryPath); // setup the PackageManager host tests utilities class, and get various paths we'll need... mPMHostUtils = new PackageManagerHostTestUtils(getDevice()); mPMHostUtils.determinePrivateAppPath(getTestAppFilePath(INTERNAL_LOC_APK), INTERNAL_LOC_PKG); // Ensure the default is set to let the system decide where to install apps // (It's ok for individual tests to override and change this during their test, but should // reset it back when they're done) mPMHostUtils.setDevicePreferredInstallLocation( PackageManagerHostTestUtils.InstallLocPreference.AUTO); }