1 /* 2 * Copyright (C) 2020 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.network; 18 19 import android.content.Context; 20 import android.content.pm.PackageManager; 21 import android.os.UserManager; 22 import android.text.TextUtils; 23 24 import androidx.preference.Preference; 25 26 import com.android.settings.Utils; 27 import com.android.settings.core.BasePreferenceController; 28 import com.android.settings.network.telephony.MobileNetworkUtils; 29 import com.android.settings.system.ResetDashboardFragment; 30 31 /** 32 * Controller for erasing Euicc data 33 */ 34 public class EraseEuiccDataController extends BasePreferenceController { 35 private ResetDashboardFragment mHostFragment; 36 37 private final UserManager mUm; 38 EraseEuiccDataController(Context context, String preferenceKey)39 public EraseEuiccDataController(Context context, String preferenceKey) { 40 super(context, preferenceKey); 41 mUm = context.getSystemService(UserManager.class); 42 } 43 setFragment(ResetDashboardFragment hostFragment)44 public void setFragment(ResetDashboardFragment hostFragment) { 45 mHostFragment = hostFragment; 46 } 47 48 @Override handlePreferenceTreeClick(Preference preference)49 public boolean handlePreferenceTreeClick(Preference preference) { 50 if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) { 51 return false; 52 } 53 if (SubscriptionUtil.shouldShowRacDialogWhenErasingAllEsims(mContext)) { 54 EuiccRacConnectivityDialogFragment.show(mHostFragment); 55 } else { 56 EraseEuiccDataDialogFragment.show(mHostFragment); 57 } 58 return true; 59 } 60 61 @Override getAvailabilityStatus()62 public int getAvailabilityStatus() { 63 boolean isAllowedUser = (mUm.isAdminUser() || Utils.isDemoUser(mContext)) 64 && !MobileNetworkUtils.isMobileNetworkUserRestricted(mContext); 65 boolean hasEuiccFeature = mContext.getPackageManager().hasSystemFeature( 66 PackageManager.FEATURE_TELEPHONY_EUICC); 67 return SubscriptionUtil.isSimHardwareVisible(mContext) 68 && isAllowedUser 69 && hasEuiccFeature ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE; 70 } 71 } 72