コード例 #1
0
ファイル: EmulatorConsole.cs プロジェクト: yuva2achieve/dot42
		/// <summary>
		/// Starts the connection of the console. </summary>
		/// <returns> true if success. </returns>
		private bool start()
		{

			DnsEndPoint socketAddr;
			try
			{
				socketAddr = new DnsEndPoint(HOST, mPort);
			}
			catch (ArgumentException)
			{
				return false;
			}

			try
			{
				mSocketChannel = SocketChannel.open(socketAddr);
			}
			catch (IOException)
			{
				return false;
			}

			// read some stuff from it
			readLines();

			return true;
		}
コード例 #2
0
        /// <summary>
        /// Runs a log service on the <seealso cref="Device"/>, and provides its output to the <seealso cref="LogReceiver"/>.
        /// <p/>This call is blocking until <seealso cref="LogReceiver#isCancelled()"/> returns true. </summary>
        /// <param name="adbSockAddr"> the socket address to connect to adb </param>
        /// <param name="device"> the Device on which to run the service </param>
        /// <param name="logName"> the name of the log file to output </param>
        /// <param name="rcvr"> the <seealso cref="LogReceiver"/> to receive the log output </param>
        /// <exception cref="TimeoutException"> in case of timeout on the connection. </exception>
        /// <exception cref="AdbCommandRejectedException"> if adb rejects the command </exception>
        /// <exception cref="IOException"> in case of I/O error on the connection. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void runLogService(java.net.InetSocketAddress adbSockAddr, Device device, String logName, com.android.ddmlib.log.LogReceiver rcvr) throws TimeoutException, AdbCommandRejectedException, java.io.IOException
        public static void runLogService(EndPoint adbSockAddr, Device device, string logName, LogReceiver rcvr)
        {
            SocketChannel adbChan = null;

            try
            {
                adbChan = SocketChannel.open(adbSockAddr);
                adbChan.configureBlocking(false);

                // if the device is not -1, then we first tell adb we're looking to talk
                // to a specific device
                setDevice(adbChan, device);

                var request = formAdbRequest("log:" + logName);
                write(adbChan, request);

                AdbResponse resp = readAdbResponse(adbChan, false);                 // readDiagString
                if (resp.okay == false)
                {
                    throw new AdbCommandRejectedException(resp.message);
                }

                var        data = new byte[16384];
                ByteBuffer buf  = ByteBuffer.wrap(data);
                while (true)
                {
                    int count;

                    if (rcvr != null && rcvr.cancelled)
                    {
                        break;
                    }

                    count = adbChan.read(buf);
                    if (count < 0)
                    {
                        break;
                    }
                    else if (count == 0)
                    {
                        Thread.Sleep(WAIT_TIME * 5);
                    }
                    else
                    {
                        if (rcvr != null)
                        {
                            rcvr.parseNewData(buf.array(), buf.arrayOffset(), buf.position);
                        }
                        buf.rewind();
                    }
                }
            }
            finally
            {
                if (adbChan != null)
                {
                    adbChan.close();
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Reboot the device.
        /// </summary>
        /// <param name="into"> what to reboot into (recovery, bootloader).  Or null to just reboot. </param>
        /// <exception cref="TimeoutException"> in case of timeout on the connection. </exception>
        /// <exception cref="AdbCommandRejectedException"> if adb rejects the command </exception>
        /// <exception cref="IOException"> in case of I/O error on the connection. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void reboot(String into, java.net.InetSocketAddress adbSockAddr, Device device) throws TimeoutException, AdbCommandRejectedException, java.io.IOException
        public static void reboot(string into, EndPoint adbSockAddr, Device device)
        {
            byte[] request;
            if (into == null)
            {
                request = formAdbRequest("reboot:");                 //$NON-NLS-1$
            }
            else
            {
                request = formAdbRequest("reboot:" + into);                 //$NON-NLS-1$
            }

            SocketChannel adbChan = null;

            try
            {
                adbChan = SocketChannel.open(adbSockAddr);
                adbChan.configureBlocking(false);

                // if the device is not -1, then we first tell adb we're looking to talk
                // to a specific device
                setDevice(adbChan, device);

                write(adbChan, request);
            }
            finally
            {
                if (adbChan != null)
                {
                    adbChan.close();
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Remove a port forwarding between a local and a remote port. </summary>
        /// <param name="adbSockAddr"> the socket address to connect to adb </param>
        /// <param name="device"> the device on which to remove the port fowarding </param>
        /// <param name="localPort"> the local port of the forward </param>
        /// <param name="remotePort"> the remote port. </param>
        /// <exception cref="TimeoutException"> in case of timeout on the connection. </exception>
        /// <exception cref="AdbCommandRejectedException"> if adb rejects the command </exception>
        /// <exception cref="IOException"> in case of I/O error on the connection. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void removeForward(java.net.InetSocketAddress adbSockAddr, Device device, int localPort, int remotePort) throws TimeoutException, AdbCommandRejectedException, java.io.IOException
        public static void removeForward(EndPoint adbSockAddr, Device device, int localPort, int remotePort)
        {
            SocketChannel adbChan = null;

            try
            {
                adbChan = SocketChannel.open(adbSockAddr);
                adbChan.configureBlocking(false);

                var request = formAdbRequest(string.Format("host-serial:{0}:killforward:tcp:{1:D};tcp:{2:D}", device.serialNumber, localPort, remotePort));                 //$NON-NLS-1$

                write(adbChan, request);

                AdbResponse resp = readAdbResponse(adbChan, false);                 // readDiagString
                if (resp.okay == false)
                {
                    Log.w("remove-forward", "Error creating forward: " + resp.message);
                    throw new AdbCommandRejectedException(resp.message);
                }
            }
            finally
            {
                if (adbChan != null)
                {
                    adbChan.close();
                }
            }
        }
コード例 #5
0
ファイル: SyncService.cs プロジェクト: yuva2achieve/dot42
        /// <summary>
        /// Opens the sync connection. This must be called before any calls to push[File] / pull[File]. </summary>
        /// <returns> true if the connection opened, false if adb refuse the connection. This can happen
        /// if the <seealso cref="Device"/> is invalid. </returns>
        /// <exception cref="TimeoutException"> in case of timeout on the connection. </exception>
        /// <exception cref="AdbCommandRejectedException"> if adb rejects the command </exception>
        /// <exception cref="IOException"> If the connection to adb failed. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: boolean openSync() throws TimeoutException, AdbCommandRejectedException, java.io.IOException
        internal bool openSync()
        {
            try
            {
                mChannel = SocketChannel.open(mAddress);
                mChannel.configureBlocking(false);

                // target a specific device
                AdbHelper.setDevice(mChannel, mDevice);

                var request = AdbHelper.formAdbRequest("sync:");                 //$NON-NLS-1$
                AdbHelper.write(mChannel, request, -1, DdmPreferences.timeOut);

                AdbHelper.AdbResponse resp = AdbHelper.readAdbResponse(mChannel, false);                 // readDiagString

                if (resp.okay == false)
                {
                    Log.w("ddms", "Got unhappy response from ADB sync req: " + resp.message);
                    mChannel.close();
                    mChannel = null;
                    return(false);
                }
            }
            catch (TimeoutException e)
            {
                if (mChannel != null)
                {
                    try
                    {
                        mChannel.close();
                    }
                    catch (IOException)
                    {
                        // we want to throw the original exception, so we ignore this one.
                    }
                    mChannel = null;
                }

                throw e;
            }
            catch (IOException e)
            {
                if (mChannel != null)
                {
                    try
                    {
                        mChannel.close();
                    }
                    catch (IOException)
                    {
                        // we want to throw the original exception, so we ignore this one.
                    }
                    mChannel = null;
                }

                throw e;
            }

            return(true);
        }
コード例 #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void openChannel() throws java.io.IOException
            internal virtual void openChannel()
            {
                if (socketChannel == null)
                {
                    socketChannel = SocketChannel.open();
                    // Use a non-blocking channel as we are polling for data
                    socketChannel.configureBlocking(false);
                    // Connect has no timeout
                    socketChannel.socket().SoTimeout = 0;
                }
            }
コード例 #7
0
        /// <summary>
        /// Attempts to connect to the debug bridge server. </summary>
        /// <returns> a connect socket if success, null otherwise </returns>
        private SocketChannel openAdbConnection()
        {
            Log.d("DeviceMonitor", "Connecting to adb for Device List Monitoring...");

            SocketChannel adbChannel = null;

            try
            {
                adbChannel = SocketChannel.open(AndroidDebugBridge.socketAddress);
                adbChannel.socket().NoDelay = true;
            }
            catch (IOException)
            {
            }

            return(adbChannel);
        }
コード例 #8
0
        /// <summary>
        /// Create and connect a new pass-through socket, from the host to a port on
        /// the device.
        /// </summary>
        /// <param name="adbSockAddr"> </param>
        /// <param name="device"> the device to connect to. Can be null in which case the connection will be
        /// to the first available device. </param>
        /// <param name="devicePort"> the port we're opening </param>
        /// <exception cref="TimeoutException"> in case of timeout on the connection. </exception>
        /// <exception cref="IOException"> in case of I/O error on the connection. </exception>
        /// <exception cref="AdbCommandRejectedException"> if adb rejects the command </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static java.nio.channels.SocketChannel open(java.net.InetSocketAddress adbSockAddr, Device device, int devicePort) throws java.io.IOException, TimeoutException, AdbCommandRejectedException
        public static SocketChannel open(EndPoint adbSockAddr, Device device, int devicePort)
        {
            SocketChannel adbChan = SocketChannel.open(adbSockAddr);

            try
            {
                adbChan.socket().NoDelay = true;
                adbChan.configureBlocking(false);

                // if the device is not -1, then we first tell adb we're looking to
                // talk to a specific device
                setDevice(adbChan, device);

                var req = createAdbForwardRequest(null, devicePort);
                // Log.hexDump(req);

                write(adbChan, req);

                AdbResponse resp = readAdbResponse(adbChan, false);
                if (resp.okay == false)
                {
                    throw new AdbCommandRejectedException(resp.message);
                }

                adbChan.configureBlocking(true);
            }
            catch (TimeoutException e)
            {
                adbChan.close();
                throw e;
            }
            catch (IOException e)
            {
                adbChan.close();
                throw e;
            }

            return(adbChan);
        }
コード例 #9
0
        /// <summary>
        /// Executes a shell command on the device and retrieve the output. The output is
        /// handed to <var>rcvr</var> as it arrives.
        /// </summary>
        /// <param name="adbSockAddr"> the <seealso cref="InetSocketAddress"/> to adb. </param>
        /// <param name="command"> the shell command to execute </param>
        /// <param name="device"> the <seealso cref="IDevice"/> on which to execute the command. </param>
        /// <param name="rcvr"> the <seealso cref="IShellOutputReceiver"/> that will receives the output of the shell
        ///            command </param>
        /// <param name="maxTimeToOutputResponse"> max time between command output. If more time passes
        ///            between command output, the method will throw
        ///            <seealso cref="ShellCommandUnresponsiveException"/>. A value of 0 means the method will
        ///            wait forever for command output and never throw. </param>
        /// <exception cref="TimeoutException"> in case of timeout on the connection when sending the command. </exception>
        /// <exception cref="AdbCommandRejectedException"> if adb rejects the command </exception>
        /// <exception cref="ShellCommandUnresponsiveException"> in case the shell command doesn't send any output
        ///            for a period longer than <var>maxTimeToOutputResponse</var>. </exception>
        /// <exception cref="IOException"> in case of I/O error on the connection.
        /// </exception>
        /// <seealso cref= DdmPreferences#getTimeOut() </seealso>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static void executeRemoteCommand(java.net.InetSocketAddress adbSockAddr, String command, IDevice device, IShellOutputReceiver rcvr, int maxTimeToOutputResponse) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, java.io.IOException
        internal static void executeRemoteCommand(EndPoint adbSockAddr, string command, IDevice device, IShellOutputReceiver rcvr, int maxTimeToOutputResponse)
        {
            Log.v("ddms", "execute: running " + command);

            SocketChannel adbChan = null;

            try
            {
                adbChan = SocketChannel.open(adbSockAddr);
                adbChan.configureBlocking(false);

                // if the device is not -1, then we first tell adb we're looking to
                // talk
                // to a specific device
                setDevice(adbChan, device);

                var request = formAdbRequest("shell:" + command);                 //$NON-NLS-1$
                write(adbChan, request);

                AdbResponse resp = readAdbResponse(adbChan, false);                 // readDiagString
                if (resp.okay == false)
                {
                    Log.e("ddms", "ADB rejected shell command (" + command + "): " + resp.message);
                    throw new AdbCommandRejectedException(resp.message);
                }

                var        data = new byte[16384];
                ByteBuffer buf  = ByteBuffer.wrap(data);
                int        timeToResponseCount = 0;
                while (true)
                {
                    int count;

                    if (rcvr != null && rcvr.cancelled)
                    {
                        Log.v("ddms", "execute: cancelled");
                        break;
                    }

                    count = adbChan.read(buf);
                    if (count < 0)
                    {
                        // we're at the end, we flush the output
                        rcvr.flush();
                        Log.v("ddms", "execute '" + command + "' on '" + device + "' : EOF hit. Read: " + count);
                        break;
                    }
                    else if (count == 0)
                    {
                        int wait = WAIT_TIME * 5;
                        timeToResponseCount += wait;
                        if (maxTimeToOutputResponse > 0 && timeToResponseCount > maxTimeToOutputResponse)
                        {
                            throw new ShellCommandUnresponsiveException();
                        }
                        Thread.Sleep(wait);
                    }
                    else
                    {
                        // reset timeout
                        timeToResponseCount = 0;

                        // send data to receiver if present
                        if (rcvr != null)
                        {
                            rcvr.addOutput(buf.array(), buf.arrayOffset(), buf.position);
                        }
                        buf.rewind();
                    }
                }
            }
            finally
            {
                if (adbChan != null)
                {
                    adbChan.close();
                }
                Log.v("ddms", "execute: returning");
            }
        }
コード例 #10
0
        /// <summary>
        /// Retrieve the frame buffer from the device. </summary>
        /// <exception cref="TimeoutException"> in case of timeout on the connection. </exception>
        /// <exception cref="AdbCommandRejectedException"> if adb rejects the command </exception>
        /// <exception cref="IOException"> in case of I/O error on the connection. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static RawImage getFrameBuffer(java.net.InetSocketAddress adbSockAddr, Device device) throws TimeoutException, AdbCommandRejectedException, java.io.IOException
        internal static RawImage getFrameBuffer(EndPoint adbSockAddr, Device device)
        {
            RawImage imageParams = new RawImage();
            var      request     = formAdbRequest("framebuffer:");    //$NON-NLS-1$

            byte[] nudge = { 0 };
            byte[] reply;

            SocketChannel adbChan = null;

            try
            {
                adbChan = SocketChannel.open(adbSockAddr);
                adbChan.configureBlocking(false);

                // if the device is not -1, then we first tell adb we're looking to talk
                // to a specific device
                setDevice(adbChan, device);

                write(adbChan, request);

                AdbResponse resp = readAdbResponse(adbChan, false);                 // readDiagString
                if (resp.okay == false)
                {
                    throw new AdbCommandRejectedException(resp.message);
                }

                // first the protocol version.
                reply = new byte[4];
                read(adbChan, reply);

                ByteBuffer buf = ByteBuffer.wrap(reply);
                buf.order = ByteOrder.LITTLE_ENDIAN;

                int version = buf.getInt();

                // get the header size (this is a count of int)
                int headerSize = RawImage.getHeaderSize(version);

                // read the header
                reply = new byte[headerSize * 4];
                read(adbChan, reply);

                buf       = ByteBuffer.wrap(reply);
                buf.order = ByteOrder.LITTLE_ENDIAN;

                // fill the RawImage with the header
                if (imageParams.readHeader(version, buf) == false)
                {
                    Log.e("Screenshot", "Unsupported protocol: " + version);
                    return(null);
                }

                Log.d("ddms", "image params: bpp=" + imageParams.bpp + ", size=" + imageParams.size + ", width=" + imageParams.width + ", height=" + imageParams.height);

                write(adbChan, nudge);

                reply = new byte[imageParams.size];
                read(adbChan, reply);

                imageParams.data = reply;
            }
            finally
            {
                if (adbChan != null)
                {
                    adbChan.close();
                }
            }

            return(imageParams);
        }