• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.telephony;
18 
19 import android.app.Activity;
20 import android.app.settings.SettingsEnums;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.os.Bundle;
24 import android.os.UserManager;
25 import android.provider.SearchIndexableResource;
26 import android.provider.Settings;
27 import android.telephony.SubscriptionManager;
28 import android.telephony.TelephonyManager;
29 import android.text.TextUtils;
30 import android.util.Log;
31 import android.view.Menu;
32 import android.view.MenuInflater;
33 import android.view.MenuItem;
34 
35 import com.android.internal.telephony.TelephonyIntents;
36 import com.android.settings.R;
37 import com.android.settings.core.FeatureFlags;
38 import com.android.settings.dashboard.RestrictedDashboardFragment;
39 import com.android.settings.datausage.BillingCyclePreferenceController;
40 import com.android.settings.datausage.DataUsageSummaryPreferenceController;
41 import com.android.settings.development.featureflags.FeatureFlagPersistent;
42 import com.android.settings.network.telephony.cdma.CdmaSubscriptionPreferenceController;
43 import com.android.settings.network.telephony.cdma.CdmaSystemSelectPreferenceController;
44 import com.android.settings.network.telephony.gsm.AutoSelectPreferenceController;
45 import com.android.settings.network.telephony.gsm.OpenNetworkSelectPagePreferenceController;
46 import com.android.settings.search.BaseSearchIndexProvider;
47 import com.android.settings.search.Indexable;
48 import com.android.settings.widget.PreferenceCategoryController;
49 import com.android.settingslib.core.AbstractPreferenceController;
50 import com.android.settingslib.search.SearchIndexable;
51 
52 import java.util.ArrayList;
53 import java.util.Arrays;
54 import java.util.List;
55 
56 import androidx.annotation.VisibleForTesting;
57 import androidx.preference.Preference;
58 
59 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
60 public class MobileNetworkSettings extends RestrictedDashboardFragment {
61 
62     private static final String LOG_TAG = "NetworkSettings";
63     public static final int REQUEST_CODE_EXIT_ECM = 17;
64     public static final int REQUEST_CODE_DELETE_SUBSCRIPTION = 18;
65     @VisibleForTesting
66     static final String KEY_CLICKED_PREF = "key_clicked_pref";
67 
68     //String keys for preference lookup
69     private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key";
70     private static final String BUTTON_CDMA_SUBSCRIPTION_KEY = "cdma_subscription_key";
71 
72     private TelephonyManager mTelephonyManager;
73     private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
74 
75     private CdmaSystemSelectPreferenceController mCdmaSystemSelectPreferenceController;
76     private CdmaSubscriptionPreferenceController mCdmaSubscriptionPreferenceController;
77 
78     private UserManager mUserManager;
79     private String mClickedPrefKey;
80 
MobileNetworkSettings()81     public MobileNetworkSettings() {
82         super(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);
83     }
84 
85     @Override
getMetricsCategory()86     public int getMetricsCategory() {
87         return SettingsEnums.MOBILE_NETWORK;
88     }
89 
90     /**
91      * Invoked on each preference click in this hierarchy, overrides
92      * PreferenceActivity's implementation.  Used to make sure we track the
93      * preference click events.
94      */
95     @Override
onPreferenceTreeClick(Preference preference)96     public boolean onPreferenceTreeClick(Preference preference) {
97         if (super.onPreferenceTreeClick(preference)) {
98             return true;
99         }
100         final String key = preference.getKey();
101 
102         if (TextUtils.equals(key, BUTTON_CDMA_SYSTEM_SELECT_KEY)
103                 || TextUtils.equals(key, BUTTON_CDMA_SUBSCRIPTION_KEY)) {
104             if (mTelephonyManager.getEmergencyCallbackMode()) {
105                 startActivityForResult(
106                         new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
107                         REQUEST_CODE_EXIT_ECM);
108                 mClickedPrefKey = key;
109             }
110             return true;
111         }
112 
113         return false;
114     }
115 
116     @Override
createPreferenceControllers(Context context)117     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
118         mSubId = getArguments().getInt(Settings.EXTRA_SUB_ID,
119                 MobileNetworkUtils.getSearchableSubscriptionId(context));
120 
121         if (FeatureFlagPersistent.isEnabled(getContext(), FeatureFlags.NETWORK_INTERNET_V2) &&
122             mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
123             return Arrays.asList(
124                     new DataUsageSummaryPreferenceController(getActivity(), getSettingsLifecycle(),
125                             this, mSubId));
126         }
127         return Arrays.asList();
128     }
129 
130     @Override
onAttach(Context context)131     public void onAttach(Context context) {
132         super.onAttach(context);
133 
134         if (FeatureFlagPersistent.isEnabled(getContext(), FeatureFlags.NETWORK_INTERNET_V2)) {
135             use(CallsDefaultSubscriptionController.class).init(getLifecycle());
136             use(SmsDefaultSubscriptionController.class).init(getLifecycle());
137             use(MobileNetworkSwitchController.class).init(getLifecycle(), mSubId);
138             use(CarrierSettingsVersionPreferenceController.class).init(mSubId);
139             use(BillingCyclePreferenceController.class).init(mSubId);
140             use(MmsMessagePreferenceController.class).init(mSubId);
141             use(DataDuringCallsPreferenceController.class).init(getLifecycle(), mSubId);
142             use(DisabledSubscriptionController.class).init(getLifecycle(), mSubId);
143             use(DeleteSimProfilePreferenceController.class).init(mSubId, this,
144                     REQUEST_CODE_DELETE_SUBSCRIPTION);
145             use(DisableSimFooterPreferenceController.class).init(mSubId);
146         }
147         use(MobileDataPreferenceController.class).init(getFragmentManager(), mSubId);
148         use(RoamingPreferenceController.class).init(getFragmentManager(), mSubId);
149         use(ApnPreferenceController.class).init(mSubId);
150         use(CarrierPreferenceController.class).init(mSubId);
151         use(DataUsagePreferenceController.class).init(mSubId);
152         use(PreferredNetworkModePreferenceController.class).init(mSubId);
153         use(EnabledNetworkModePreferenceController.class).init(mSubId);
154         use(DataServiceSetupPreferenceController.class).init(mSubId);
155         if (!FeatureFlagPersistent.isEnabled(getContext(), FeatureFlags.NETWORK_INTERNET_V2)) {
156             use(EuiccPreferenceController.class).init(mSubId);
157         }
158         use(WifiCallingPreferenceController.class).init(mSubId);
159 
160         final OpenNetworkSelectPagePreferenceController openNetworkSelectPagePreferenceController =
161                 use(OpenNetworkSelectPagePreferenceController.class).init(mSubId);
162         final AutoSelectPreferenceController autoSelectPreferenceController =
163                 use(AutoSelectPreferenceController.class)
164                         .init(mSubId)
165                         .addListener(openNetworkSelectPagePreferenceController);
166         use(PreferenceCategoryController.class).setChildren(
167                 Arrays.asList(autoSelectPreferenceController));
168 
169         mCdmaSystemSelectPreferenceController = use(CdmaSystemSelectPreferenceController.class);
170         mCdmaSystemSelectPreferenceController.init(getPreferenceManager(), mSubId);
171         mCdmaSubscriptionPreferenceController = use(CdmaSubscriptionPreferenceController.class);
172         mCdmaSubscriptionPreferenceController.init(getPreferenceManager(), mSubId);
173 
174         final VideoCallingPreferenceController videoCallingPreferenceController =
175                 use(VideoCallingPreferenceController.class).init(mSubId);
176         use(Enhanced4gLtePreferenceController.class).init(mSubId)
177                 .addListener(videoCallingPreferenceController);
178     }
179 
180     @Override
onCreate(Bundle icicle)181     public void onCreate(Bundle icicle) {
182         Log.i(LOG_TAG, "onCreate:+");
183         super.onCreate(icicle);
184         final Context context = getContext();
185 
186         mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
187         mTelephonyManager = TelephonyManager.from(context).createForSubscriptionId(mSubId);
188 
189         onRestoreInstance(icicle);
190     }
191 
192     @VisibleForTesting
onRestoreInstance(Bundle icicle)193     void onRestoreInstance(Bundle icicle) {
194         if (icicle != null) {
195             mClickedPrefKey = icicle.getString(KEY_CLICKED_PREF);
196         }
197     }
198 
199     @Override
getPreferenceScreenResId()200     protected int getPreferenceScreenResId() {
201         if (FeatureFlagPersistent.isEnabled(getContext(), FeatureFlags.NETWORK_INTERNET_V2)) {
202             return R.xml.mobile_network_settings_v2;
203         } else {
204             return R.xml.mobile_network_settings;
205         }
206     }
207 
208     @Override
getLogTag()209     protected String getLogTag() {
210         return LOG_TAG;
211     }
212 
213     @Override
onSaveInstanceState(Bundle outState)214     public void onSaveInstanceState(Bundle outState) {
215         super.onSaveInstanceState(outState);
216         outState.putString(KEY_CLICKED_PREF, mClickedPrefKey);
217     }
218 
219     @Override
onActivityResult(int requestCode, int resultCode, Intent data)220     public void onActivityResult(int requestCode, int resultCode, Intent data) {
221         switch (requestCode) {
222             case REQUEST_CODE_EXIT_ECM:
223                 if (resultCode != Activity.RESULT_CANCELED) {
224                     // If the phone exits from ECM mode, show the CDMA
225                     final Preference preference = getPreferenceScreen()
226                             .findPreference(mClickedPrefKey);
227                     if (preference != null) {
228                         preference.performClick();
229                     }
230                 }
231                 break;
232 
233             case REQUEST_CODE_DELETE_SUBSCRIPTION:
234                 final Activity activity = getActivity();
235                 if (activity != null && !activity.isFinishing()) {
236                     activity.finish();
237                 }
238                 break;
239 
240             default:
241                 break;
242         }
243     }
244 
245     @Override
onCreateOptionsMenu(Menu menu, MenuInflater inflater)246     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
247         if (FeatureFlagPersistent.isEnabled(getContext(), FeatureFlags.NETWORK_INTERNET_V2) &&
248                 mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
249             final MenuItem item = menu.add(Menu.NONE, R.id.edit_sim_name, Menu.NONE,
250                     R.string.mobile_network_sim_name);
251             item.setIcon(com.android.internal.R.drawable.ic_mode_edit);
252             item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
253         }
254         super.onCreateOptionsMenu(menu, inflater);
255     }
256 
257     @Override
onOptionsItemSelected(MenuItem menuItem)258     public boolean onOptionsItemSelected(MenuItem menuItem) {
259         if (FeatureFlagPersistent.isEnabled(getContext(), FeatureFlags.NETWORK_INTERNET_V2) &&
260                 mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
261             if (menuItem.getItemId() == R.id.edit_sim_name) {
262                 RenameMobileNetworkDialogFragment.newInstance(mSubId).show(
263                         getFragmentManager(), RenameMobileNetworkDialogFragment.TAG);
264                 return true;
265             }
266         }
267         return super.onOptionsItemSelected(menuItem);
268     }
269 
270     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
271             new BaseSearchIndexProvider() {
272                 @Override
273                 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
274                         boolean enabled) {
275                     final ArrayList<SearchIndexableResource> result = new ArrayList<>();
276 
277                     final SearchIndexableResource sir = new SearchIndexableResource(context);
278                     sir.xmlResId = R.xml.mobile_network_settings;
279                     result.add(sir);
280                     return result;
281                 }
282 
283                 /** suppress full page if user is not admin */
284                 @Override
285                 protected boolean isPageSearchEnabled(Context context) {
286                     return context.getSystemService(UserManager.class).isAdminUser();
287                 }
288             };
289 }
290