public void doWithDevice( final IDevice device ) throws MojoExecutionException { String deviceLogLinePrefix = DeviceHelper.getDeviceLogLinePrefix( device ); try { device.installPackage( apkFile.getAbsolutePath(), true ); getLog().info( deviceLogLinePrefix + "Successfully installed " + apkFile.getAbsolutePath() ); getLog().debug( " to " + DeviceHelper.getDescriptiveName( device ) ); } catch ( InstallException e ) { throw new MojoExecutionException( deviceLogLinePrefix + "Install of " + apkFile.getAbsolutePath() + " failed.", e ); } } } );
@Override public void installApks(ImmutableList<Path> apks, InstallOptions installOptions) { ImmutableList<File> apkFiles = apks.stream().map(Path::toFile).collect(toImmutableList()); try { if (getVersion() .isGreaterOrEqualThan(AndroidVersion.ALLOW_SPLIT_APK_INSTALLATION.getApiLevel())) { device.installPackages( apkFiles, installOptions.getAllowReinstall(), installOptions.getAllowDowngrade() ? ImmutableList.of("-d") : ImmutableList.of(), installOptions.getTimeout().toMillis(), TimeUnit.MILLISECONDS); } else { device.installPackage( Iterables.getOnlyElement(apkFiles).toString(), installOptions.getAllowReinstall(), installOptions.getAllowDowngrade() ? "-d" : null); } } catch (InstallException e) { throw InstallationException.builder() .withCause(e) .withMessage("Installation of the app failed.") .build(); } } }
try { String extraArgument = getGrantAllExtraArgument(deviceDetails); device.installPackage(otherApk.getAbsolutePath(), true, extraArgument); } catch (InstallException e) { logInfo("InstallException while install other apk on device [%s]", serial); device.installPackage(testApk.getAbsolutePath(), true, extraArgument); } catch (InstallException e) { logInfo("InstallException while install test apk on device [%s]", serial);
@Test public void allowDowngrade_preL() throws Exception { when(mockDevice.getVersion()).thenReturn(new AndroidVersion(VersionCodes.KITKAT)); DdmlibDevice ddmlibDevice = new DdmlibDevice(mockDevice); ddmlibDevice.installApks( ImmutableList.of(APK_PATH), InstallOptions.builder().setAllowDowngrade(true).build()); verify(mockDevice).installPackage(eq(APK_PATH.toString()), anyBoolean(), eq("-d")); }
@Test public void doesNotAllowDowngrade() throws Exception { when(mockDevice.getVersion()).thenReturn(new AndroidVersion(VersionCodes.KITKAT)); DdmlibDevice ddmlibDevice = new DdmlibDevice(mockDevice); ddmlibDevice.installApks( ImmutableList.of(APK_PATH), InstallOptions.builder().setAllowDowngrade(false).build()); // -d should *not* be passed as extra arg. verify(mockDevice).installPackage(eq(APK_PATH.toString()), anyBoolean(), (String) isNull()); }
/** * Installs an Android application on device. This is a helper method that combines the * syncPackageToDevice, installRemotePackage, and removePackage steps * * @param packageFilePath the absolute file system path to file on local host to install * @param reinstall set to <code>true</code> if re-install of app should be performed * @param extraArgs optional extra arguments to pass. See 'adb shell pm install --help' for * available options. * @throws InstallException if the installation fails. */ @Override public void installPackage(String packageFilePath, boolean reinstall, String... extraArgs) throws InstallException { device.installPackage(packageFilePath, reinstall, extraArgs); }
@Override public void installPackage(File packageFilePath, boolean reinstall, String... extraArgs) throws AndroidExecutionException { if (!Validate.isReadable(packageFilePath.getAbsoluteFile())) { throw new IllegalArgumentException("File " + packageFilePath.getAbsoluteFile() + " must represent a readable APK file"); } try { delegate.installPackage(packageFilePath.getAbsolutePath(), reinstall, extraArgs); } catch (InstallException e) { throw new AndroidExecutionException("Unable to install APK from " + packageFilePath.getAbsolutePath(), e); } }
@Override public void installPackage(File packageFilePath, boolean reinstall, String... extraArgs) throws AndroidExecutionException { Validate.isReadable(packageFilePath.getAbsoluteFile(), "File " + packageFilePath.getAbsoluteFile() + " must represent a readable APK file"); try { String retval = delegate.installPackage(packageFilePath.getAbsolutePath(), reinstall, extraArgs); if (retval != null) { throw new AndroidExecutionException("Unable to install APK from " + packageFilePath.getAbsolutePath() + ". Command failed with status code: " + retval); } } catch (InstallException e) { throw new AndroidExecutionException("Unable to install APK from " + packageFilePath.getAbsolutePath(), e); } }
@Override public void installPackage(@NonNull File apkFile, @NonNull Collection<String> options, int timeout, ILogger logger) throws DeviceException { try { iDevice.installPackage(apkFile.getAbsolutePath(), true /*reinstall*/, options.isEmpty() ? null : options.toArray(new String[options.size()])); } catch (Exception e) { logger.error(e, "Unable to install " + apkFile.getAbsolutePath()); throw new DeviceException(e); } }
@Override public void installPackage(@NonNull File apkFile, @NonNull Collection<String> options, int timeout, ILogger logger) throws DeviceException { try { iDevice.installPackage(apkFile.getAbsolutePath(), true /*reinstall*/, options.isEmpty() ? null : options.toArray(new String[options.size()])); } catch (Exception e) { logger.error(e, "Unable to install " + apkFile.getAbsolutePath()); throw new DeviceException(e); } }
@Override public void installPackage(File packageFilePath, boolean reinstall, String... extraArgs) throws AndroidExecutionException { Validate.isReadable(packageFilePath, "File " + packageFilePath + " must represent a readable APK file"); try { String retval = delegate.installPackage(packageFilePath.getAbsolutePath(), reinstall, extraArgs); if (retval != null) { throw new AndroidExecutionException("Unable to install APK from " + packageFilePath.getAbsolutePath() + ". Command failed with status code: " + retval); } } catch (InstallException e) { throw new AndroidExecutionException("Unable to install APK from " + packageFilePath.getAbsolutePath(), e); } }
private void reinstall(final IDevice device, final String appPackage, final File appApk) { final String message = format("Error while installing %s on %s", appPackage, device.getSerialNumber()); tryThrice(true, message, () -> { try { logger.debug("Uninstalling {} from {}", appPackage, device.getSerialNumber()); device.uninstallPackage(appPackage); logger.debug("Installing {} to {}", appPackage, device.getSerialNumber()); device.installPackage(appApk.getAbsolutePath(), true, optionalAutoGrantPermissionFlag(device)); } catch (InstallException e) { throw new RuntimeException(message, e); } }); }
try { String extraArgument = getGrantAllExtraArgument(deviceDetails); device.installPackage(otherApk.getAbsolutePath(), true, extraArgument); } catch (InstallException e) { logInfo("InstallException while install other apk on device [%s]", serial); device.installPackage(testApk.getAbsolutePath(), true, extraArgument); } catch (InstallException e) { logInfo("InstallException while install test apk on device [%s]", serial);