Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
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)));
        }
Ejemplo n.º 3
0
        public List <string> Run(params string[] args)
        {
            var builder = new ProcessArgumentBuilder();

            foreach (var arg in args)
            {
                builder.Append(arg);
            }

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

            return(r.StandardOutput.Concat(r.StandardError).ToList());
        }
Ejemplo n.º 4
0
        public List <AdbDevice> GetDevices()
        {
            var devices = new List <AdbDevice>();

            //adb devices -l
            var builder = new ProcessArgumentBuilder();

            builder.Append("devices");
            builder.Append("-l");

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

            if (r.StandardOutput.Count > 1)
            {
                foreach (var line in r.StandardOutput?.Skip(1))
                {
                    var parts = Regex.Split(line, "\\s+");

                    var d = new AdbDevice
                    {
                        Serial = parts[0].Trim()
                    };

                    if (parts.Length > 1 && (parts[1]?.ToLowerInvariant() ?? "offline") == "offline")
                    {
                        continue;
                    }

                    if (parts.Length > 2)
                    {
                        foreach (var part in parts.Skip(2))
                        {
                            var bits = part.Split(new[] { ':' }, 2);
                            if (bits == null || bits.Length != 2)
                            {
                                continue;
                            }

                            switch (bits[0].ToLower())
                            {
                            case "usb":
                                d.Usb = bits[1];
                                break;

                            case "product":
                                d.Product = bits[1];
                                break;

                            case "model":
                                d.Model = bits[1];
                                break;

                            case "device":
                                d.Device = bits[1];
                                break;
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(d?.Serial))
                    {
                        devices.Add(d);
                    }
                }
            }

            return(devices);
        }