feat(debug): 新增用户Debug模式入口及调试功能

- 连续点击触发Debug密码弹窗,验证后进入DebugActivity
- 新增UserDebugDialog及相关样式和颜色资源
- 新增开发者选项、USB、蓝牙、相机、TF卡、恢复出厂、应用安装等状态的getter方法
- 将部分系统设置方法改为public以支持调试页面调用
- 移除ShakeDetectionManager中的高频日志输出
This commit is contained in:
2026-08-13 15:26:31 +08:00
parent e7a570fe09
commit 314c053e56
16 changed files with 1008 additions and 8 deletions

View File

@@ -0,0 +1,140 @@
package com.aoleyun.sn.activity.debug;
import android.util.Log;
import android.view.View;
import android.widget.CompoundButton;
import com.aoleyun.sn.R;
import com.aoleyun.sn.base.mvvm.BaseMvvmActivity;
import com.aoleyun.sn.databinding.ActivityDebugBinding;
import com.aoleyun.sn.utils.JgyUtils;
import com.aoleyun.sn.utils.SysSettingUtils;
import com.hjq.toast.Toaster;
public class DebugActivity extends BaseMvvmActivity<DebugViewModel, ActivityDebugBinding> {
private static final String TAG = "DebugActivity";
private JgyUtils jgyUtils;
@Override
protected int getLayoutId() {
return R.layout.activity_debug;
}
@Override
protected void initDataBinding() {
mViewModel.setCtx(this);
mViewModel.setLifecycle(getLifecycleSubject());
mViewModel.setVDBinding(mViewDataBinding);
mViewDataBinding.setClick(new BtnClick());
}
@Override
protected void initView() {
jgyUtils = JgyUtils.getInstance();
initListener();
}
@Override
protected void initData() {
boolean canReset = SysSettingUtils.getCanReset(DebugActivity.this);
Log.e(TAG, "initData: canReset = " + canReset);
mViewDataBinding.swRestore.setChecked(canReset);
boolean usbStatus = SysSettingUtils.isDisableUsbStatus(DebugActivity.this);
Log.e(TAG, "initData: usbStatus = " + usbStatus);
mViewDataBinding.swUsbDebug.setChecked(usbStatus);
int tf = SysSettingUtils.getTF(DebugActivity.this);
Log.e(TAG, "initData: tf = " + tf);
mViewDataBinding.swTf.setChecked(tf == 0);
boolean developer = jgyUtils.getDeveloperOptions();
Log.e(TAG, "initData: developer = " + developer);
mViewDataBinding.swDeveloper.setChecked(developer);
int bluetooth = SysSettingUtils.getBluetooth(DebugActivity.this);
Log.e(TAG, "initData: bluetooth = " + bluetooth);
mViewDataBinding.swBluetooth.setChecked(bluetooth == 0);
int camera = SysSettingUtils.getCamera(DebugActivity.this);
Log.e(TAG, "initData: camera = " + camera);
mViewDataBinding.swCamera.setChecked(camera == 0);
int appinstall = SysSettingUtils.getAdminApp(DebugActivity.this);
Log.e(TAG, "initData: appinstall = " + appinstall);
mViewDataBinding.swAppinstall.setChecked(appinstall == 0);
}
private void initListener() {
mViewDataBinding.swRestore.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// isChecked=true 允许恢复出厂 -> state=0; false 禁止 -> state=1
SysSettingUtils.setCanReset(DebugActivity.this, isChecked ? 0 : 1);
Toaster.show("恢复出厂设置已" + (isChecked ? "开启" : "关闭"));
}
});
mViewDataBinding.swUsbDebug.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// isChecked=true 开启 -> state=1(MTP); false 仅充电 -> state=0
SysSettingUtils.setUsbStatus(DebugActivity.this, isChecked ? 1 : 0);
Toaster.show("USB调试已" + (isChecked ? "开启" : "关闭"));
}
});
mViewDataBinding.swTf.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// isChecked=true 开启 -> state=0; false 关闭 -> state=1
SysSettingUtils.setTF(DebugActivity.this, isChecked ? 0 : 1);
Toaster.show("存储卡已" + (isChecked ? "开启" : "关闭"));
}
});
mViewDataBinding.swDeveloper.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
jgyUtils.setDeveloperOptions(isChecked ? 1 : 0);
Toaster.show("开发者选项已" + (isChecked ? "开启" : "关闭"));
}
});
mViewDataBinding.swBluetooth.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// isChecked=true 开启 -> state=0; false 关闭 -> state=1
SysSettingUtils.setBluetooth(DebugActivity.this, isChecked ? 0 : 1);
Toaster.show("蓝牙已" + (isChecked ? "开启" : "关闭"));
}
});
mViewDataBinding.swCamera.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// isChecked=true 开启 -> state=0; false 关闭 -> state=1
SysSettingUtils.setCamera(DebugActivity.this, isChecked ? 0 : 1);
Toaster.show("摄像头已" + (isChecked ? "开启" : "关闭"));
}
});
mViewDataBinding.swAppinstall.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// isChecked=true 允许安装 -> state=0; false 禁止 -> state=1
SysSettingUtils.setAdminApp(DebugActivity.this, isChecked ? 0 : 1);
Toaster.show("允许安装应用已" + (isChecked ? "开启" : "关闭"));
}
});
}
public class BtnClick {
public void refresh(View view) {
initData();
}
}
}

