package com.droidlogic.app;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.Rect;
import android.hardware.display.DisplayManager;
import android.os.IBinder;
import android.util.Log;
import android.view.Display;
import android.view.SurfaceControl;
import android.view.WindowManager;
import com.seewo.sdk.internal.model.SDKParsable;

/* JADX INFO: loaded from: classes.dex */
public class ScreenControlManager implements SDKParsable {
    public static final int AMLOGIC_CAPTURE_OSD_ONLY = 2;
    public static final int AMLOGIC_CAPTURE_VIDEO_AND_OSD = 1;
    public static final int AMLOGIC_CAPTURE_VIDEO_ONLY = 0;
    private static final int SDK_VERSION_ANDROID_11 = 30;
    private static final int SDK_VERSION_ANDROID_13 = 33;
    private static final String TAG = "ScreenControlManager";

    private static class INSTANCE {
        private static final ScreenControlManager I = new ScreenControlManager();

        private INSTANCE() {
        }
    }

    static {
        System.loadLibrary("screencontrol_jni");
    }

    private static Bitmap adjustRotation(Bitmap bitmap, int i2) {
        Matrix matrix = new Matrix();
        matrix.postRotate(i2, bitmap.getWidth() / 2.0f, bitmap.getHeight() / 2.0f);
        Bitmap bitmapCreateBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        new Canvas(bitmapCreateBitmap).drawBitmap(bitmap, matrix, null);
        return bitmapCreateBitmap;
    }

    /* JADX WARN: Removed duplicated region for block: B:11:0x001a  */
    /* JADX WARN: Removed duplicated region for block: B:21:0x0033  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static android.graphics.Bitmap captureAmlogic(android.content.Context r10, int r11, int r12, int r13) {
        /*
            com.seewo.sdk.model.SDKShotType r0 = com.seewo.sdk.model.SDKShotType.VIDEO_ONLY
            int r0 = r0.ordinal()
            r1 = 2
            if (r13 != r0) goto Lc
            r13 = 0
        La:
            r9 = r13
            goto L18
        Lc:
            com.seewo.sdk.model.SDKShotType r0 = com.seewo.sdk.model.SDKShotType.OSD_ONLY
            int r0 = r0.ordinal()
            if (r13 != r0) goto L16
            r9 = r1
            goto L18
        L16:
            r13 = 1
            goto La
        L18:
            if (r9 != r1) goto L33
            int r13 = android.os.Build.VERSION.SDK_INT
            r0 = 33
            if (r13 < r0) goto L25
            android.graphics.Bitmap r10 = invokeScreenshotSDK33(r10, r11, r12)
            return r10
        L25:
            r10 = 30
            if (r13 < r10) goto L2e
            android.graphics.Bitmap r10 = invokeScreenshotSDK28(r11, r12)
            return r10
        L2e:
            android.graphics.Bitmap r10 = android.view.SurfaceControl.screenshot(r11, r12)
            return r10
        L33:
            java.lang.StringBuilder r10 = new java.lang.StringBuilder
            r10.<init>()
            java.lang.String r13 = "captureAmlogic:type "
            r10.append(r13)
            r10.append(r9)
            java.lang.String r10 = r10.toString()
            java.lang.String r13 = "ScreenControlManager"
            android.util.Log.i(r13, r10)
            com.droidlogic.app.ScreenControlManager r2 = com.droidlogic.app.ScreenControlManager.INSTANCE.access$100()
            r3 = 0
            r4 = 0
            r5 = r11
            r6 = r12
            r7 = r11
            r8 = r12
            byte[] r10 = r2.native_ScreenCapBuffer(r3, r4, r5, r6, r7, r8, r9)
            if (r10 != 0) goto L6f
            java.lang.StringBuilder r11 = new java.lang.StringBuilder
            r11.<init>()
            java.lang.String r12 = "captureAmlogic: "
            r11.append(r12)
            r11.append(r10)
            java.lang.String r10 = r11.toString()
            android.util.Log.i(r13, r10)
            r10 = 0
            return r10
        L6f:
            android.graphics.Bitmap$Config r13 = android.graphics.Bitmap.Config.ARGB_8888
            android.graphics.Bitmap r11 = android.graphics.Bitmap.createBitmap(r11, r12, r13)
            java.nio.ByteBuffer r10 = java.nio.ByteBuffer.wrap(r10)
            r11.copyPixelsFromBuffer(r10)
            boolean r10 = isReverseScreen()
            if (r10 == 0) goto L8c
            r10 = 180(0xb4, float:2.52E-43)
            android.graphics.Bitmap r10 = adjustRotation(r11, r10)
            r11.recycle()
            return r10
        L8c:
            return r11
        */
        throw new UnsupportedOperationException("Method not decompiled: com.droidlogic.app.ScreenControlManager.captureAmlogic(android.content.Context, int, int, int):android.graphics.Bitmap");
    }

    public static void getScreenInfo(Context context, int[] iArr) {
        Point point = new Point();
        ((WindowManager) context.getApplicationContext().getSystemService("window")).getDefaultDisplay().getSize(point);
        iArr[0] = point.x;
        iArr[1] = point.y;
    }

    private static Bitmap invokeScreenshotSDK28(int i2, int i3) {
        Log.i(TAG, "invokeScreenshotSDK28: ");
        try {
            return (Bitmap) Class.forName("android.view.SurfaceControl").getDeclaredMethod("screenshot", Rect.class, Integer.TYPE, Integer.TYPE, Integer.TYPE).invoke(null, new Rect(0, 0, 0, 0), Integer.valueOf(i2), Integer.valueOf(i3), 0);
        } catch (Exception e) {
            Log.e(TAG, "screenshot error!", e);
            return null;
        }
    }

    private static Bitmap invokeScreenshotSDK33(Context context, int i2, int i3) {
        try {
            Display display = ((DisplayManager) context.getSystemService("display")).getDisplay(0);
            IBinder iBinder = (IBinder) SurfaceControl.class.getMethod("getPhysicalDisplayToken", Long.TYPE).invoke(null, Class.forName("android.view.DisplayAddress$Physical").getMethod("getPhysicalDisplayId", new Class[0]).invoke(display.getClass().getMethod("getAddress", new Class[0]).invoke(display, new Object[0]), new Object[0]));
            Class<?> cls = Class.forName("android.view.SurfaceControl$DisplayCaptureArgs$Builder");
            Object objNewInstance = cls.getConstructor(IBinder.class).newInstance(iBinder);
            cls.getMethod("setSourceCrop", Rect.class).invoke(objNewInstance, new Rect(0, 0, i2, i3));
            cls.getMethod("setSize", Integer.TYPE, Integer.TYPE).invoke(objNewInstance, Integer.valueOf(i2), Integer.valueOf(i3));
            Object objInvoke = cls.getMethod("build", new Class[0]).invoke(objNewInstance, new Object[0]);
            Object objInvoke2 = SurfaceControl.class.getMethod("captureDisplay", objInvoke.getClass()).invoke(null, objInvoke);
            return (Bitmap) objInvoke2.getClass().getMethod("asBitmap", new Class[0]).invoke(objInvoke2, new Object[0]);
        } catch (Exception e) {
            Log.e(TAG, "captureScreen failed", e);
            return null;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:96:0x0094 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:66:0x009e -> B:81:0x00b9). Please report as a decompilation issue!!! */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private static boolean isReverseScreen() throws java.lang.Throwable {
        /*
            java.lang.String r0 = "ScreenControlManager"
            java.io.File r1 = new java.io.File
            java.lang.String r2 = "/factorydata/tvconfig/panel/vbyone_1region.ini"
            r1.<init>(r2)
            boolean r2 = r1.exists()
            r3 = 0
            if (r2 != 0) goto L11
            return r3
        L11:
            r2 = 0
            java.io.FileInputStream r4 = new java.io.FileInputStream     // Catch: java.lang.Throwable -> L62 java.io.IOException -> L67
            r4.<init>(r1)     // Catch: java.lang.Throwable -> L62 java.io.IOException -> L67
            java.io.BufferedReader r1 = new java.io.BufferedReader     // Catch: java.lang.Throwable -> L58 java.io.IOException -> L5d
            java.io.InputStreamReader r5 = new java.io.InputStreamReader     // Catch: java.lang.Throwable -> L58 java.io.IOException -> L5d
            r5.<init>(r4)     // Catch: java.lang.Throwable -> L58 java.io.IOException -> L5d
            r1.<init>(r5)     // Catch: java.lang.Throwable -> L58 java.io.IOException -> L5d
        L21:
            java.lang.String r2 = r1.readLine()     // Catch: java.io.IOException -> L56 java.lang.Throwable -> L91
            if (r2 == 0) goto L35
            java.lang.String r2 = r2.trim()     // Catch: java.io.IOException -> L56 java.lang.Throwable -> L91
            java.lang.String r5 = "panel_reverse=1"
            boolean r2 = r2.equalsIgnoreCase(r5)     // Catch: java.io.IOException -> L56 java.lang.Throwable -> L91
            if (r2 == 0) goto L21
            r2 = 1
            r3 = r2
        L35:
            r1.close()     // Catch: java.lang.Throwable -> L43 java.io.IOException -> L45
            r4.close()     // Catch: java.io.IOException -> L3d
            goto L90
        L3d:
            r1 = move-exception
            h.c.c.s.d.d(r0, r1)
            goto L90
        L43:
            r1 = move-exception
            goto L4d
        L45:
            r1 = move-exception
            h.c.c.s.d.d(r0, r1)     // Catch: java.lang.Throwable -> L43
            r4.close()     // Catch: java.io.IOException -> L3d
            goto L90
        L4d:
            r4.close()     // Catch: java.io.IOException -> L51
            goto L55
        L51:
            r2 = move-exception
            h.c.c.s.d.d(r0, r2)
        L55:
            throw r1
        L56:
            r2 = move-exception
            goto L6b
        L58:
            r1 = move-exception
            r6 = r2
            r2 = r1
            r1 = r6
            goto L92
        L5d:
            r1 = move-exception
            r6 = r2
            r2 = r1
            r1 = r6
            goto L6b
        L62:
            r1 = move-exception
            r4 = r2
            r2 = r1
            r1 = r4
            goto L92
        L67:
            r1 = move-exception
            r4 = r2
            r2 = r1
            r1 = r4
        L6b:
            h.c.c.s.d.d(r0, r2)     // Catch: java.lang.Throwable -> L91
            if (r1 == 0) goto L90
            r1.close()     // Catch: java.lang.Throwable -> L79 java.io.IOException -> L7b
            if (r4 == 0) goto L90
            r4.close()     // Catch: java.io.IOException -> L3d
            goto L90
        L79:
            r1 = move-exception
            goto L85
        L7b:
            r1 = move-exception
            h.c.c.s.d.d(r0, r1)     // Catch: java.lang.Throwable -> L79
            if (r4 == 0) goto L90
            r4.close()     // Catch: java.io.IOException -> L3d
            goto L90
        L85:
            if (r4 == 0) goto L8f
            r4.close()     // Catch: java.io.IOException -> L8b
            goto L8f
        L8b:
            r2 = move-exception
            h.c.c.s.d.d(r0, r2)
        L8f:
            throw r1
        L90:
            return r3
        L91:
            r2 = move-exception
        L92:
            if (r1 == 0) goto Lb9
            r1.close()     // Catch: java.lang.Throwable -> La2 java.io.IOException -> La4
            if (r4 == 0) goto Lb9
            r4.close()     // Catch: java.io.IOException -> L9d
            goto Lb9
        L9d:
            r1 = move-exception
            h.c.c.s.d.d(r0, r1)
            goto Lb9
        La2:
            r1 = move-exception
            goto Lae
        La4:
            r1 = move-exception
            h.c.c.s.d.d(r0, r1)     // Catch: java.lang.Throwable -> La2
            if (r4 == 0) goto Lb9
            r4.close()     // Catch: java.io.IOException -> L9d
            goto Lb9
        Lae:
            if (r4 == 0) goto Lb8
            r4.close()     // Catch: java.io.IOException -> Lb4
            goto Lb8
        Lb4:
            r2 = move-exception
            h.c.c.s.d.d(r0, r2)
        Lb8:
            throw r1
        Lb9:
            throw r2
        */
        throw new UnsupportedOperationException("Method not decompiled: com.droidlogic.app.ScreenControlManager.isReverseScreen():boolean");
    }

    private native void native_ConnectScreenControl();

    private native void native_ForceStop();

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

    private native byte[] native_ScreenCapBuffer(int i2, int i3, int i4, int i5, int i6, int i7, int i8);

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

    private ScreenControlManager() {
        native_ConnectScreenControl();
    }
}
