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