STF 之环境搭建可能的几个坑里提到过
初始化设备时,提示类似 Setup had an error Error: Service had an error: "Error: Not found; no service started."
官方认为有可能是杀毒软件的问题;实测需要手动先启动一个 UI 页面。现在都是手动到后台进行操作的,希望可以把这个添加到业务逻辑里进行处理。
STF 启动时,device 模块启动是由lib/units/device/index.js
处理。这里到依赖就包括里 STFService 的处理.dependency(require('./plugins/service')
这里先启动 Agent——使用命令行 exec 的方式启动 apk 中的 main 方法
export CLASSPATH='/data/app/jp.co.cyberagent.stf-1.apk'; exec app_process /system/bin 'jp.co.cyberagent.stf.Agent'
中手机端启动 socket 服务提供:输入、点击、转屏?、唤醒?的服务(TODO)然后就会启动 service 服务
am startservice --user 0 -a jp.co.cyberagent.stf.ACTION_START -n jp.co.cyberagent.stf/.Service
会优先使用带参数--user 0
方式,失败带情况下再使用不带此参数方式启动。也启动 socket 服务,提供包括:电池监控、连接监控、转屏、浏览器等跟身边本身有关的服务。
Agent 和 Service 都来自 STFService.apk,源码可参考这里
目前采用的方式是:在抛出服务异常之前,主动启动异常 IdentityActivity。这样下次执行设备初始化时,Service 就可以正常启动了。 ——不破坏目前的业务逻辑。观察一下效果再说
//before throw error, try to start ui activity first. next time, it will launch normally.
function startIdentityActivity(tag) {
log.info("try to start Identivity first ", tag)
return adb.shell(options.serial, util.format('am start -n %s/%s','jp.co.cyberagent.stf', '.IdentityActivity'))
.timeout(15000)
.then(function (out){
log.info("start UI identityActivity for ",options.serial)
})
}
这个方法这 callService 方法里抛出异常之前进行调用。 STF 中的 adb 命令都是异步操作,所以方法需要返回,调用的时候需要等待返回后再进行抛出 Error。
类似——
startIdentityActivity("user").then(function() {
throw new Error(util.format(
'Service had an error: "%s"'
, line
))
}).catch(streamutil.NoSuchLineError, function(){
return true
})
就是从接手 STF 才开始学 Nodejs 的,刚刚两个月。上面的调用会抛出异常——
Unhandled rejection Error: Service had an error: "Error: Not found; no service started."
at /Users/gebitang/projects/project-remote/RemoteDevice/lib/units/device/plugins/service.js:117:25
at tryCatcher (/Users/gebitang/projects/project-remote/RemoteDevice/node_modules/adbkit/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (/Users/gebitang/projects/project-remote/RemoteDevice/node_modules/adbkit/node_modules/bluebird/js/main/promise.js:503:31)
at Promise._settlePromiseAt (/Users/gebitang/projects/project-remote/RemoteDevice/node_modules/adbkit/node_modules/bluebird/js/main/promise.js:577:18)
at Promise._settlePromises (/Users/gebitang/projects/project-remote/RemoteDevice/node_modules/adbkit/node_modules/bluebird/js/main/promise.js:693:14)
at Async._drainQueue (/Users/gebitang/projects/project-remote/RemoteDevice/node_modules/adbkit/node_modules/bluebird/js/main/async.js:123:16)
at Async._drainQueues (/Users/gebitang/projects/project-remote/RemoteDevice/node_modules/adbkit/node_modules/bluebird/js/main/async.js:133:10)
at Immediate.Async.drainQueues (/Users/gebitang/projects/project-remote/RemoteDevice/node_modules/adbkit/node_modules/bluebird/js/main/async.js:15:14)
at runCallback (timers.js:810:20)
at tryOnImmediate (timers.js:768:5)
at processImmediate [as _immediateCallback] (timers.js:745:5
目前还不知道如何处理:(
欢迎留言指教:)