Beispiel #1
0
        /// <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;
        }