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.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.os.UserManager; 22 23 import androidx.annotation.VisibleForTesting; 24 25 import com.android.settings.R; 26 import com.android.settings.dashboard.DashboardFragment; 27 import com.android.settings.network.telephony.CallsDefaultSubscriptionController; 28 import com.android.settings.network.telephony.NetworkProviderWifiCallingPreferenceController; 29 import com.android.settings.network.telephony.SmsDefaultSubscriptionController; 30 import com.android.settings.search.BaseSearchIndexProvider; 31 import com.android.settingslib.core.AbstractPreferenceController; 32 import com.android.settingslib.search.SearchIndexable; 33 34 import java.util.ArrayList; 35 import java.util.List; 36 37 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) 38 public class NetworkProviderCallsSmsFragment extends DashboardFragment { 39 @VisibleForTesting 40 static final String LOG_TAG = "NetworkProviderCallsSmsFragment"; 41 @VisibleForTesting 42 static final String KEY_PREFERENCE_CATEGORY_CALLING = "provider_model_calling_category"; 43 44 @VisibleForTesting 45 static final String KEY_PREFERENCE_CALLS= "provider_model_calls_preference"; 46 @VisibleForTesting 47 static final String KEY_PREFERENCE_SMS = "provider_model_sms_preference"; 48 49 private NetworkProviderWifiCallingPreferenceController 50 mNetworkProviderWifiCallingPreferenceController; 51 52 @Override createPreferenceControllers(Context context)53 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 54 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 55 controllers.add(new CallsDefaultSubscriptionController(context, KEY_PREFERENCE_CALLS, 56 getSettingsLifecycle(), this)); 57 controllers.add(new SmsDefaultSubscriptionController(context, KEY_PREFERENCE_SMS, 58 getSettingsLifecycle(), this)); 59 mNetworkProviderWifiCallingPreferenceController = 60 new NetworkProviderWifiCallingPreferenceController(context, 61 KEY_PREFERENCE_CATEGORY_CALLING); 62 mNetworkProviderWifiCallingPreferenceController.init(getSettingsLifecycle()); 63 controllers.add(mNetworkProviderWifiCallingPreferenceController); 64 65 return controllers; 66 } 67 68 @Override onResume()69 public void onResume() { 70 super.onResume(); 71 updatePreferenceStates(); 72 } 73 74 @Override getPreferenceScreenResId()75 protected int getPreferenceScreenResId() { 76 return R.xml.network_provider_calls_sms; 77 } 78 79 @Override getLogTag()80 protected String getLogTag() { 81 return LOG_TAG; 82 } 83 84 @Override getMetricsCategory()85 public int getMetricsCategory() { 86 return SettingsEnums.NETWORK_PROVIDER_CALLS_SMS; 87 } 88 89 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 90 new BaseSearchIndexProvider(R.xml.network_provider_calls_sms) { 91 92 @Override 93 protected boolean isPageSearchEnabled(Context context) { 94 return SubscriptionUtil.isSimHardwareVisible(context) && 95 context.getSystemService(UserManager.class).isAdminUser(); 96 } 97 }; 98 } 99