コード例 #1
0
ファイル: DeviceMonitor.cs プロジェクト: thechampanurag/madb
        /// <summary>
        /// Processes the incoming device data.
        /// </summary>
        /// <param name="length">The length.</param>
        private void ProcessIncomingDeviceData(int length)
        {
            List <Device> list = new List <Device> ( );

            if (length > 0)
            {
                byte[] buffer = new byte[length];
                String result = Read(MainAdbConnection, buffer);

                String[] devices = result.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                devices.ForEach(d => {
                    try {
                        var dv = Device.CreateFromAdbData(d);
                        if (dv != null)
                        {
                            list.Add(dv);
                        }
                    } catch (ArgumentException ae) {
                        Log.e(TAG, ae);
                    }
                });
            }

            // now merge the new devices with the old ones.
            UpdateDevices(list);
        }
コード例 #2
0
ファイル: AdbHelper.cs プロジェクト: thechampanurag/madb
        /// <summary>
        /// Gets the devices that are available for communication.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <returns>A list of devices that are connected.</returns>
        /// <gist id="a8acf10d48370d138247" />
        public List <Device> GetDevices(IPEndPoint address)
        {
            // -l will return additional data
            using (var socket = ExecuteRawSocketCommand(address, "host:devices-l")) {
                byte[] reply = new byte[4];

                if (!Read(socket, reply))
                {
                    Log.e(TAG, "error in getting data length");
                    return(null);
                }
                String lenHex = reply.GetString(Encoding.Default);
                int    len    = int.Parse(lenHex, System.Globalization.NumberStyles.HexNumber);

                reply = new byte[len];
                if (!Read(socket, reply))
                {
                    Log.e(TAG, "error in getting data");
                    return(null);
                }

                List <Device> s    = new List <Device>();
                String[]      data = reply.GetString(Encoding.Default).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                data.ForEach(item => {
                    var device = Device.CreateFromAdbData(item);
                    s.Add(device);
                });

                return(s);
            }
        }
コード例 #3
0
        /// <summary>
        /// Processes the incoming device data.
        /// </summary>
        /// <param name="length">The length.</param>
        private void ProcessIncomingDeviceData(int length)
        {
            List <Device> list = new List <Device>();

            if (length > 0)
            {
                byte[] buffer = new byte[length];
                string result = Read(MainAdbConnection, buffer);

                string[] devices = result.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string d in devices)
                {
                    try
                    {
                        Log.V(TAG, "Received device data: {0}", d);
                        Device device = Device.CreateFromAdbData(d);
                        if (device != null)
                        {
                            list.Add(device);
                        }
                    }
                    catch (ArgumentException ae)
                    {
                        Log.E(TAG, ae);
                    }
                }
            }

            // now merge the new devices with the old ones.
            UpdateDevices(list);
        }
コード例 #4
0
ファイル: AdbHelper.cs プロジェクト: rbergen/CherryUpdater
        /// <summary>
        /// Gets the devices that are available for communication.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <returns></returns>
        public List <Device> GetDevices(IPEndPoint address)
        {
            byte[] request = FormAdbRequest("host:devices");             //$NON-NLS-1$
            byte[] reply;
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                socket.ReceiveTimeout = SOCKET_TIMEOUT;
                socket.SendTimeout    = SOCKET_TIMEOUT;
                socket.Connect(address);
                socket.Blocking = true;
                if (!Write(socket, request))
                {
                    throw new AdbException("failed asking for devices");
                }

                AdbResponse resp = ReadAdbResponse(socket, false /* readDiagstring */);
                if (!resp.IOSuccess || !resp.Okay)
                {
                    Log.E(TAG, "Got timeout or unhappy response from ADB fb req: " + resp.Message);
                    socket.Close();
                    return(null);
                }

                reply = new byte[4];
                if (!Read(socket, reply))
                {
                    Log.E(TAG, "error in getting data length");
                    socket.Close();
                    return(null);
                }
                string lenHex = Encoding.Default.GetString(reply);
                int    len    = int.Parse(lenHex, System.Globalization.NumberStyles.HexNumber);

                reply = new byte[len];
                if (!Read(socket, reply))
                {
                    Log.E(TAG, "error in getting data");
                    socket.Close();
                    return(null);
                }

                List <Device> s    = new List <Device>();
                string[]      data = Encoding.Default.GetString(reply).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var item in data)
                {
                    s.Add(Device.CreateFromAdbData(item));
                }
                return(s);
            }
            finally
            {
                socket.Close();
            }
        }