View File

@@ -0,0 +1,18 @@
package com.aoleyun.sn.activity.debug;
import com.aoleyun.sn.base.mvvm.BaseViewModel;
import com.aoleyun.sn.databinding.ActivityDebugBinding;
import com.trello.rxlifecycle4.android.ActivityEvent;
public class DebugViewModel extends BaseViewModel<ActivityDebugBinding, ActivityEvent> {
@Override
public ActivityDebugBinding getVDBinding() {
return binding;
}
@Override
public void onDestroy() {
}
}

View File

@@ -23,7 +23,7 @@ import androidx.lifecycle.Observer;
import com.aoleyun.sn.BuildConfig;
import com.aoleyun.sn.R;
import com.aoleyun.sn.activity.requestlog.RequestLogActivity;
import com.aoleyun.sn.activity.debug.DebugActivity;
import com.aoleyun.sn.activity.update.UpdateActivity;
import com.aoleyun.sn.base.mvvm.BaseMvvmActivity;
import com.aoleyun.sn.bean.AppSettings;
@@ -33,6 +33,7 @@ import com.aoleyun.sn.comm.JGYActions;
import com.aoleyun.sn.comm.PackageNames;
import com.aoleyun.sn.databinding.ActivityMainBinding;
import com.aoleyun.sn.dialog.UpdateDialog;
import com.aoleyun.sn.dialog.UserDebugDialog;
import com.aoleyun.sn.service.main.MainService;
import com.aoleyun.sn.utils.ApkUtils;
import com.aoleyun.sn.utils.GlideLoadUtils;
@@ -93,10 +94,49 @@ public class MainActivity extends BaseMvvmActivity<MainViewModel, ActivityMainBi
mHits[mHits.length - 1] = SystemClock.uptimeMillis();
if (mHits[0] >= (SystemClock.uptimeMillis() - DURATION)) {
mHits = new long[COUNTS];//重新初始化数组
startActivity(new Intent(MainActivity.this, RequestLogActivity.class));
// startActivity(new Intent(MainActivity.this, RequestLogActivity.class));
showDebugDialog();
}
}
private UserDebugDialog mUserDebugDialog;
private void showDebugDialog() {
if (mUserDebugDialog != null) {
mUserDebugDialog.dismiss();
mUserDebugDialog = null;
}
mUserDebugDialog = new UserDebugDialog(this);
mUserDebugDialog.setOnClickBottomListener(new UserDebugDialog.OnClickBottomListener() {
@Override
public void onPositiveClick() {
if ("10262022".equals(mUserDebugDialog.getEdittext())) {
// mMMKV.encode(CommonConfig.EnableDebug, true);
Toaster.show("进入用户Debug模式");
startActivity(new Intent(MainActivity.this, DebugActivity.class));
// AdminManager.getInstance().setRestoreFactoryDisabled(1);
// AdminManager.getInstance().removeActiveDeviceAdmin();
} else {
Toaster.show("密码错误");
}
mUserDebugDialog.dismiss();
}
@Override
public void onNegtiveClick() {
mUserDebugDialog.dismiss();
}
});
// if (ScreenUtils.isTablet(MainActivity.this)) {
// AutoSizeCompat.autoConvertDensityBaseOnWidth(getResources(), BaseAlertDialogBuilder.ALERT_BASE_WIDTH_TABLE);
// } else {
// AutoSizeCompat.autoConvertDensityBaseOnWidth(getResources(), BaseAlertDialogBuilder.ALERT_BASE_WIDTH);
// }
mUserDebugDialog.show();
mUserDebugDialog.getWindow().setGravity(Gravity.CENTER);
mUserDebugDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
mUserDebugDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
}
@Override
public void onDisconnected() {

View File

@@ -137,7 +137,7 @@ public class ShakeDetectionManager implements SensorEventListener {
@Override
public void onSensorChanged(SensorEvent event) {
int sensorType = event.sensor.getType();
Log.e(TAG, "onSensorChanged: sensorType = " + sensorType + ", values=" + event.values[0] + "," + event.values[1] + "," + event.values[2]);
// Log.e(TAG, "onSensorChanged: sensorType = " + sensorType + ", values=" + event.values[0] + "," + event.values[1] + "," + event.values[2]);
if (sensorType == Sensor.TYPE_STEP_DETECTOR) {
handleStepDetection();
} else if (sensorType == Sensor.TYPE_LINEAR_ACCELERATION

View File

@@ -0,0 +1,248 @@
package com.aoleyun.sn.dialog;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.aoleyun.sn.R;
/**
* description:自定义dialog
*/
public class UserDebugDialog extends AlertDialog {
/**
* 显示的标题
*/
private TextView titleTv;
/**
* 确认和取消按钮
*/
private Button negtiveBn, positiveBn;
private EditText editText;
private Context mContext;
public UserDebugDialog(Context context) {
super(context, R.style.UserDebugDialog);
this.mContext = context;
}
/**
* 都是内容数据
*/
private String message;
private String title;
private String positive, negtive;
private int imageResId = -1;
/**
* 底部是否只有一个按钮
*/
private boolean isSingle = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_userdebug);
//按空白处不能取消动画
setCanceledOnTouchOutside(false);
//初始化界面控件
initView();
//初始化界面数据
refreshView();
//初始化界面控件的事件
initEvent();
}
/**
* 初始化界面的确定和取消监听器
*/
private void initEvent() {
//设置确定按钮被点击后,向外界提供监听
positiveBn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (onClickBottomListener != null) {
onClickBottomListener.onPositiveClick();
}
}
});
//设置取消按钮被点击后,向外界提供监听
negtiveBn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (onClickBottomListener != null) {
onClickBottomListener.onNegtiveClick();
}
}
});
}
/**
* 初始化界面控件的显示数据
*/
private void refreshView() {
//如果用户自定了title和message
// if (!TextUtils.isEmpty(title)) {
// titleTv.setText(title);
// titleTv.setVisibility(View.VISIBLE);
// } else {
// titleTv.setVisibility(View.GONE);
// }
//如果设置按钮的文字
if (!TextUtils.isEmpty(positive)) {
positiveBn.setText(positive);
} else {
positiveBn.setText("确定");
}
if (!TextUtils.isEmpty(negtive)) {
negtiveBn.setText(negtive);
} else {
negtiveBn.setText("取消");
}
/**
* 只显示一个按钮的时候隐藏取消按钮,回掉只执行确定的事件
*/
if (isSingle) {
negtiveBn.setVisibility(View.GONE);
} else {
negtiveBn.setVisibility(View.VISIBLE);
}
}
@Override
public void show() {
super.show();
refreshView();
}
/**
* 初始化界面控件
*/
private void initView() {
negtiveBn = findViewById(R.id.bt_cancel);
positiveBn = findViewById(R.id.bt_confirm);
titleTv = findViewById(R.id.tv_title);
editText = findViewById(R.id.editText);
}
/**
* 设置确定取消按钮的回调
*/
private OnClickBottomListener onClickBottomListener;
public void setOnClickBottomListener(OnClickBottomListener onClickBottomListener) {
this.onClickBottomListener = onClickBottomListener;
}
public interface OnClickBottomListener {
/**
* 点击确定按钮事件
*/
void onPositiveClick();
/**
* 点击取消按钮事件
*/
void onNegtiveClick();
}
public String getMessage() {
return message;
}
public UserDebugDialog setMessage(String message) {
this.message = message;
return this;
}
public String getTitle() {
return title;
}
public UserDebugDialog setTitle(String title) {
this.title = title;
return this;
}
public String getPositive() {
return positive;
}
public UserDebugDialog setPositive(String positive) {
this.positive = positive;
return this;
}
public String getNegtive() {
return negtive;
}
public UserDebugDialog setNegtive(String negtive) {
this.negtive = negtive;
return this;
}
public UserDebugDialog setNegtiveText(String negtive) {
negtiveBn.setText(negtive);
return this;
}
public int getImageResId() {
return imageResId;
}
public boolean isSingle() {
return isSingle;
}
public UserDebugDialog setSingle(boolean single) {
isSingle = single;
return this;
}
public UserDebugDialog setImageResId(int imageResId) {
this.imageResId = imageResId;
return this;
}
public void showKeyboard() {
if (editText != null) {
//设置可获得焦点
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
//请求获得焦点
editText.requestFocus();
//调用系统输入法
InputMethodManager inputManager = (InputMethodManager) editText
.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(editText, 0);
}
}
@Override
public void dismiss() {
super.dismiss();
}
public String getEdittext() {
if (!TextUtils.isEmpty(editText.getText().toString())) {
return editText.getText().toString().trim();
} else {
return "";
}
}
}

