package com.pgl.ssdk;

import android.content.Context;
import android.content.SharedPreferences;
import android.hardware.input.InputManager;
import android.os.Build;
import android.text.TextUtils;
import android.view.InputDevice;
import android.view.MotionEvent;
import java.util.Arrays;

/* JADX INFO: loaded from: classes.dex */
public class y {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static int f24795a = 0;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static int f24796b = 0;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static int f24797c = 0;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private static int f24798d = 0;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private static int f24799e = 0;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private static int f24800f = 0;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static volatile boolean f24801g = false;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private static boolean f24802h = false;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private static InputManager f24803i;

    public static class a implements Runnable {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final /* synthetic */ String f24804a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ Context f24805b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        final /* synthetic */ int f24806c;

        public a(String str, Context context, int i10) {
            this.f24804a = str;
            this.f24805b = context;
            this.f24806c = i10;
        }

        @Override // java.lang.Runnable
        public void run() {
            String str;
            if (y.f24801g) {
                com.pgl.ssdk.ces.a.meta(171, null, this.f24804a);
            }
            InputManager inputManagerB = y.b(this.f24805b);
            if (inputManagerB == null) {
                return;
            }
            InputDevice inputDevice = inputManagerB.getInputDevice(this.f24806c);
            y.h();
            if (inputDevice == null) {
                y.b();
                y.c();
                str = "nihc";
            } else {
                if (!inputDevice.isVirtual()) {
                    if (Build.VERSION.SDK_INT < 29 || !inputDevice.isExternal()) {
                        return;
                    }
                    y.f();
                    y.g();
                    y.c("eihc");
                    return;
                }
                y.d();
                y.e();
                str = "vihc";
            }
            y.c(str);
        }
    }

    public static /* synthetic */ int b() {
        int i10 = f24797c;
        f24797c = i10 + 1;
        return i10;
    }

    public static /* synthetic */ int c() {
        int i10 = f24800f;
        f24800f = i10 + 1;
        return i10;
    }

    public static /* synthetic */ int d() {
        int i10 = f24795a;
        f24795a = i10 + 1;
        return i10;
    }

    public static /* synthetic */ int e() {
        int i10 = f24798d;
        f24798d = i10 + 1;
        return i10;
    }

    public static /* synthetic */ int f() {
        int i10 = f24796b;
        f24796b = i10 + 1;
        return i10;
    }

    public static /* synthetic */ int g() {
        int i10 = f24799e;
        f24799e = i10 + 1;
        return i10;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static void h() {
        if (f24802h) {
            return;
        }
        try {
            SharedPreferences sharedPreferencesA = aw.a(z.a());
            if (sharedPreferencesA != null) {
                f24800f = sharedPreferencesA.getInt("nihc", 0);
                f24799e = sharedPreferencesA.getInt("eihc", 0);
                f24798d = sharedPreferencesA.getInt("vihc", 0);
                f24802h = true;
            }
        } catch (Throwable unused) {
        }
    }

    public static int b(String str) {
        if (TextUtils.isEmpty(str)) {
            return -1;
        }
        h();
        str.getClass();
        switch (str) {
        }
        return -1;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static void c(String str) {
        try {
            SharedPreferences sharedPreferencesA = aw.a(z.a());
            if (sharedPreferencesA != null) {
                sharedPreferencesA.edit().putInt(str, sharedPreferencesA.getInt(str, 0) + 1).apply();
            }
        } catch (Throwable unused) {
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:20:0x0042  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static void a(MotionEvent motionEvent, Context context) {
        String string;
        if (motionEvent == null || context == null) {
            return;
        }
        if (f24801g) {
            if (motionEvent.getToolType(0) == 0 || motionEvent.getSource() == 0 || motionEvent.getSource() == 2) {
                string = Arrays.toString(new Exception().getStackTrace());
                if (string.contains("android.view.InputEventReceiver") || string.contains("android.view.ViewRootImpl$WindowInputEventReceiver")) {
                    string = null;
                } else if (string.contains("android.view.ViewRootImpl$InputStage")) {
                }
            }
        }
        ar.b(new a(string, context, motionEvent.getDeviceId()));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static InputManager b(Context context) {
        if (f24803i == null) {
            f24803i = (InputManager) context.getSystemService("input");
        }
        return f24803i;
    }
}
