1 /* 2 * Copyright (C) 2024 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 static androidx.core.text.HtmlCompat.FROM_HTML_MODE_COMPACT; 20 21 import android.app.Dialog; 22 import android.app.settings.SettingsEnums; 23 import android.content.DialogInterface; 24 import android.os.Bundle; 25 import android.text.Html; 26 import android.text.method.LinkMovementMethod; 27 import android.widget.TextView; 28 29 import androidx.annotation.NonNull; 30 import androidx.annotation.Nullable; 31 import androidx.appcompat.app.AlertDialog; 32 import androidx.fragment.app.Fragment; 33 import androidx.fragment.app.FragmentManager; 34 35 import com.android.settings.R; 36 import com.android.settings.core.instrumentation.InstrumentedDialogFragment; 37 38 /** Dialog when user interacts 16K pages developer option and device is not OEM unlocked */ 39 public class Enable16KOemUnlockDialog extends InstrumentedDialogFragment 40 implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener { 41 42 public static final String TAG = "Enable16KOemUnlockDialog"; 43 44 /** This method is used to prompt user to do OEM unlock before using 16k */ show(@onNull Fragment hostFragment)45 public static void show(@NonNull Fragment hostFragment) { 46 final FragmentManager manager = hostFragment.getActivity().getSupportFragmentManager(); 47 Fragment existingFragment = manager.findFragmentByTag(TAG); 48 if (existingFragment == null) { 49 existingFragment = new Enable16KOemUnlockDialog(); 50 } 51 52 if (existingFragment instanceof Enable16KOemUnlockDialog) { 53 existingFragment.setTargetFragment(hostFragment, 0 /* requestCode */); 54 ((Enable16KOemUnlockDialog) existingFragment).show(manager, TAG); 55 } 56 } 57 58 @Override getMetricsCategory()59 public int getMetricsCategory() { 60 return SettingsEnums.DIALOG_ENABLE_16K_PAGES; 61 } 62 63 @NonNull 64 @Override onCreateDialog(@ullable Bundle savedInstanceState)65 public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { 66 return new AlertDialog.Builder(getActivity()) 67 .setTitle(R.string.confirm_oem_unlock_for_16k_title) 68 .setMessage( 69 Html.fromHtml( 70 getString(R.string.confirm_oem_unlock_for_16k_text), 71 FROM_HTML_MODE_COMPACT)) 72 .setPositiveButton(android.R.string.ok, this /* onClickListener */) 73 .create(); 74 } 75 76 @Override onClick(@onNull DialogInterface dialog, int buttonId)77 public void onClick(@NonNull DialogInterface dialog, int buttonId) { 78 // Do nothing. OEM unlock has to be done by user 79 } 80 81 @Override onDismiss(@onNull DialogInterface dialog)82 public void onDismiss(@NonNull DialogInterface dialog) { 83 super.onDismiss(dialog); 84 } 85 86 @Override onStart()87 public void onStart() { 88 super.onStart(); 89 ((TextView) getDialog().findViewById(android.R.id.message)) 90 .setMovementMethod(LinkMovementMethod.getInstance()); 91 } 92 } 93