1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.development; 18 19 import android.app.Dialog; 20 import android.app.settings.SettingsEnums; 21 import android.content.Context; 22 import android.content.DialogInterface; 23 import android.os.Bundle; 24 import android.os.PowerManager; 25 import android.os.SystemProperties; 26 27 import androidx.appcompat.app.AlertDialog; 28 import androidx.fragment.app.Fragment; 29 import androidx.fragment.app.FragmentManager; 30 31 import com.android.settings.R; 32 import com.android.settings.core.instrumentation.InstrumentedDialogFragment; 33 34 public class RebootWithMteDialog extends InstrumentedDialogFragment 35 implements DialogInterface.OnClickListener { 36 37 public static final String TAG = "RebootWithMteDlg"; 38 private Context mContext; 39 RebootWithMteDialog(Context context)40 public RebootWithMteDialog(Context context) { 41 mContext = context; 42 } 43 show(Context context, Fragment host)44 public static void show(Context context, Fragment host) { 45 FragmentManager manager = host.getActivity().getSupportFragmentManager(); 46 if (manager.findFragmentByTag(TAG) == null) { 47 RebootWithMteDialog dialog = new RebootWithMteDialog(context); 48 dialog.setTargetFragment(host, 0 /* requestCode */); 49 dialog.show(manager, TAG); 50 } 51 } 52 53 @Override getMetricsCategory()54 public int getMetricsCategory() { 55 return SettingsEnums.REBOOT_WITH_MTE_DIALOG; 56 } 57 58 @Override onCreateDialog(Bundle savedInstanceState)59 public Dialog onCreateDialog(Bundle savedInstanceState) { 60 return new AlertDialog.Builder(getActivity()) 61 .setTitle(R.string.reboot_with_mte_title) 62 .setMessage(R.string.reboot_with_mte_message) 63 .setPositiveButton(android.R.string.ok, this /* onClickListener */) 64 .setNegativeButton(android.R.string.cancel, null /* onClickListener */) 65 .setIcon(android.R.drawable.ic_dialog_alert) 66 .create(); 67 } 68 69 @Override onClick(DialogInterface dialog, int which)70 public void onClick(DialogInterface dialog, int which) { 71 PowerManager pm = mContext.getSystemService(PowerManager.class); 72 SystemProperties.set("arm64.memtag.bootctl", "memtag-once"); 73 pm.reboot(null); 74 } 75 } 76