package com.droidlogic.app;

import android.util.Log;

/* JADX INFO: loaded from: classes.dex */
public class RecordControlManager {
    public static final int REMOTE_EXCEPTION = -65535;
    private static final String TAG = "RecordControlManager";
    private static RecordControlManager mInstance;
    private RecordVideoImpl mHidlCallback;

    public interface RecordVideoImpl {
        void handleVideoNotifyMsg(int i2, byte[] bArr);
    }

    static {
        Log.i(TAG, "before loadLibrary: recordcontrol_jni");
        System.loadLibrary("recordcontrol_jni");
        Log.i(TAG, "after loadLibrary: recordcontrol_jni");
    }

    public RecordControlManager() {
        native_ConnectScreenControl();
    }

    private static String byteArrayToHexString(byte[] bArr, int i2) {
        StringBuilder sb = new StringBuilder();
        if (bArr.length < i2) {
            i2 = bArr.length;
        }
        for (int i3 = 0; i3 < i2; i3++) {
            String hexString = Integer.toHexString(bArr[i3] & 255);
            sb.append("0x");
            if (hexString.length() == 1) {
                sb.append("0");
            }
            sb.append(hexString);
            sb.append(" ");
        }
        return sb.toString().toUpperCase();
    }

    public static RecordControlManager getInstance() {
        if (mInstance == null) {
            mInstance = new RecordControlManager();
        }
        return mInstance;
    }

    private native void native_ConnectScreenControl();

    private native void native_ForceStop();

    private native int native_ScreenRecord(int i2, int i3, int i4, int i5, int i6, int i7, String str);

    public void addNotifyHandle(RecordVideoImpl recordVideoImpl) {
        Log.d(TAG, "addNotifyHandle:" + recordVideoImpl);
        this.mHidlCallback = recordVideoImpl;
    }

    public void postVideoEventFromNative(int i2, byte[] bArr) {
        if (this.mHidlCallback != null) {
            Log.d(TAG, "postVideoEventFromNative: " + byteArrayToHexString(bArr, 5));
            this.mHidlCallback.handleVideoNotifyMsg(i2, bArr);
        }
    }

    public void removeNotifyHandle() {
        Log.d(TAG, "removeNotifyHandle:");
        this.mHidlCallback = null;
    }

    public int startScreenRecord(int i2, int i3, int i4, int i5, int i6, int i7, String str) {
        Log.d(TAG, "startScreenRecord wdith:" + i2 + ",height:" + i3 + ",frameRate:" + i4 + ",bitRate:" + i5 + ",limitTimeSec:" + i6 + ",sourceType:" + i7 + ",filename:" + str);
        try {
            return native_ScreenRecord(i2, i3, i4, i5, i6, i7, str);
        } catch (Exception e2) {
            Log.e(TAG, "startScreenRecord: ScreenControlService is dead!:" + e2);
            return -65535;
        }
    }

    public void stopScreenRecord() {
        Log.d(TAG, "stopScreenRecord()");
        native_ForceStop();
    }
}
