"use strict";
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;
    }
    async sendBroadcastToDevice(action, extras) {
        extras = extras || {};
        const broadcastCommand = ["am", "broadcast", "-a", `${action}`];
        _.each(extras, (value, key) => broadcastCommand.push("-e", key, value));
        const result = await 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);
    }
    async composeCommand(params) {
        return super.composeCommand(params, this.identifier);
    }
}
exports.DeviceAndroidDebugBridge = DeviceAndroidDebugBridge;
