@yume-chan/adb 0.0.9 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +55 -0
- package/CHANGELOG.md +35 -0
- package/LICENSE +21 -21
- package/README.md +240 -257
- package/esm/adb.d.ts +48 -0
- package/esm/adb.d.ts.map +1 -0
- package/esm/adb.js +141 -145
- package/esm/adb.js.map +1 -1
- package/{dts → esm}/auth.d.ts +17 -7
- package/esm/auth.d.ts.map +1 -0
- package/esm/auth.js +69 -109
- package/esm/auth.js.map +1 -1
- package/esm/backend.d.ts +9 -0
- package/esm/backend.d.ts.map +1 -0
- package/{dts → esm}/commands/base.d.ts +1 -1
- package/esm/commands/base.d.ts.map +1 -0
- package/esm/commands/base.js +1 -0
- package/esm/commands/base.js.map +1 -1
- package/{dts → esm}/commands/framebuffer.d.ts +3 -3
- package/esm/commands/framebuffer.d.ts.map +1 -0
- package/esm/commands/framebuffer.js +15 -18
- package/esm/commands/framebuffer.js.map +1 -1
- package/esm/commands/index.d.ts +9 -0
- package/esm/commands/index.d.ts.map +1 -0
- package/esm/commands/index.js +8 -8
- package/esm/commands/index.js.map +1 -1
- package/esm/commands/install.d.ts +4 -0
- package/esm/commands/install.d.ts.map +1 -0
- package/esm/commands/install.js +21 -13
- package/esm/commands/install.js.map +1 -1
- package/esm/commands/power.d.ts +23 -0
- package/esm/commands/power.d.ts.map +1 -0
- package/esm/commands/power.js +45 -0
- package/esm/commands/power.js.map +1 -0
- package/{dts → esm}/commands/reverse.d.ts +3 -3
- package/esm/commands/reverse.d.ts.map +1 -0
- package/esm/commands/reverse.js +50 -60
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/index.d.ts +57 -0
- package/esm/commands/subprocess/index.d.ts.map +1 -0
- package/esm/commands/subprocess/index.js +83 -0
- package/esm/commands/subprocess/index.js.map +1 -0
- package/esm/commands/subprocess/legacy.d.ts +28 -0
- package/esm/commands/subprocess/legacy.d.ts.map +1 -0
- package/esm/commands/subprocess/legacy.js +44 -0
- package/esm/commands/subprocess/legacy.js.map +1 -0
- package/esm/commands/subprocess/protocol.d.ts +38 -0
- package/esm/commands/subprocess/protocol.d.ts.map +1 -0
- package/esm/commands/subprocess/protocol.js +155 -0
- package/esm/commands/subprocess/protocol.js.map +1 -0
- package/esm/commands/subprocess/types.d.ts +47 -0
- package/esm/commands/subprocess/types.d.ts.map +1 -0
- package/esm/commands/{shell → subprocess}/types.js +0 -0
- package/{cjs/commands/shell → esm/commands/subprocess}/types.js.map +1 -1
- package/{dts/commands/shell → esm/commands/subprocess}/utils.d.ts +0 -0
- package/esm/commands/subprocess/utils.d.ts.map +1 -0
- package/esm/commands/{shell → subprocess}/utils.js +0 -0
- package/esm/commands/subprocess/utils.js.map +1 -0
- package/esm/commands/sync/index.d.ts +8 -0
- package/esm/commands/sync/index.d.ts.map +1 -0
- package/esm/commands/sync/index.js +7 -7
- package/esm/commands/sync/index.js.map +1 -1
- package/{dts → esm}/commands/sync/list.d.ts +4 -4
- package/esm/commands/sync/list.d.ts.map +1 -0
- package/esm/commands/sync/list.js +16 -19
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +11 -0
- package/esm/commands/sync/pull.d.ts.map +1 -0
- package/esm/commands/sync/pull.js +17 -11
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +8 -0
- package/esm/commands/sync/push.d.ts.map +1 -0
- package/esm/commands/sync/push.js +19 -37
- package/esm/commands/sync/push.js.map +1 -1
- package/{dts → esm}/commands/sync/request.d.ts +3 -3
- package/esm/commands/sync/request.d.ts.map +1 -0
- package/esm/commands/sync/request.js +24 -26
- package/esm/commands/sync/request.js.map +1 -1
- package/{dts → esm}/commands/sync/response.d.ts +3 -3
- package/esm/commands/sync/response.d.ts.map +1 -0
- package/esm/commands/sync/response.js +16 -19
- package/esm/commands/sync/response.js.map +1 -1
- package/{dts → esm}/commands/sync/stat.d.ts +4 -4
- package/esm/commands/sync/stat.d.ts.map +1 -0
- package/esm/commands/sync/stat.js +22 -27
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +83 -0
- package/esm/commands/sync/sync.d.ts.map +1 -0
- package/esm/commands/sync/sync.js +92 -89
- package/esm/commands/sync/sync.js.map +1 -1
- package/{dts → esm}/commands/tcpip.d.ts +1 -1
- package/{dts → esm}/commands/tcpip.d.ts.map +1 -1
- package/esm/commands/tcpip.js +14 -19
- package/esm/commands/tcpip.js.map +1 -1
- package/esm/crypto.d.ts +24 -0
- package/esm/crypto.d.ts.map +1 -0
- package/esm/crypto.js +33 -31
- package/esm/crypto.js.map +1 -1
- package/{dts → esm}/features.d.ts +0 -0
- package/{dts → esm}/features.d.ts.map +0 -0
- package/esm/features.js +1 -1
- package/esm/features.js.map +1 -1
- package/esm/index.d.ts +11 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +10 -10
- package/esm/index.js.map +1 -1
- package/esm/packet.d.ts +28 -0
- package/esm/packet.d.ts.map +1 -0
- package/esm/packet.js +26 -53
- package/esm/packet.js.map +1 -1
- package/esm/socket/controller.d.ts +37 -0
- package/esm/socket/controller.d.ts.map +1 -0
- package/esm/socket/controller.js +52 -66
- package/esm/socket/controller.js.map +1 -1
- package/{dts → esm}/socket/dispatcher.d.ts +10 -23
- package/esm/socket/dispatcher.d.ts.map +1 -0
- package/esm/socket/dispatcher.js +148 -164
- package/esm/socket/dispatcher.js.map +1 -1
- package/esm/socket/index.d.ts +3 -0
- package/esm/socket/index.d.ts.map +1 -0
- package/esm/socket/index.js +2 -6
- package/esm/socket/index.js.map +1 -1
- package/esm/socket/socket.d.ts +34 -0
- package/esm/socket/socket.d.ts.map +1 -0
- package/esm/socket/socket.js +69 -14
- package/esm/socket/socket.js.map +1 -1
- package/esm/stream/buffered.d.ts +35 -0
- package/esm/stream/buffered.d.ts.map +1 -0
- package/esm/stream/buffered.js +123 -0
- package/esm/stream/buffered.js.map +1 -0
- package/esm/stream/detect.bak.d.ts +240 -0
- package/esm/stream/detect.bak.d.ts.map +1 -0
- package/esm/stream/detect.bak.js +60 -0
- package/esm/stream/detect.bak.js.map +1 -0
- package/esm/stream/detect.d.ts +18 -0
- package/esm/stream/detect.d.ts.map +1 -0
- package/esm/stream/detect.js +6 -0
- package/esm/stream/detect.js.map +1 -0
- package/esm/stream/detect.native.d.ts +240 -0
- package/esm/stream/detect.native.d.ts.map +1 -0
- package/esm/stream/detect.native.js +60 -0
- package/esm/stream/detect.native.js.map +1 -0
- package/esm/stream/detect.polyfill.d.ts +18 -0
- package/esm/stream/detect.polyfill.d.ts.map +1 -0
- package/esm/stream/detect.polyfill.js +6 -0
- package/esm/stream/detect.polyfill.js.map +1 -0
- package/esm/stream/index.d.ts +4 -0
- package/esm/stream/index.d.ts.map +1 -0
- package/esm/stream/index.js +3 -2
- package/esm/stream/index.js.map +1 -1
- package/esm/stream/transform.d.ts +98 -0
- package/esm/stream/transform.d.ts.map +1 -0
- package/esm/stream/transform.js +352 -0
- package/esm/stream/transform.js.map +1 -0
- package/{dts → esm}/utils/auto-reset-event.d.ts +1 -1
- package/esm/utils/auto-reset-event.d.ts.map +1 -0
- package/esm/utils/auto-reset-event.js +2 -1
- package/esm/utils/auto-reset-event.js.map +1 -1
- package/esm/utils/base64.d.ts +5 -0
- package/esm/utils/base64.d.ts.map +1 -0
- package/esm/utils/base64.js +116 -80
- package/esm/utils/base64.js.map +1 -1
- package/esm/utils/encoding.d.ts +3 -0
- package/esm/utils/encoding.d.ts.map +1 -0
- package/esm/utils/encoding.js +11 -0
- package/esm/utils/encoding.js.map +1 -0
- package/esm/utils/index.d.ts +4 -0
- package/esm/utils/index.d.ts.map +1 -0
- package/esm/utils/index.js +3 -4
- package/esm/utils/index.js.map +1 -1
- package/package.json +49 -50
- package/src/adb.ts +247 -242
- package/src/auth.ts +170 -156
- package/src/backend.ts +11 -24
- package/src/commands/base.ts +11 -11
- package/src/commands/framebuffer.ts +73 -73
- package/src/commands/index.ts +8 -8
- package/src/commands/install.ts +32 -21
- package/src/commands/power.ts +54 -0
- package/src/commands/reverse.ts +136 -133
- package/src/commands/subprocess/index.ts +124 -0
- package/src/commands/subprocess/legacy.ts +58 -0
- package/src/commands/subprocess/protocol.ts +185 -0
- package/src/commands/subprocess/types.ts +55 -0
- package/src/commands/{shell → subprocess}/utils.ts +20 -20
- package/src/commands/sync/index.ts +7 -7
- package/src/commands/sync/list.ts +40 -39
- package/src/commands/sync/pull.ts +43 -34
- package/src/commands/sync/push.ts +41 -46
- package/src/commands/sync/request.ts +49 -48
- package/src/commands/sync/response.ts +58 -57
- package/src/commands/sync/stat.ts +123 -121
- package/src/commands/sync/sync.ts +145 -113
- package/src/commands/tcpip.ts +21 -21
- package/src/crypto.ts +280 -280
- package/src/features.ts +5 -5
- package/src/index.ts +11 -10
- package/src/packet.ts +69 -89
- package/src/socket/dispatcher.ts +256 -269
- package/src/socket/index.ts +2 -6
- package/src/socket/socket.ts +129 -28
- package/src/stream/buffered.ts +147 -0
- package/src/stream/detect.native.ts +362 -0
- package/src/stream/detect.polyfill.ts +25 -0
- package/src/stream/detect.ts +25 -0
- package/src/stream/index.ts +3 -2
- package/src/stream/transform.ts +427 -0
- package/src/utils/auto-reset-event.ts +41 -41
- package/src/utils/base64.ts +306 -274
- package/src/utils/encoding.ts +13 -0
- package/src/utils/index.ts +3 -4
- package/tsconfig.build.json +3 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.test.json +10 -0
- package/cjs/adb.js +0 -205
- package/cjs/adb.js.map +0 -1
- package/cjs/auth.js +0 -141
- package/cjs/auth.js.map +0 -1
- package/cjs/backend.js +0 -3
- package/cjs/backend.js.map +0 -1
- package/cjs/commands/base.js +0 -12
- package/cjs/commands/base.js.map +0 -1
- package/cjs/commands/demo-mode.js +0 -174
- package/cjs/commands/demo-mode.js.map +0 -1
- package/cjs/commands/framebuffer.js +0 -66
- package/cjs/commands/framebuffer.js.map +0 -1
- package/cjs/commands/index.js +0 -12
- package/cjs/commands/index.js.map +0 -1
- package/cjs/commands/install.js +0 -20
- package/cjs/commands/install.js.map +0 -1
- package/cjs/commands/reverse.js +0 -105
- package/cjs/commands/reverse.js.map +0 -1
- package/cjs/commands/shell/index.js +0 -56
- package/cjs/commands/shell/index.js.map +0 -1
- package/cjs/commands/shell/legacy.js +0 -37
- package/cjs/commands/shell/legacy.js.map +0 -1
- package/cjs/commands/shell/protocol.js +0 -83
- package/cjs/commands/shell/protocol.js.map +0 -1
- package/cjs/commands/shell/types.js +0 -3
- package/cjs/commands/shell/utils.js +0 -23
- package/cjs/commands/shell/utils.js.map +0 -1
- package/cjs/commands/sync/index.js +0 -11
- package/cjs/commands/sync/index.js.map +0 -1
- package/cjs/commands/sync/list.js +0 -36
- package/cjs/commands/sync/list.js.map +0 -1
- package/cjs/commands/sync/pull.js +0 -34
- package/cjs/commands/sync/pull.js.map +0 -1
- package/cjs/commands/sync/push.js +0 -49
- package/cjs/commands/sync/push.js.map +0 -1
- package/cjs/commands/sync/request.js +0 -48
- package/cjs/commands/sync/request.js.map +0 -1
- package/cjs/commands/sync/response.js +0 -53
- package/cjs/commands/sync/response.js.map +0 -1
- package/cjs/commands/sync/stat.js +0 -109
- package/cjs/commands/sync/stat.js.map +0 -1
- package/cjs/commands/sync/sync.js +0 -118
- package/cjs/commands/sync/sync.js.map +0 -1
- package/cjs/commands/tcpip.js +0 -28
- package/cjs/commands/tcpip.js.map +0 -1
- package/cjs/crypto.js +0 -231
- package/cjs/crypto.js.map +0 -1
- package/cjs/features.js +0 -10
- package/cjs/features.js.map +0 -1
- package/cjs/index.js +0 -14
- package/cjs/index.js.map +0 -1
- package/cjs/packet.js +0 -77
- package/cjs/packet.js.map +0 -1
- package/cjs/socket/close-event-emitter.js +0 -32
- package/cjs/socket/close-event-emitter.js.map +0 -1
- package/cjs/socket/controller.js +0 -84
- package/cjs/socket/controller.js.map +0 -1
- package/cjs/socket/data-event-emitter.js +0 -29
- package/cjs/socket/data-event-emitter.js.map +0 -1
- package/cjs/socket/dispatcher.js +0 -219
- package/cjs/socket/dispatcher.js.map +0 -1
- package/cjs/socket/index.js +0 -10
- package/cjs/socket/index.js.map +0 -1
- package/cjs/socket/logger.js +0 -3
- package/cjs/socket/logger.js.map +0 -1
- package/cjs/socket/socket.js +0 -24
- package/cjs/socket/socket.js.map +0 -1
- package/cjs/stream/buffered-stream.js +0 -78
- package/cjs/stream/buffered-stream.js.map +0 -1
- package/cjs/stream/index.js +0 -6
- package/cjs/stream/index.js.map +0 -1
- package/cjs/stream/stream.js +0 -45
- package/cjs/stream/stream.js.map +0 -1
- package/cjs/utils/auto-reset-event.js +0 -37
- package/cjs/utils/auto-reset-event.js.map +0 -1
- package/cjs/utils/base64.js +0 -210
- package/cjs/utils/base64.js.map +0 -1
- package/cjs/utils/chunk.js +0 -75
- package/cjs/utils/chunk.js.map +0 -1
- package/cjs/utils/event-queue.js +0 -108
- package/cjs/utils/event-queue.js.map +0 -1
- package/cjs/utils/index.js +0 -8
- package/cjs/utils/index.js.map +0 -1
- package/dts/adb.d.ts +0 -46
- package/dts/adb.d.ts.map +0 -1
- package/dts/auth.d.ts.map +0 -1
- package/dts/backend.d.ts +0 -15
- package/dts/backend.d.ts.map +0 -1
- package/dts/commands/base.d.ts.map +0 -1
- package/dts/commands/demo-mode.d.ts +0 -41
- package/dts/commands/demo-mode.d.ts.map +0 -1
- package/dts/commands/framebuffer.d.ts.map +0 -1
- package/dts/commands/index.d.ts +0 -9
- package/dts/commands/index.d.ts.map +0 -1
- package/dts/commands/install.d.ts +0 -3
- package/dts/commands/install.d.ts.map +0 -1
- package/dts/commands/reverse.d.ts.map +0 -1
- package/dts/commands/shell/index.d.ts +0 -20
- package/dts/commands/shell/index.d.ts.map +0 -1
- package/dts/commands/shell/legacy.d.ts +0 -27
- package/dts/commands/shell/legacy.d.ts.map +0 -1
- package/dts/commands/shell/protocol.d.ts +0 -37
- package/dts/commands/shell/protocol.d.ts.map +0 -1
- package/dts/commands/shell/types.d.ts +0 -15
- package/dts/commands/shell/types.d.ts.map +0 -1
- package/dts/commands/shell/utils.d.ts.map +0 -1
- package/dts/commands/sync/index.d.ts +0 -8
- package/dts/commands/sync/index.d.ts.map +0 -1
- package/dts/commands/sync/list.d.ts.map +0 -1
- package/dts/commands/sync/pull.d.ts +0 -11
- package/dts/commands/sync/pull.d.ts.map +0 -1
- package/dts/commands/sync/push.d.ts +0 -8
- package/dts/commands/sync/push.d.ts.map +0 -1
- package/dts/commands/sync/request.d.ts.map +0 -1
- package/dts/commands/sync/response.d.ts.map +0 -1
- package/dts/commands/sync/stat.d.ts.map +0 -1
- package/dts/commands/sync/sync.d.ts +0 -68
- package/dts/commands/sync/sync.d.ts.map +0 -1
- package/dts/crypto.d.ts +0 -17
- package/dts/crypto.d.ts.map +0 -1
- package/dts/index.d.ts +0 -11
- package/dts/index.d.ts.map +0 -1
- package/dts/packet.d.ts +0 -27
- package/dts/packet.d.ts.map +0 -1
- package/dts/socket/close-event-emitter.d.ts +0 -8
- package/dts/socket/close-event-emitter.d.ts.map +0 -1
- package/dts/socket/controller.d.ts +0 -43
- package/dts/socket/controller.d.ts.map +0 -1
- package/dts/socket/data-event-emitter.d.ts +0 -10
- package/dts/socket/data-event-emitter.d.ts.map +0 -1
- package/dts/socket/dispatcher.d.ts.map +0 -1
- package/dts/socket/index.d.ts +0 -7
- package/dts/socket/index.d.ts.map +0 -1
- package/dts/socket/logger.d.ts +0 -9
- package/dts/socket/logger.d.ts.map +0 -1
- package/dts/socket/socket.d.ts +0 -22
- package/dts/socket/socket.d.ts.map +0 -1
- package/dts/stream/buffered-stream.d.ts +0 -30
- package/dts/stream/buffered-stream.d.ts.map +0 -1
- package/dts/stream/index.d.ts +0 -3
- package/dts/stream/index.d.ts.map +0 -1
- package/dts/stream/stream.d.ts +0 -15
- package/dts/stream/stream.d.ts.map +0 -1
- package/dts/utils/auto-reset-event.d.ts.map +0 -1
- package/dts/utils/base64.d.ts +0 -7
- package/dts/utils/base64.d.ts.map +0 -1
- package/dts/utils/chunk.d.ts +0 -3
- package/dts/utils/chunk.d.ts.map +0 -1
- package/dts/utils/event-queue.d.ts +0 -35
- package/dts/utils/event-queue.d.ts.map +0 -1
- package/dts/utils/index.d.ts +0 -5
- package/dts/utils/index.d.ts.map +0 -1
- package/esm/commands/demo-mode.js +0 -170
- package/esm/commands/demo-mode.js.map +0 -1
- package/esm/commands/shell/index.js +0 -52
- package/esm/commands/shell/index.js.map +0 -1
- package/esm/commands/shell/legacy.js +0 -33
- package/esm/commands/shell/legacy.js.map +0 -1
- package/esm/commands/shell/protocol.js +0 -79
- package/esm/commands/shell/protocol.js.map +0 -1
- package/esm/commands/shell/types.js.map +0 -1
- package/esm/commands/shell/utils.js.map +0 -1
- package/esm/socket/close-event-emitter.js +0 -28
- package/esm/socket/close-event-emitter.js.map +0 -1
- package/esm/socket/data-event-emitter.js +0 -25
- package/esm/socket/data-event-emitter.js.map +0 -1
- package/esm/socket/logger.js +0 -2
- package/esm/socket/logger.js.map +0 -1
- package/esm/stream/buffered-stream.js +0 -73
- package/esm/stream/buffered-stream.js.map +0 -1
- package/esm/stream/stream.js +0 -41
- package/esm/stream/stream.js.map +0 -1
- package/esm/utils/chunk.js +0 -70
- package/esm/utils/chunk.js.map +0 -1
- package/esm/utils/event-queue.js +0 -104
- package/esm/utils/event-queue.js.map +0 -1
- package/src/commands/demo-mode.ts +0 -160
- package/src/commands/shell/index.ts +0 -68
- package/src/commands/shell/legacy.ts +0 -42
- package/src/commands/shell/protocol.ts +0 -94
- package/src/commands/shell/types.ts +0 -21
- package/src/socket/close-event-emitter.ts +0 -28
- package/src/socket/controller.ts +0 -105
- package/src/socket/data-event-emitter.ts +0 -27
- package/src/socket/logger.ts +0 -12
- package/src/stream/buffered-stream.ts +0 -100
- package/src/stream/stream.ts +0 -50
- package/src/utils/chunk.ts +0 -70
- package/src/utils/event-queue.ts +0 -145
- package/tsconfig.cjs.json +0 -11
- package/tsconfig.esm.json +0 -28
- package/tsconfig.esm.tsbuildinfo +0 -1305
- package/tsconfig.json +0 -18
package/src/auth.ts
CHANGED
|
@@ -1,156 +1,170 @@
|
|
|
1
|
-
import { PromiseResolver } from '@yume-chan/async';
|
|
2
|
-
import { Disposable } from '@yume-chan/event';
|
|
3
|
-
import { ValueOrPromise } from '@yume-chan/struct';
|
|
4
|
-
import { calculatePublicKey, calculatePublicKeyLength, sign } from './crypto';
|
|
5
|
-
import { AdbCommand, AdbPacket,
|
|
6
|
-
import { calculateBase64EncodedLength, encodeBase64 } from './utils';
|
|
7
|
-
|
|
8
|
-
export type AdbKeyIterable = Iterable<
|
|
9
|
-
|
|
10
|
-
export interface AdbCredentialStore {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
private
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
private
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
1
|
+
import { PromiseResolver } from '@yume-chan/async';
|
|
2
|
+
import type { Disposable } from '@yume-chan/event';
|
|
3
|
+
import type { ValueOrPromise } from '@yume-chan/struct';
|
|
4
|
+
import { calculatePublicKey, calculatePublicKeyLength, sign } from './crypto.js';
|
|
5
|
+
import { AdbCommand, AdbPacket, type AdbPacketCore } from './packet.js';
|
|
6
|
+
import { calculateBase64EncodedLength, encodeBase64 } from './utils/index.js';
|
|
7
|
+
|
|
8
|
+
export type AdbKeyIterable = Iterable<Uint8Array> | AsyncIterable<Uint8Array>;
|
|
9
|
+
|
|
10
|
+
export interface AdbCredentialStore {
|
|
11
|
+
/**
|
|
12
|
+
* Generate and store a RSA private key with modulus length `2048` and public exponent `65537`.
|
|
13
|
+
*
|
|
14
|
+
* The returned `Uint8Array` is the private key in PKCS #8 format.
|
|
15
|
+
*/
|
|
16
|
+
generateKey(): ValueOrPromise<Uint8Array>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Synchronously or asynchronously iterate through all stored RSA private keys.
|
|
20
|
+
*
|
|
21
|
+
* Each call to `iterateKeys` must return a different iterator that iterate through all stored keys.
|
|
22
|
+
*/
|
|
23
|
+
iterateKeys(): AdbKeyIterable;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export enum AdbAuthType {
|
|
27
|
+
Token = 1,
|
|
28
|
+
Signature = 2,
|
|
29
|
+
PublicKey = 3,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface AdbAuthenticator {
|
|
33
|
+
/**
|
|
34
|
+
* @param getNextRequest
|
|
35
|
+
*
|
|
36
|
+
* Call this function to get the next authentication request packet from device.
|
|
37
|
+
*
|
|
38
|
+
* After calling `getNextRequest`, authenticator can `yield` a packet as response, or `return` to indicate its incapability of handling the request.
|
|
39
|
+
*
|
|
40
|
+
* After `return`, the `AdbAuthenticatorHandler` will move on to next authenticator and never go back.
|
|
41
|
+
*
|
|
42
|
+
* Calling `getNextRequest` multiple times without `yield` or `return` will always return the same request.
|
|
43
|
+
*/
|
|
44
|
+
(
|
|
45
|
+
credentialStore: AdbCredentialStore,
|
|
46
|
+
getNextRequest: () => Promise<AdbPacket>
|
|
47
|
+
): AsyncIterable<AdbPacketCore>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const AdbSignatureAuthenticator: AdbAuthenticator = async function* (
|
|
51
|
+
credentialStore: AdbCredentialStore,
|
|
52
|
+
getNextRequest: () => Promise<AdbPacket>,
|
|
53
|
+
): AsyncIterable<AdbPacketCore> {
|
|
54
|
+
for await (const key of credentialStore.iterateKeys()) {
|
|
55
|
+
const packet = await getNextRequest();
|
|
56
|
+
|
|
57
|
+
if (packet.arg0 !== AdbAuthType.Token) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const signature = sign(key, packet.payload);
|
|
62
|
+
yield {
|
|
63
|
+
command: AdbCommand.Auth,
|
|
64
|
+
arg0: AdbAuthType.Signature,
|
|
65
|
+
arg1: 0,
|
|
66
|
+
payload: new Uint8Array(signature),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const AdbPublicKeyAuthenticator: AdbAuthenticator = async function* (
|
|
72
|
+
credentialStore: AdbCredentialStore,
|
|
73
|
+
getNextRequest: () => Promise<AdbPacket>,
|
|
74
|
+
): AsyncIterable<AdbPacketCore> {
|
|
75
|
+
const packet = await getNextRequest();
|
|
76
|
+
|
|
77
|
+
if (packet.arg0 !== AdbAuthType.Token) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let privateKey: Uint8Array | undefined;
|
|
82
|
+
for await (const key of credentialStore.iterateKeys()) {
|
|
83
|
+
privateKey = key;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
if (!privateKey) {
|
|
89
|
+
privateKey = await credentialStore.generateKey();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const publicKeyLength = calculatePublicKeyLength();
|
|
93
|
+
const [publicKeyBase64Length] = calculateBase64EncodedLength(publicKeyLength);
|
|
94
|
+
|
|
95
|
+
// The public key is null terminated,
|
|
96
|
+
// So we allocate the buffer with one extra byte.
|
|
97
|
+
const publicKeyBuffer = new Uint8Array(publicKeyBase64Length + 1);
|
|
98
|
+
|
|
99
|
+
calculatePublicKey(privateKey, publicKeyBuffer);
|
|
100
|
+
encodeBase64(
|
|
101
|
+
publicKeyBuffer.subarray(0, publicKeyLength),
|
|
102
|
+
publicKeyBuffer
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
yield {
|
|
106
|
+
command: AdbCommand.Auth,
|
|
107
|
+
arg0: AdbAuthType.PublicKey,
|
|
108
|
+
arg1: 0,
|
|
109
|
+
payload: publicKeyBuffer,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const AdbDefaultAuthenticators: AdbAuthenticator[] = [
|
|
114
|
+
AdbSignatureAuthenticator,
|
|
115
|
+
AdbPublicKeyAuthenticator,
|
|
116
|
+
];
|
|
117
|
+
|
|
118
|
+
export class AdbAuthenticationHandler implements Disposable {
|
|
119
|
+
public readonly authenticators: readonly AdbAuthenticator[];
|
|
120
|
+
|
|
121
|
+
private readonly credentialStore: AdbCredentialStore;
|
|
122
|
+
|
|
123
|
+
private pendingRequest = new PromiseResolver<AdbPacket>();
|
|
124
|
+
|
|
125
|
+
private iterator: AsyncIterator<AdbPacketCore> | undefined;
|
|
126
|
+
|
|
127
|
+
public constructor(
|
|
128
|
+
authenticators: readonly AdbAuthenticator[],
|
|
129
|
+
credentialStore: AdbCredentialStore
|
|
130
|
+
) {
|
|
131
|
+
this.authenticators = authenticators;
|
|
132
|
+
this.credentialStore = credentialStore;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private getNextRequest = (): Promise<AdbPacket> => {
|
|
136
|
+
return this.pendingRequest.promise;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
private async* runAuthenticator(): AsyncGenerator<AdbPacketCore> {
|
|
140
|
+
for (const authenticator of this.authenticators) {
|
|
141
|
+
for await (const packet of authenticator(this.credentialStore, this.getNextRequest)) {
|
|
142
|
+
// If the authenticator yielded a response
|
|
143
|
+
// Prepare `nextRequest` for next authentication request
|
|
144
|
+
this.pendingRequest = new PromiseResolver<AdbPacket>();
|
|
145
|
+
|
|
146
|
+
// Yield the response to outer layer
|
|
147
|
+
yield packet;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// If the authenticator returned,
|
|
151
|
+
// Next authenticator will be given the same `pendingRequest`
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
throw new Error('Cannot authenticate with device');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public async handle(packet: AdbPacket): Promise<AdbPacketCore> {
|
|
158
|
+
if (!this.iterator) {
|
|
159
|
+
this.iterator = this.runAuthenticator();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
this.pendingRequest.resolve(packet);
|
|
163
|
+
const result = await this.iterator.next();
|
|
164
|
+
return result.value;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public dispose() {
|
|
168
|
+
this.iterator?.return?.();
|
|
169
|
+
}
|
|
170
|
+
}
|
package/src/backend.ts
CHANGED
|
@@ -1,24 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
connect?(): ValueOrPromise<void>;
|
|
14
|
-
|
|
15
|
-
encodeUtf8(input: string): ArrayBuffer;
|
|
16
|
-
|
|
17
|
-
decodeUtf8(buffer: ArrayBuffer): string;
|
|
18
|
-
|
|
19
|
-
write(buffer: ArrayBuffer): ValueOrPromise<void>;
|
|
20
|
-
|
|
21
|
-
read(length: number): ValueOrPromise<ArrayBuffer>;
|
|
22
|
-
|
|
23
|
-
dispose(): ValueOrPromise<void>;
|
|
24
|
-
}
|
|
1
|
+
import type { ValueOrPromise } from '@yume-chan/struct';
|
|
2
|
+
import type { AdbPacketCore, AdbPacketInit } from "./packet.js";
|
|
3
|
+
import type { ReadableWritablePair } from "./stream/index.js";
|
|
4
|
+
|
|
5
|
+
export interface AdbBackend {
|
|
6
|
+
readonly serial: string;
|
|
7
|
+
|
|
8
|
+
readonly name: string | undefined;
|
|
9
|
+
|
|
10
|
+
connect(): ValueOrPromise<ReadableWritablePair<AdbPacketCore, AdbPacketInit>>;
|
|
11
|
+
}
|
package/src/commands/base.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { AutoDisposable } from '@yume-chan/event';
|
|
2
|
-
import { Adb } from '../adb';
|
|
3
|
-
|
|
4
|
-
export class AdbCommandBase extends AutoDisposable {
|
|
5
|
-
protected adb: Adb;
|
|
6
|
-
|
|
7
|
-
public constructor(adb: Adb) {
|
|
8
|
-
super();
|
|
9
|
-
this.adb = adb;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
1
|
+
import { AutoDisposable } from '@yume-chan/event';
|
|
2
|
+
import type { Adb } from '../adb.js';
|
|
3
|
+
|
|
4
|
+
export class AdbCommandBase extends AutoDisposable {
|
|
5
|
+
protected adb: Adb;
|
|
6
|
+
|
|
7
|
+
public constructor(adb: Adb) {
|
|
8
|
+
super();
|
|
9
|
+
this.adb = adb;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import Struct from "@yume-chan/struct";
|
|
2
|
-
import { Adb } from '../adb';
|
|
3
|
-
import { AdbBufferedStream } from '../stream';
|
|
4
|
-
|
|
5
|
-
const Version =
|
|
6
|
-
new Struct({ littleEndian: true })
|
|
7
|
-
.uint32('version');
|
|
8
|
-
|
|
9
|
-
/*
|
|
10
|
-
* ADB uses 8 int32 fields to describe bit depths
|
|
11
|
-
* The only combination I have seen is RGBA8888, which is
|
|
12
|
-
* red_offset: 0
|
|
13
|
-
* red_length: 8
|
|
14
|
-
* blue_offset: 16
|
|
15
|
-
* blue_length: 8
|
|
16
|
-
* green_offset: 8
|
|
17
|
-
* green_length: 8
|
|
18
|
-
* alpha_offset: 24
|
|
19
|
-
* alpha_length: 8
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
export const AdbFrameBufferV1 =
|
|
23
|
-
new Struct({ littleEndian: true })
|
|
24
|
-
.uint32('bpp')
|
|
25
|
-
.uint32('size')
|
|
26
|
-
.uint32('width')
|
|
27
|
-
.uint32('height')
|
|
28
|
-
.uint32('red_offset')
|
|
29
|
-
.uint32('red_length')
|
|
30
|
-
.uint32('blue_offset')
|
|
31
|
-
.uint32('blue_length')
|
|
32
|
-
.uint32('green_offset')
|
|
33
|
-
.uint32('green_length')
|
|
34
|
-
.uint32('alpha_offset')
|
|
35
|
-
.uint32('alpha_length')
|
|
36
|
-
.
|
|
37
|
-
|
|
38
|
-
export type AdbFrameBufferV1 = typeof AdbFrameBufferV1['TDeserializeResult'];
|
|
39
|
-
|
|
40
|
-
export const AdbFrameBufferV2 =
|
|
41
|
-
new Struct({ littleEndian: true })
|
|
42
|
-
.uint32('bpp')
|
|
43
|
-
.uint32('colorSpace')
|
|
44
|
-
.uint32('size')
|
|
45
|
-
.uint32('width')
|
|
46
|
-
.uint32('height')
|
|
47
|
-
.uint32('red_offset')
|
|
48
|
-
.uint32('red_length')
|
|
49
|
-
.uint32('blue_offset')
|
|
50
|
-
.uint32('blue_length')
|
|
51
|
-
.uint32('green_offset')
|
|
52
|
-
.uint32('green_length')
|
|
53
|
-
.uint32('alpha_offset')
|
|
54
|
-
.uint32('alpha_length')
|
|
55
|
-
.
|
|
56
|
-
|
|
57
|
-
export type AdbFrameBufferV2 = typeof AdbFrameBufferV2['TDeserializeResult'];
|
|
58
|
-
|
|
59
|
-
export type AdbFrameBuffer = AdbFrameBufferV1 | AdbFrameBufferV2;
|
|
60
|
-
|
|
61
|
-
export async function framebuffer(adb: Adb): Promise<AdbFrameBuffer> {
|
|
62
|
-
const socket = await adb.createSocket('framebuffer:');
|
|
63
|
-
const stream = new AdbBufferedStream(socket);
|
|
64
|
-
const { version } = await Version.deserialize(stream);
|
|
65
|
-
switch (version) {
|
|
66
|
-
case 1:
|
|
67
|
-
return AdbFrameBufferV1.deserialize(stream);
|
|
68
|
-
case 2:
|
|
69
|
-
return AdbFrameBufferV2.deserialize(stream);
|
|
70
|
-
default:
|
|
71
|
-
throw new Error('Unknown FrameBuffer version');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
1
|
+
import Struct from "@yume-chan/struct";
|
|
2
|
+
import type { Adb } from '../adb.js';
|
|
3
|
+
import { AdbBufferedStream } from '../stream/index.js';
|
|
4
|
+
|
|
5
|
+
const Version =
|
|
6
|
+
new Struct({ littleEndian: true })
|
|
7
|
+
.uint32('version');
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* ADB uses 8 int32 fields to describe bit depths
|
|
11
|
+
* The only combination I have seen is RGBA8888, which is
|
|
12
|
+
* red_offset: 0
|
|
13
|
+
* red_length: 8
|
|
14
|
+
* blue_offset: 16
|
|
15
|
+
* blue_length: 8
|
|
16
|
+
* green_offset: 8
|
|
17
|
+
* green_length: 8
|
|
18
|
+
* alpha_offset: 24
|
|
19
|
+
* alpha_length: 8
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
export const AdbFrameBufferV1 =
|
|
23
|
+
new Struct({ littleEndian: true })
|
|
24
|
+
.uint32('bpp')
|
|
25
|
+
.uint32('size')
|
|
26
|
+
.uint32('width')
|
|
27
|
+
.uint32('height')
|
|
28
|
+
.uint32('red_offset')
|
|
29
|
+
.uint32('red_length')
|
|
30
|
+
.uint32('blue_offset')
|
|
31
|
+
.uint32('blue_length')
|
|
32
|
+
.uint32('green_offset')
|
|
33
|
+
.uint32('green_length')
|
|
34
|
+
.uint32('alpha_offset')
|
|
35
|
+
.uint32('alpha_length')
|
|
36
|
+
.uint8Array('data', { lengthField: 'size' });
|
|
37
|
+
|
|
38
|
+
export type AdbFrameBufferV1 = typeof AdbFrameBufferV1['TDeserializeResult'];
|
|
39
|
+
|
|
40
|
+
export const AdbFrameBufferV2 =
|
|
41
|
+
new Struct({ littleEndian: true })
|
|
42
|
+
.uint32('bpp')
|
|
43
|
+
.uint32('colorSpace')
|
|
44
|
+
.uint32('size')
|
|
45
|
+
.uint32('width')
|
|
46
|
+
.uint32('height')
|
|
47
|
+
.uint32('red_offset')
|
|
48
|
+
.uint32('red_length')
|
|
49
|
+
.uint32('blue_offset')
|
|
50
|
+
.uint32('blue_length')
|
|
51
|
+
.uint32('green_offset')
|
|
52
|
+
.uint32('green_length')
|
|
53
|
+
.uint32('alpha_offset')
|
|
54
|
+
.uint32('alpha_length')
|
|
55
|
+
.uint8Array('data', { lengthField: 'size' });
|
|
56
|
+
|
|
57
|
+
export type AdbFrameBufferV2 = typeof AdbFrameBufferV2['TDeserializeResult'];
|
|
58
|
+
|
|
59
|
+
export type AdbFrameBuffer = AdbFrameBufferV1 | AdbFrameBufferV2;
|
|
60
|
+
|
|
61
|
+
export async function framebuffer(adb: Adb): Promise<AdbFrameBuffer> {
|
|
62
|
+
const socket = await adb.createSocket('framebuffer:');
|
|
63
|
+
const stream = new AdbBufferedStream(socket);
|
|
64
|
+
const { version } = await Version.deserialize(stream);
|
|
65
|
+
switch (version) {
|
|
66
|
+
case 1:
|
|
67
|
+
return AdbFrameBufferV1.deserialize(stream);
|
|
68
|
+
case 2:
|
|
69
|
+
return AdbFrameBufferV2.deserialize(stream);
|
|
70
|
+
default:
|
|
71
|
+
throw new Error('Unknown FrameBuffer version');
|
|
72
|
+
}
|
|
73
|
+
}
|
package/src/commands/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './base';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './reverse';
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './sync';
|
|
8
|
-
export * from './tcpip';
|
|
1
|
+
export * from './base.js';
|
|
2
|
+
export * from './framebuffer.js';
|
|
3
|
+
export * from './install.js';
|
|
4
|
+
export * from './power.js';
|
|
5
|
+
export * from './reverse.js';
|
|
6
|
+
export * from './subprocess/index.js';
|
|
7
|
+
export * from './sync/index.js';
|
|
8
|
+
export * from './tcpip.js';
|
package/src/commands/install.ts
CHANGED
|
@@ -1,21 +1,32 @@
|
|
|
1
|
-
import { Adb } from "../adb";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
):
|
|
9
|
-
const filename = `/data/local/tmp/${Math.random().toString().
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
1
|
+
import type { Adb } from "../adb.js";
|
|
2
|
+
import { WrapWritableStream, WritableStream } from "../stream/index.js";
|
|
3
|
+
import { escapeArg } from "./subprocess/index.js";
|
|
4
|
+
import type { AdbSync } from "./sync/index.js";
|
|
5
|
+
|
|
6
|
+
export function install(
|
|
7
|
+
adb: Adb,
|
|
8
|
+
): WritableStream<Uint8Array> {
|
|
9
|
+
const filename = `/data/local/tmp/${Math.random().toString().substring(2)}.apk`;
|
|
10
|
+
|
|
11
|
+
return new WrapWritableStream<Uint8Array, WritableStream<Uint8Array>, AdbSync>({
|
|
12
|
+
async start() {
|
|
13
|
+
// Upload apk file to tmp folder
|
|
14
|
+
const sync = await adb.sync();
|
|
15
|
+
const writable = sync.write(filename, undefined, undefined);
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
writable,
|
|
19
|
+
state: sync,
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
async close(sync) {
|
|
23
|
+
sync.dispose();
|
|
24
|
+
|
|
25
|
+
// Invoke `pm install` to install it
|
|
26
|
+
await adb.subprocess.spawnAndWaitLegacy(['pm', 'install', escapeArg(filename)]);
|
|
27
|
+
|
|
28
|
+
// Remove the temp file
|
|
29
|
+
await adb.rm(filename);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// cspell: ignore bootloader
|
|
2
|
+
// cspell: ignore fastboot
|
|
3
|
+
// cspell: ignore keyevent
|
|
4
|
+
// cspell: ignore longpress
|
|
5
|
+
|
|
6
|
+
import { AdbCommandBase } from "./base.js";
|
|
7
|
+
|
|
8
|
+
export class AdbPower extends AdbCommandBase {
|
|
9
|
+
public reboot(name: string = '') {
|
|
10
|
+
return this.adb.createSocketAndWait(`reboot:${name}`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public bootloader() {
|
|
14
|
+
return this.reboot('bootloader');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public fastboot() {
|
|
18
|
+
return this.reboot('fastboot');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public recovery() {
|
|
22
|
+
return this.reboot('recovery');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public sideload() {
|
|
26
|
+
return this.reboot('sideload');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Reboot to Qualcomm Emergency Download (EDL) Mode.
|
|
31
|
+
*
|
|
32
|
+
* Only works on some Qualcomm devices.
|
|
33
|
+
*/
|
|
34
|
+
public qualcommEdlMode() {
|
|
35
|
+
return this.reboot('edl');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public powerOff() {
|
|
39
|
+
return this.adb.subprocess.spawnAndWaitLegacy(['reboot', '-p']);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public powerButton(longPress: boolean = false) {
|
|
43
|
+
return this.adb.subprocess.spawnAndWaitLegacy(['input', 'keyevent', longPress ? '--longpress POWER' : 'POWER']);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Reboot to Samsung Odin download mode.
|
|
48
|
+
*
|
|
49
|
+
* Only works on Samsung devices.
|
|
50
|
+
*/
|
|
51
|
+
public samsungOdin() {
|
|
52
|
+
return this.reboot('download');
|
|
53
|
+
}
|
|
54
|
+
}
|