1 /* 2 * Copyright (C) 2021 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 package com.android.settings.network.helper; 17 18 import android.app.KeyguardManager; 19 import android.content.Context; 20 import android.provider.Settings; 21 22 import com.android.settings.R; 23 24 import java.util.function.Predicate; 25 26 /** 27 * {@link Predicate} for detecting the configuration of confirm SIM deletion. 28 */ 29 public class ConfirmationSimDeletionPredicate implements Predicate<Context> { 30 31 public static final String KEY_CONFIRM_SIM_DELETION = "confirm_sim_deletion"; 32 33 private static final ConfirmationSimDeletionPredicate sSingleton = 34 new ConfirmationSimDeletionPredicate(); 35 36 // Get singleton of this predicate getSingleton()37 public static final ConfirmationSimDeletionPredicate getSingleton() { 38 return sSingleton; 39 } 40 41 /** 42 * Get default configuration of confirm SIM deletion. 43 * 44 * @param Context context 45 * @return the configuration of confirm SIM deletion 46 */ getDefaultValue(Context context)47 private static boolean getDefaultValue(Context context) { 48 return context.getResources() 49 .getBoolean(R.bool.config_sim_deletion_confirmation_default_on); 50 } 51 52 /** 53 * Get the configuration of confirm SIM deletion. 54 * 55 * @param Context context 56 * @return the configuration of confirm SIM deletion 57 */ test(Context context)58 public boolean test(Context context) { 59 final KeyguardManager keyguardManager = context.getSystemService(KeyguardManager.class); 60 if ((keyguardManager != null) && !keyguardManager.isKeyguardSecure()) { 61 return false; 62 } 63 return Settings.Global.getInt(context.getContentResolver(), KEY_CONFIRM_SIM_DELETION, 64 getDefaultValue(context) ? 1 : 0) == 1; 65 } 66 } 67