Ejemplo n.º 1
0
        public void Install(FileInfo pathOnDevice,
                            bool forwardLock                   = false,
                            bool reinstall                     = false,
                            bool allowTestApks                 = false,
                            string installerPackageName        = null,
                            bool installOnSharedStorage        = false,
                            bool installOnInternalSystemMemory = false,
                            bool allowVersionDowngrade         = false,
                            bool grantAllManifestPermissions   = false)
        {
            // install[options] path
            var builder = new ProcessArgumentBuilder();

            runner.AddSerial(AdbSerial, builder);

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

            builder.Append("install");

            if (forwardLock)
            {
                builder.Append("-l");
            }
            if (reinstall)
            {
                builder.Append("-r");
            }
            if (allowTestApks)
            {
                builder.Append("-t");
            }
            if (installOnSharedStorage)
            {
                builder.Append("-s");
            }
            if (installOnInternalSystemMemory)
            {
                builder.Append("-f");
            }
            if (allowVersionDowngrade)
            {
                builder.Append("-d");
            }
            if (grantAllManifestPermissions)
            {
                builder.Append("-g");
            }

            builder.AppendQuoted(pathOnDevice.FullName);

            runner.RunAdb(AndroidSdkHome, builder);
        }
Ejemplo n.º 2
0
        public List <string> StartProfiling(string process, FileInfo outputFile)
        {
            // broadcast [options] intent
            var builder = new ProcessArgumentBuilder();

            runner.AddSerial(AdbSerial, builder);

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

            builder.Append("profile");
            builder.Append("start");

            builder.Append(process);

            builder.AppendQuoted(outputFile.FullName);

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

            return(r.StandardOutput);
        }
Ejemplo n.º 3
0
        internal bool InstallOrUninstall(bool install, IEnumerable <string> packages)
        {
            CheckSdkManagerVersion();

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

            if (!install)
            {
                builder.Append("--uninstall");
            }

            foreach (var pkg in packages)
            {
                builder.AppendQuoted(pkg);
            }

            BuildStandardOptions(builder);

            var output = run(true, builder);

            return(true);
        }
Ejemplo n.º 4
0
        public List <string> Logcat(AdbLogcatOptions options = null, string filter = null, string adbSerial = null)
        {
            // logcat[option][filter - specs]
            if (options == null)
            {
                options = new AdbLogcatOptions();
            }

            // adb uninstall -k <package>
            // -k keeps data & cache dir
            var builder = new ProcessArgumentBuilder();

            runner.AddSerial(adbSerial, builder);

            builder.Append("logcat");

            if (options.BufferType != AdbLogcatBufferType.Main)
            {
                builder.Append("-b");
                builder.Append(options.BufferType.ToString().ToLowerInvariant());
            }

            if (options.Clear || options.PrintSize)
            {
                if (options.Clear)
                {
                    builder.Append("-c");
                }
                else if (options.PrintSize)
                {
                    builder.Append("-g");
                }
            }
            else
            {
                // Always dump, since we want to return and not listen to logcat forever
                // in the future might be nice to add an alias that takes a cancellation token
                // and can pipe output until that token is cancelled.
                //if (options.Dump)
                builder.Append("-d");

                if (options.OutputFile != null)
                {
                    builder.Append("-f");
                    builder.AppendQuoted(options.OutputFile.FullName);

                    if (options.NumRotatedLogs.HasValue)
                    {
                        builder.Append("-n");
                        builder.Append(options.NumRotatedLogs.Value.ToString());
                    }

                    var kb = options.LogRotationKb ?? 16;
                    builder.Append("-r");
                    builder.Append(kb.ToString());
                }

                if (options.SilentFilter)
                {
                    builder.Append("-s");
                }

                if (options.Verbosity != AdbLogcatOutputVerbosity.Brief)
                {
                    builder.Append("-v");
                    builder.Append(options.Verbosity.ToString().ToLowerInvariant());
                }
            }

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

            return(r.StandardOutput);
        }
