appium-uiautomator2-driver 3.0.5 → 3.0.7

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.
@@ -6,13 +6,9 @@ import {
6
6
  TEST_APK_PATH as testApkPath,
7
7
  version as serverVersion
8
8
  } from 'appium-uiautomator2-server';
9
- import {
10
- util, logger, tempDir, fs, timing
11
- } from 'appium/support';
9
+ import { util, logger, timing } from 'appium/support';
12
10
  import B from 'bluebird';
13
- import {isWriteable, signApp} from './helpers';
14
11
  import axios from 'axios';
15
- import path from 'path';
16
12
 
17
13
  const REQD_PARAMS = ['adb', 'tmpDir', 'host', 'systemPort', 'devicePort', 'disableWindowAnimation'];
18
14
  const SERVER_LAUNCH_TIMEOUT = 30000;
@@ -78,30 +74,18 @@ class UiAutomator2Server {
78
74
  this.jwproxy.didInstrumentationExit = false;
79
75
  }
80
76
 
81
- async prepareServerPackage(appPath, appId, tmpRoot) {
77
+ /**
78
+ * @param {string} appPath
79
+ * @param {string} appId
80
+ * @returns {Promise<{installState: import('appium-adb').InstallState, appPath: string; appId: string}>}
81
+ */
82
+ async prepareServerPackage(appPath, appId) {
82
83
  const resultInfo = {
83
- wasSigned: false,
84
84
  installState: this.adb.APP_INSTALL_STATE.NOT_INSTALLED,
85
85
  appPath,
86
86
  appId,
87
87
  };
88
88
 
89
- if (await this.adb.checkApkCert(resultInfo.appPath, appId)) {
90
- resultInfo.wasSigned = true;
91
- } else {
92
- if (!await isWriteable(appPath)) {
93
- this.log.warn(
94
- `Server package at '${appPath}' is not writeable. ` +
95
- `Will copy it into the temporary location at '${tmpRoot}' as a workaround. ` +
96
- `Consider making this file writeable manually in order to improve the performance of session startup.`
97
- );
98
- const dstPath = path.resolve(tmpRoot, path.basename(appPath));
99
- await fs.copyFile(appPath, dstPath);
100
- resultInfo.appPath = dstPath;
101
- }
102
- await signApp(this.adb, resultInfo.appPath);
103
- }
104
-
105
89
  if (appId === SERVER_TEST_PACKAGE_ID && await this.adb.isAppInstalled(appId)) {
106
90
  // There is no point in getting the state for the test server,
107
91
  // since it does not contain any version info
@@ -119,59 +103,52 @@ class UiAutomator2Server {
119
103
  * @param {number} installTimeout - Installation timeout
120
104
  */
121
105
  async installServerApk (installTimeout = SERVER_INSTALL_RETRIES * 1000) {
122
- const tmpRoot = await tempDir.openDir();
123
- try {
124
- const packagesInfo = await B.all(
125
- [
126
- {
127
- appPath: apkPath,
128
- appId: SERVER_PACKAGE_ID,
129
- }, {
130
- appPath: testApkPath,
131
- appId: SERVER_TEST_PACKAGE_ID,
132
- },
133
- ].map(({appPath, appId}) => this.prepareServerPackage(appPath, appId, tmpRoot))
134
- );
106
+ const packagesInfo = await B.all(
107
+ [
108
+ {
109
+ appPath: apkPath,
110
+ appId: SERVER_PACKAGE_ID,
111
+ }, {
112
+ appPath: testApkPath,
113
+ appId: SERVER_TEST_PACKAGE_ID,
114
+ },
115
+ ].map(({appPath, appId}) => this.prepareServerPackage(appPath, appId))
116
+ );
135
117
 
136
- this.log.debug(`Server packages status: ${JSON.stringify(packagesInfo)}`);
137
- // We want to enforce uninstall in case the current server package has not been signed properly
138
- // or if any of server packages is not installed, while the other does
139
- const shouldUninstallServerPackages = packagesInfo.some(({wasSigned}) => !wasSigned)
140
- || (packagesInfo.some(({installState}) => installState === this.adb.APP_INSTALL_STATE.NOT_INSTALLED)
141
- && !packagesInfo.every(({installState}) => installState === this.adb.APP_INSTALL_STATE.NOT_INSTALLED));
142
- // Install must always follow uninstall. Also, perform the install if
143
- // any of server packages is not installed or is outdated
144
- const shouldInstallServerPackages = shouldUninstallServerPackages || packagesInfo.some(({installState}) => [
145
- this.adb.APP_INSTALL_STATE.NOT_INSTALLED,
146
- this.adb.APP_INSTALL_STATE.OLDER_VERSION_INSTALLED,
147
- ].includes(installState));
148
- this.log.info(`Server packages are ${shouldInstallServerPackages ? '' : 'not '}going to be (re)installed`);
149
- if (shouldInstallServerPackages && shouldUninstallServerPackages) {
150
- this.log.info('Full packages reinstall is going to be performed');
151
- }
152
- if (shouldUninstallServerPackages) {
153
- const silentUninstallPkg = async (pkgId) => {
154
- try {
155
- await this.adb.uninstallApk(pkgId);
156
- } catch (err) {
157
- this.log.info(`Cannot uninstall '${pkgId}': ${err.message}`);
158
- }
159
- };
160
- await B.all(packagesInfo.map(({appId}) => silentUninstallPkg(appId)));
161
- }
162
- if (shouldInstallServerPackages) {
163
- const installPkg = async (pkgPath) => {
164
- await this.adb.install(pkgPath, {
165
- noIncremental: true,
166
- replace: true,
167
- timeout: installTimeout,
168
- timeoutCapName: 'uiautomator2ServerInstallTimeout'
169
- });
170
- };
171
- await B.all(packagesInfo.map(({appPath}) => installPkg(appPath)));
172
- }
173
- } finally {
174
- await fs.rimraf(tmpRoot);
118
+ this.log.debug(`Server packages status: ${JSON.stringify(packagesInfo)}`);
119
+ // Enforce server packages reinstall if any of the packages is not installed, while the other is
120
+ const shouldUninstallServerPackages = (packagesInfo.some(({installState}) => installState === this.adb.APP_INSTALL_STATE.NOT_INSTALLED)
121
+ && !packagesInfo.every(({installState}) => installState === this.adb.APP_INSTALL_STATE.NOT_INSTALLED));
122
+ // Install must always follow uninstall. Also, perform the install if
123
+ // any of server packages is not installed or is outdated
124
+ const shouldInstallServerPackages = shouldUninstallServerPackages || packagesInfo.some(({installState}) => [
125
+ this.adb.APP_INSTALL_STATE.NOT_INSTALLED,
126
+ this.adb.APP_INSTALL_STATE.OLDER_VERSION_INSTALLED,
127
+ ].includes(installState));
128
+ this.log.info(`Server packages are ${shouldInstallServerPackages ? '' : 'not '}going to be (re)installed`);
129
+ if (shouldInstallServerPackages && shouldUninstallServerPackages) {
130
+ this.log.info('Full packages reinstall is going to be performed');
131
+ }
132
+ if (shouldUninstallServerPackages) {
133
+ const silentUninstallPkg = async (pkgId) => {
134
+ try {
135
+ await this.adb.uninstallApk(pkgId);
136
+ } catch (err) {
137
+ this.log.info(`Cannot uninstall '${pkgId}': ${err.message}`);
138
+ }
139
+ };
140
+ await B.all(packagesInfo.map(({appId}) => silentUninstallPkg(appId)));
141
+ }
142
+ if (shouldInstallServerPackages) {
143
+ const installPkg = async (pkgPath) => {
144
+ await this.adb.install(pkgPath, {
145
+ noIncremental: true,
146
+ replace: true,
147
+ timeout: installTimeout,
148
+ timeoutCapName: 'uiautomator2ServerInstallTimeout'
149
+ });
150
+ };
151
+ await B.all(packagesInfo.map(({appPath}) => installPkg(appPath)));
175
152
  }
176
153
 
177
154
  await this.verifyServicesAvailability();