예제 #1
0
        /// <summary>
        /// Opens the client.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="pid">The pid.</param>
        /// <param name="port">The port.</param>
        /// <param name="monitorThread">The monitor thread.</param>
        private void OpenClient(Device device, int pid, int port, MonitorThread monitorThread)
        {
            Socket clientSocket;

            try {
                clientSocket = AdbHelper.Instance.CreatePassThroughConnection(AndroidDebugBridge.SocketAddress, device, pid);

                clientSocket.Blocking = true;
            } catch (IOException ioe) {
                Log.w(TAG, "Failed to connect to client {0}: {1}'", pid, ioe.Message);
                return;
            }

            CreateClient(device, pid, clientSocket, port, monitorThread);
        }
예제 #2
0
        /// <summary>
        /// Opens the client.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="pid">The pid.</param>
        /// <param name="port">The port.</param>
        /// <param name="monitorThread">The monitor thread.</param>
        private void OpenClient( Device device, int pid, int port, MonitorThread monitorThread )
        {
            Socket clientSocket;
            try {
                clientSocket = AdbHelper.Instance.CreatePassThroughConnection ( AndroidDebugBridge.SocketAddress, device, pid );

                clientSocket.Blocking = true;
            } catch ( IOException ioe ) {
                Log.w ( TAG, "Failed to connect to client {0}: {1}'", pid, ioe.Message );
                return;
            }

            CreateClient ( device, pid, clientSocket, port, monitorThread );
        }
예제 #3
0
        /// <summary>
        /// Creates the client.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="pid">The pid.</param>
        /// <param name="socket">The socket.</param>
        /// <param name="debuggerPort">The debugger port.</param>
        /// <param name="monitorThread">The monitor thread.</param>
        private void CreateClient( Device device, int pid, Socket socket, int debuggerPort, MonitorThread monitorThread )
        {
            /*
             * Successfully connected to something. Create a Client object, add
             * it to the list, and initiate the JDWP handshake.
             */

            Client client = new Client ( device, socket, pid );

            if ( client.SendHandshake ( ) ) {
                try {
                    if ( AndroidDebugBridge.ClientSupport ) {
                        client.ListenForDebugger ( debuggerPort );
                    }
                } catch ( IOException ) {
                    client.ClientData.DebuggerConnectionStatus = Managed.Adb.ClientData.DebuggerStatus.ERROR;
                    Log.e ( "ddms", "Can't bind to local {0} for debugger", debuggerPort );
                    // oh well
                }

                client.RequestAllocationStatus ( );
            } else {
                Log.e ( "ddms", "Handshake with {0} failed!", client );
                /*
                 * The handshake send failed. We could remove it now, but if the
                 * failure is "permanent" we'll just keep banging on it and
                 * getting the same result. Keep it in the list with its "error"
                 * state so we don't try to reopen it.
                 */
            }

            if ( client.IsValid ) {
                device.Clients.Add ( client );
                monitorThread.Clients.Add ( client );
            } else {
                client = null;
            }
        }
예제 #4
0
        /// <summary>
        /// Creates the client.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="pid">The pid.</param>
        /// <param name="socket">The socket.</param>
        /// <param name="debuggerPort">The debugger port.</param>
        /// <param name="monitorThread">The monitor thread.</param>
        private void CreateClient(Device device, int pid, Socket socket, int debuggerPort, MonitorThread monitorThread)
        {
            /*
             * Successfully connected to something. Create a Client object, add
             * it to the list, and initiate the JDWP handshake.
             */

            Client client = new Client(device, socket, pid);

            if (client.SendHandshake( ))
            {
                try {
                    if (AndroidDebugBridge.ClientSupport)
                    {
                        client.ListenForDebugger(debuggerPort);
                    }
                } catch (IOException) {
                    client.ClientData.DebuggerConnectionStatus = Managed.Adb.ClientData.DebuggerStatus.ERROR;
                    Log.e("ddms", "Can't bind to local {0} for debugger", debuggerPort);
                    // oh well
                }

                client.RequestAllocationStatus( );
            }
            else
            {
                Log.e("ddms", "Handshake with {0} failed!", client);

                /*
                 * The handshake send failed. We could remove it now, but if the
                 * failure is "permanent" we'll just keep banging on it and
                 * getting the same result. Keep it in the list with its "error"
                 * state so we don't try to reopen it.
                 */
            }

            if (client.IsValid)
            {
                device.Clients.Add(client);
                monitorThread.Clients.Add(client);
            }
            else
            {
                client = null;
            }
        }
예제 #5
0
        private void DeviceClientMonitorLoop( )
        {
            do
            {
                try {
                    // This synchronized block stops us from doing the select() if a new
                    // Device is being added.
                    // @see startMonitoringDevice()
                    lock ( Devices ) {
                    }

                    //int count = Selector.Select ( );
                    int count = 0;

                    if (!IsRunning)
                    {
                        return;
                    }

                    lock ( ClientsToReopen ) {
                        if (ClientsToReopen.Count > 0)
                        {
                            Dictionary <IClient, int> .KeyCollection clients = ClientsToReopen.Keys;
                            MonitorThread monitorThread = MonitorThread.Instance;

                            foreach (IClient client in clients)
                            {
                                Device device = client.DeviceImplementation;
                                int    pid    = client.ClientData.Pid;

                                monitorThread.DropClient(client, false /* notify */);

                                // This is kinda bad, but if we don't wait a bit, the client
                                // will never answer the second handshake!
                                WaitBeforeContinue( );

                                int port = ClientsToReopen[client];

                                if (port == DebugPortManager.NO_STATIC_PORT)
                                {
                                    port = GetNextDebuggerPort( );
                                }
                                Log.d("DeviceMonitor", "Reopening " + client);
                                OpenClient(device, pid, port, monitorThread);
                                device.OnClientListChanged(EventArgs.Empty);
                            }

                            ClientsToReopen.Clear( );
                        }
                    }

                    if (count == 0)
                    {
                        continue;
                    }

                    /*List<SelectionKey> keys = Selector.selectedKeys();
                     * List<SelectionKey>.Enumerator iter = keys.GetEnumerator();
                     *
                     * while (iter.MoveNext()) {
                     *              SelectionKey key = iter.next();
                     *              iter.remove();
                     *
                     *              if (key.isValid() && key.isReadable()) {
                     *                              Object attachment = key.attachment();
                     *
                     *                              if (attachment instanceof Device) {
                     *                                              Device device = (Device)attachment;
                     *
                     *                                              SocketChannel socket = device.getClientMonitoringSocket();
                     *
                     *                                              if (socket != null) {
                     *                                                              try {
                     *                                                                              int length = readLength(socket, mLengthBuffer2);
                     *
                     *                                                                              processIncomingJdwpData(device, socket, length);
                     *                                                              } catch (IOException ioe) {
                     *                                                                              Log.d("DeviceMonitor",
                     *                                                                                                              "Error reading jdwp list: " + ioe.getMessage());
                     *                                                                              socket.close();
                     *
                     *                                                                              // restart the monitoring of that device
                     *                                                                              synchronized (mDevices) {
                     *                                                                                              if (mDevices.contains(device)) {
                     *                                                                                                              Log.d("DeviceMonitor",
                     *                                                                                                                                              "Restarting monitoring service for " + device);
                     *                                                                                                              startMonitoringDevice(device);
                     *                                                                                              }
                     *                                                                              }
                     *                                                              }
                     *                                              }
                     *                              }
                     *              }
                     * }*/
                } catch (IOException e) {
                    if (!IsRunning)
                    {
                    }
                }
            } while (IsRunning);
        }