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