"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeviceAndroidDebugBridge = void 0;
const android_debug_bridge_1 = require("./android-debug-bridge");
const _ = require("lodash");
class DeviceAndroidDebugBridge extends android_debug_bridge_1.AndroidDebugBridge {
    constructor(identifier, $childProcess, $errors, $logger, $staticConfig, $androidDebugBridgeResultHandler) {
        super($childProcess, $errors, $logger, $staticConfig, $androidDebugBridgeResultHandler);
        this.identifier = identifier;
        this.$childProcess = $childProcess;
        this.$errors = $errors;
        this.$logger = $logger;
        this.$staticConfig = $staticConfig;
        this.$androidDebugBridgeResultHandler = $androidDebugBridgeResultHandler;
    }
    sendBroadcastToDevice(action, extras) {
        return __awaiter(this, void 0, void 0, function* () {
            extras = extras || {};
            const broadcastCommand = ["am", "broadcast", "-a", `${action}`];
            _.each(extras, (value, key) => broadcastCommand.push("-e", key, value));
            const result = yield this.executeShellCommand(broadcastCommand);
            this.$logger.trace(`Broadcast result ${result} from ${broadcastCommand}`);
            const match = result.match(/Broadcast completed: result=(\d+)/);
            if (match) {
                return +match[1];
            }
            this.$errors.fail("Unable to broadcast to android device:\n%s", result);
        });
    }
    composeCommand(params) {
        const _super = Object.create(null, {
            composeCommand: { get: () => super.composeCommand }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return _super.composeCommand.call(this, params, this.identifier);
        });
    }
}
exports.DeviceAndroidDebugBridge = DeviceAndroidDebugBridge;
//# sourceMappingURL=device-android-debug-bridge.js.map