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 getWindow().addSystemFlags( 47 android.view.WindowManager.LayoutParams 48 .SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); 49 50 addPreferencesFromResource(R.xml.gsm_umts_call_options); 51 52 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) { 58 //disable the entire screen 59 getPreferenceScreen().setEnabled(false); 60 } 61 } 62 63 @Override onOptionsItemSelected(MenuItem item)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 init(PreferenceScreen prefScreen, SubscriptionInfoHelper subInfoHelper)73 public static void init(PreferenceScreen prefScreen, SubscriptionInfoHelper subInfoHelper) { 74 PersistableBundle b = null; 75 if (subInfoHelper.hasSubId()) { 76 b = PhoneGlobals.getInstance().getCarrierConfigForSubId(subInfoHelper.getSubId()); 77 } else { 78 b = PhoneGlobals.getInstance().getCarrierConfig(); 79 } 80 81 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 90 // 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); 96 if (Flags.ensureAccessToCallSettingsIsRestricted() && mobileNetworkConfigsRestricted) { 97 Log.i(LOG_TAG, "Mobile network configs are restricted, hiding GSM call " 98 + "forwarding, additional call settings, and call options."); 99 } 100 101 Preference callForwardingPref = prefScreen.findPreference(CALL_FORWARDING_KEY); 102 if (callForwardingPref != null) { 103 if (b != null && b.getBoolean( 104 CarrierConfigManager.KEY_CALL_FORWARDING_VISIBILITY_BOOL) && 105 (!Flags.ensureAccessToCallSettingsIsRestricted() || 106 !mobileNetworkConfigsRestricted)) { 107 callForwardingPref.setIntent( 108 subInfoHelper.getIntent(GsmUmtsCallForwardOptions.class)); 109 callForwardingPref.setEnabled(isAirplaneModeOff); 110 } 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( 121 CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALLER_ID_VISIBILITY_BOOL)) && 122 (!Flags.ensureAccessToCallSettingsIsRestricted() || 123 !mobileNetworkConfigsRestricted)) { 124 additionalGsmSettingsPref.setIntent( 125 subInfoHelper.getIntent(GsmUmtsAdditionalCallOptions.class)); 126 additionalGsmSettingsPref.setEnabled(isAirplaneModeOff); 127 } else { 128 prefScreen.removePreference(additionalGsmSettingsPref); 129 } 130 } 131 132 Preference callBarringPref = prefScreen.findPreference(CALL_BARRING_KEY); 133 if (callBarringPref != null) { 134 if (b != null && b.getBoolean(CarrierConfigManager.KEY_CALL_BARRING_VISIBILITY_BOOL) && 135 (!Flags.ensureAccessToCallSettingsIsRestricted() || 136 !mobileNetworkConfigsRestricted)) { 137 callBarringPref.setIntent(subInfoHelper.getIntent(GsmUmtsCallBarringOptions.class)); 138 callBarringPref.setEnabled(isAirplaneModeOff); 139 } else { 140 prefScreen.removePreference(callBarringPref); 141 } 142 } 143 } 144 } 145