コード例 #1
0
        protected override Task <ExitCode> InvokeInternal(ILogger logger)
        {
            logger.LogDebug($"Android Uninstall command called: App = {_arguments.PackageName}{Environment.NewLine}");


            // Package Name is not guaranteed to match file name, so it needs to be mandatory.
            string apkPackageName = _arguments.PackageName;

            var runner = new AdbRunner(logger);

            try
            {
                using (logger.BeginScope("Find device where to uninstall APK"))
                {
                    // Make sure the adb server is started
                    runner.StartAdbServer();

                    var deviceId = _arguments.DeviceId;

                    if (string.IsNullOrEmpty(deviceId))
                    {
                        // trying to find out if there is only one device with the app installed
                        deviceId = runner.GetUniqueDeviceToUse(logger, "package:" + apkPackageName, "app");
                        if (string.IsNullOrEmpty(deviceId))
                        {
                            return(Task.FromResult(ExitCode.ADB_DEVICE_ENUMERATION_FAILURE));
                        }
                    }

                    runner.SetActiveDevice(deviceId);

                    logger.LogDebug($"Working with {runner.GetAdbVersion()}");

                    runner.UninstallApk(apkPackageName);
                    return(Task.FromResult(ExitCode.SUCCESS));
                }
            }
            catch (Exception toLog)
            {
                logger.LogCritical(toLog, $"Failure to uninstall test package: {toLog.Message}");
            }

            return(Task.FromResult(ExitCode.GENERAL_FAILURE));
        }