/// <summary>
        /// Perform the action.
        /// </summary>
        protected override void DoWork()
        {
            // Listen for devices
            deviceMonitor.Start();
            deviceMonitor.WaitForInitialUpdate();

            // Perform the connect
            connecting = true;
            var adb = new Adb { Logger = LogOutput };
            adb.Connect(host, port, Adb.Timeout.Connect);
        }
Example #2
0
        /// <summary>
        /// Gets a (cached) property from the device.
        /// </summary>
        private string GetProperty(string propertyName)
        {
            string result;

            if (properties.TryGetValue(propertyName, out result))
            {
                return(result);
            }
            result = Adb.GetProperty(this, propertyName, Adb.Timeout.GetProperty, false);
            properties[propertyName] = result;
            return(result);
        }
Example #3
0
 /// <summary>
 /// Execute the install.
 /// </summary>
 public override bool Execute()
 {
     try
     {
         var adb = new Adb();
         adb.Logger += s => {
             if(!string.IsNullOrEmpty(s))
                 Log.LogMessage(MessageImportance.High, s);
         };
         adb.InstallApk(null, Package.ItemSpec, GetApkName, true, Adb.Timeout.InstallApk);
         return true;
     }
     catch (Exception ex)
     {
         Log.LogErrorFromException(ex);
         return false;
     }
 }
Example #4
0
        /// <summary>
        /// Connect to the VM in the given process id on the given device.
        /// </summary>
        public void Connect(IDevice device, int pid, MapFile mapFile)
        {
            // Disconnect any pending connections
            Disconnect();

            // Cleanup
            process = null;
            this.mapFile = mapFile;
            this.pid = pid;

            // Setup forward
            var port = GetFreePort();
            var adb = new Adb();
            adb.ForwardJdwp(device, port, pid);

            // Establish connection
            connection = new JdwpConnection(new IPEndPoint(IPAddress.Parse("127.0.0.1"), port), ChunkHandler, pid, PacketHandler);
            connection.Disconnect += OnConnectionDisconnect;

            // Notify
            ConnectedChanged.Fire(this);
        }
Example #5
0
            /// <summary>
            /// Check the result of this runner.
            /// </summary>
            public void CheckResult(Adb adb, out bool retry, out bool uninstall)
            {
                retry = false;
                uninstall = false;

                if (certificateFailure)
                {
                    // Remove first, then retry
                    adb.Log("Certificate mismatch. Uninstalling...");
                    uninstall = true;
                    retry = true;
                }
                else if (alreadyExists)
                {
                    // This should not happen because we install with reinstall flag on.
                    throw new AdbException("Install failed. The package already exists.");
                }
                else if (invalidApk)
                {
                    // Compile/format/verify error
                    throw new AdbException("Install failed. Invalid APK. Check the device log for details.");
                }
                else if (invalidUri)
                {
                    // ? error
                    throw new AdbException("Install failed. Invalid URI. Check the device log for details.");
                }
                else if (couldntCopy)
                {
                    // ? error
                    throw new AdbException("Install failed. Couldn't copy to final destination. Check the device log for details.");
                }
                else if (failures.Count > 0)
                {
                    // Unknown error
                    throw new AdbException(string.Format("Install failed ({0}). Check the device log for details.", failures[0]));
                }
            }
            /// <summary>
            /// Check the result of this runner.
            /// </summary>
            public void CheckResult(Adb adb, out bool retry, out bool uninstall)
            {
                retry     = false;
                uninstall = false;

                if (certificateFailure)
                {
                    // Remove first, then retry
                    adb.Log("Certificate mismatch. Uninstalling...");
                    uninstall = true;
                    retry     = true;
                }
                else if (alreadyExists)
                {
                    // This should not happen because we install with reinstall flag on.
                    throw new AdbException("Install failed. The package already exists.");
                }
                else if (invalidApk)
                {
                    // Compile/format/verify error
                    throw new AdbException("Install failed. Invalid APK. Check the device log for details.");
                }
                else if (invalidUri)
                {
                    // ? error
                    throw new AdbException("Install failed. Invalid URI. Check the device log for details.");
                }
                else if (couldntCopy)
                {
                    // ? error
                    throw new AdbException("Install failed. Couldn't copy to final destination. Check the device log for details.");
                }
                else if (failures.Count > 0)
                {
                    // Unknown error
                    throw new AdbException(string.Format("Install failed ({0}). Check the device log for details.", failures[0]));
                }
            }
Example #7
0
 private static void UninstallAPKByPackageName(string name)
 {
     var log = new StringBuilder();
     try
     {
         Console.Write("Uninstalling {0}", name);
         var adb = new Adb();
         adb.Logger += x => log.AppendLine(x);
         adb.UninstallApk(null, name, Adb.Timeout.UninstallApk);
         Console.WriteLine(" OK");
     }
     catch (Exception ex)
     {
         Console.WriteLine();
         Console.WriteLine(log);
         Console.WriteLine("Failed to uninstall {0} because {1}", name, ex.Message);
     }
 }
Example #8
0
        /// <summary>
        /// Run the packet on the given (already started) device.
        /// </summary>
        private void RunOnStartedDevice(IDevice device)
        {
            // Set state
            stateUpdate(LauncherStates.Deploying, string.Empty);

            // Prepare debug launcher
            Launcher.PrepareForLaunch();

            // Install package
            if (IsCancelled) return;
            var adb = new Adb();
            adb.Logger += LogLine;
            LogLine(string.Format("----- Installing {0}", apkPath));
            adb.InstallApk(device.Serial, apkPath, packageName, Adb.Timeout.InstallApk);
            LogLine(string.Format("----- Installed {0}", apkPath));

            // Prepare for debugger attachment (if debuggable)
            if (IsCancelled) return;
            if (debuggable)
            {
                Launcher.StartLaunchMonitor(ide, device, apkPath, packageName, minSdkVersion, launchFlags, stateUpdate, cancellationTokenSource.Token);
            }

            // Run activity
            if (IsCancelled) return;            
            stateUpdate(LauncherStates.Starting, string.Empty);
            LogLine(string.Format("----- Starting activity {0}", activity));
            adb.StartActivity(device, packageName, activity, debuggable, Adb.Timeout.StartActivity, this);
            LogLine(string.Format("----- Started activity {0}", activity));
            stateUpdate(LauncherStates.Started, string.Empty);
        }
Example #9
0
        /// <summary>
        /// Background thread
        /// </summary>
        private void RunLogServiceAsync(IDevice device)
        {
            var attempt = 0;
            while (attempt < 10)
            {
                attempt++;
                try
                {
                    // Ensure server is running
                    var adb = new Adb();
                    adb.StartServer(Adb.Timeout.StartServer);

                    // Run log messages
                    adb.RunLogService(new LogServiceListener(this, Thread.CurrentThread), device, Adb.LogNames.Main);
                }
                catch (Exception ex)
                {
                    ErrorLog.DumpError(ex);
                }
            }
        }