コード例 #1
0
        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();
            });
        }
コード例 #2
0
 /// <summary>
 /// Create new adb controller
 /// </summary>
 /// <param name="adbPath"></param>
 internal AdbController(string adbPath, ILog logger)
 {
     server.StartServer(Path.Combine(adbPath, "adb.exe"), false);
     this.logger = logger;
     KillPortUsage();
     monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));
     monitor.DeviceConnected    += OnDeviceConnected;
     monitor.DeviceDisconnected += OnDeviceDisconnected;
     devices = client.GetDevices();
 }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
ファイル: AddDevice.cs プロジェクト: oznotes/Onions-Service
        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);
            }
        }
コード例 #5
0
 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);
 }
コード例 #6
0
ファイル: CommandADB.cs プロジェクト: islenny/Phone-Hub
 private void StartServer()
 {
     if (AdbClient == null)
     {
         server.StartServer(AdbPath, restartServerIfNewer: false);
         AdbClient = new AdbClient();
     }
 }
コード例 #7
0
ファイル: Form1.cs プロジェクト: PixelBotTH/GetColorADB
        public Form1()
        {
            InitializeComponent();

            AdbServer server = new AdbServer();

            server.StartServer(Application.StartupPath + "/adb/adb.exe", restartServerIfNewer: false);
        }
コード例 #8
0
 private void StartServer()
 {
     if (AdbClient == null)
     {
         var _ = server.StartServer(CommandStr, restartServerIfNewer: false);
         AdbClient = new AdbClient();
     }
 }
コード例 #9
0
 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);
 }
コード例 #10
0
 public void Iniciar()
 {
     if (server == null)
     {
         server = new AdbServer();
         var result = server.StartServer(this.getPath() + "adb.exe", restartServerIfNewer: false);
         server.RestartServer();
     }
 }
コード例 #11
0
ファイル: AdbServerTests.cs プロジェクト: parkheeyoung/madb
        public void StartServerNotRunningNoExecutableTest()
        {
            Factories.AdbSocketFactory = (endPoint) =>
            {
                throw new SocketException(AdbServer.ConnectionRefused);
            };

            var result = AdbServer.StartServer(null, false);
        }
コード例 #12
0
ファイル: AdbServerTests.cs プロジェクト: parkheeyoung/madb
        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]);
        }
コード例 #13
0
        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];
        }
コード例 #14
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;
        }
コード例 #15
0
        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());
        }
コード例 #16
0
 public Extractor(string adbPath)
 {
     //if couldn't resolve adb path throw error
     if (!File.Exists(adbPath))
     {
         throw new Exception("adb.exe not found.");
     }
     //start adb daemon
     _server.StartServer(adbPath, true);
     //command line client for adb
     _adbCmd = new MyAdbCommandLineClient(adbPath);
 }
コード例 #17
0
ファイル: AdbServerTests.cs プロジェクト: parkheeyoung/madb
        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]);
        }
コード例 #18
0
        public void startADB()
        {
            _vm.Status      = "adb Starting....";
            AdbServerStatus = null;

            Task task = Task.Factory.StartNew(() =>
            {
                var result = server.StartServer(@".\adb\adb.exe", restartServerIfNewer: false);

                AdbServerStatus = result;
                _vm.Status      = $"adb {result}";
            });
        }
コード例 #19
0
 private void StartAdb()
 {
     // Trying to start ADB server and find device
     try
     {
         server.StartServer(adbPath, false);
     }
     catch
     {
         MessageBox.Show(File.Exists(adbPath)
             ? "Can't start ADB server. Please, check log and ask developer for it"
             : "Can't find ADB server EXE. Please, redownload app. ");
     }
 }
コード例 #20
0
ファイル: AdbServerTests.cs プロジェクト: parkheeyoung/madb
        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);
        }
コード例 #21
0
        internal static bool StartServer(string?adbPath = null)
        {
            if (string.IsNullOrEmpty(adbPath) && SearchCurrentDirectoryForADB(out adbPath))
            {
                if (string.IsNullOrEmpty(adbPath))
                {
                    throw new AdbFilesNotFoundException();
                }
            }

            Logger.Trace("ADB files found at " + adbPath + " directory.");
            Logger.Info($"{Constants.ADB_EXE_NAME} found at {adbPath + "/" + Constants.ADB_EXE_NAME}");
            Console.WriteLine(Server.StartServer(adbPath + "/" + Constants.ADB_EXE_NAME, false));
            return(true);
        }
コード例 #22
0
        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();
        }
コード例 #23
0
        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;
        }
コード例 #24
0
ファイル: AdbServerTests.cs プロジェクト: parkheeyoung/madb
        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]);
        }