View File

@@ -2166,6 +2166,12 @@ public class JgyUtils {
}
}
public boolean getDeveloperOptions() {
int development = Settings.System.getInt(crv, CommonConfig.AOLE_ACTION_DEVELOPER_OPTIONS, 0);
int adb = Settings.Global.getInt(crv, Settings.Global.ADB_ENABLED, 0);
return development == 1 && adb == 1;
}
private String chromium_pkg = "org.chromium.browser";
public void hookWebView() {

View File

@@ -203,7 +203,7 @@ public class SysSettingUtils {
}
}
private static void setUsbStatus(Context context, int state) {
public static void setUsbStatus(Context context, int state) {
Log.e(TAG, "setUsbStatus: " + state);
//USB数据功能管控
//仅充电:usb_charge
@@ -330,6 +330,11 @@ public class SysSettingUtils {
context.sendBroadcast(usbIntent);
}
// }
}
public static boolean isDisableUsbStatus(Context context) {
return "usb_charge".equals(Settings.System.getString(context.getContentResolver(), "aole_usb_choose"));
}
/**
@@ -495,6 +500,11 @@ public class SysSettingUtils {
}
}
public static int getBluetooth(Context context) {
int setting_bht = Settings.System.getInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_BHT_FORBID_ON, 0);
return setting_bht;
}
private static void setHotspot(Context context, int state) {
try {
Intent intent = new Intent();
@@ -633,7 +643,7 @@ public class SysSettingUtils {
}
}
private static void setCamera(Context context, int state) {
public static void setCamera(Context context, int state) {
try {
//摄像头开关
boolean qch_app_camera = Settings.System.putInt(context.getContentResolver(), "qch_app_camera", 0);
@@ -681,7 +691,11 @@ public class SysSettingUtils {
}
}
private static void setTF(Context context, int state) {
public static int getCamera(Context context) {
return Settings.System.getInt(context.getContentResolver(), "qch_app_camera", 0);
}
public static void setTF(Context context, int state) {
//存储卡
if (JgyUtils.isAllWinnerDevice()) {
AllwinnerCubeMdmManager.getInstance().setSDEnable(state == 0);
@@ -773,6 +787,10 @@ public class SysSettingUtils {
}
}
public static int getTF(Context context) {
return Settings.System.getInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_SDCARD_FORBID_ON, 0);
}
private static void setIcon(Context context, int state) {
}
@@ -788,7 +806,7 @@ public class SysSettingUtils {
Log.e(TAG, "qch_app_wallpaper" + state);
}
private static void setCanReset(Context context, int state) {
public static void setCanReset(Context context, int state) {
Log.e(TAG, "setCanReset: state = " + state);
Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_RESTORE_FORBID_ON, state);
//默认打开
@@ -797,6 +815,10 @@ public class SysSettingUtils {
}
}
public static boolean getCanReset(Context context) {
return Settings.System.getInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_RESTORE_FORBID_ON, 0) == 0;
}
//aole_restore_forbid_on=1,禁止恢复出厂设置
//aole_restore_forbid_on=0,允许恢复出厂设置
private static void setCanReset(Context context, JsonObject jsonObject) {
@@ -985,7 +1007,11 @@ public class SysSettingUtils {
}
private static void setAdminApp(Context context, int state) {
public static int getAdminApp(Context context) {
return Settings.System.getInt(context.getContentResolver(), CommonConfig.AOLE_APP_ALLOW_INSTALL, 0);
}
public static void setAdminApp(Context context, int state) {
Log.e(TAG, "setAdminApp: state = " + state);
if (JgyUtils.isAllWinnerDevice()) {
AllwinnerCubeMdmManager.getInstance().setInstallPackageEnable(state == 0);