package com.android.systemui.usb;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.debug.IAdbManager;
import android.os.Bundle;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.CheckBox;
import com.ifpdos.debugmenu.R;
import com.seewo.sdk.OpenSDK;
import com.seewo.sdk.SDKTouchHelper;

/* JADX INFO: loaded from: classes.dex */
public class UsbDebuggingActivity extends Activity implements DialogInterface.OnClickListener {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final /* synthetic */ int f1933b = 0;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public CheckBox f1934e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public a f1935f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public String f1936g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public boolean f1937h;

    public class a extends BroadcastReceiver {
        public final Activity a;

        public a(Activity activity) {
            this.a = activity;
        }

        @Override // android.content.BroadcastReceiver
        public void onReceive(Context context, Intent intent) {
            if ("android.hardware.usb.action.USB_STATE".equals(intent.getAction()) && !intent.getBooleanExtra("connected", false)) {
                Log.d("UsbDebuggingActivity", "USB disconnected, notifying service");
                UsbDebuggingActivity usbDebuggingActivity = UsbDebuggingActivity.this;
                int i2 = UsbDebuggingActivity.f1933b;
                usbDebuggingActivity.a(false, false);
                this.a.finish();
            }
        }
    }

    public final void a(boolean z, boolean z2) {
        try {
            IAdbManager iAdbManagerAsInterface = IAdbManager.Stub.asInterface(ServiceManager.getService("adb"));
            if (z) {
                iAdbManagerAsInterface.allowDebugging(z2, this.f1936g);
            } else {
                iAdbManagerAsInterface.denyDebugging();
            }
            this.f1937h = true;
        } catch (Exception e2) {
            Log.e("UsbDebuggingActivity", "Unable to notify Usb service", e2);
        }
    }

    @Override // android.content.DialogInterface.OnClickListener
    public void onClick(DialogInterface dialogInterface, int i2) {
        boolean z = i2 == -1;
        a(z, z && this.f1934e.isChecked());
        finish();
    }

    @Override // android.app.Activity
    public void onCreate(Bundle bundle) {
        getWindow().setType(2008);
        super.onCreate(bundle);
        if (!OpenSDK.getInstance().isConnected()) {
            OpenSDK.getInstance().connect(this);
        }
        if (SystemProperties.getInt("service.adb.tcp.port", 0) == 0) {
            this.f1935f = new a(this);
            registerReceiver(this.f1935f, new IntentFilter("android.hardware.usb.action.USB_STATE"));
        }
        Intent intent = getIntent();
        String stringExtra = intent.getStringExtra("fingerprints");
        this.f1936g = intent.getStringExtra("key");
        d.b.a.a.a.U(d.b.a.a.a.B("mKey="), this.f1936g, "Debugging");
        if (stringExtra == null || this.f1936g == null) {
            finish();
            return;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.usb_debugging_title);
        builder.setMessage(getString(R.string.usb_debugging_message, new Object[]{stringExtra}));
        builder.setPositiveButton(R.string.usb_debugging_allow, this);
        builder.setNegativeButton(android.R.string.cancel, this);
        View viewInflate = LayoutInflater.from(builder.getContext()).inflate(R.layout.always_use_checkbox, (ViewGroup) null);
        CheckBox checkBox = (CheckBox) viewInflate.findViewById(R.id.alwaysUse);
        this.f1934e = checkBox;
        checkBox.setText(getString(R.string.usb_debugging_always));
        builder.setView(viewInflate);
        builder.setCancelable(false);
        builder.show();
    }

    @Override // android.app.Activity
    public void onDestroy() {
        a aVar = this.f1935f;
        if (aVar != null) {
            unregisterReceiver(aVar);
        }
        if (isFinishing() && !this.f1937h) {
            a(false, false);
        }
        super.onDestroy();
    }

    @Override // android.app.Activity
    public void onPause() {
        SDKTouchHelper.I.postOsdStatus(false);
        super.onPause();
    }

    @Override // android.app.Activity
    public void onResume() {
        SDKTouchHelper.I.postOsdStatus(true);
        super.onResume();
    }

    @Override // android.app.Activity, android.view.Window.Callback
    public void onWindowAttributesChanged(WindowManager.LayoutParams layoutParams) {
        super.onWindowAttributesChanged(layoutParams);
    }
}