コード例 #25
0
ファイル: AdbClass.cs プロジェクト: azn5red-archive/BotRoC
 private void StartAdbServer()
 {
     try
     {
         log.Debug("Trying to connect to emulator");
         server = new AdbServer();
         server.StartServer(@"./resources/Android/adb.exe", restartServerIfNewer: false);
         client = (AdbClient)AdbClient.Instance;            // AdbClient.Instance.CreateAdbForwardRequest("localhost", 21503);
         device = AdbClient.Instance.GetDevices()[0];
         log.Info("Connected to : " + device);
     }
     catch (Exception e)
     {
         client.KillAdb();
         log.Error("Connexion error : " + e.Data);
     }
 }
コード例 #26
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
         });
     }
 }
コード例 #27
0
        public MainWindow()
        {
            InitializeComponent();


            AdbServer         server = new AdbServer();
            StartServerResult result = server.StartServer(@"C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe", restartServerIfNewer: false);

            txtStatus.Text = "Adb Status : " + result.ToString();
            txtIP.Text     = Properties.Settings.Default.LastIp;
            GetListOfDevices();

            var monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));

            monitor.DeviceConnected    += this.OnDeviceConnected;
            monitor.DeviceDisconnected += Monitor_DeviceDisconnected;
            monitor.Start();
        }
コード例 #28
0
ファイル: Form1.cs プロジェクト: gdincu/MDC-Android-Tool
        private void Form1_Load(object sender, EventArgs e)
        {
            //Retrieve commands from the settings.xml file
            ReadValuesAsync(Commands, "Commands");

            //Starts the AdbServer
            AdbServer server = new AdbServer();
            //Extracts the ADB path from the settings file
            string ADBPath = XElement.Load(Settings).Element("ADBPath").Value;

            server.StartServer(ADBPath, restartServerIfNewer: false);

            // ChecksHowManyDevicesAreCurrentlyConnected
            while (!NumberOfDevicesConnectedEqualsOne())
            {
                if (ReturnNumberOfDevicesConnected().Equals(0))
                {
                    if (MessageBox.Show("Please connect a device to continue!", "Connect a device!", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                    {
                        Environment.Exit(0);
                    }
                }

                if (ReturnNumberOfDevicesConnected() > 1)
                {
                    if (MessageBox.Show("Please ensure that only one device is connected!", "Check number of connected devices!", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                    {
                        Environment.Exit(0);
                    }
                }
            }

            ReadValuesAsync(Items, "Items");
            ReadValuesAsync(EOTBarcodes, "EOTBarcodes");
            ReadValuesAsync(URIs, "URIs");
            ReadValuesAsync(HandheldDevices, "HandheldDevices");

            PopulateListBox(listBox1, Items);
            PopulateListBox(listBox2, EOTBarcodes);
            PopulateListBox(listBox3, URIs);
            PopulateListBox(listBox4, Commands);
            PopulateListBox(listBox5, ReturnListOfInstalledApps());
        }
コード例 #29
0
ファイル: ADB.cs プロジェクト: QuestMods/QuestHome
        public StartServerResult Initialize()
        {
            var config = Program.config;

            if (config[s].ContainsKey("path"))
            {
                return(StartServerResult.AlreadyRunning);
            }
            server = new AdbServer();
            var result = server.StartServer(config[s]["path"], restartServerIfNewer: false);
            // Logger.Trace("ADB Connected Devices: {}", AdbClient.Instance.GetDevices().ToJson());
            var monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));

            monitor.DeviceConnected    += OnDeviceConnected;
            monitor.DeviceChanged      += DeviceChanged;
            monitor.DeviceDisconnected += DeviceDisconnected;
            Task.Factory.StartNew(() => monitor.Start());
            return(result);
        }
コード例 #30
0
        private void btnInfo_Click(object sender, EventArgs e)
        {
            AdbServer server  = new AdbServer();
            var       result  = server.StartServer("adb.exe", restartServerIfNewer: false);
            var       devices = AdbClient.Instance.GetDevices();
            int       i       = 1;

            rtbInfo.Text = "";
            foreach (var device in devices)
            {
                rtbInfo.Text = rtbInfo.Text + "\n" + "Device " + i + ":\n" +
                               "\t>> Phone Name: " + device.Name + "\n" +
                               "\t>> Phone Model: " + device.Model + "\n" +
                               "\t>> Phone Product: " + device.Product + "\n" +
                               "\t>> Phone Serial: " + device.Serial;
                i++;
                rtbInfo.Text = rtbInfo.Text + "\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ";
            }
        }