@aiot-toolkit/emulator 2.0.5-widget-provider-beta.2 → 2.0.5

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.
@@ -9,59 +9,81 @@ var _path = _interopRequireDefault(require("path"));
9
9
  var _utils = require("../utils");
10
10
  var _common = _interopRequireDefault(require("./common"));
11
11
  var _Vvd = require("../typing/Vvd");
12
+ var _shared = require("../shared");
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
14
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
14
15
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
- /**
16
- * MiwearInstance
17
- * 针对 Vela正式版(4.0)的镜像
16
+ /**
17
+ * MiwearInstance
18
+ * 针对 Vela正式版(4.0)的镜像
18
19
  */
19
20
  class MiwearInstance extends _common.default {
20
21
  static emulatorStartedFlag = /quickapp_rpk_installer_init|rpk installer init done/;
21
22
  static appInstalledFlag = /InstallState_Finished|install finished/;
22
23
  imageType = (() => _Vvd.VelaImageType.REL)();
23
24
  appDir = '/data/quickapp/app';
24
-
25
- /**
26
- * 使用 pm 安装快应用
27
- * @param targeRpk 快应用的rpk文件路径
25
+ static isAppInstalled(log, targetRpk) {
26
+ // 注意:targetRpk 可能包含特殊字符,需要转义
27
+ const escapedRpk = targetRpk.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
28
+ const reg = new RegExp(`executeInstall: rpk install: ${escapedRpk} .* success`);
29
+ return reg.test(log);
30
+ }
31
+ /**
32
+ * 使用 pm 安装快应用
33
+ * @param targeRpk 快应用的rpk文件路径
28
34
  */
29
- async install(targeRpk) {
35
+ async install(targeRpk, options) {
30
36
  const installCmd = `adb -s ${this.sn} shell pm install ${targeRpk}`;
31
37
  this.logger(`Excuting: ${installCmd}`);
32
38
  adbMiwt.execAdbCmd(installCmd);
33
39
  return new Promise((resolve, reject) => {
40
+ const clearFn = () => {
41
+ clearTimeout(timer);
42
+ this.stdoutReadline.off('line', func);
43
+ };
34
44
  const func = msg => {
35
- if (MiwearInstance.isAppInstalled(msg)) {
36
- clearTimeout(timer);
45
+ if (MiwearInstance.isAppInstalled(msg, targeRpk)) {
37
46
  this.logger(`Install to ${this.vvdName} ${targeRpk} successfully`);
38
- this.stdoutReadline.off('line', func);
47
+ clearFn();
39
48
  resolve();
40
49
  }
41
50
  if (MiwearInstance.isAppInstallFailed(msg)) {
42
- clearTimeout(timer);
43
- this.stdoutReadline.off('line', func);
44
51
  this.logger(`Failed Install to ${this.vvdName} ${targeRpk}`);
45
- reject(msg);
52
+ this.logger(_shared.RpkInstallFailedReason.LowStorage);
53
+ clearFn();
54
+ reject(_shared.RpkInstallFailedReason.LowStorage);
55
+ }
56
+
57
+ // 当前安装进程被占用
58
+ if (msg.includes('installRpk: installation is running, please wait')) {
59
+ this.logger(_shared.RpkInstallFailedReason.Busy);
60
+ clearFn();
61
+ reject(_shared.RpkInstallFailedReason.Busy);
46
62
  }
47
63
  };
64
+ function getTimeout(size) {
65
+ if (!size) return 10 * 1000;
66
+ const mu = size / 1024 / 1024;
67
+ return mu < 1 ? 10 * 1000 : mu < 4 ? 60 * 1000 : 2 * 60 * 1000;
68
+ }
69
+ const timeout = getTimeout(options?.size);
48
70
  let timer = setTimeout(() => {
49
71
  this.stdoutReadline.off('line', func);
50
72
  this.logger(`Install to ${this.vvdName} ${targeRpk} timeout`);
51
- reject('Install timeout');
52
- }, 2 * 60 * 1000);
73
+ reject(_shared.RpkInstallFailedReason.Timeout);
74
+ }, timeout);
53
75
  this.stdoutReadline.on('line', func);
54
76
  this.stdoutReadline.on('close', () => {
55
- this.stdoutReadline.removeAllListeners();
77
+ this.stdoutReadline.off('line', func);
56
78
  clearTimeout(timer);
57
- reject('Device poweroff');
79
+ reject(_shared.RpkInstallFailedReason.Poweroff);
58
80
  });
59
81
  });
60
82
  }
61
83
 
62
- /**
63
- * 使用 pm 卸载快应用
64
- * @param packageName 快应用的包名
84
+ /**
85
+ * 使用 pm 卸载快应用
86
+ * @param packageName 快应用的包名
65
87
  */
66
88
  uninstall(packageName) {
67
89
  adbMiwt.execAdbCmd(`adb -s ${this.sn} shell pm uninstall ${packageName}`);
@@ -98,9 +120,9 @@ class MiwearInstance extends _common.default {
98
120
  }
99
121
  async closeApp(appName) {
100
122
  const stopCmd = `adb -s ${this.sn} shell am stop ${appName}`;
123
+ this.logger(`Excuting: ${stopCmd}`);
101
124
  await adbMiwt.execAdbCmdAsync(stopCmd);
102
125
  this.logger(`Stop ${this.vvdName} ${appName} successfully`);
103
- // 这里是为了等am stop命令清除资源等
104
126
  }
105
127
  async reboot() {
106
128
  await super.reboot();
@@ -3,5 +3,4 @@ import MiwearInstance from './miwear';
3
3
  export declare class VelaMiwear5 extends MiwearInstance {
4
4
  imageType: VelaImageType;
5
5
  appDir: string;
6
- static emulatorStartedFlag: RegExp;
7
6
  }
@@ -10,6 +10,5 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
10
10
  class VelaMiwear5 extends _miwear.default {
11
11
  imageType = (() => _Vvd.VelaImageType.VELA_MIWEAR_WATCH_5)();
12
12
  appDir = '/data/app';
13
- static emulatorStartedFlag = /\[App Active Flag/;
14
13
  }
15
14
  exports.VelaMiwear5 = VelaMiwear5;
@@ -7,7 +7,10 @@ declare class PreInstance extends CommonEmulatorInstance {
7
7
  imageType: VelaImageType;
8
8
  appDir: string;
9
9
  static emulatorStartedFlag: RegExp;
10
- install(rpkPath: string, appPackageName?: string): Promise<void>;
10
+ install(rpkPath: string, opt: {
11
+ packageName: string;
12
+ size?: number;
13
+ }): Promise<void>;
11
14
  uninstall(packageName: string): Promise<void>;
12
15
  /**
13
16
  * 在模拟器中启动快应用
@@ -10,17 +10,17 @@ var _common = _interopRequireDefault(require("./common"));
10
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
11
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
12
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
- /**
14
- * 不带 miwear 的 4.0 镜像
13
+ /**
14
+ * 不带 miwear 的 4.0 镜像
15
15
  */
16
16
  class PreInstance extends _common.default {
17
17
  imageType = (() => _Vvd.VelaImageType.PRE)();
18
18
  appDir = '/data/quickapp/app';
19
19
  static emulatorStartedFlag = /(NSH)/;
20
- async install(rpkPath, appPackageName) {
20
+ async install(rpkPath, opt) {
21
21
  // 基于 vapp 启动的应用只需要将 rpk 解压到指定的目录下
22
- rpkPath = rpkPath || `${this.appDir}/${appPackageName}.rpk`;
23
- const targetPath = `${this.appDir}/${appPackageName}`;
22
+ rpkPath = rpkPath || `${this.appDir}/${opt.packageName}.rpk`;
23
+ const targetPath = `${this.appDir}/${opt.packageName}`;
24
24
  const mkdirCmd = `adb -s ${this.sn} shell mkdir ${targetPath}`;
25
25
  this.logger(`Excuting: ${mkdirCmd}`);
26
26
  await adbMiwt.execAdbCmdAsync(mkdirCmd);
@@ -36,10 +36,10 @@ class PreInstance extends _common.default {
36
36
  await adbMiwt.execAdbCmdAsync(mkdirCmd);
37
37
  }
38
38
 
39
- /**
40
- * 在模拟器中启动快应用
41
- * 通过vapp命令启动,调试时需额外配置--jsdebugger参数
42
- * @param options
39
+ /**
40
+ * 在模拟器中启动快应用
41
+ * 通过vapp命令启动,调试时需额外配置--jsdebugger参数
42
+ * @param options
43
43
  */
44
44
  async startApp(packageName) {
45
45
  let debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -10,4 +10,9 @@ export declare class Vela5Instance extends MiwearInstance {
10
10
  * @param targeRpk 快应用的rpk文件路径
11
11
  */
12
12
  install(targeRpk: string): Promise<void>;
13
+ /** 使用 am start 启动快应用 */
14
+ startApp(packageName: string): Promise<void>;
15
+ /** 重启模拟器 */
16
+ reboot(): Promise<void>;
17
+ closeApp(appName: string): Promise<void>;
13
18
  }
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Vela5Instance = void 0;
7
+ var _shared = require("../shared");
7
8
  var _Vvd = require("../typing/Vvd");
9
+ var _logcat = require("../vvd/logcat");
8
10
  var _miwear = _interopRequireDefault(require("./miwear"));
9
11
  var adbMiwt = _interopRequireWildcard(require("@miwt/adb"));
10
12
  var _util = require("util");
@@ -12,14 +14,14 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
12
14
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
16
  class Vela5Instance extends _miwear.default {
15
- static emulatorStartedFlag = /Boot completed/;
17
+ static emulatorStartedFlag = /booting completed|Boot completed/;
16
18
  static appStartedFlag = /Start main loop/;
17
19
  imageType = (() => _Vvd.VelaImageType.VELA_WATCH_5)();
18
20
  appDir = '/data/app';
19
21
 
20
- /**
21
- * 使用 pm 安装快应用
22
- * @param targeRpk 快应用的rpk文件路径
22
+ /**
23
+ * 使用 pm 安装快应用
24
+ * @param targeRpk 快应用的rpk文件路径
23
25
  */
24
26
  async install(targeRpk) {
25
27
  const installCmd = `adb -s ${this.sn} shell pm install ${targeRpk}`;
@@ -35,5 +37,62 @@ class Vela5Instance extends _miwear.default {
35
37
  return Promise.reject(res);
36
38
  }
37
39
  }
40
+
41
+ /** 使用 am start 启动快应用 */
42
+ async startApp(packageName) {
43
+ const startCmd = `adb -s ${this.sn} shell am start ${packageName}`;
44
+ this.logger(`Excuting: ${startCmd}`);
45
+ adbMiwt.execAdbCmdAsync(startCmd);
46
+ return new Promise((resolve, reject) => {
47
+ const clearFn = () => {
48
+ clearTimeout(timer);
49
+ this.stdoutReadline.off('line', func);
50
+ };
51
+ const func = msg => {
52
+ if (Vela5Instance.appStartedFlag.test(msg)) {
53
+ this.logger(`Start ${packageName} for ${this.vvdName} successfully`);
54
+ clearFn();
55
+ resolve();
56
+ }
57
+ const escapedPackageName = packageName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
58
+ const reg = new RegExp(`Failed to open: .+?/${escapedPackageName}/manifest\.json`);
59
+ if (reg.test(msg)) {
60
+ this.logger(`Failed Start ${packageName} for ${this.vvdName}`);
61
+ clearFn();
62
+ reject(_shared.RpkStartFailedReason.getManifestFailed);
63
+ }
64
+ };
65
+ let timer = setTimeout(() => {
66
+ this.stdoutReadline.off('line', func);
67
+ this.logger(`Start ${packageName} for ${this.vvdName} timeout`);
68
+ reject('Timeout');
69
+ }, 8 * 1000);
70
+ this.stdoutReadline.on('line', func);
71
+ });
72
+ }
73
+
74
+ /** 重启模拟器 */
75
+ async reboot() {
76
+ const rebootCmd = `adb -s ${this.sn} shell reboot`;
77
+ this.logger(`Excuting: ${rebootCmd}`);
78
+ await adbMiwt.execAdbCmdAsync(rebootCmd);
79
+ await this.isConnected();
80
+ if (this.logcatProcess.exitCode !== null) {
81
+ // 如果 logcat 进程被杀死,则重新创建
82
+ const r = (0, _logcat.creatLogcat)(this.sn, this.onStdout, this.onErrout);
83
+ this.logcatProcess = r.logcatProcess;
84
+ this.stdoutReadline = r.stdoutReadline;
85
+ this.stderrReadline = r.stderrReadline;
86
+ this.disposeReadlines = r.dispose;
87
+ }
88
+ }
89
+ async closeApp(appName) {
90
+ await super.closeApp(appName);
91
+ await new Promise(resolve => {
92
+ setTimeout(() => {
93
+ resolve();
94
+ }, 2000);
95
+ });
96
+ }
38
97
  }
39
98
  exports.Vela5Instance = Vela5Instance;
@@ -6,3 +6,12 @@ import { VelaImageType } from '../typing/Vvd';
6
6
  export declare function isVelaImageType(value: any): value is VelaImageType;
7
7
  export declare function isMiwearImageType(val: VelaImageType): boolean;
8
8
  export declare function getDefaultImage(): VelaImageType;
9
+ export declare enum RpkStartFailedReason {
10
+ getManifestFailed = "Get app manifest.json failed"
11
+ }
12
+ export declare enum RpkInstallFailedReason {
13
+ Busy = "Installation process is busy",
14
+ Timeout = "Install timeout",
15
+ Poweroff = "Device poweroff",
16
+ LowStorage = "Application exceeds maximum quantity or remaining space is low"
17
+ }
@@ -3,13 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.RpkStartFailedReason = exports.RpkInstallFailedReason = void 0;
6
7
  exports.getDefaultImage = getDefaultImage;
7
8
  exports.isMiwearImageType = isMiwearImageType;
8
9
  exports.isVelaImageType = isVelaImageType;
9
10
  var _Vvd = require("../typing/Vvd");
10
- /**
11
- * 本文件用于导出一些同构内容,请勿引用非同构内容,例如 nodejs 特性内容,或者 browser 特性内容
12
- * @TODO 项目转为 ESM 模块后,可以删除
11
+ /**
12
+ * 本文件用于导出一些同构内容,请勿引用非同构内容,例如 nodejs 特性内容,或者 browser 特性内容
13
+ * @TODO 项目转为 ESM 模块后,可以删除
13
14
  * */
14
15
 
15
16
  function isVelaImageType(value) {
@@ -20,4 +21,15 @@ function isMiwearImageType(val) {
20
21
  }
21
22
  function getDefaultImage() {
22
23
  return _Vvd.VelaImageType.VELA_MIWEAR_WATCH_5;
23
- }
24
+ }
25
+ let RpkStartFailedReason = exports.RpkStartFailedReason = /*#__PURE__*/function (RpkStartFailedReason) {
26
+ RpkStartFailedReason["getManifestFailed"] = "Get app manifest.json failed";
27
+ return RpkStartFailedReason;
28
+ }({});
29
+ let RpkInstallFailedReason = exports.RpkInstallFailedReason = /*#__PURE__*/function (RpkInstallFailedReason) {
30
+ RpkInstallFailedReason["Busy"] = "Installation process is busy";
31
+ RpkInstallFailedReason["Timeout"] = "Install timeout";
32
+ RpkInstallFailedReason["Poweroff"] = "Device poweroff";
33
+ RpkInstallFailedReason["LowStorage"] = "Application exceeds maximum quantity or remaining space is low";
34
+ return RpkInstallFailedReason;
35
+ }({});
@@ -1 +1 @@
1
- ModemSimulator = on
1
+ ModemSimulator = on
@@ -1,39 +1,45 @@
1
- {
2
- "AvdId": "Vela_Virtual_Device",
3
- "abi.type": "armeabi-v7a",
4
- "avd.ini.displayname": "Vela_Virtual_Device",
5
- "avd.ini.encoding": "UTF-8",
6
- "fastboot.forceChosenSnapshotBoot": "no",
7
- "fastboot.forceColdBoot": "yes",
8
- "fastboot.forceFastBoot": "no",
9
- "hw.accelerometer": "yes",
10
- "hw.arc": false,
11
- "hw.audioInput": "yes",
12
- "hw.battery": "yes",
13
- "hw.camera.back": "None",
14
- "hw.camera.front": "None",
15
- "hw.cpu.arch": "arm",
16
- "hw.cpu.ncore": 4,
17
- "hw.dPad": "no",
18
- "hw.gps": "yes",
19
- "hw.gpu.enabled": "no",
20
- "hw.gpu.mode": "host",
21
- "hw.initialOrientation": "Portrait",
22
- "hw.keyboard": "yes",
23
- "hw.lcd.density": 420,
24
- "hw.lcd.height": 466,
25
- "hw.lcd.width": 466,
26
- "hw.mainKeys": "no",
27
- "hw.ramSize": 512,
28
- "hw.sdCard": "no",
29
- "hw.sensors.orientation": "yes",
30
- "hw.sensors.proximity": "yes",
31
- "hw.trackBall": "no",
32
- "image.sysdir.2": "",
33
- "runtime.network.latency": "none",
34
- "runtime.network.speed": "full",
35
- "showDeviceFrame": "yes",
36
- "skin.dynamic": "no",
37
- "skin.name": "",
38
- "skin.path": ""
39
- }
1
+ {
2
+ "AvdId": "Vela_Virtual_Device",
3
+ "abi.type": "armeabi-v7a",
4
+ "avd.ini.displayname": "Vela_Virtual_Device",
5
+ "avd.ini.encoding": "UTF-8",
6
+ "fastboot.forceChosenSnapshotBoot": "no",
7
+ "fastboot.forceColdBoot": "yes",
8
+ "fastboot.forceFastBoot": "no",
9
+ "hw.arc": false,
10
+ "hw.audioInput": "yes",
11
+ "hw.battery": "yes",
12
+ "hw.camera.back": "None",
13
+ "hw.camera.front": "None",
14
+ "hw.cpu.arch": "arm",
15
+ "hw.cpu.ncore": 4,
16
+ "hw.dPad": "no",
17
+ "hw.gps": "yes",
18
+ "hw.gpu.enabled": "no",
19
+ "hw.gpu.mode": "host",
20
+ "hw.initialOrientation": "Portrait",
21
+ "hw.keyboard": "yes",
22
+ "hw.lcd.density": 420,
23
+ "hw.lcd.height": 466,
24
+ "hw.lcd.width": 466,
25
+ "hw.mainKeys": "no",
26
+ "hw.ramSize": 1024,
27
+ "hw.sdCard": "no",
28
+ "hw.sensors.orientation": "yes",
29
+ "hw.trackBall": "no",
30
+ "image.sysdir.2": "",
31
+ "runtime.network.latency": "none",
32
+ "runtime.network.speed": "full",
33
+ "showDeviceFrame": "yes",
34
+ "skin.dynamic": "no",
35
+ "skin.name": "",
36
+ "skin.path": "",
37
+ "hw.accelerometer": "yes",
38
+ "hw.gyroscope": "yes",
39
+ "hw.sensors.proximity": "yes",
40
+ "hw.sensors.magnetic_field": "yes",
41
+ "hw.sensors.temperature": "yes",
42
+ "hw.sensors.light": "yes",
43
+ "hw.sensors.humidity": "yes",
44
+ "hw.sensors.heart_rate": "yes"
45
+ }
@@ -1 +1 @@
1
- 10.0.2.15:101
1
+ 10.0.2.15:101
@@ -1,2 +1,2 @@
1
- This contains all the protobuf files that are shipped with the emulator.
2
- These were taken at sha b5705ca57ad61b81413aca46d82baf5ceeaeed8c
1
+ This contains all the protobuf files that are shipped with the emulator.
2
+ These were taken at sha b5705ca57ad61b81413aca46d82baf5ceeaeed8c