Beispiel #1
0
        public void Install(FileInfo apkFile, string adbSerial = null)
        {
            // adb uninstall -k <package>
            // -k keeps data & cache dir
            var builder = new ProcessArgumentBuilder();

            runner.AddSerial(adbSerial, builder);

            builder.Append("install");
            builder.Append(apkFile.FullName);

            runner.RunAdb(AndroidSdkHome, builder);
        }
        public List <PackageListInfo> ListPackages(bool includeUninstalled = false, PackageListState showState = PackageListState.All, PackageSourceType showSource = PackageSourceType.All)
        {
            // list packages [options] filter
            // start [options] intent
            var builder = new ProcessArgumentBuilder();

            runner.AddSerial(AdbSerial, builder);

            builder.Append("shell");
            builder.Append("pm");

            builder.Append("list");
            builder.Append("packages");
            builder.Append("-f");
            builder.Append("-i");

            if (showState == PackageListState.OnlyDisabled)
            {
                builder.Append("-d");
            }
            else if (showState == PackageListState.OnlyEnabled)
            {
                builder.Append("-e");
            }

            if (showSource == PackageSourceType.OnlySystem)
            {
                builder.Append("-s");
            }
            else if (showSource == PackageSourceType.OnlyThirdParty)
            {
                builder.Append("-3");
            }

            if (includeUninstalled)
            {
                builder.Append("-u");
            }

            var r = runner.RunAdb(AndroidSdkHome, builder);

            var results = new List <PackageListInfo>();

            const string rxPackageListInfo = "^package:(?<path>.*?)=(?<package>.*?)\\s+installer=(?<installer>.*?)$";

            foreach (var line in r.StandardOutput)
            {
                var m = Regex.Match(line, rxPackageListInfo, RegexOptions.Singleline);

                var installPath = m?.Groups?["path"]?.Value;
                var packageName = m?.Groups?["package"]?.Value;
                var installer   = m?.Groups?["installer"]?.Value;

                if (!string.IsNullOrEmpty(installPath) && !string.IsNullOrEmpty(packageName))
                {
                    results.Add(new PackageListInfo
                    {
                        InstallPath = new FileInfo(installPath),
                        PackageName = packageName,
                        Installer   = installer,
                    });
                }
            }
            return(results);
        }
Beispiel #3
0
        public bool StartActivity(string adbIntentArguments, ActivityManagerStartOptions options = null)
        {
            if (options == null)
            {
                options = new ActivityManagerStartOptions();
            }

            // start [options] intent
            var builder = new ProcessArgumentBuilder();

            runner.AddSerial(AdbSerial, builder);

            builder.Append("shell");
            builder.Append("am");

            builder.Append("start");

            if (options.EnableDebugging)
            {
                builder.Append("-D");
            }
            if (options.WaitForLaunch)
            {
                builder.Append("-W");
            }
            if (options.ProfileToFile != null)
            {
                if (options.ProfileUntilIdle)
                {
                    builder.Append("-P");
                }
                else
                {
                    builder.Append("--start");
                }
                builder.AppendQuoted(options.ProfileToFile.FullName);
            }
            if (options.RepeatLaunch.HasValue && options.RepeatLaunch.Value > 0)
            {
                builder.Append("-R");
                builder.Append(options.RepeatLaunch.Value.ToString());
            }
            if (options.ForceStopTarget)
            {
                builder.Append("-S");
            }
            if (options.EnableOpenGLTrace)
            {
                builder.Append("--opengl-trace");
            }
            if (!string.IsNullOrEmpty(options.RunAsUserId))
            {
                builder.Append("--user");
                builder.Append(options.RunAsUserId);
            }

            builder.Append(adbIntentArguments);

            var r = runner.RunAdb(AndroidSdkHome, builder);

            return(r.StandardOutput.Any(l => l.StartsWith("Starting:", StringComparison.OrdinalIgnoreCase)));
        }