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.os.Bundle;
20 import android.os.PersistableBundle;
21 import android.preference.Preference;
22 import android.preference.PreferenceActivity;
23 import android.preference.PreferenceScreen;
24 import android.provider.Settings;
25 import android.telephony.CarrierConfigManager;
26 import android.view.MenuItem;
27 
28 import com.android.internal.telephony.PhoneConstants;
29 
30 public class GsmUmtsCallOptions extends PreferenceActivity {
31     private static final String LOG_TAG = "GsmUmtsCallOptions";
32     private final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
33 
34     public static final String CALL_FORWARDING_KEY = "call_forwarding_key";
35     public static final String CALL_BARRING_KEY = "call_barring_key";
36     public static final String ADDITIONAL_GSM_SETTINGS_KEY = "additional_gsm_call_settings_key";
37 
38     @Override
onCreate(Bundle icicle)39     protected void onCreate(Bundle icicle) {
40         super.onCreate(icicle);
41 
42         addPreferencesFromResource(R.xml.gsm_umts_call_options);
43 
44         SubscriptionInfoHelper subInfoHelper = new SubscriptionInfoHelper(this, getIntent());
45         subInfoHelper.setActionBarTitle(
46                 getActionBar(), getResources(), R.string.labelGsmMore_with_label);
47         init(getPreferenceScreen(), subInfoHelper);
48 
49         if (subInfoHelper.getPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
50             //disable the entire screen
51             getPreferenceScreen().setEnabled(false);
52         }
53     }
54 
55     @Override
onOptionsItemSelected(MenuItem item)56     public boolean onOptionsItemSelected(MenuItem item) {
57         final int itemId = item.getItemId();
58         if (itemId == android.R.id.home) {
59             onBackPressed();
60             return true;
61         }
62         return super.onOptionsItemSelected(item);
63     }
64 
init(PreferenceScreen prefScreen, SubscriptionInfoHelper subInfoHelper)65     public static void init(PreferenceScreen prefScreen, SubscriptionInfoHelper subInfoHelper) {
66         PersistableBundle b = null;
67         if (subInfoHelper.hasSubId()) {
68             b = PhoneGlobals.getInstance().getCarrierConfigForSubId(subInfoHelper.getSubId());
69         } else {
70             b = PhoneGlobals.getInstance().getCarrierConfig();
71         }
72 
73         boolean isAirplaneModeOff = true;
74         if (b != null && b.getBoolean(
75                 CarrierConfigManager.KEY_DISABLE_SUPPLEMENTARY_SERVICES_IN_AIRPLANE_MODE_BOOL)) {
76             int airplaneMode = Settings.Global.getInt(
77                     subInfoHelper.getPhone().getContext().getContentResolver(),
78                     Settings.Global.AIRPLANE_MODE_ON, PhoneGlobals.AIRPLANE_OFF);
79             isAirplaneModeOff = PhoneGlobals.AIRPLANE_ON != airplaneMode;
80         }
81 
82         Preference callForwardingPref = prefScreen.findPreference(CALL_FORWARDING_KEY);
83         if (callForwardingPref != null) {
84             if (b != null && b.getBoolean(
85                     CarrierConfigManager.KEY_CALL_FORWARDING_VISIBILITY_BOOL)) {
86                 callForwardingPref.setIntent(
87                         subInfoHelper.getIntent(GsmUmtsCallForwardOptions.class));
88                 callForwardingPref.setEnabled(isAirplaneModeOff);
89             } else {
90                 prefScreen.removePreference(callForwardingPref);
91             }
92         }
93 
94         Preference additionalGsmSettingsPref =
95                 prefScreen.findPreference(ADDITIONAL_GSM_SETTINGS_KEY);
96         if (additionalGsmSettingsPref != null) {
97             if (b != null && (b.getBoolean(
98                     CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALL_WAITING_VISIBILITY_BOOL)
99                     || b.getBoolean(
100                     CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALLER_ID_VISIBILITY_BOOL))) {
101                 additionalGsmSettingsPref.setIntent(
102                         subInfoHelper.getIntent(GsmUmtsAdditionalCallOptions.class));
103                 additionalGsmSettingsPref.setEnabled(isAirplaneModeOff);
104             } else {
105                 prefScreen.removePreference(additionalGsmSettingsPref);
106             }
107         }
108 
109         Preference callBarringPref = prefScreen.findPreference(CALL_BARRING_KEY);
110         if (callBarringPref != null) {
111             if (b != null && b.getBoolean(CarrierConfigManager.KEY_CALL_BARRING_VISIBILITY_BOOL)) {
112                 callBarringPref.setIntent(subInfoHelper.getIntent(GsmUmtsCallBarringOptions.class));
113                 callBarringPref.setEnabled(isAirplaneModeOff);
114             } else {
115                 prefScreen.removePreference(callBarringPref);
116             }
117         }
118     }
119 }
120