blob: 8ff7ecc692ba3ddd8ade39f9b0a1fd0bfecd7faf [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 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.phone;
18
Grant Menke86618372023-08-10 17:04:22 -070019import android.content.Context;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070020import android.os.Bundle;
Aida Takeshi7c3b4a32016-08-11 13:42:24 +080021import android.os.PersistableBundle;
Grant Menke86618372023-08-10 17:04:22 -070022import android.os.UserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023import android.preference.Preference;
24import android.preference.PreferenceActivity;
25import android.preference.PreferenceScreen;
SongFerngWang022b5da2019-11-25 22:52:03 +080026import android.provider.Settings;
Aida Takeshi7c3b4a32016-08-11 13:42:24 +080027import android.telephony.CarrierConfigManager;
Grant Menke86618372023-08-10 17:04:22 -070028import android.util.Log;
Sanket Padawee09a6f62015-03-05 11:59:39 -080029import android.view.MenuItem;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import com.android.internal.telephony.PhoneConstants;
32
33public class GsmUmtsCallOptions extends PreferenceActivity {
34 private static final String LOG_TAG = "GsmUmtsCallOptions";
35 private final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
36
SongFerngWangbed485e2018-07-09 21:15:29 +080037 public static final String CALL_FORWARDING_KEY = "call_forwarding_key";
38 public static final String CALL_BARRING_KEY = "call_barring_key";
SongFerngWang022b5da2019-11-25 22:52:03 +080039 public static final String ADDITIONAL_GSM_SETTINGS_KEY = "additional_gsm_call_settings_key";
Sanket Padawee09a6f62015-03-05 11:59:39 -080040
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041 @Override
42 protected void onCreate(Bundle icicle) {
43 super.onCreate(icicle);
44
45 addPreferencesFromResource(R.xml.gsm_umts_call_options);
46
Sanket Padawee09a6f62015-03-05 11:59:39 -080047 SubscriptionInfoHelper subInfoHelper = new SubscriptionInfoHelper(this, getIntent());
48 subInfoHelper.setActionBarTitle(
49 getActionBar(), getResources(), R.string.labelGsmMore_with_label);
50 init(getPreferenceScreen(), subInfoHelper);
51
52 if (subInfoHelper.getPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053 //disable the entire screen
54 getPreferenceScreen().setEnabled(false);
55 }
56 }
Sanket Padawee09a6f62015-03-05 11:59:39 -080057
58 @Override
59 public boolean onOptionsItemSelected(MenuItem item) {
60 final int itemId = item.getItemId();
61 if (itemId == android.R.id.home) {
62 onBackPressed();
63 return true;
64 }
65 return super.onOptionsItemSelected(item);
66 }
67
68 public static void init(PreferenceScreen prefScreen, SubscriptionInfoHelper subInfoHelper) {
Aida Takeshi7c3b4a32016-08-11 13:42:24 +080069 PersistableBundle b = null;
70 if (subInfoHelper.hasSubId()) {
71 b = PhoneGlobals.getInstance().getCarrierConfigForSubId(subInfoHelper.getSubId());
72 } else {
73 b = PhoneGlobals.getInstance().getCarrierConfig();
74 }
SongFerngWangf6fd9922018-06-28 17:21:43 +080075
SongFerngWang022b5da2019-11-25 22:52:03 +080076 boolean isAirplaneModeOff = true;
77 if (b != null && b.getBoolean(
78 CarrierConfigManager.KEY_DISABLE_SUPPLEMENTARY_SERVICES_IN_AIRPLANE_MODE_BOOL)) {
79 int airplaneMode = Settings.Global.getInt(
80 subInfoHelper.getPhone().getContext().getContentResolver(),
81 Settings.Global.AIRPLANE_MODE_ON, PhoneGlobals.AIRPLANE_OFF);
82 isAirplaneModeOff = PhoneGlobals.AIRPLANE_ON != airplaneMode;
83 }
84
Grant Menke86618372023-08-10 17:04:22 -070085 // If mobile network configs are restricted, then hide the GsmUmtsCallForwardOptions,
86 // GsmUmtsAdditionalCallOptions, and GsmUmtsCallBarringOptions.
87 UserManager userManager = (UserManager) subInfoHelper.getPhone().getContext()
88 .getSystemService(Context.USER_SERVICE);
89 boolean mobileNetworkConfigsRestricted =
90 userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);
91 if (mobileNetworkConfigsRestricted) {
92 Log.i(LOG_TAG, "Mobile network configs are restricted, hiding GSM call "
93 + "forwarding, additional call settings, and call options.");
94 }
95
SongFerngWangf6fd9922018-06-28 17:21:43 +080096 Preference callForwardingPref = prefScreen.findPreference(CALL_FORWARDING_KEY);
97 if (callForwardingPref != null) {
98 if (b != null && b.getBoolean(
Grant Menke86618372023-08-10 17:04:22 -070099 CarrierConfigManager.KEY_CALL_FORWARDING_VISIBILITY_BOOL) &&
100 !mobileNetworkConfigsRestricted) {
SongFerngWangf6fd9922018-06-28 17:21:43 +0800101 callForwardingPref.setIntent(
102 subInfoHelper.getIntent(GsmUmtsCallForwardOptions.class));
SongFerngWang022b5da2019-11-25 22:52:03 +0800103 callForwardingPref.setEnabled(isAirplaneModeOff);
SongFerngWangf6fd9922018-06-28 17:21:43 +0800104 } else {
105 prefScreen.removePreference(callForwardingPref);
106 }
107 }
108
109 Preference additionalGsmSettingsPref =
110 prefScreen.findPreference(ADDITIONAL_GSM_SETTINGS_KEY);
111 if (additionalGsmSettingsPref != null) {
112 if (b != null && (b.getBoolean(
113 CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALL_WAITING_VISIBILITY_BOOL)
114 || b.getBoolean(
Grant Menke86618372023-08-10 17:04:22 -0700115 CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALLER_ID_VISIBILITY_BOOL)) &&
116 !mobileNetworkConfigsRestricted) {
SongFerngWangf6fd9922018-06-28 17:21:43 +0800117 additionalGsmSettingsPref.setIntent(
118 subInfoHelper.getIntent(GsmUmtsAdditionalCallOptions.class));
SongFerngWang022b5da2019-11-25 22:52:03 +0800119 additionalGsmSettingsPref.setEnabled(isAirplaneModeOff);
SongFerngWangf6fd9922018-06-28 17:21:43 +0800120 } else {
121 prefScreen.removePreference(additionalGsmSettingsPref);
122 }
123 }
124
125 Preference callBarringPref = prefScreen.findPreference(CALL_BARRING_KEY);
126 if (callBarringPref != null) {
Grant Menke86618372023-08-10 17:04:22 -0700127 if (b != null && b.getBoolean(CarrierConfigManager.KEY_CALL_BARRING_VISIBILITY_BOOL) &&
128 !mobileNetworkConfigsRestricted) {
SongFerngWangf6fd9922018-06-28 17:21:43 +0800129 callBarringPref.setIntent(subInfoHelper.getIntent(GsmUmtsCallBarringOptions.class));
SongFerngWang022b5da2019-11-25 22:52:03 +0800130 callBarringPref.setEnabled(isAirplaneModeOff);
SongFerngWangf6fd9922018-06-28 17:21:43 +0800131 } else {
132 prefScreen.removePreference(callBarringPref);
133 }
Aida Takeshi7c3b4a32016-08-11 13:42:24 +0800134 }
Sanket Padawee09a6f62015-03-05 11:59:39 -0800135 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136}