Exemplo n.º 1
0
        private void ProcessTrackingDevicesNotification(int length)
        {
            List <Device> currentDevices = new List <Device>();

            if (length > 0)
            {
                byte[]   buffer  = new byte[length];
                string   result  = ReadString(this.socketTrackDevices, buffer);
                string[] devices = result.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string deviceData in devices)
                {
                    try
                    {
                        Device device = Device.CreateFromAdbData(deviceData);
                        if (device != null)
                        {
                            currentDevices.Add(device);
                        }
                    }
                    catch (ArgumentException ae)
                    {
                        Log.e(loggingTag, ae);
                    }
                }
            }

            UpdateDevices(currentDevices);
        }
Exemplo n.º 2
0
        /**
         * Returns the list of devices currently known to the ADB server at the
         * indicated endpoint. Never throws; rather, an possibly incomplete list
         * of devices is returned instead.
         */
        public List <Device> GetDevices(IPEndPoint address)
        {
            List <Device> result = new List <Device>();

            try {
                // -l will return additional data
                using (Socket socket = ExecuteRawSocketCommand(address, "host:devices-l"))
                {
                    byte[] reply = new byte[4];
                    Read(socket, reply);    // throws

                    string lenHex = reply.GetString(Encoding.Default);
                    int    len    = int.Parse(lenHex, NumberStyles.HexNumber);

                    reply = new byte[len];
                    Read(socket, reply);    //throws

                    string[] data = reply.GetString(Encoding.Default).Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);

                    // Device might disappear before we get to it, which might cause throwing.
                    // Ignore in that case: what else could we do?
                    foreach (string deviceData in data)
                    {
                        Device device;
                        try {
                            device = Device.CreateFromAdbData(deviceData);
                        }
                        catch (Exception e)
                        {
                            device = null;
                            Log.e(LOGGING_TAG, e);
                        }
                        if (device != null)
                        {
                            result.Add(device);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.e(LOGGING_TAG, e);
            }
            return(result);
        }