Authenticated confirmation before deletion of eSim
adds an authentication confirmation before deleting an eSim this feature is turned on/off in the security page Bug: 138861284 Test: mp settingsg Change-Id: I32e0e3bff2091ec1097b3c37fa066d966e3373df
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.
|
||||
*/
|
||||
|
||||
package com.android.settings.security;
|
||||
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||
|
||||
/** Enable/disable user confirmation before deleting an eSim */
|
||||
public class ConfirmSimDeletionPreferenceController extends TogglePreferenceController {
|
||||
public static final String KEY_CONFIRM_SIM_DELETION = "confirm_sim_deletion";
|
||||
private boolean mConfirmationDefaultOn;
|
||||
|
||||
public ConfirmSimDeletionPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mConfirmationDefaultOn =
|
||||
context.getResources()
|
||||
.getBoolean(R.bool.config_sim_deletion_confirmation_default_on);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
// hide if eSim is not supported on the device
|
||||
return MobileNetworkUtils.showEuiccSettings(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
private boolean getGlobalState() {
|
||||
return Settings.Global.getInt(
|
||||
mContext.getContentResolver(),
|
||||
KEY_CONFIRM_SIM_DELETION,
|
||||
mConfirmationDefaultOn ? 1 : 0)
|
||||
== 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return getGlobalState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
Settings.Global.putInt(
|
||||
mContext.getContentResolver(), KEY_CONFIRM_SIM_DELETION, isChecked ? 1 : 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
|
||||
final KeyguardManager keyguardManager = mContext.getSystemService(KeyguardManager.class);
|
||||
if (!keyguardManager.isKeyguardSecure()) {
|
||||
preference.setEnabled(false);
|
||||
if (preference instanceof TwoStatePreference) {
|
||||
((TwoStatePreference) preference).setChecked(false);
|
||||
}
|
||||
preference.setSummary(R.string.disabled_because_no_backup_security);
|
||||
} else {
|
||||
preference.setEnabled(true);
|
||||
if (preference instanceof TwoStatePreference) {
|
||||
((TwoStatePreference) preference).setChecked(getGlobalState());
|
||||
}
|
||||
preference.setSummary(R.string.confirm_sim_deletion_description);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user