1 /*
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 
17 package com.android.phone;
18 
19 import android.content.Context;
20 import android.os.Bundle;
21 import android.os.PersistableBundle;
22 import android.os.UserManager;
23 import android.preference.Preference;
24 import android.preference.PreferenceActivity;
25 import android.preference.PreferenceScreen;
26 import android.provider.Settings;
27 import android.telephony.CarrierConfigManager;
28 import android.util.Log;
29 import android.view.MenuItem;
30 
31 import com.android.internal.telephony.PhoneConstants;
32 import com.android.internal.telephony.flags.Flags;
33 
34 public class GsmUmtsCallOptions extends PreferenceActivity {
35     private static final String LOG_TAG = "GsmUmtsCallOptions";
36     private final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
37 
38     public static final String CALL_FORWARDING_KEY = "call_forwarding_key";
39     public static final String CALL_BARRING_KEY = "call_barring_key";
40     public static final String ADDITIONAL_GSM_SETTINGS_KEY = "additional_gsm_call_settings_key";
41 
42     @Override
onCreate(Bundle icicle)43     protected void onCreate(Bundle icicle) {
44         super.onCreate(icicle);
45 
46         addPreferencesFromResource(R.xml.gsm_umts_call_options);
47 
48         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) {
54             //disable the entire screen
55             getPreferenceScreen().setEnabled(false);
56         }
57     }
58 
59     @Override
onOptionsItemSelected(MenuItem item)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 
init(PreferenceScreen prefScreen, SubscriptionInfoHelper subInfoHelper)69     public static void init(PreferenceScreen prefScreen, SubscriptionInfoHelper subInfoHelper) {
70         PersistableBundle b = null;
71         if (subInfoHelper.hasSubId()) {
72             b = PhoneGlobals.getInstance().getCarrierConfigForSubId(subInfoHelper.getSubId());
73         } else {
74             b = PhoneGlobals.getInstance().getCarrierConfig();
75         }
76 
77         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 
86         // 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);
92         if (Flags.ensureAccessToCallSettingsIsRestricted() && mobileNetworkConfigsRestricted) {
93             Log.i(LOG_TAG, "Mobile network configs are restricted, hiding GSM call "
94                     + "forwarding, additional call settings, and call options.");
95         }
96 
97         Preference callForwardingPref = prefScreen.findPreference(CALL_FORWARDING_KEY);
98         if (callForwardingPref != null) {
99             if (b != null && b.getBoolean(
100                     CarrierConfigManager.KEY_CALL_FORWARDING_VISIBILITY_BOOL) &&
101                     (!Flags.ensureAccessToCallSettingsIsRestricted() ||
102                             !mobileNetworkConfigsRestricted)) {
103                 callForwardingPref.setIntent(
104                         subInfoHelper.getIntent(GsmUmtsCallForwardOptions.class));
105                 callForwardingPref.setEnabled(isAirplaneModeOff);
106             } 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(
117                     CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALLER_ID_VISIBILITY_BOOL)) &&
118                     (!Flags.ensureAccessToCallSettingsIsRestricted() ||
119                             !mobileNetworkConfigsRestricted)) {
120                 additionalGsmSettingsPref.setIntent(
121                         subInfoHelper.getIntent(GsmUmtsAdditionalCallOptions.class));
122                 additionalGsmSettingsPref.setEnabled(isAirplaneModeOff);
123             } else {
124                 prefScreen.removePreference(additionalGsmSettingsPref);
125             }
126         }
127 
128         Preference callBarringPref = prefScreen.findPreference(CALL_BARRING_KEY);
129         if (callBarringPref != null) {
130             if (b != null && b.getBoolean(CarrierConfigManager.KEY_CALL_BARRING_VISIBILITY_BOOL) &&
131                     (!Flags.ensureAccessToCallSettingsIsRestricted() ||
132                             !mobileNetworkConfigsRestricted)) {
133                 callBarringPref.setIntent(subInfoHelper.getIntent(GsmUmtsCallBarringOptions.class));
134                 callBarringPref.setEnabled(isAirplaneModeOff);
135             } else {
136                 prefScreen.removePreference(callBarringPref);
137             }
138         }
139     }
140 }
141