blob: 0e666a5ba367bab7646fcb24dfca30f8a430d11e [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
Tyler Gunn662cb392025-01-17 23:34:46 +000046 getWindow().addSystemFlags(
47 android.view.WindowManager.LayoutParams
48 .SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
49
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050 addPreferencesFromResource(R.xml.gsm_umts_call_options);
51
Sanket Padawee09a6f62015-03-05 11:59:39 -080052 SubscriptionInfoHelper subInfoHelper = new SubscriptionInfoHelper(this, getIntent());
53 subInfoHelper.setActionBarTitle(
54 getActionBar(), getResources(), R.string.labelGsmMore_with_label);
55 init(getPreferenceScreen(), subInfoHelper);
56
57 if (subInfoHelper.getPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058 //disable the entire screen
59 getPreferenceScreen().setEnabled(false);
60 }
61 }
Sanket Padawee09a6f62015-03-05 11:59:39 -080062
63 @Override
64 public boolean onOptionsItemSelected(MenuItem item) {
65 final int itemId = item.getItemId();
66 if (itemId == android.R.id.home) {
67 onBackPressed();
68 return true;
69 }
70 return super.onOptionsItemSelected(item);
71 }
72
73 public static void init(PreferenceScreen prefScreen, SubscriptionInfoHelper subInfoHelper) {
Aida Takeshi7c3b4a32016-08-11 13:42:24 +080074 PersistableBundle b = null;
75 if (subInfoHelper.hasSubId()) {
76 b = PhoneGlobals.getInstance().getCarrierConfigForSubId(subInfoHelper.getSubId());
77 } else {
78 b = PhoneGlobals.getInstance().getCarrierConfig();
79 }
SongFerngWangf6fd9922018-06-28 17:21:43 +080080
SongFerngWang022b5da2019-11-25 22:52:03 +080081 boolean isAirplaneModeOff = true;
82 if (b != null && b.getBoolean(
83 CarrierConfigManager.KEY_DISABLE_SUPPLEMENTARY_SERVICES_IN_AIRPLANE_MODE_BOOL)) {
84 int airplaneMode = Settings.Global.getInt(
85 subInfoHelper.getPhone().getContext().getContentResolver(),
86 Settings.Global.AIRPLANE_MODE_ON, PhoneGlobals.AIRPLANE_OFF);
87 isAirplaneModeOff = PhoneGlobals.AIRPLANE_ON != airplaneMode;
88 }
89
Grant Menke86618372023-08-10 17:04:22 -070090 // If mobile network configs are restricted, then hide the GsmUmtsCallForwardOptions,
91 // GsmUmtsAdditionalCallOptions, and GsmUmtsCallBarringOptions.
92 UserManager userManager = (UserManager) subInfoHelper.getPhone().getContext()
93 .getSystemService(Context.USER_SERVICE);
94 boolean mobileNetworkConfigsRestricted =
95 userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);
Grant Menke549b51c2023-11-08 10:31:37 -080096 if (Flags.ensureAccessToCallSettingsIsRestricted() && mobileNetworkConfigsRestricted) {
Grant Menke86618372023-08-10 17:04:22 -070097 Log.i(LOG_TAG, "Mobile network configs are restricted, hiding GSM call "
98 + "forwarding, additional call settings, and call options.");
99 }
100
SongFerngWangf6fd9922018-06-28 17:21:43 +0800101 Preference callForwardingPref = prefScreen.findPreference(CALL_FORWARDING_KEY);
102 if (callForwardingPref != null) {
103 if (b != null && b.getBoolean(
Grant Menke86618372023-08-10 17:04:22 -0700104 CarrierConfigManager.KEY_CALL_FORWARDING_VISIBILITY_BOOL) &&
Grant Menke549b51c2023-11-08 10:31:37 -0800105 (!Flags.ensureAccessToCallSettingsIsRestricted() ||
106 !mobileNetworkConfigsRestricted)) {
SongFerngWangf6fd9922018-06-28 17:21:43 +0800107 callForwardingPref.setIntent(
108 subInfoHelper.getIntent(GsmUmtsCallForwardOptions.class));
SongFerngWang022b5da2019-11-25 22:52:03 +0800109 callForwardingPref.setEnabled(isAirplaneModeOff);
SongFerngWangf6fd9922018-06-28 17:21:43 +0800110 } else {
111 prefScreen.removePreference(callForwardingPref);
112 }
113 }
114
115 Preference additionalGsmSettingsPref =
116 prefScreen.findPreference(ADDITIONAL_GSM_SETTINGS_KEY);
117 if (additionalGsmSettingsPref != null) {
118 if (b != null && (b.getBoolean(
119 CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALL_WAITING_VISIBILITY_BOOL)
120 || b.getBoolean(
Grant Menke86618372023-08-10 17:04:22 -0700121 CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALLER_ID_VISIBILITY_BOOL)) &&
Grant Menke549b51c2023-11-08 10:31:37 -0800122 (!Flags.ensureAccessToCallSettingsIsRestricted() ||
123 !mobileNetworkConfigsRestricted)) {
SongFerngWangf6fd9922018-06-28 17:21:43 +0800124 additionalGsmSettingsPref.setIntent(
125 subInfoHelper.getIntent(GsmUmtsAdditionalCallOptions.class));
SongFerngWang022b5da2019-11-25 22:52:03 +0800126 additionalGsmSettingsPref.setEnabled(isAirplaneModeOff);
SongFerngWangf6fd9922018-06-28 17:21:43 +0800127 } else {
128 prefScreen.removePreference(additionalGsmSettingsPref);
129 }
130 }
131
132 Preference callBarringPref = prefScreen.findPreference(CALL_BARRING_KEY);
133 if (callBarringPref != null) {
Grant Menke86618372023-08-10 17:04:22 -0700134 if (b != null && b.getBoolean(CarrierConfigManager.KEY_CALL_BARRING_VISIBILITY_BOOL) &&
Grant Menke549b51c2023-11-08 10:31:37 -0800135 (!Flags.ensureAccessToCallSettingsIsRestricted() ||
136 !mobileNetworkConfigsRestricted)) {
SongFerngWangf6fd9922018-06-28 17:21:43 +0800137 callBarringPref.setIntent(subInfoHelper.getIntent(GsmUmtsCallBarringOptions.class));
SongFerngWang022b5da2019-11-25 22:52:03 +0800138 callBarringPref.setEnabled(isAirplaneModeOff);
SongFerngWangf6fd9922018-06-28 17:21:43 +0800139 } else {
140 prefScreen.removePreference(callBarringPref);
141 }
Aida Takeshi7c3b4a32016-08-11 13:42:24 +0800142 }
Sanket Padawee09a6f62015-03-05 11:59:39 -0800143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144}