Android 13 USB调试加密
2023-12-27 23:44:08
介绍
客户需要开发者模式开启时,打开USB调试需要加入密码显示,我们的思路是在打开USB调试时弹出的弹框下方加入输入密码框。
效果展示
修改
字符串资源
路径:vendor/mediatek/proprietary/packages/apps/MtkSettings/res/values/strings.xml
<string name="student_password_error">wrong password</string>
<string name="student_hint_passwork">Please enter your password</string>
路径:vendor/mediatek/proprietary/packages/apps/MtkSettings/res/values-zh-rCN/strings.xml
<string name="student_password_error">密码错误</string>
<string name="student_hint_passwork">请输入密码</string>
我们通过相关字符串找到了弹框出现的代码?onCreateDialog
实际上代码中的布尔值studentSwitch 是动态的来开关这个功能 如果不需要可以默认写成true
String password 实际上就可以自定义成自己想要的密码
路径:vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/development/EnableAdbWarningDialog.java?? ?
//*/soda water studentmode usb passworkd
import android.widget.EditText;
import android.text.InputType;
import android.widget.LinearLayout;
import android.graphics.Color;
import android.widget.Toast;
import android.provider.Settings;
//*/
//此处重写创建弹框的方法
//*/soda water studentmode usb passworkd
private EditText input;
//*/
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
//*/soda water studentmode usb passworkd
boolean studentSwitch = Settings.Global.getInt(getContext().getContentResolver(), "student_model_switch", 0) != 0;
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.adb_warning_title);
if(studentSwitch){
LinearLayout layout = new LinearLayout(getContext());
layout.setOrientation(LinearLayout.VERTICAL);
input = new EditText(getActivity());
input.setHint(R.string.student_hint_passwork);
input.setInputType(InputType.TYPE_CLASS_NUMBER);
input.setTextColor(Color.BLACK);
int marginStartEnd = 50;
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
);
layoutParams.setMargins(marginStartEnd, 0, marginStartEnd, 0);
input.setLayoutParams(layoutParams);
layout.addView(input);
builder.setView(layout);
}
builder.setMessage(R.string.adb_warning_message)
.setPositiveButton(android.R.string.yes, this /* onClickListener */)
.setNegativeButton(android.R.string.no, this /* onClickListener */);
return builder.create();
}
//这里是点击确认时的监听 密码错误时我们弹出提示即可
@Override
public void onClick(DialogInterface dialog, int which) {
final AdbDialogHost host = (AdbDialogHost) getTargetFragment();
if (host == null) {
return;
}
if (which == DialogInterface.BUTTON_POSITIVE) {
//*/soda water studentmode usb passworkd
boolean studentSwitch = Settings.Global.getInt(getContext().getContentResolver(), "student_model_switch", 0) != 0;
String password = Settings.Global.getString(getContext().getContentResolver(), "student_password_global");
if(studentSwitch){
if((password != null && input != null && input.getText().toString().equals(password))){
host.onEnableAdbDialogConfirmed();
}else{
host.onEnableAdbDialogDismissed();
Toast.makeText(getContext(),R.string.student_password_error, Toast.LENGTH_SHORT).show();
}
}else{
host.onEnableAdbDialogConfirmed();
}
//*/
} else {
host.onEnableAdbDialogDismissed();
}
}
文章来源:https://blog.csdn.net/dsadff546765/article/details/135151443
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!