use of com.facebook.buck.android.AdbHelper in project buck by facebook.
the class InstallCommand method installApk.
private int installApk(CommandRunnerParams params, HasInstallableApk hasInstallableApk, ExecutionContext executionContext, SourcePathResolver pathResolver) throws IOException, InterruptedException {
final AdbHelper adbHelper = AdbHelper.get(executionContext, params.getBuckConfig().getRestartAdbOnFailure());
// Uninstall the app first, if requested.
if (shouldUninstallFirst()) {
String packageName = AdbHelper.tryToExtractPackageNameFromManifest(pathResolver, hasInstallableApk.getApkInfo());
adbHelper.uninstallApp(packageName, uninstallOptions().shouldKeepUserData());
// Perhaps the app wasn't installed to begin with, shouldn't stop us.
}
if (!adbHelper.installApk(pathResolver, hasInstallableApk, shouldInstallViaSd(), false)) {
return 1;
}
// Is either of --activity or --run present?
if (shouldStartActivity()) {
int exitCode = adbHelper.startActivity(pathResolver, hasInstallableApk, getActivityToStart(), waitForDebugger);
if (exitCode != 0) {
return exitCode;
}
}
return 0;
}
use of com.facebook.buck.android.AdbHelper in project buck by facebook.
the class UninstallCommand method runWithoutHelp.
@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
// Parse all of the build targets specified by the user.
BuildRuleResolver resolver;
ImmutableSet<BuildTarget> buildTargets;
try (CommandThreadManager pool = new CommandThreadManager("Uninstall", getConcurrencyLimit(params.getBuckConfig()))) {
TargetGraphAndBuildTargets result = params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), getArguments()), /* ignoreBuckAutodepsFiles */
false);
buildTargets = result.getBuildTargets();
resolver = Preconditions.checkNotNull(params.getActionGraphCache().getActionGraph(params.getBuckEventBus(), params.getBuckConfig().isActionGraphCheckingEnabled(), params.getBuckConfig().isSkipActionGraphCache(), result.getTargetGraph(), params.getBuckConfig().getKeySeed())).getResolver();
} catch (BuildTargetException | BuildFileParseException e) {
params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
return 1;
}
// Make sure that only one build target is specified.
if (buildTargets.size() != 1) {
params.getBuckEventBus().post(ConsoleEvent.severe("Must specify exactly one android_binary() rule."));
return 1;
}
BuildTarget buildTarget = Iterables.get(buildTargets, 0);
// Find the android_binary() rule from the parse.
BuildRule buildRule;
try {
buildRule = resolver.requireRule(buildTarget);
} catch (NoSuchBuildTargetException e) {
throw new HumanReadableException(e.getHumanReadableErrorMessage());
}
if (!(buildRule instanceof HasInstallableApk)) {
params.getBuckEventBus().post(ConsoleEvent.severe(String.format("Specified rule %s must be of type android_binary() or apk_genrule() but was %s().\n", buildRule.getFullyQualifiedName(), buildRule.getType())));
return 1;
}
HasInstallableApk hasInstallableApk = (HasInstallableApk) buildRule;
// We need this in case adb isn't already running.
try (ExecutionContext context = createExecutionContext(params)) {
final AdbHelper adbHelper = new AdbHelper(adbOptions(params.getBuckConfig()), targetDeviceOptions(), context, params.getConsole(), params.getBuckEventBus(), params.getBuckConfig().getRestartAdbOnFailure());
// Find application package name from manifest and uninstall from matching devices.
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
String appId = AdbHelper.tryToExtractPackageNameFromManifest(pathResolver, hasInstallableApk.getApkInfo());
return adbHelper.uninstallApp(appId, uninstallOptions().shouldKeepUserData()) ? 0 : 1;
}
}
Aggregations