Skip to content

Instantly share code, notes, and snippets.

@dismal002
Created May 28, 2025 23:29
Show Gist options
  • Save dismal002/7f0e54301084e790e5dfee8eabc4f194 to your computer and use it in GitHub Desktop.
Save dismal002/7f0e54301084e790e5dfee8eabc4f194 to your computer and use it in GitHub Desktop.
package com.android.systemui.usb;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.IUsbManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.ServiceManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.method.PasswordTransformationMethod;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.internal.app.AlertActivity;
import java.util.Calendar;
public class UsbGowildDebuggingActivity extends AlertActivity implements DialogInterface.OnClickListener {
final String alwaysAllowKey = "2399754";
private CheckBox mAlwaysAllow;
private UsbDisconnectedReceiver mDisconnectedReceiver;
Handler mH = new Handler() {
public void handleMessage(Message msg) {
try {
IUsbManager.Stub.asInterface(ServiceManager.getService("usb")).allowUsbDebugging(msg.what == 100, UsbGowildDebuggingActivity.this.mKey);
} catch (Exception e) {
Log.e("UsbGowildDebuggingActivity", "Unable to notify Usb service", e);
}
UsbGowildDebuggingActivity.this.finish();
}
};
/* access modifiers changed from: private */
public String mKey;
String onceAllowKey = "";
/* JADX WARNING: type inference failed for: r13v0, types: [com.android.systemui.usb.UsbGowildDebuggingActivity, android.content.Context, com.android.internal.app.AlertActivity, android.app.Activity] */
public void onCreate(Bundle icicle) {
UsbGowildDebuggingActivity.super.onCreate(icicle);
this.mDisconnectedReceiver = new UsbDisconnectedReceiver(this);
Intent intent = getIntent();
String fingerprints = intent.getStringExtra("fingerprints");
this.mKey = intent.getStringExtra("key");
if (fingerprints == null || this.mKey == null) {
finish();
return;
}
createOnceKey(fingerprints);
LinearLayout rootLayout = new LinearLayout(this);
rootLayout.setOrientation(1);
rootLayout.setBackgroundColor(0);
TextView tipsView = new TextView(this);
tipsView.setText(getResources().getString(2131492912, new Object[]{fingerprints}));
tipsView.setGravity(81);
tipsView.setTextSize(20.0f);
tipsView.setBackgroundColor(0);
EditText pinText = new EditText(this);
pinText.setTextSize(20.0f);
pinText.setHint("your pin");
pinText.setFocusable(false);
pinText.setFocusableInTouchMode(false);
pinText.setTransformationMethod(PasswordTransformationMethod.getInstance());
pinText.setGravity(17);
pinText.setBackgroundColor(0);
LinearLayout.LayoutParams tipParams = new LinearLayout.LayoutParams(-1, -1);
tipParams.weight = 0.3f;
rootLayout.addView(tipsView, tipParams);
LinearLayout.LayoutParams pinParams = new LinearLayout.LayoutParams(-1, -1);
pinParams.weight = 0.5f;
rootLayout.addView(pinText, pinParams);
keyboardVoiew(rootLayout, pinText);
pinText.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
UsbGowildDebuggingActivity.this.mH.removeMessages(100);
UsbGowildDebuggingActivity.this.mH.removeMessages(101);
}
public void afterTextChanged(Editable s) {
if ("2399754".equals(s.toString())) {
UsbGowildDebuggingActivity.this.mH.sendEmptyMessageDelayed(100, 1300);
} else if (UsbGowildDebuggingActivity.this.onceAllowKey.equals(s.toString())) {
UsbGowildDebuggingActivity.this.mH.sendEmptyMessageDelayed(101, 1300);
}
}
});
setContentView(rootLayout);
}
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode != 19) {
return UsbGowildDebuggingActivity.super.onKeyUp(keyCode, event);
}
finish();
return true;
}
private class UsbDisconnectedReceiver extends BroadcastReceiver {
private final Activity mActivity;
public UsbDisconnectedReceiver(Activity activity) {
this.mActivity = activity;
}
public void onReceive(Context content, Intent intent) {
if ("android.hardware.usb.action.USB_STATE".equals(intent.getAction()) && !intent.getBooleanExtra("connected", false)) {
this.mActivity.finish();
}
}
}
public void onStart() {
UsbGowildDebuggingActivity.super.onStart();
registerReceiver(this.mDisconnectedReceiver, new IntentFilter("android.hardware.usb.action.USB_STATE"));
}
/* access modifiers changed from: protected */
public void onStop() {
if (this.mDisconnectedReceiver != null) {
unregisterReceiver(this.mDisconnectedReceiver);
}
UsbGowildDebuggingActivity.super.onStop();
}
public void onClick(DialogInterface dialog, int which) {
boolean allow;
boolean alwaysAllow = true;
if (which == -1) {
allow = true;
} else {
allow = false;
}
if (!allow || !this.mAlwaysAllow.isChecked()) {
alwaysAllow = false;
}
try {
IUsbManager service = IUsbManager.Stub.asInterface(ServiceManager.getService("usb"));
if (allow) {
service.allowUsbDebugging(alwaysAllow, this.mKey);
} else {
service.denyUsbDebugging();
}
} catch (Exception e) {
Log.e("UsbGowildDebuggingActivity", "Unable to notify Usb service", e);
}
finish();
}
/* JADX WARNING: type inference failed for: r9v0, types: [com.android.systemui.usb.UsbGowildDebuggingActivity, android.content.Context] */
private void keyboardVoiew(LinearLayout rootLayout, final EditText pinText) {
LinearLayout keyboardLine = new LinearLayout(this);
keyboardLine.setBackgroundColor(0);
LinearLayout.LayoutParams keyParams = new LinearLayout.LayoutParams(-1, -1);
keyParams.setMargins(250, 0, 250, 0);
keyParams.weight = 0.3f;
LinearLayout.LayoutParams keyButtonParams = new LinearLayout.LayoutParams(-2, -2);
keyButtonParams.weight = 1.0f;
for (int i = 0; i < 10; i++) {
final Button keyButton = new Button(this);
if (i == 0) {
keyButton.requestFocus();
}
keyButton.setGravity(17);
keyButton.setText(String.valueOf(i));
keyboardLine.addView(keyButton, keyButtonParams);
keyButton.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
keyButton.setScaleX(0.85f);
keyButton.setScaleY(0.85f);
return;
}
keyButton.setScaleX(1.0f);
keyButton.setScaleY(1.0f);
}
});
keyButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
pinText.setText(pinText.getText().toString() + keyButton.getText());
}
});
}
rootLayout.addView(keyboardLine, keyParams);
}
private void createOnceKey(String fingerprints) {
int keyTmp = 0;
Calendar calendar = Calendar.getInstance();
for (int i = 0; i < fingerprints.length(); i++) {
keyTmp += fingerprints.charAt(i) ^ calendar.get(11);
}
this.onceAllowKey = String.valueOf(keyTmp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment