/// <summary> /// Return true or false to represent Adb is started successful or not /// </summary> /// <param name="adbPath"></param> /// <returns></returns> public static bool StartServer(string adbPath) { ProcessStartInfo adb = new ProcessStartInfo(adbPath) { UseShellExecute = false, CreateNoWindow = true, RedirectStandardInput = true, RedirectStandardOutput = true }; Process.Start(adb); IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties(); TcpConnectionInformation[] tcpConnections = ipProperties.GetActiveTcpConnections(); foreach (TcpConnectionInformation info in tcpConnections) { if (info.LocalEndPoint.Address == IPAddress.Loopback && info.LocalEndPoint.Port >= 5037 && info.LocalEndPoint.Port <= 5040 && info.State == TcpState.Listen && info.LocalEndPoint.Port == CurrentPort) { Variables.AdvanceLog("Adb port listening on " + info.LocalEndPoint.Port); AdbServer server = new AdbServer(); server.StartServer(adbPath, false); return(true); } } return(false); }
private void RefreshConnectedDevices() { AdbServer srv = AndroidADBDriver.GetADBServer(); var devices = AdbClient.Instance.GetDevices(); DevicesGrid.ItemsSource = devices; }
static Communicator() { string _mutexName = Assembly.GetExecutingAssembly().GetName().Name + "-Mutex"; ServerInstanceMutex = new Mutex(false, _mutexName); Logger.Warning("Trying to acquire server mutex..."); bool mutexAcquired; try { mutexAcquired = ServerInstanceMutex.WaitOne(60000); } catch (AbandonedMutexException) { mutexAcquired = true; } if (!mutexAcquired) { Logger.Error("Failed to acquire server mutex."); Logger.Error("You might be running multiple instances of the same process."); Logger.Error("Running multiple instances can cause unavoidable errors. Exiting now..."); throw new MultipleInstancesRunningException(); } ServerInstanceMutex.WaitOne(); Server = new AdbServer(); }
public bool RunServer(int websocketport = 0) { adb_server_ = new AdbServer(); try { var ret = adb_server_.StartServer(adb_path_, true); if (ret != StartServerResult.Started) { adb_server_.RestartServer(); } var monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort))); monitor.DeviceConnected += this.OnDeviceConnectedNotify; monitor.DeviceDisconnected += this.OnDeviceDisconnectedNotify; monitor.DeviceChanged += this.OnDeviceChangedNotify; monitor.Start(); } catch (Exception e) { log_.Error($"RunServer {e.ToString()}"); adb_server_ = null; return(false); } finally { } RunWebSocket(websocketport); return(true); }
public MainWindowViewModel() { Scrcpy = new ScrcpyViewModel(); LoadAvailableDevicesCommand = ReactiveCommand.Create(LoadAvailableDevices); Task.Run(async() => { // Start ADB server if needed var srv = new AdbServer(); if (!srv.GetStatus().IsRunning) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { srv.StartServer("ScrcpyNet/adb.exe", false); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { srv.StartServer("/usr/bin/adb", false); } else { log.Warning("Can't automatically start the ADB server on this platform."); } } await LoadAvailableDevicesCommand.Execute(); }); }
private bool ADBCheck() { //try adb - not success AdbServer server = new AdbServer(); circularProgressBar1.Value = 0; circularProgressBar1.ProgressColor1 = System.Drawing.Color.GreenYellow; circularProgressBar1.ProgressColor2 = System.Drawing.Color.LimeGreen; for (int i = 0; i < 100; i++) { circularProgressBar1.Value += 1; circularProgressBar1.Update(); ShowOFF(); } //try -> check if tools exist. var result = server.StartServer(@"Tools\adb.exe", restartServerIfNewer: false); try { var mydevice = AdbClient.Instance.GetDevices().FirstOrDefault(); var receiver = new ConsoleOutputReceiver(); Console.WriteLine(String.IsNullOrEmpty(mydevice.ToString())); return(true); } catch (Exception ex) { // There is no android adb device. if (ex is System.ArgumentNullException || ex is System.NullReferenceException) { // simply pass. } Failed(); return(false); } }
public Form1() { InitializeComponent(); this.connect_button.Click += new System.EventHandler(this.Connect_button_Click); this.FormClosing += new FormClosingEventHandler(Form1_FormClosing); AdbServer server = new AdbServer(); var result = server.StartServer(@"adb\\adb.exe", restartServerIfNewer: false); }
public Form1() { InitializeComponent(); AdbServer server = new AdbServer(); server.StartServer(Application.StartupPath + "/adb/adb.exe", restartServerIfNewer: false); }
public void StartServerNotRunningNoExecutableTest() { Factories.AdbSocketFactory = (endPoint) => { throw new SocketException(AdbServer.ConnectionRefused); }; var result = AdbServer.StartServer(null, false); }
public void Iniciar() { if (server == null) { server = new AdbServer(); var result = server.StartServer(this.getPath() + "adb.exe", restartServerIfNewer: false); server.RestartServer(); } }
public void GetStatusOtherExceptionTest() { Factories.AdbSocketFactory = (endPoint) => { throw new Exception(); }; var status = AdbServer.GetStatus(); }
public HomeForm() { InitializeComponent(); server = new AdbServer(); currentDevice = null; IsDisconnect = IsConnect = IsDebuging = false; st = new ADBProccessDLL.Setting(); stateMessage = ""; }
public MyADB(string AdbShellFilename) { server = new AdbServer(); var result = server.StartServer(AdbShellFilename, restartServerIfNewer: false); Console.WriteLine("Adb server connection state: " + result.ToString()); client = new AdbClient(); TargetDevice = client.GetDevices()[0]; }
public static void Init() { Debug.Assert(!_isInitialized, "Bootstrapper already initialized"); LoggingService.Provide(new TraceLogger()); SetupEnvironmentVariables(); var adb = new AdbServer(); var result = adb.StartServer(Constants.AdbPath, restartServerIfNewer: false); _isInitialized = true; }
public void StartServerOutdatedRunningNoExecutableTest() { this.socket.Responses.Enqueue(AdbResponse.OK); this.socket.ResponseMessages.Enqueue("0010"); var result = AdbServer.StartServer(null, false); Assert.AreEqual(1, this.socket.Requests.Count); Assert.AreEqual("host:version", this.socket.Requests[0]); }
public void Initialize() { this.socket = new DummyAdbSocket(); this.adbSocketFactory = (endPoint) => this.socket; this.commandLineClient = new DummyAdbCommandLineClient(); this.adbCommandLineClientFactory = (version) => this.commandLineClient; this.adbClient = new AdbClient(AdbClient.DefaultEndPoint, this.adbSocketFactory); this.adbServer = new AdbServer(this.adbClient, this.adbCommandLineClientFactory); }
public void GetStatusNotRunningTest() { Factories.AdbSocketFactory = (endPoint) => { throw new SocketException(AdbServer.ConnectionRefused); }; var status = AdbServer.GetStatus(); Assert.IsFalse(status.IsRunning); Assert.IsNull(status.Version); }
public void GetStatusOtherSocketExceptionTest() { this.adbSocketFactory = (endPoint) => { throw new SocketException(); }; this.adbClient = new AdbClient(AdbClient.DefaultEndPoint, this.adbSocketFactory); this.adbServer = new AdbServer(this.adbClient, this.adbCommandLineClientFactory); Assert.Throws <SocketException>(() => this.adbServer.GetStatus()); }
public void StartServerNotRunningNoExecutableTest() { this.adbSocketFactory = (endPoint) => { throw new SocketException(AdbServer.ConnectionRefused); }; this.adbClient = new AdbClient(AdbClient.DefaultEndPoint, this.adbSocketFactory); this.adbServer = new AdbServer(this.adbClient, this.adbCommandLineClientFactory); var result = this.adbServer.StartServer(null, false); }
private void Form1_Load(object sender, EventArgs e) { AdbServer server = new AdbServer(); var result = server.StartServer(@"C:\Users\i.g.dincu\Downloads\platform-tools_r30.0.4-windows\platform-tools\adb.exe", restartServerIfNewer: false); var device = AdbClient.Instance.GetDevices().First(); var receiver = new ConsoleOutputReceiver(); AdbClient.Instance.ExecuteRemoteCommand("ip route", device, receiver); MessageBox.Show(receiver.ToString()); }
public void GetStatusOtherExceptionTest() { this.adbSocketFactory = (endPoint) => { throw new Exception(); }; this.adbClient = new AdbClient(AdbClient.DefaultEndPoint, this.adbSocketFactory); this.adbServer = new AdbServer(this.adbClient, this.adbCommandLineClientFactory); var status = this.adbServer.GetStatus(); }
public void StartServerAlreadyRunningTest() { this.socket.Responses.Enqueue(AdbResponse.OK); this.socket.ResponseMessages.Enqueue("0020"); var result = AdbServer.StartServer(null, false); Assert.AreEqual(StartServerResult.AlreadyRunning, result); Assert.AreEqual(1, this.socket.Requests.Count); Assert.AreEqual("host:version", this.socket.Requests[0]); }
public void ConstructorTest() { var adbServer = new AdbServer(); Assert.IsNotNull(adbServer); Assert.IsNotNull(adbServer.EndPoint); Assert.IsInstanceOfType(adbServer.EndPoint, typeof(IPEndPoint)); var endPoint = (IPEndPoint)adbServer.EndPoint; Assert.AreEqual(IPAddress.Loopback, endPoint.Address); Assert.AreEqual(AdbServer.AdbServerPort, endPoint.Port); }
public void GetStatusNotRunningTest() { var adbClientMock = new Mock <IAdbClient>(); adbClientMock.Setup(c => c.GetAdbVersion()) .Throws(new SocketException(AdbServer.ConnectionRefused)); var adbServer = new AdbServer(adbClientMock.Object, this.adbCommandLineClientFactory); var status = adbServer.GetStatus(); Assert.IsFalse(status.IsRunning); Assert.IsNull(status.Version); }
public void StartServerNotRunningTest() { Factories.AdbSocketFactory = (endPoint) => { throw new SocketException(AdbServer.ConnectionRefused); }; this.commandLineClient.Version = new Version(1, 0, 32); Assert.IsFalse(this.commandLineClient.ServerStarted); var result = AdbServer.StartServer("adb.exe", false); Assert.IsTrue(this.commandLineClient.ServerStarted); }
public void GetStatusRunningTest() { this.socket.Responses.Enqueue(AdbResponse.OK); this.socket.ResponseMessages.Enqueue("0020"); var status = AdbServer.GetStatus(); Assert.AreEqual(0, this.socket.Responses.Count); Assert.AreEqual(0, this.socket.ResponseMessages.Count); Assert.AreEqual(1, this.socket.Requests.Count); Assert.AreEqual("host:version", this.socket.Requests[0]); Assert.IsTrue(status.IsRunning); Assert.AreEqual(new Version(1, 0, 32), status.Version); }
public Form1() { server = new AdbServer(); var result = server.StartServer(@"C:\adb\adb.exe", restartServerIfNewer: false); Console.WriteLine("Adb server connection state: " + result.ToString()); client = new AdbClient(); var devices = client.GetDevices(); TargetDevice = devices[0]; //to-do: query user; 0 devices; InitializeComponent(); GetAndShowContinously(); }
private void Initialize() { AdbServer server = new AdbServer(); var result = server.StartServer(@"D:\Android\Sdk\platform-tools\adb.exe", restartServerIfNewer: false); client = (AdbClient)AdbClient.Instance; device = client.GetDevices().Single(); //timer1 = new System.Windows.Forms.Timer { Interval = 50, Enabled = true }; //timer1.Tick += Timer1_Tick; //sw.Start(); ReadBonusImages(); ImageUpdateLoop(); initialized = true; }
public void StartServerIntermediateRestartNotRequestedRunningTest() { this.socket.Responses.Enqueue(AdbResponse.OK); this.socket.ResponseMessages.Enqueue("001f"); this.commandLineClient.Version = new Version(1, 0, 32); Assert.IsFalse(this.commandLineClient.ServerStarted); var result = AdbServer.StartServer("adb.exe", false); Assert.IsFalse(this.commandLineClient.ServerStarted); Assert.AreEqual(1, this.socket.Requests.Count); Assert.AreEqual("host:version", this.socket.Requests[0]); }
public LogicReturn StartServer() { adbServer = new AdbServer(); try { var result = adbServer.StartServer(AdbExecutablePath, false); return(new LogicReturn { Success = true, Data = result.ToString() }); } catch (Exception ex) { return(new LogicReturn { Success = false, Data = ex.Message }); } }