Search in sources :

Example 1 with AdbHelper

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;
}
Also used : AdbHelper(com.facebook.buck.android.AdbHelper)

Example 2 with AdbHelper

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;
    }
}
Also used : NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildTargetException(com.facebook.buck.model.BuildTargetException) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildRule(com.facebook.buck.rules.BuildRule) AdbHelper(com.facebook.buck.android.AdbHelper) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets) HasInstallableApk(com.facebook.buck.android.HasInstallableApk)

Aggregations

AdbHelper (com.facebook.buck.android.AdbHelper)2 HasInstallableApk (com.facebook.buck.android.HasInstallableApk)1 BuildFileParseException (com.facebook.buck.json.BuildFileParseException)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 BuildTargetException (com.facebook.buck.model.BuildTargetException)1 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)1 BuildRule (com.facebook.buck.rules.BuildRule)1 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)1 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)1 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)1 TargetGraphAndBuildTargets (com.facebook.buck.rules.TargetGraphAndBuildTargets)1 ExecutionContext (com.facebook.buck.step.ExecutionContext)1 HumanReadableException (com.facebook.buck.util.HumanReadableException)1