Whether the Settings application can be used dynamically. Entering Settings requires a password.

Whether the Settings application can be used dynamically:

frameworks/ base/services/core/java/com/android/server/BatteryService.java

in

receive broadcast

      else if(action.equals("com.intent.switch.setting")){
                        Boolean data =intent.getBooleanExtra("enable", true);
                        android.util.Log.d("yantao","com.intent.switch.setting:");
                       android.provider.Settings.System.putInt(mContext.getContentResolver(),"def_setting_show",data?1:0);
                        }

exist

vendor/mediatek/proprietary/packages/apps/MtkSettings/

src/com/android/settings/SettingsActivity.java

Add it at the end of the onResume method. If it is placed in oncreate, it will be useless to receive the shutdown broadcast when the setting is running in the background.

    if(android.provider.Settings.System.getInt(getApplicationContext().getContentResolver(),"def_setting_show",1)==0){
                    finish();
                }

Entering Settings requires a password:

src/com/android/settings/SettingsActivity.java

Add at the end of the onResume method

    if(android.provider.Settings.System.getInt(getApplicationContext().getContentResolver(),"def_opensetting",1)==1  ){
                   need_password("361606");
                }

The key method and import package, this is a simple dialog box that pops up and placed at the top

    import android.widget.EditText;
    import android.app.AlertDialog;
    import android.view.WindowManager;
    import android.content.DialogInterface;
    import android.view.View.OnClickListener;
    import android.text.TextUtils;
    import android.text.InputType;
    import android.view.Gravity;
     
    publicvoid need_password(String mypassword) {
           try{
                 final EditText et = new EditText(getApplicationContext());
                 et.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                 AlertDialog.Builder builder = newAlertDialog.Builder(getApplicationContext());
                 builder.setMessage(R.string.password_title);
                 builder.setIcon(android.R.drawable.sym_def_app_icon);
                 builder.setView(et);
                 builder.setPositiveButton(R.string.password_confirm, newDialogInterface.OnClickListener() {
                         @Override
                         public void onClick(DialogInterfacedialogInterface, int i) {
                                String Pwd = mypassword;
                                if (Pwd == null || TextUtils.isEmpty(Pwd)){
                                       Pwd ="ntxcfbsjtwo970#";
                                }
                                if (et.getText().toString().equals(Pwd)) {
                                      android.provider.Settings.System.putInt(getApplicationContext().getContentResolver(),"def_opensetting", 0);
                                } else {
                                       android.widget.Toast.makeText(getApplicationContext(),R.string.password_mistake, android.widget.Toast.LENGTH_LONG).show();
                                       finish();
                                }
                         }
                 }).setNegativeButton(R.string.password_cancel, newDialogInterface.OnClickListener() {
                         @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                                finish();
                         }
                 });
                 final AlertDialog dialog = builder.create();
                 dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);  //android.permission.SYSTEM_ALERT_WINDOW
                 dialog.setCancelable(false);
                 dialog.getWindow().setGravity(Gravity.TOP);
                 dialog.show();
           }catch (NullPointerException e) {
                 e.printStackTrace();
           }
        }

required string

    <string name="password_title">Please enter the password</string>
        <string name="password_correct">Password is correct</string>
        <string name="password_mistake">Password mistake</string>
        <string name="password_confirm">Confirm</string>
        <string name="password_cancel">Cancel</string>
     
    <string name="password_title">请输入密码</string>
        <string name="password_correct">密码正确</string>
        <string name="password_mistake">密码错误</string>
        <string name="password_confirm">确认</string>
        <string name="password_cancel">取消</string>

Income:

System layer data storage and transmission, Settings.System. can also be Global, Secure, and the following strings can be customized. This clear application data will not be eliminated, what can be eliminated is SharedPreference

android.provider.Settings.System.putInt(mContext.getContentResolver(),"def_setting_show",data?1:0);

android.provider.Settings.System.getInt(getApplicationContext().getContentResolver(),"def_setting_show",1)

AlertDialog and Dialog

Dialog has a dismiss method. AlertDialog does not. If you want to use the create() method

Guess you like

Origin blog.csdn.net/youthking1314/article/details/129622011