最終證明這是一個(gè)個(gè)性化的錯(cuò)誤。
上傳本地apk進(jìn)行安裝時(shí),進(jìn)行到50%之后就報(bào)錯(cuò)——導(dǎo)致系統(tǒng)推出冈爹。
2020-7-20 15:38:02 INF/storage:temp 17950 [*] Uploaded "67a219fbe4ce8e2ab4c1fc5ce60195d3" to "/home/stf/tempSaveDir/upload_a0cfd8e997b752e14aecb2202cb0c1c4"
2020-7-20 15:38:02 INF/websocket 17944 [*] installMsg manifest undefined
/home/stf/RemoteDeviceNew/node_modules/protobufjs/dist/ProtoBuf.js:2641
throw Error("Illegal value for "+this.toString(true)+" of type "+this.type.name+": "+val+" ("+msg+")");
^
Error: Illegal value for Message.Field .InstallMessage.manifest of type string: undefined (not a string)
at Field.<anonymous> (/home/stf/RemoteDeviceNew/node_modules/protobufjs/dist/ProtoBuf.js:2641:27)
at Field.ProtoBuf.Reflect.FieldPrototype.verifyValue (/home/stf/RemoteDeviceNew/node_modules/protobufjs/dist/ProtoBuf.js:2721:29)
at MessagePrototype.set (/home/stf/RemoteDeviceNew/node_modules/protobufjs/dist/ProtoBuf.js:1799:63)
at new Message (/home/stf/RemoteDeviceNew/node_modules/protobufjs/dist/ProtoBuf.js:1728:42)
at Socket.<anonymous> (/home/stf/RemoteDeviceNew/lib/units/websocket/index.js:830:15)
at emitThree (events.js:136:13)
at Socket.emit (events.js:217:7)
at /home/stf/RemoteDeviceNew/node_modules/socket.io/lib/socket.js:528:12
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickCallback (internal/process/next_tick.js:181:9)
2020-7-20 15:38:02 FTL/cli:local 17862 [*] Child process had an error ExitError: Exit code "1"
at ChildProcess.<anonymous> (/home/stf/RemoteDeviceNew/lib/util/procutil.js:49:23)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
重新加載為數(shù)不多的前端知識(shí),先搜索對(duì)應(yīng)的關(guān)鍵字欧引,在對(duì)應(yīng)的位置增加log信息频伤。
lib/units/websocket/index.js
830行報(bào)錯(cuò),同時(shí)提示.InstallMessage.manifest of type string: undefined
芝此”镄ぃ可以推測(cè)出沒(méi)有獲取到apk的manifest信息。
// lib/units/websocket/index.js
.on('device.install', function(channel, responseChannel, data) {
joinChannel(responseChannel)
push.send([
channel
, wireutil.transaction(
responseChannel
, new wire.InstallMessage(
data.href
, data.launch === true
, JSON.stringify(data.manifest)
)
)
])
})
// wire.proto
message InstallMessage {
required string href = 1;
required bool launch = 2;
optional string manifest = 3;
}
拿到原始的apk分析后婚苹,是正常的文件岸更,可以正常安裝。
前端處理上傳文件并進(jìn)行安裝的服務(wù)為res/app/components/stf/install/install-service.js
膊升。進(jìn)度到50%時(shí)怎炊,實(shí)際上已經(jīng)將文件上傳成功了,然后開(kāi)始進(jìn)行安裝的動(dòng)作廓译。通過(guò)文件后綴來(lái)區(qū)分apk和ipa的區(qū)別(這塊是定制的內(nèi)容)评肆。看起來(lái)是像是通過(guò)http強(qiáng)求獲取manifest文件內(nèi)容的?這塊先忽略非区。
看本地上傳文件的處理lib/units/storage/temp.js
注意到log內(nèi)容包含Uploaded "67a219fbe4ce8e2ab4c1fc5ce60195d3" to "/home/stf/tempSaveDir/upload_a0cfd8e997b752e14aecb2202cb0c1c4"
似乎文件名做了處理瓜挽。
跟蹤了一下這個(gè)temp.js文件的git歷史記錄,看起來(lái)是同步代碼時(shí)增加了一部分處理文件的操作——
form.on('fileBegin', function(name, file) {
var md5 = crypto.createHash('md5')
file.name = md5.update(file.name).digest('hex')
})
將這段代碼刪除后征绸,恢復(fù)正常久橙。