日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

老李推荐: 第8章4节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-启动AndroidDebugBridge 2...

發布時間:2024/4/17 Android 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 老李推荐: 第8章4节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-启动AndroidDebugBridge 2... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第81-86行,整個方法的主體就是創建一個”Device List Monitor”的線程。線程運行方法run直接調用DeviceMonitor的deviceMonitorLoop方法來進行無限循環監控設備狀態了。

155?? private void deviceMonitorLoop()

156?? {

157???? do

158???? {

159?????? try

160?????? {

161???????? if (this.mMainAdbConnection == null) {

162?????????? Log.d("DeviceMonitor", "Opening adb connection");

163?????????? this.mMainAdbConnection =

openAdbConnection();

164?????????? if (this.mMainAdbConnection == null) {

165???????????? this.mConnectionAttempt += 1;

166???????? ????Log.e("DeviceMonitor", "Connection attempts: " + this.mConnectionAttempt);

167???????????? if (this.mConnectionAttempt > 10) {

168?????????????? if (!this.mServer.startAdb()) {

169???????????????? this.mRestartAttemptCount += 1;

170???????????????? Log.e("DeviceMonitor", "adb restart attempts: " + this.mRestartAttemptCount);

171?????????????? }

172?????????????? else {

173???????????????? this.mRestartAttemptCount = 0;

174?????????????? }

175???????????? }

176???????????? waitABit();

177?????????? } else {

178???????????? Log.d("DeviceMonitor", "Connected to adb for device monitoring");

179???????????? this.mConnectionAttempt = 0;

180?????????? }

181???????? }

182

183???????? if ((this.mMainAdbConnection != null) &&

(!this.mMonitoring)) {

184?????????? this.mMonitoring = sendDeviceListMonitoringRequest();

185???????? }

186

187???????? if (this.mMonitoring)

188???????? {

189?????????? int length = readLength(this.mMainAdbConnection, this.mLengthBuffer);

190

191?????????? if (length >= 0)

192?????????? {

193???????????? processIncomingDeviceData(length);

194

195

196???????????? this.mInitialDeviceListDone = true;

197?????????? }

198???????? }

199?????? }

200?????? catch (AsynchronousCloseException ace) {}catch (TimeoutException ioe)

201?????? {

202???????? handleExpectionInMonitorLoop(ioe);

203?????? } catch (IOException ioe) {

204???????? handleExpectionInMonitorLoop(ioe);

205?????? }

206???? } while (!this.mQuit);

207?? }

代碼8-4-3 DeviceMonitor - deviceMonitorLoop

?

  • 第一步:163行,如果還沒有連接上的ADB服務器的話就先連接上
  • 第二步: 168行,確保ADB服務器已經啟動
  • 第三步:?183-185行,往ADB服務器發送監控命令,監控所有連接上來的移除的設備
  • 第四步: 處理所獲得的監控設備列表

我們先看第一步,在上一節中我們已經看到ADB服務器的啟動過程了,但是我們還沒有看到ADB客戶端是怎么連接上服務器的,一下的代碼就是一個實例:

255?? private SocketChannel openAdbConnection()

256?? {

257?? ??Log.d("DeviceMonitor", "Connecting to adb for Device List Monitoring...");

258

259???? SocketChannel adbChannel = null;

260???? try {

261?????? adbChannel =

SocketChannel.open(

AndroidDebugBridge.getSocketAddress());

262?????? adbChannel.socket().setTcpNoDelay(true);

263???? }

264???? catch (IOException e) {}

265

266???? return adbChannel;

267?? }

代碼8-4-4 DeviceMonitor - openAdbConnection

?

轉載于:https://www.cnblogs.com/poptest/p/5089490.html

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的老李推荐: 第8章4节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-启动AndroidDebugBridge 2...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。