Esempio n. 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();
            });
        }
Esempio n. 2
0
        public void GetStatusOtherExceptionTest()
        {
            Factories.AdbSocketFactory = (endPoint) =>
            {
                throw new Exception();
            };

            var status = AdbServer.GetStatus();
        }
Esempio n. 3
0
 public void ServerWatchDog()
 {
     while (_isEngineRunning)
     {
         if (!_server.GetStatus().IsRunning)
         {
             StartServer();
         }
         Thread.Sleep(1000);
     }
 }
Esempio n. 4
0
        public void GetStatusNotRunningTest()
        {
            Factories.AdbSocketFactory = (endPoint) =>
            {
                throw new SocketException(AdbServer.ConnectionRefused);
            };

            var status = AdbServer.GetStatus();

            Assert.IsFalse(status.IsRunning);
            Assert.IsNull(status.Version);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        public void StartScrcpyServer(UsbDeviceEventArgs dev)
        {
            Task <int> task = new Task <int>(() =>
            {
                try
                {
                    OnVideoDataArrived cb = OnMirrorImageArrive;
                    RegistVideoCB(cb);
                    GC.KeepAlive(cb);
                    OnScrcpyLog cb2 = OnScrcpyLog1;
                    RegistScrcpyLogCB(cb2);
                    GC.KeepAlive(cb);
                    SetADBFolderPath(Marshal.StringToHGlobalAnsi(adb_path_)
                                     , Marshal.StringToHGlobalAnsi(adb_svr_path_));
                    IntPtr[] sbs = GetCommand($"-s {dev.GetSerial()} -m {Display_height} -b 2M");
                    var ret      = RunScrcpy(sbs.Length, sbs);

                    return(ret);
                }
                catch (Exception e)
                {
                    log_.Error($"StartScrcpyServer {e.ToString()}");
                }
                finally
                {
                    OnDeviceDisconnected?.Invoke(this, dev);
                    if (!adb_server_.GetStatus().IsRunning)
                    {
                        adb_server_.RestartServer();
                    }
                }
                return(-1);
            });

            task.Start();
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            Console.WriteLine("Connecting to the ADB server. Please wait..");

            AdbServer       server        = new AdbServer();
            AdbServerStatus currentStatus = server.GetStatus();

            StartServerResult startStatus = server.StartServer(ConfigurationManager.AppSettings["AdbPath"], restartServerIfNewer: false);

            switch (startStatus)
            {
            case StartServerResult.AlreadyRunning:
                Console.WriteLine("ADB daemon already running.");
                break;

            case StartServerResult.RestartedOutdatedDaemon:
                Console.WriteLine("Restarted outdated ADB daemon.");
                break;

            case StartServerResult.Started:
                Console.WriteLine("ADB daemon has been started.");
                break;
            }

            AdbClient client = new AdbClient();

            Console.WriteLine("Currently connected devices:");

            List <DeviceData> devices = client.GetDevices();

            for (int c = 0; c < devices.Count; c++)
            {
                Console.WriteLine($"\t{c}: {devices[c].Name}");
            }

            Console.Write("Device to attach: ");
            int deviceNumber = int.Parse(Console.ReadLine());

            Console.WriteLine("Running processes: ");

            List <ProcInfo> procs = GetProcs(client, devices[deviceNumber]);

            foreach (ProcInfo proc in procs)
            {
                Console.WriteLine($"\t{proc.Name}");
            }

            Console.Write("Process to monitor (name): ");
            string procName = Console.ReadLine();

            Console.Write("Keyword to search for: ");
            string keyWord = Console.ReadLine();

            if (string.IsNullOrEmpty(keyWord))
            {
                keyWord = null;
            }

            ProcInfo procToMonitor = procs.Where(n => n.Name == procName).FirstOrDefault();

            if (procToMonitor != null)
            {
                Console.WriteLine($"Watching {procToMonitor.Name} with PID {procToMonitor.Pid}...");
                DateTime lastLoggedAt = new DateTime();
                for (; ;)
                {
                    procs = GetProcs(client, devices[deviceNumber]);
                    if (procs.Any(n => n.Pid == procToMonitor.Pid && n.Name == n.Name))
                    {
                        ConsoleOutputReceiver logcatInspect = new ConsoleOutputReceiver();
                        client.ExecuteRemoteCommand("logcat -d", devices[deviceNumber], logcatInspect);
                        string[] allLogs = logcatInspect.ToString().Split("\n");
                        foreach (string log in allLogs)
                        {
                            string dateTimeString = Regex.Match(log, @"\d{2}-\d{2} \d{1,2}:\d{1,2}:\d{1,2}.\d{1,3}").Value;
                            if (!string.IsNullOrEmpty(dateTimeString))
                            {
                                DateTime loggedAt = DateTime.ParseExact(dateTimeString, "MM-dd HH:mm:ss.fff", null);
                                if (loggedAt > lastLoggedAt)
                                {
                                    if (keyWord != null && log.Contains(keyWord))
                                    {
                                        Console.WriteLine($"Keyword {keyWord} found: {log}");
                                    }
                                    lastLoggedAt = loggedAt;
                                }
                            }
                        }
                        Thread.Sleep(1000);
                    }
                    else
                    {
                        Console.WriteLine("Broke! Dumping logs!");
                        break;
                    }
                }
            }

            ConsoleOutputReceiver consoleOutput = new ConsoleOutputReceiver();

            client.ExecuteRemoteCommand("logcat -d", devices[deviceNumber], consoleOutput);

            File.WriteAllText($"logcat_dump_{procToMonitor.Name}_{procToMonitor.Pid}.txt", consoleOutput.ToString());

            return;
        }