public AndroidAppInstall(TargetDeviceAndroid InDevice, string InName, string InAndroidPackageName, string InCommandLine)
 {
     AndroidDevice      = InDevice;
     Name               = InName;
     AndroidPackageName = InAndroidPackageName;
     CommandLine        = InCommandLine;
 }
        static public ITargetDevice[] GetDefaultDevices()
        {
            var Result = RunAdbGlobalCommand("devices");

            MatchCollection DeviceMatches = Regex.Matches(Result.Output, @"([\d\w\.\:]{8,32})\s+device");

            List <ITargetDevice> Devices = new List <ITargetDevice>();

            foreach (string Device in GetAllAvailableDevices())
            {
                ITargetDevice NewDevice = new TargetDeviceAndroid(Device);
                Devices.Add(NewDevice);
            }

            return(Devices.ToArray());
        }
        public static void RemoveInstance()
        {
            lock (Globals.MainLock)
            {
                InstanceCount--;

                if (InstanceCount == 0 && bUsingCustomKeys)
                {
                    Reset();

                    Log.Info("Running adb kill-server to refresh credentials");
                    TargetDeviceAndroid.RunAdbGlobalCommand("kill-server");
                    Thread.Sleep(2500);
                }
            }
        }
 public AndroidAppInstance(TargetDeviceAndroid InDevice, AndroidAppInstall InInstall, IProcessResult InProcess)
 {
     AndroidDevice = InDevice;
     Install       = InInstall;
     LaunchProcess = InProcess;
 }
 public ITargetDevice[] GetDefaultDevices()
 {
     return(TargetDeviceAndroid.GetDefaultDevices());
 }
        public static void AddInstance(AndroidDeviceData DeviceData = null)
        {
            lock (Globals.MainLock)
            {
                string KeyPath = Globals.Params.ParseValue("adbkeys", null);

                // setup key store from device data
                if (String.IsNullOrEmpty(KeyPath) && DeviceData != null)
                {
                    // checked that cached keys are the same
                    if (!String.IsNullOrEmpty(PrivateKey))
                    {
                        if (PrivateKey != DeviceData.privateKey)
                        {
                            throw new AutomationException("ADB device private keys must match");
                        }
                    }

                    if (!String.IsNullOrEmpty(PublicKey))
                    {
                        if (PublicKey != DeviceData.publicKey)
                        {
                            throw new AutomationException("ADB device public keys must match");
                        }
                    }

                    PrivateKey = DeviceData.privateKey;
                    PublicKey  = DeviceData.publicKey;

                    if (String.IsNullOrEmpty(PublicKey) || String.IsNullOrEmpty(PrivateKey))
                    {
                        throw new AutomationException("Invalid key in device data");
                    }

                    KeyPath = Path.Combine(Globals.TempDir, "AndroidADBKeys");

                    if (!Directory.Exists(KeyPath))
                    {
                        Directory.CreateDirectory(KeyPath);
                    }

                    if (InstanceCount == 0)
                    {
                        byte[] data = Convert.FromBase64String(PrivateKey);
                        File.WriteAllText(KeyPath + "/adbkey", Encoding.UTF8.GetString(data));

                        data = Convert.FromBase64String(PublicKey);
                        File.WriteAllText(KeyPath + "/adbkey.pub", Encoding.UTF8.GetString(data));
                    }
                }

                if (InstanceCount == 0 && !String.IsNullOrEmpty(KeyPath))
                {
                    Log.Info("Using adb keys at {0}", KeyPath);

                    string LocalKeyPath = Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), ".android");

                    string RemoteKeyFile    = Path.Combine(KeyPath, "adbkey");
                    string RemotePubKeyFile = Path.Combine(KeyPath, "adbkey.pub");
                    string LocalKeyFile     = Path.Combine(LocalKeyPath, "adbkey");
                    string LocalPubKeyFile  = Path.Combine(LocalKeyPath, "adbkey.pub");
                    string BackupSentry     = Path.Combine(LocalKeyPath, "gauntlet.inuse");

                    if (File.Exists(RemoteKeyFile) == false)
                    {
                        throw new AutomationException("adbkey at {0} does not exist", KeyPath);
                    }

                    if (File.Exists(RemotePubKeyFile) == false)
                    {
                        throw new AutomationException("adbkey.pub at {0} does not exist", KeyPath);
                    }

                    if (File.Exists(BackupSentry) == false)
                    {
                        if (File.Exists(LocalKeyFile))
                        {
                            File.Copy(LocalKeyFile, LocalKeyFile + KeyBackupExt, true);
                        }

                        if (File.Exists(LocalPubKeyFile))
                        {
                            File.Copy(LocalPubKeyFile, LocalPubKeyFile + KeyBackupExt, true);
                        }
                        File.WriteAllText(BackupSentry, "placeholder");
                    }

                    File.Copy(RemoteKeyFile, LocalKeyFile, true);
                    File.Copy(RemotePubKeyFile, LocalPubKeyFile, true);

                    bUsingCustomKeys = true;

                    Log.Info("Running adb kill-server to refresh credentials");
                    TargetDeviceAndroid.RunAdbGlobalCommand("kill-server");

                    Thread.Sleep(5000);
                }

                InstanceCount++;
            }
        }