• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.phone;
2 
3 import android.app.ActionBar;
4 import android.app.Dialog;
5 import android.os.Bundle;
6 import android.os.PersistableBundle;
7 import android.preference.Preference;
8 import android.preference.PreferenceScreen;
9 import android.telephony.CarrierConfigManager;
10 import android.util.Log;
11 import android.view.MenuItem;
12 
13 import com.android.internal.telephony.Phone;
14 import com.android.phone.settings.SuppServicesUiUtil;
15 
16 import java.util.ArrayList;
17 
18 public class GsmUmtsAdditionalCallOptions extends TimeConsumingPreferenceActivity {
19     private static final String LOG_TAG = "GsmUmtsAdditionalCallOptions";
20     private final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
21 
22     public static final String BUTTON_CLIR_KEY  = "button_clir_key";
23     public static final String BUTTON_CW_KEY    = "button_cw_key";
24 
25     private static final int CW_WARNING_DIALOG = 201;
26     private static final int CALLER_ID_WARNING_DIALOG = 202;
27 
28     private CLIRListPreference mCLIRButton;
29     private CallWaitingSwitchPreference mCWButton;
30 
31     private final ArrayList<Preference> mPreferences = new ArrayList<Preference>();
32     private int mInitIndex = 0;
33     private Phone mPhone;
34     private SubscriptionInfoHelper mSubscriptionInfoHelper;
35 
36     private boolean mShowCLIRButton = true;
37     private boolean mShowCWButton = true;
38     private boolean mCLIROverUtPrecautions = false;
39     private boolean mCWOverUtPrecautions = false;
40 
41     @Override
onCreate(Bundle icicle)42     protected void onCreate(Bundle icicle) {
43         super.onCreate(icicle);
44 
45         getWindow().addSystemFlags(
46                 android.view.WindowManager.LayoutParams
47                         .SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
48 
49         addPreferencesFromResource(R.xml.gsm_umts_additional_options);
50 
51         mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
52         mSubscriptionInfoHelper.setActionBarTitle(
53                 getActionBar(), getResources(), R.string.additional_gsm_call_settings_with_label);
54         mPhone = mSubscriptionInfoHelper.getPhone();
55 
56         PreferenceScreen prefSet = getPreferenceScreen();
57         mCLIRButton = (CLIRListPreference) prefSet.findPreference(BUTTON_CLIR_KEY);
58         mCWButton = (CallWaitingSwitchPreference) prefSet.findPreference(BUTTON_CW_KEY);
59 
60         PersistableBundle b = null;
61         if (mSubscriptionInfoHelper.hasSubId()) {
62             b = PhoneGlobals.getInstance().getCarrierConfigForSubId(
63                     mSubscriptionInfoHelper.getSubId());
64         } else {
65             b = PhoneGlobals.getInstance().getCarrierConfig();
66         }
67 
68         if (b != null) {
69             mShowCLIRButton = b.getBoolean(
70                     CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALLER_ID_VISIBILITY_BOOL);
71             mShowCWButton = b.getBoolean(
72                     CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALL_WAITING_VISIBILITY_BOOL);
73             mCLIROverUtPrecautions = mShowCLIRButton && b.getBoolean(
74                     CarrierConfigManager.KEY_CALLER_ID_OVER_UT_WARNING_BOOL);
75             mCWOverUtPrecautions = mShowCWButton && b.getBoolean(
76                     CarrierConfigManager.KEY_CALL_WAITING_OVER_UT_WARNING_BOOL);
77             if (DBG) {
78                 Log.d(LOG_TAG, "mCLIROverUtPrecautions:" + mCLIROverUtPrecautions
79                         + ",mCWOverUtPrecautions:" + mCWOverUtPrecautions);
80             }
81         }
82 
83         boolean isSsOverUtPrecautions = SuppServicesUiUtil.isSsOverUtPrecautions(this, mPhone);
84 
85         if (mCLIRButton != null) {
86             if (mShowCLIRButton) {
87                 if (mCLIROverUtPrecautions && isSsOverUtPrecautions) {
88                     mCLIRButton.setEnabled(false);
89                 } else {
90                     mPreferences.add(mCLIRButton);
91                 }
92             } else {
93                 prefSet.removePreference(mCLIRButton);
94             }
95         }
96 
97         if (mCWButton != null) {
98             if (mShowCWButton) {
99                 if (mCWOverUtPrecautions && isSsOverUtPrecautions) {
100                     mCWButton.setEnabled(false);
101                 } else {
102                     mPreferences.add(mCWButton);
103                 }
104             } else {
105                 prefSet.removePreference(mCWButton);
106             }
107         }
108 
109         if (mPreferences.size() != 0) {
110             if (icicle == null) {
111                 if (DBG) Log.d(LOG_TAG, "start to init ");
112                 doPreferenceInit(mInitIndex);
113             } else {
114                 if (DBG) Log.d(LOG_TAG, "restore stored states");
115                 mInitIndex = mPreferences.size();
116                 if (mShowCWButton && mCWButton != null && mCWButton.isEnabled()) {
117                     mCWButton.init(this, true, mPhone);
118                 }
119                 if (mShowCLIRButton && mCLIRButton != null && mCLIRButton.isEnabled()) {
120                     mCLIRButton.init(this, true, mPhone);
121                     int[] clirArray = icicle.getIntArray(mCLIRButton.getKey());
122                     if (clirArray != null) {
123                         if (DBG) {
124                             Log.d(LOG_TAG, "onCreate:  clirArray[0]="
125                                     + clirArray[0] + ", clirArray[1]=" + clirArray[1]);
126                         }
127                         mCLIRButton.handleGetCLIRResult(clirArray);
128                     } else {
129                         mCLIRButton.init(this, false, mPhone);
130                     }
131                 }
132             }
133         }
134 
135         ActionBar actionBar = getActionBar();
136         if (actionBar != null) {
137             // android.R.id.home will be triggered in onOptionsItemSelected()
138             actionBar.setDisplayHomeAsUpEnabled(true);
139         }
140     }
141 
142     @Override
onResume()143     public void onResume() {
144         super.onResume();
145         int indexOfStartInit = mPreferences.size();
146         boolean isPrecaution = SuppServicesUiUtil.isSsOverUtPrecautions(this, mPhone);
147         dismissWarningDialog();
148 
149         if (mShowCLIRButton && mCLIROverUtPrecautions && mCLIRButton != null) {
150             if (isPrecaution) {
151                 showWarningDialog(CW_WARNING_DIALOG);
152                 if (mCLIRButton.isEnabled()) {
153                     if (mPreferences.contains(mCLIRButton)) {
154                         mPreferences.remove(mCLIRButton);
155                     }
156                     mCLIRButton.setEnabled(false);
157                 }
158             } else {
159                 if (!mPreferences.contains(mCLIRButton)) {
160                     mCLIRButton.setEnabled(true);
161                     mPreferences.add(mCLIRButton);
162                 }
163             }
164         }
165         if (mShowCWButton && mCWOverUtPrecautions && mCWButton != null) {
166             if (isPrecaution) {
167                 showWarningDialog(CALLER_ID_WARNING_DIALOG);
168                 if (mCWButton.isEnabled()) {
169                     if (mPreferences.contains(mCWButton)) {
170                         mPreferences.remove(mCWButton);
171                     }
172                     mCWButton.setEnabled(false);
173                 }
174             } else {
175                 if (!mPreferences.contains(mCWButton)) {
176                     mCWButton.setEnabled(true);
177                     mPreferences.add(mCWButton);
178                 }
179             }
180         }
181 
182         if (indexOfStartInit < mPreferences.size()) {
183             mInitIndex = indexOfStartInit;
184             doPreferenceInit(indexOfStartInit);
185         }
186     }
187 
188     @Override
onSaveInstanceState(Bundle outState)189     protected void onSaveInstanceState(Bundle outState) {
190         super.onSaveInstanceState(outState);
191 
192         if (mShowCLIRButton && mCLIRButton.clirArray != null) {
193             outState.putIntArray(mCLIRButton.getKey(), mCLIRButton.clirArray);
194         }
195     }
196 
197     @Override
onFinished(Preference preference, boolean reading)198     public void onFinished(Preference preference, boolean reading) {
199         if (mInitIndex < mPreferences.size()-1 && !isFinishing()) {
200             mInitIndex++;
201             doPreferenceInit(mInitIndex);
202         }
203         super.onFinished(preference, reading);
204     }
205 
206     @Override
onOptionsItemSelected(MenuItem item)207     public boolean onOptionsItemSelected(MenuItem item) {
208         final int itemId = item.getItemId();
209         if (itemId == android.R.id.home) {  // See ActionBar#setDisplayHomeAsUpEnabled()
210             CallFeaturesSetting.goUpToTopLevelSetting(this, mSubscriptionInfoHelper);
211             return true;
212         }
213         return super.onOptionsItemSelected(item);
214     }
215 
doPreferenceInit(int index)216     private void doPreferenceInit(int index) {
217         if (mPreferences.size() > index) {
218             Preference pref = mPreferences.get(index);
219             if (pref instanceof CallWaitingSwitchPreference) {
220                 ((CallWaitingSwitchPreference) pref).init(this, false, mPhone);
221             } else if (pref instanceof CLIRListPreference) {
222                 ((CLIRListPreference) pref).init(this, false, mPhone);
223             }
224         }
225     }
226 
227     @Override
onCreateDialog(int id)228     protected Dialog onCreateDialog(int id) {
229         if (id == CW_WARNING_DIALOG) {
230             return SuppServicesUiUtil.showBlockingSuppServicesDialog(this, mPhone, BUTTON_CW_KEY);
231         } else if (id == CALLER_ID_WARNING_DIALOG) {
232             return SuppServicesUiUtil.showBlockingSuppServicesDialog(this, mPhone, BUTTON_CLIR_KEY);
233         }
234         return super.onCreateDialog(id);
235     }
236 
showWarningDialog(int id)237     private void showWarningDialog(int id) {
238         showDialog(id);
239     }
240 
dismissWarningDialog()241     private void dismissWarningDialog() {
242         dismissDialogSafely(CW_WARNING_DIALOG);
243         dismissDialogSafely(CALLER_ID_WARNING_DIALOG);
244     }
245 }
246