WirelessSettings.java revision 9a23adf69dc53126c9858b19760eab5b67c23b97
1/*
2 * Copyright (C) 2009 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
17package com.android.settings;
18
19
20import android.app.Activity;
21import android.app.AlertDialog;
22import android.app.Dialog;
23import android.app.admin.DevicePolicyManager;
24import android.content.ActivityNotFoundException;
25import android.content.ComponentName;
26import android.content.Context;
27import android.content.DialogInterface;
28import android.content.Intent;
29import android.content.pm.PackageManager;
30import android.content.res.Resources;
31import android.net.ConnectivityManager;
32import android.net.NetworkInfo;
33import android.net.Uri;
34import android.nfc.NfcAdapter;
35import android.nfc.NfcManager;
36import android.os.Bundle;
37import android.os.SystemProperties;
38import android.os.UserHandle;
39import android.os.UserManager;
40import android.preference.Preference;
41import android.preference.Preference.OnPreferenceChangeListener;
42import android.preference.PreferenceScreen;
43import android.preference.SwitchPreference;
44import android.provider.SearchIndexableResource;
45import android.provider.Settings;
46import android.telephony.TelephonyManager;
47import android.text.TextUtils;
48import android.util.Log;
49
50import com.android.ims.ImsManager;
51import com.android.internal.telephony.SmsApplication;
52import com.android.internal.telephony.SmsApplication.SmsApplicationData;
53import com.android.internal.telephony.TelephonyIntents;
54import com.android.internal.telephony.TelephonyProperties;
55import com.android.settings.nfc.NfcEnabler;
56import com.android.settings.search.BaseSearchIndexProvider;
57import com.android.settings.search.Indexable;
58import java.util.ArrayList;
59import java.util.Arrays;
60import java.util.Collection;
61import java.util.List;
62
63public class WirelessSettings extends SettingsPreferenceFragment
64        implements OnPreferenceChangeListener, Indexable {
65    private static final String TAG = "WirelessSettings";
66
67    private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
68    private static final String KEY_TOGGLE_NFC = "toggle_nfc";
69    private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
70    private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
71    private static final String KEY_VPN_SETTINGS = "vpn_settings";
72    private static final String KEY_TETHER_SETTINGS = "tether_settings";
73    private static final String KEY_PROXY_SETTINGS = "proxy_settings";
74    private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
75    private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan";
76    private static final String KEY_SMS_APPLICATION = "sms_application";
77    private static final String KEY_TOGGLE_NSD = "toggle_nsd"; //network service discovery
78    private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";
79    private static final String KEY_WFC_SETTINGS = "wifi_calling_settings";
80
81    public static final String EXIT_ECM_RESULT = "exit_ecm_result";
82    public static final int REQUEST_CODE_EXIT_ECM = 1;
83
84    private AirplaneModeEnabler mAirplaneModeEnabler;
85    private SwitchPreference mAirplaneModePreference;
86    private NfcEnabler mNfcEnabler;
87    private NfcAdapter mNfcAdapter;
88    private NsdEnabler mNsdEnabler;
89
90    private ConnectivityManager mCm;
91    private TelephonyManager mTm;
92    private PackageManager mPm;
93    private UserManager mUm;
94
95    private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
96    private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
97
98    private AppListPreference mSmsApplicationPreference;
99    private PreferenceScreen mButtonWfc;
100
101    /**
102     * Invoked on each preference click in this hierarchy, overrides
103     * PreferenceFragment's implementation.  Used to make sure we track the
104     * preference click events.
105     */
106    @Override
107    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
108        log("onPreferenceTreeClick: preference=" + preference);
109        if (preference == mAirplaneModePreference && Boolean.parseBoolean(
110                SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
111            // In ECM mode launch ECM app dialog
112            startActivityForResult(
113                new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
114                REQUEST_CODE_EXIT_ECM);
115            return true;
116        } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
117            onManageMobilePlanClick();
118        }
119        // Let the intents be launched by the Preference manager
120        return super.onPreferenceTreeClick(preferenceScreen, preference);
121    }
122
123    private String mManageMobilePlanMessage;
124    public void onManageMobilePlanClick() {
125        log("onManageMobilePlanClick:");
126        mManageMobilePlanMessage = null;
127        Resources resources = getActivity().getResources();
128
129        NetworkInfo ni = mCm.getProvisioningOrActiveNetworkInfo();
130        if (mTm.hasIccCard() && (ni != null)) {
131            // Check for carrier apps that can handle provisioning first
132            Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
133            List<String> carrierPackages =
134                    mTm.getCarrierPackageNamesForIntent(provisioningIntent);
135            if (carrierPackages != null && !carrierPackages.isEmpty()) {
136                if (carrierPackages.size() != 1) {
137                    Log.w(TAG, "Multiple matching carrier apps found, launching the first.");
138                }
139                provisioningIntent.setPackage(carrierPackages.get(0));
140                startActivity(provisioningIntent);
141                return;
142            }
143
144            // Get provisioning URL
145            String url = mCm.getMobileProvisioningUrl();
146            if (!TextUtils.isEmpty(url)) {
147                Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
148                        Intent.CATEGORY_APP_BROWSER);
149                intent.setData(Uri.parse(url));
150                intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
151                        Intent.FLAG_ACTIVITY_NEW_TASK);
152                try {
153                    startActivity(intent);
154                } catch (ActivityNotFoundException e) {
155                    Log.w(TAG, "onManageMobilePlanClick: startActivity failed" + e);
156                }
157            } else {
158                // No provisioning URL
159                String operatorName = mTm.getSimOperatorName();
160                if (TextUtils.isEmpty(operatorName)) {
161                    // Use NetworkOperatorName as second choice in case there is no
162                    // SPN (Service Provider Name on the SIM). Such as with T-mobile.
163                    operatorName = mTm.getNetworkOperatorName();
164                    if (TextUtils.isEmpty(operatorName)) {
165                        mManageMobilePlanMessage = resources.getString(
166                                R.string.mobile_unknown_sim_operator);
167                    } else {
168                        mManageMobilePlanMessage = resources.getString(
169                                R.string.mobile_no_provisioning_url, operatorName);
170                    }
171                } else {
172                    mManageMobilePlanMessage = resources.getString(
173                            R.string.mobile_no_provisioning_url, operatorName);
174                }
175            }
176        } else if (mTm.hasIccCard() == false) {
177            // No sim card
178            mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
179        } else {
180            // NetworkInfo is null, there is no connection
181            mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
182        }
183        if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
184            log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
185            showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
186        }
187    }
188
189    private void initSmsApplicationSetting() {
190        log("initSmsApplicationSetting:");
191        Collection<SmsApplicationData> smsApplications =
192                SmsApplication.getApplicationCollection(getActivity());
193
194        // If the list is empty the dialog will be empty, but we will not crash.
195        int count = smsApplications.size();
196        String[] packageNames = new String[count];
197        int i = 0;
198        for (SmsApplicationData smsApplicationData : smsApplications) {
199            packageNames[i] = smsApplicationData.mPackageName;
200            i++;
201        }
202        String defaultPackageName = null;
203        ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true);
204        if (appName != null) {
205            defaultPackageName = appName.getPackageName();
206        }
207        mSmsApplicationPreference.setPackageNames(packageNames, defaultPackageName);
208    }
209
210    @Override
211    public Dialog onCreateDialog(int dialogId) {
212        log("onCreateDialog: dialogId=" + dialogId);
213        switch (dialogId) {
214            case MANAGE_MOBILE_PLAN_DIALOG_ID:
215                return new AlertDialog.Builder(getActivity())
216                            .setMessage(mManageMobilePlanMessage)
217                            .setCancelable(false)
218                            .setPositiveButton(com.android.internal.R.string.ok,
219                                    new DialogInterface.OnClickListener() {
220                                @Override
221                                public void onClick(DialogInterface dialog, int id) {
222                                    log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
223                                    mManageMobilePlanMessage = null;
224                                }
225                            })
226                            .create();
227        }
228        return super.onCreateDialog(dialogId);
229    }
230
231    private void log(String s) {
232        Log.d(TAG, s);
233    }
234
235    private boolean isSmsSupported() {
236        // Some tablet has sim card but could not do telephony operations. Skip those.
237        return mTm.isSmsCapable();
238    }
239
240    @Override
241    public void onCreate(Bundle savedInstanceState) {
242        super.onCreate(savedInstanceState);
243        if (savedInstanceState != null) {
244            mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
245        }
246        log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
247
248        mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
249        mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
250        mPm = getPackageManager();
251        mUm = (UserManager) getSystemService(Context.USER_SERVICE);
252
253        addPreferencesFromResource(R.xml.wireless_settings);
254
255        final int myUserId = UserHandle.myUserId();
256        final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER;
257        final boolean isRestrictedUser = mUm.getUserInfo(myUserId).isRestricted();
258
259        final Activity activity = getActivity();
260        mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
261        SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
262        PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
263        SwitchPreference nsd = (SwitchPreference) findPreference(KEY_TOGGLE_NSD);
264
265        mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
266        mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
267
268        mSmsApplicationPreference = (AppListPreference) findPreference(KEY_SMS_APPLICATION);
269        // Restricted users cannot currently read/write SMS.
270        if (isRestrictedUser) {
271            removePreference(KEY_SMS_APPLICATION);
272        } else {
273            mSmsApplicationPreference.setOnPreferenceChangeListener(this);
274            initSmsApplicationSetting();
275        }
276
277        if (ImsManager.isWfcEnabledByPlatform(activity)) {
278            mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
279        } else {
280            removePreference(KEY_WFC_SETTINGS);
281        }
282
283        // Remove NSD checkbox by default
284        getPreferenceScreen().removePreference(nsd);
285        //mNsdEnabler = new NsdEnabler(activity, nsd);
286
287        String toggleable = Settings.Global.getString(activity.getContentResolver(),
288                Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
289
290        //enable/disable wimax depending on the value in config.xml
291        final boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
292                com.android.internal.R.bool.config_wimaxEnabled);
293        if (!isWimaxEnabled
294                || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
295            PreferenceScreen root = getPreferenceScreen();
296            Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
297            if (ps != null) root.removePreference(ps);
298        } else {
299            if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
300                    && isWimaxEnabled) {
301                Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
302                ps.setDependency(KEY_TOGGLE_AIRPLANE);
303            }
304        }
305
306        // Manually set dependencies for Wifi when not toggleable.
307        if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
308            findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
309        }
310        // Disable VPN.
311        if (isSecondaryUser || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
312            removePreference(KEY_VPN_SETTINGS);
313        }
314
315        // Manually set dependencies for Bluetooth when not toggleable.
316        if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
317            // No bluetooth-dependent items in the list. Code kept in case one is added later.
318        }
319
320        // Manually set dependencies for NFC when not toggleable.
321        if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
322            findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
323            findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
324        }
325
326        // Remove NFC if not available
327        mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
328        if (mNfcAdapter == null) {
329            getPreferenceScreen().removePreference(nfc);
330            getPreferenceScreen().removePreference(androidBeam);
331            mNfcEnabler = null;
332        }
333
334        // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
335        // if it's a wifi-only device, or if the settings are restricted.
336        if (isSecondaryUser || Utils.isWifiOnly(getActivity())
337                || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
338            removePreference(KEY_MOBILE_NETWORK_SETTINGS);
339            removePreference(KEY_MANAGE_MOBILE_PLAN);
340        }
341        // Remove Mobile Network Settings and Manage Mobile Plan
342        // if config_show_mobile_plan sets false.
343        final boolean isMobilePlanEnabled = this.getResources().getBoolean(
344                R.bool.config_show_mobile_plan);
345        if (!isMobilePlanEnabled) {
346            Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
347            if (pref != null) {
348                removePreference(KEY_MANAGE_MOBILE_PLAN);
349            }
350        }
351
352        // Remove SMS Application if the device does not support SMS
353        if (!isSmsSupported()) {
354            removePreference(KEY_SMS_APPLICATION);
355        }
356
357        // Remove Airplane Mode settings if it's a stationary device such as a TV.
358        if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
359            removePreference(KEY_TOGGLE_AIRPLANE);
360        }
361
362        // Enable Proxy selector settings if allowed.
363        Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
364        final DevicePolicyManager mDPM = (DevicePolicyManager)
365                activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
366        // proxy UI disabled until we have better app support
367        getPreferenceScreen().removePreference(mGlobalProxy);
368        mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
369
370        // Disable Tethering if it's not allowed or if it's a wifi-only device
371        final ConnectivityManager cm =
372                (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
373        if (isSecondaryUser || !cm.isTetheringSupported()
374                || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
375            getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
376        } else {
377            Preference p = findPreference(KEY_TETHER_SETTINGS);
378            p.setTitle(Utils.getTetheringLabel(cm));
379
380            // Grey out if provisioning is not available.
381            p.setEnabled(!TetherSettings
382                    .isProvisioningNeededButUnavailable(getActivity()));
383        }
384
385        // Enable link to CMAS app settings depending on the value in config.xml.
386        boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
387                com.android.internal.R.bool.config_cellBroadcastAppLinks);
388        try {
389            if (isCellBroadcastAppLinkEnabled) {
390                if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
391                        == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
392                    isCellBroadcastAppLinkEnabled = false;  // CMAS app disabled
393                }
394            }
395        } catch (IllegalArgumentException ignored) {
396            isCellBroadcastAppLinkEnabled = false;  // CMAS app not installed
397        }
398        if (isSecondaryUser || !isCellBroadcastAppLinkEnabled
399                || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) {
400            PreferenceScreen root = getPreferenceScreen();
401            Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
402            if (ps != null) root.removePreference(ps);
403        }
404    }
405
406    @Override
407    public void onStart() {
408        super.onStart();
409
410        initSmsApplicationSetting();
411    }
412
413    @Override
414    public void onResume() {
415        super.onResume();
416
417        mAirplaneModeEnabler.resume();
418        if (mNfcEnabler != null) {
419            mNfcEnabler.resume();
420        }
421        if (mNsdEnabler != null) {
422            mNsdEnabler.resume();
423        }
424
425        final Context context = getActivity();
426        if (ImsManager.isWfcEnabledByPlatform(context)) {
427            mButtonWfc.setSummary(WifiCallingSettings.getWfcModeSummary(
428                    context, ImsManager.getWfcMode(context)));
429        }
430    }
431
432    @Override
433    public void onSaveInstanceState(Bundle outState) {
434        super.onSaveInstanceState(outState);
435
436        if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
437            outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
438        }
439    }
440
441    @Override
442    public void onPause() {
443        super.onPause();
444
445        mAirplaneModeEnabler.pause();
446        if (mNfcEnabler != null) {
447            mNfcEnabler.pause();
448        }
449        if (mNsdEnabler != null) {
450            mNsdEnabler.pause();
451        }
452    }
453
454    @Override
455    public void onActivityResult(int requestCode, int resultCode, Intent data) {
456        if (requestCode == REQUEST_CODE_EXIT_ECM) {
457            Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
458            // Set Airplane mode based on the return value and checkbox state
459            mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
460                    mAirplaneModePreference.isChecked());
461        }
462        super.onActivityResult(requestCode, resultCode, data);
463    }
464
465    @Override
466    protected int getHelpResource() {
467        return R.string.help_url_more_networks;
468    }
469
470    @Override
471    public boolean onPreferenceChange(Preference preference, Object newValue) {
472        if (preference == mSmsApplicationPreference && newValue != null) {
473            SmsApplication.setDefaultApplication(newValue.toString(), getActivity());
474            return true;
475        }
476        return false;
477    }
478
479    /**
480     * For Search.
481     */
482    public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
483        new BaseSearchIndexProvider() {
484            @Override
485            public List<SearchIndexableResource> getXmlResourcesToIndex(
486                    Context context, boolean enabled) {
487                SearchIndexableResource sir = new SearchIndexableResource(context);
488                sir.xmlResId = R.xml.wireless_settings;
489                return Arrays.asList(sir);
490            }
491
492            @Override
493            public List<String> getNonIndexableKeys(Context context) {
494                final ArrayList<String> result = new ArrayList<String>();
495
496                result.add(KEY_TOGGLE_NSD);
497
498                final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
499                final int myUserId = UserHandle.myUserId();
500                final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER;
501                final boolean isRestrictedUser = um.getUserInfo(myUserId).isRestricted();
502                final boolean isWimaxEnabled = !isSecondaryUser
503                        && context.getResources().getBoolean(
504                        com.android.internal.R.bool.config_wimaxEnabled);
505                if (!isWimaxEnabled
506                        || um.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
507                    result.add(KEY_WIMAX_SETTINGS);
508                }
509
510                if (isSecondaryUser) { // Disable VPN
511                    result.add(KEY_VPN_SETTINGS);
512                }
513
514                // Remove NFC if not available
515                final NfcManager manager = (NfcManager)
516                        context.getSystemService(Context.NFC_SERVICE);
517                if (manager != null) {
518                    NfcAdapter adapter = manager.getDefaultAdapter();
519                    if (adapter == null) {
520                        result.add(KEY_TOGGLE_NFC);
521                        result.add(KEY_ANDROID_BEAM_SETTINGS);
522                    }
523                }
524
525                // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
526                if (isSecondaryUser || Utils.isWifiOnly(context)) {
527                    result.add(KEY_MOBILE_NETWORK_SETTINGS);
528                    result.add(KEY_MANAGE_MOBILE_PLAN);
529                }
530
531                // Remove Mobile Network Settings and Manage Mobile Plan
532                // if config_show_mobile_plan sets false.
533                final boolean isMobilePlanEnabled = context.getResources().getBoolean(
534                        R.bool.config_show_mobile_plan);
535                if (!isMobilePlanEnabled) {
536                    result.add(KEY_MANAGE_MOBILE_PLAN);
537                }
538
539                // Remove SMS Application if the device does not support SMS
540                TelephonyManager tm =
541                        (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
542                if (!tm.isSmsCapable() || isRestrictedUser) {
543                    result.add(KEY_SMS_APPLICATION);
544                }
545
546                final PackageManager pm = context.getPackageManager();
547
548                // Remove Airplane Mode settings if it's a stationary device such as a TV.
549                if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
550                    result.add(KEY_TOGGLE_AIRPLANE);
551                }
552
553                // proxy UI disabled until we have better app support
554                result.add(KEY_PROXY_SETTINGS);
555
556                // Disable Tethering if it's not allowed or if it's a wifi-only device
557                ConnectivityManager cm = (ConnectivityManager)
558                        context.getSystemService(Context.CONNECTIVITY_SERVICE);
559                if (isSecondaryUser || !cm.isTetheringSupported()) {
560                    result.add(KEY_TETHER_SETTINGS);
561                }
562
563                // Enable link to CMAS app settings depending on the value in config.xml.
564                boolean isCellBroadcastAppLinkEnabled = context.getResources().getBoolean(
565                        com.android.internal.R.bool.config_cellBroadcastAppLinks);
566                try {
567                    if (isCellBroadcastAppLinkEnabled) {
568                        if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
569                                == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
570                            isCellBroadcastAppLinkEnabled = false;  // CMAS app disabled
571                        }
572                    }
573                } catch (IllegalArgumentException ignored) {
574                    isCellBroadcastAppLinkEnabled = false;  // CMAS app not installed
575                }
576                if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
577                    result.add(KEY_CELL_BROADCAST_SETTINGS);
578                }
579
580                return result;
581            }
582        };
583}
584