package net.northking.cctp.upperComputer.driver.agent;

import net.northking.cctp.upperComputer.driver.adb.Adb;
import net.northking.cctp.upperComputer.driver.adb.AdbDevice;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * 与Android Agent程序进行交互
 */

public class AndroidAgent{

    private Logger logger = LoggerFactory.getLogger(AndroidAgent.class);

    private final Adb adb;
    private final AdbDevice adbDevice;

    public AndroidAgent(Adb adb, AdbDevice adbDevice) {
        this.adb = adb;
        this.adbDevice = adbDevice;
    }

    public byte[] takeScreenshot() {
        byte[] result = null;
        StandaloneCommandRunner runner = new StandaloneCommandRunner(adb, adbDevice, "net.northking.product.cctpplus.command.ScreenShotCommand", "");
        try {
            result = runner.run();
        } catch (StandaloneCommandTimeoutException e) {
            logger.error("Android Agent执行超时", e);
        } catch (StandaloneCommandException e) {
            logger.error("Android Agent执行异常", e);
        } catch (IOException e) {
            logger.error("Android Agent执行IO异常", e);
        }
        return result;
    }


}
