修改文件:vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
//增加声明import android.app.AlertDialog;import android.content.DialogInterface;import android.text.Editable;import android.text.InputType;import android.text.Selection;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.EditText;import android.widget.TextView;import android.widget.Toast;...... //设定固定密码 private static final String PASSWORD = "1234"; @Override public boolean onPreferenceTreeClick(Preference preference) { android.util.Log.d(TAG, "Hexh preference:" + preference.getKey()); if (preference.getKey().contains("DevelopmentSettingsDashboardActivity")) { showPasswdDialog(preference); return true; } return super.onPreferenceTreeClick(preference); } private void showPasswdDialog(final Preference preference) { android.util.Log.d("DevelopmentSettingsActivity", "showPasswdDialog"); final View view = getLayoutInflater().inflate(R.layout.dialog_develop_password, null, false); final EditText password = (EditText) view.findViewById(R.id.password); final CheckBox showPasswd = (CheckBox) view.findViewById(R.id.show_password); showPasswd.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { password.setInputType(InputType.TYPE_CLASS_NUMBER | (isChecked ? InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD : InputType.TYPE_NUMBER_VARIATION_PASSWORD)); Editable etable = password.getText(); Selection.setSelection(etable, etable.length()); } }); AlertDialog.Builder builder = new AlertDialog.Builder(getContext()) .setTitle(R.string.crypt_keeper_enter_password) .setView(view) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (password.getText().toString().equals(PASSWORD)) { SystemDashboardFragment.super.onPreferenceTreeClick(preference); } else { Toast.makeText(SystemDashboardFragment.this.getContext(), R.string.lockpassword_invalid_password, Toast.LENGTH_SHORT).show(); } } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); } ......
新增文件:vendor/mediatek/proprietary/packages/apps/MtkSettings/res/layout/dialog_develop_password.xml
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2017 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --><ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="24dp"> <TextView android:text="@string/wifi_password" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="numberPassword" android:maxLength="8"/> <CheckBox android:id="@+id/show_password" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/show_password" /> </LinearLayout></ScrollView>
Android O,P版本可能会有点差别。主要是要找到system界面中点击开发者模式的位置,然后就好下手了。
