blob: be5295d53eab5b25ea65e3cf412ca61136866673 [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;
Grant Menke549b51c2023-11-08 10:31:37 -080032import com.android.internal.telephony.flags.Flags;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033
34public class GsmUmtsCallOptions extends PreferenceActivity {
35 private static final String LOG_TAG = "GsmUmtsCallOptions";
36 private final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
37
SongFerngWangbed485e2018-07-09 21:15:29 +080038 public static final String CALL_FORWARDING_KEY = "call_forwarding_key";
39 public static final String CALL_BARRING_KEY = "call_barring_key";
SongFerngWang022b5da2019-11-25 22:52:03 +080040 public static final String ADDITIONAL_GSM_SETTINGS_KEY = "additional_gsm_call_settings_key";
Sanket Padawee09a6f62015-03-05 11:59:39 -080041
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042 @Override
43 protected void onCreate(Bundle icicle) {
44 super.onCreate(icicle);
45
46 addPreferencesFromResource(R.xml.gsm_umts_call_options);
47
Sanket Padawee09a6f62015-03-05 11:59:39 -080048 SubscriptionInfoHelper subInfoHelper = new SubscriptionInfoHelper(this, getIntent());
49 subInfoHelper.setActionBarTitle(
50 getActionBar(), getResources(), R.string.labelGsmMore_with_label);
51 init(getPreferenceScreen(), subInfoHelper);
52
53 if (subInfoHelper.getPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054 //disable the entire screen
55 getPreferenceScreen().setEnabled(false);
56 }
57 }
Sanket Padawee09a6f62015-03-05 11:59:39 -080058
59 @Override
60 public boolean onOptionsItemSelected(MenuItem item) {
61 final int itemId = item.getItemId();
62 if (itemId == android.R.id.home) {
63 onBackPressed();
64 return true;
65 }
66 return super.onOptionsItemSelected(item);
67 }
68
69 public static void init(PreferenceScreen prefScreen, SubscriptionInfoHelper subInfoHelper) {
Aida Takeshi7c3b4a32016-08-11 13:42:24 +080070 PersistableBundle b = null;
71 if (subInfoHelper.hasSubId()) {
72 b = PhoneGlobals.getInstance().getCarrierConfigForSubId(subInfoHelper.getSubId());
73 } else {
74 b = PhoneGlobals.getInstance().getCarrierConfig();
75 }
SongFerngWangf6fd9922018-06-28 17:21:43 +080076
SongFerngWang022b5da2019-11-25 22:52:03 +080077 boolean isAirplaneModeOff = true;
78 if (b != null && b.getBoolean(
79 CarrierConfigManager.KEY_DISABLE_SUPPLEMENTARY_SERVICES_IN_AIRPLANE_MODE_BOOL)) {
80 int airplaneMode = Settings.Global.getInt(
81 subInfoHelper.getPhone().getContext().getContentResolver(),
82 Settings.Global.AIRPLANE_MODE_ON, PhoneGlobals.AIRPLANE_OFF);
83 isAirplaneModeOff = PhoneGlobals.AIRPLANE_ON != airplaneMode;
84 }
85
Grant Menke86618372023-08-10 17:04:22 -070086 // If mobile network configs are restricted, then hide the GsmUmtsCallForwardOptions,
87 // GsmUmtsAdditionalCallOptions, and GsmUmtsCallBarringOptions.
88 UserManager userManager = (UserManager) subInfoHelper.getPhone().getContext()
89 .getSystemService(Context.USER_SERVICE);
90 boolean mobileNetworkConfigsRestricted =
91 userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);
Grant Menke549b51c2023-11-08 10:31:37 -080092 if (Flags.ensureAccessToCallSettingsIsRestricted() && mobileNetworkConfigsRestricted) {
Grant Menke86618372023-08-10 17:04:22 -070093 Log.i(LOG_TAG, "Mobile network configs are restricted, hiding GSM call "
94 + "forwarding, additional call settings, and call options.");
95 }
96
SongFerngWangf6fd9922018-06-28 17:21:43 +080097 Preference callForwardingPref = prefScreen.findPreference(CALL_FORWARDING_KEY);
98 if (callForwardingPref != null) {
99 if (b != null && b.getBoolean(
Grant Menke86618372023-08-10 17:04:22 -0700100 CarrierConfigManager.KEY_CALL_FORWARDING_VISIBILITY_BOOL) &&
Grant Menke549b51c2023-11-08 10:31:37 -0800101 (!Flags.ensureAccessToCallSettingsIsRestricted() ||
102 !mobileNetworkConfigsRestricted)) {
SongFerngWangf6fd9922018-06-28 17:21:43 +0800103 callForwardingPref.setIntent(
104 subInfoHelper.getIntent(GsmUmtsCallForwardOptions.class));
SongFerngWang022b5da2019-11-25 22:52:03 +0800105 callForwardingPref.setEnabled(isAirplaneModeOff);
SongFerngWangf6fd9922018-06-28 17:21:43 +0800106 } else {
107 prefScreen.removePreference(callForwardingPref);
108 }
109 }
110
111 Preference additionalGsmSettingsPref =
112 prefScreen.findPreference(ADDITIONAL_GSM_SETTINGS_KEY);
113 if (additionalGsmSettingsPref != null) {
114 if (b != null && (b.getBoolean(
115 CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALL_WAITING_VISIBILITY_BOOL)
116 || b.getBoolean(
Grant Menke86618372023-08-10 17:04:22 -0700117 CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALLER_ID_VISIBILITY_BOOL)) &&
Grant Menke549b51c2023-11-08 10:31:37 -0800118 (!Flags.ensureAccessToCallSettingsIsRestricted() ||
119 !mobileNetworkConfigsRestricted)) {
SongFerngWangf6fd9922018-06-28 17:21:43 +0800120 additionalGsmSettingsPref.setIntent(
121 subInfoHelper.getIntent(GsmUmtsAdditionalCallOptions.class));
SongFerngWang022b5da2019-11-25 22:52:03 +0800122 additionalGsmSettingsPref.setEnabled(isAirplaneModeOff);
SongFerngWangf6fd9922018-06-28 17:21:43 +0800123 } else {
124 prefScreen.removePreference(additionalGsmSettingsPref);
125 }
126 }
127
128 Preference callBarringPref = prefScreen.findPreference(CALL_BARRING_KEY);
129 if (callBarringPref != null) {
Grant Menke86618372023-08-10 17:04:22 -0700130 if (b != null && b.getBoolean(CarrierConfigManager.KEY_CALL_BARRING_VISIBILITY_BOOL) &&
Grant Menke549b51c2023-11-08 10:31:37 -0800131 (!Flags.ensureAccessToCallSettingsIsRestricted() ||
132 !mobileNetworkConfigsRestricted)) {
SongFerngWangf6fd9922018-06-28 17:21:43 +0800133 callBarringPref.setIntent(subInfoHelper.getIntent(GsmUmtsCallBarringOptions.class));
SongFerngWang022b5da2019-11-25 22:52:03 +0800134 callBarringPref.setEnabled(isAirplaneModeOff);
SongFerngWangf6fd9922018-06-28 17:21:43 +0800135 } else {
136 prefScreen.removePreference(callBarringPref);
137 }
Aida Takeshi7c3b4a32016-08-11 13:42:24 +0800138 }
Sanket Padawee09a6f62015-03-05 11:59:39 -0800139 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140}