appium-android-driver
Version:
Android UiAutomator and Chrome support for Appium
40 lines • 1.94 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mobileDeviceidle = mobileDeviceidle;
const driver_1 = require("appium/driver");
const lodash_1 = __importDefault(require("lodash"));
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 (!(lodash_1.default.isString(packages) || lodash_1.default.isArray(packages))) {
throw new driver_1.errors.InvalidArgumentError(`packages argument must be a string or an array`);
}
const packagesArr = lodash_1.default.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