Ejemplo n.º 5
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.º 6
0
        public AndroidEmulatorProcess Start(string avdName, EmulatorStartOptions options = null)
        {
            if (options == null)
            {
                options = new EmulatorStartOptions();
            }

            var builder = new ProcessArgumentBuilder();

            builder.Append($"-avd {avdName}");

            if (options.NoSnapshotLoad)
            {
                builder.Append("-no-snapshot-load");
            }
            if (options.NoSnapshotSave)
            {
                builder.Append("-no-snapshot-save");
            }
            if (options.NoSnapshot)
            {
                builder.Append("-no-snapshot");
            }

            if (!string.IsNullOrEmpty(options.CameraBack))
            {
                builder.Append($"-camera-back {options.CameraBack}");
            }
            if (!string.IsNullOrEmpty(options.CameraFront))
            {
                builder.Append($"-camera-front {options.CameraFront}");
            }

            if (options.MemoryMegabytes.HasValue)
            {
                builder.Append($"-memory {options.MemoryMegabytes}");
            }

            if (options.SdCard != null)
            {
                builder.Append("-sdcard");
                builder.AppendQuoted(options.SdCard.FullName);
            }

            if (options.WipeData)
            {
                builder.Append("-wipe-data");
            }

            if (options.Debug != null && options.Debug.Length > 0)
            {
                builder.Append("-debug " + string.Join(",", options.Debug));
            }

            if (options.Logcat != null && options.Logcat.Length > 0)
            {
                builder.Append("-logcat " + string.Join(",", options.Logcat));
            }

            if (options.ShowKernel)
            {
                builder.Append("-show-kernel");
            }

            if (options.Verbose)
            {
                builder.Append("-verbose");
            }

            if (options.DnsServers != null && options.DnsServers.Length > 0)
            {
                builder.Append("-dns-server " + string.Join(",", options.DnsServers));
            }

            if (!string.IsNullOrEmpty(options.HttpProxy))
            {
                builder.Append($"-http-proxy {options.HttpProxy}");
            }

            if (!string.IsNullOrEmpty(options.NetDelay))
            {
                builder.Append($"-netdelay {options.NetDelay}");
            }

            if (options.NetFast)
            {
                builder.Append("-netfast");
            }

            if (!string.IsNullOrEmpty(options.NetSpeed))
            {
                builder.Append($"-netspeed {options.NetSpeed}");
            }

            if (options.Ports.HasValue)
            {
                builder.Append($"-ports {options.Ports.Value.console},{options.Ports.Value.adb}");
            }
            else if (options.Port.HasValue)
            {
                builder.Append($"-port {options.Port.Value}");
            }

            if (options.TcpDump != null)
            {
                builder.Append("-tcpdump");
                builder.AppendQuoted(options.TcpDump.FullName);
            }

            if (options.Acceleration.HasValue)
            {
                builder.Append($"-accel {options.Acceleration.Value.ToString().ToLowerInvariant()}");
            }

            if (options.NoAccel)
            {
                builder.Append("-no-accel");
            }

            if (options.Engine.HasValue)
            {
                builder.Append($"-engine {options.Engine.Value.ToString().ToLowerInvariant()}");
            }

            if (options.NoJni)
            {
                builder.Append("-no-jni");
            }

            if (options.SeLinux.HasValue)
            {
                builder.Append($"-selinux {options.SeLinux.Value.ToString().ToLowerInvariant()}");
            }

            if (!string.IsNullOrEmpty(options.Timezone))
            {
                builder.Append($"-timezone {options.Timezone}");
            }

            if (options.NoBootAnim)
            {
                builder.Append("-no-boot-anim");
            }

            if (options.Screen.HasValue)
            {
                builder.Append($"-screen {options.Screen.Value.ToString().ToLowerInvariant()}");
            }

            //var uuid = Guid.NewGuid().ToString("D");
            //builder.Append($"-prop emu.uuid={uuid}");

            if (options.ExtraArgs != null && options.ExtraArgs.Length > 0)
            {
                foreach (var arg in options.ExtraArgs)
                {
                    builder.Append(arg);
                }
            }

            return(new AndroidEmulatorProcess(Start(builder), avdName, AndroidSdkHome));
        }