appium-android-driver
Version:
Android UiAutomator and Chrome support for Appium
36 lines • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mobileDeviceidle = mobileDeviceidle;
const driver_1 = require("appium/driver");
const SUPPORTED_ACTIONS = ['whitelistAdd', 'whitelistRemove'];
/**
* This is a wrapper to 'adb shell dumpsys deviceidle' interface.
* Read https://www.protechtraining.com/blog/post/diving-into-android-m-doze-875
* for more details.
*
* @param action The action name to execute.
* @param packages Either a single package or multiple packages to add or remove from the idle whitelist.
* @returns Promise that resolves when the action is completed.
* @throws {errors.InvalidArgumentError} If packages argument is not a string or array.
* @throws {errors.InvalidArgumentError} If action is not one of the supported actions.
*/
async function mobileDeviceidle(action, packages) {
if (!(typeof packages === 'string' || Array.isArray(packages))) {
throw new driver_1.errors.InvalidArgumentError(`packages argument must be a string or an array`);
}
const packagesArr = Array.isArray(packages) ? packages : [packages];
const commonArgs = ['dumpsys', 'deviceidle', 'whitelist'];
let argsGenerator;
switch (action) {
case SUPPORTED_ACTIONS[0]:
argsGenerator = (pkg) => [...commonArgs, `+${pkg}`];
break;
case SUPPORTED_ACTIONS[1]:
argsGenerator = (pkg) => [...commonArgs, `-${pkg}`];
break;
default:
throw new driver_1.errors.InvalidArgumentError(`action must be one of ${JSON.stringify(SUPPORTED_ACTIONS)}. Got '${action}' instead`);
}
await this.adb.shellChunks(argsGenerator, packagesArr);
}
//# sourceMappingURL=deviceidle.js.map