• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.settings;
18 
19 import android.app.Activity;
20 import android.app.QueuedWork;
21 import android.content.Intent;
22 import android.content.pm.PackageManager;
23 import android.content.pm.ResolveInfo;
24 import android.content.res.Resources;
25 import android.graphics.Typeface;
26 import android.net.TrafficStats;
27 import android.net.Uri;
28 import android.os.AsyncResult;
29 import android.os.Bundle;
30 import android.os.Handler;
31 import android.os.Message;
32 import android.os.SystemProperties;
33 import android.telephony.CellInfo;
34 import android.telephony.CellInfoCdma;
35 import android.telephony.CellInfoGsm;
36 import android.telephony.CellInfoLte;
37 import android.telephony.CellInfoWcdma;
38 import android.telephony.CellIdentityCdma;
39 import android.telephony.CellIdentityGsm;
40 import android.telephony.CellIdentityLte;
41 import android.telephony.CellIdentityWcdma;
42 import android.telephony.CellLocation;
43 import android.telephony.CellSignalStrengthCdma;
44 import android.telephony.CellSignalStrengthGsm;
45 import android.telephony.CellSignalStrengthLte;
46 import android.telephony.CellSignalStrengthWcdma;
47 import android.telephony.DataConnectionRealTimeInfo;
48 import android.telephony.NeighboringCellInfo;
49 import android.telephony.PreciseCallState;
50 import android.telephony.PhoneStateListener;
51 import android.telephony.ServiceState;
52 import android.telephony.SignalStrength;
53 import android.telephony.SubscriptionManager;
54 import android.telephony.TelephonyManager;
55 import android.telephony.cdma.CdmaCellLocation;
56 import android.telephony.gsm.GsmCellLocation;
57 import android.util.Log;
58 import android.view.Menu;
59 import android.view.MenuItem;
60 import android.view.View;
61 import android.view.View.OnClickListener;
62 import android.widget.AdapterView;
63 import android.widget.ArrayAdapter;
64 import android.widget.Button;
65 import android.widget.CompoundButton;
66 import android.widget.CompoundButton.OnCheckedChangeListener;
67 import android.widget.EditText;
68 import android.widget.Spinner;
69 import android.widget.Switch;
70 import android.widget.TextView;
71 
72 import com.android.ims.ImsConfig;
73 import com.android.ims.ImsException;
74 import com.android.ims.ImsManager;
75 import com.android.internal.telephony.Phone;
76 import com.android.internal.telephony.PhoneConstants;
77 import com.android.internal.telephony.PhoneFactory;
78 import com.android.internal.telephony.RILConstants;
79 import com.android.internal.telephony.TelephonyProperties;
80 
81 import java.io.IOException;
82 import java.net.HttpURLConnection;
83 import java.net.URL;
84 import java.net.UnknownHostException;
85 import java.util.ArrayList;
86 import java.util.List;
87 
88 public class RadioInfo extends Activity {
89     private static final String TAG = "RadioInfo";
90 
91     private static final String[] mPreferredNetworkLabels = {
92             "WCDMA preferred",
93             "GSM only",
94             "WCDMA only",
95             "GSM auto (PRL)",
96             "CDMA auto (PRL)",
97             "CDMA only",
98             "EvDo only",
99             "Global auto (PRL)",
100             "LTE/CDMA auto (PRL)",
101             "LTE/UMTS auto (PRL)",
102             "LTE/CDMA/UMTS auto (PRL)",
103             "LTE only",
104             "LTE/WCDMA",
105             "TD-SCDMA only",
106             "TD-SCDMA/WCDMA",
107             "LTE/TD-SCDMA",
108             "TD-SCDMA/GSM",
109             "TD-SCDMA/UMTS",
110             "LTE/TD-SCDMA/WCDMA",
111             "LTE/TD-SCDMA/UMTS",
112             "TD-SCDMA/CDMA/UMTS",
113             "Global/TD-SCDMA",
114             "Unknown"
115     };
116 
117 
118     private static final int CELL_INFO_LIST_RATE_DISABLED = Integer.MAX_VALUE;
119     private static final int CELL_INFO_LIST_RATE_MAX = 0;
120 
121 
122     private static final int IMS_VOLTE_PROVISIONED_CONFIG_ID =
123         ImsConfig.ConfigConstants.VLT_SETTING_ENABLED;
124 
125     private static final int IMS_VT_PROVISIONED_CONFIG_ID =
126         ImsConfig.ConfigConstants.LVC_SETTING_ENABLED;
127 
128     private static final int IMS_WFC_PROVISIONED_CONFIG_ID =
129         ImsConfig.ConfigConstants.VOICE_OVER_WIFI_SETTING_ENABLED;
130 
131     //Values in must match mCellInfoRefreshRates
132     private static final String[] mCellInfoRefreshRateLabels = {
133             "Disabled",
134             "Immediate",
135             "Min 5s",
136             "Min 10s",
137             "Min 60s"
138     };
139 
140     //Values in seconds, must match mCellInfoRefreshRateLabels
141     private static final int mCellInfoRefreshRates[] = {
142         CELL_INFO_LIST_RATE_DISABLED,
143         CELL_INFO_LIST_RATE_MAX,
144         5000,
145         10000,
146         60000
147     };
148 
log(String s)149     private void log(String s) {
150         Log.d(TAG, s);
151     }
152 
153     private static final int EVENT_CFI_CHANGED = 302;
154 
155     private static final int EVENT_QUERY_PREFERRED_TYPE_DONE = 1000;
156     private static final int EVENT_SET_PREFERRED_TYPE_DONE = 1001;
157     private static final int EVENT_QUERY_SMSC_DONE = 1005;
158     private static final int EVENT_UPDATE_SMSC_DONE = 1006;
159 
160     private static final int MENU_ITEM_SELECT_BAND  = 0;
161     private static final int MENU_ITEM_VIEW_ADN     = 1;
162     private static final int MENU_ITEM_VIEW_FDN     = 2;
163     private static final int MENU_ITEM_VIEW_SDN     = 3;
164     private static final int MENU_ITEM_GET_PDP_LIST = 4;
165     private static final int MENU_ITEM_TOGGLE_DATA  = 5;
166 
167     private TextView mDeviceId; //DeviceId is the IMEI in GSM and the MEID in CDMA
168     private TextView number;
169     private TextView callState;
170     private TextView operatorName;
171     private TextView roamingState;
172     private TextView gsmState;
173     private TextView gprsState;
174     private TextView voiceNetwork;
175     private TextView dataNetwork;
176     private TextView dBm;
177     private TextView mMwi;
178     private TextView mCfi;
179     private TextView mLocation;
180     private TextView mNeighboringCids;
181     private TextView mCellInfo;
182     private TextView mDcRtInfoTv;
183     private TextView sent;
184     private TextView received;
185     private TextView mPingHostnameV4;
186     private TextView mPingHostnameV6;
187     private TextView mHttpClientTest;
188     private TextView dnsCheckState;
189     private EditText smsc;
190     private Switch radioPowerOnSwitch;
191     private Button cellInfoRefreshRateButton;
192     private Button dnsCheckToggleButton;
193     private Button pingTestButton;
194     private Button updateSmscButton;
195     private Button refreshSmscButton;
196     private Button oemInfoButton;
197     private Switch imsVolteProvisionedSwitch;
198     private Switch imsVtProvisionedSwitch;
199     private Switch imsWfcProvisionedSwitch;
200     private Spinner preferredNetworkType;
201     private Spinner cellInfoRefreshRateSpinner;
202 
203     private TelephonyManager mTelephonyManager;
204     private ImsManager mImsManager = null;
205     private Phone phone = null;
206 
207     private String mPingHostnameResultV4;
208     private String mPingHostnameResultV6;
209     private String mHttpClientTestResult;
210     private boolean mMwiValue = false;
211     private boolean mCfiValue = false;
212 
213     private List<CellInfo> mCellInfoResult = null;
214     private CellLocation mCellLocationResult = null;
215     private List<NeighboringCellInfo> mNeighboringCellResult = null;
216 
217     private int mPreferredNetworkTypeResult;
218     private int mCellInfoRefreshRateIndex;
219 
220     private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
221         @Override
222         public void onDataConnectionStateChanged(int state) {
223             updateDataState();
224             updateNetworkType();
225         }
226 
227         @Override
228         public void onDataActivity(int direction) {
229             updateDataStats2();
230         }
231 
232         @Override
233         public void onCallStateChanged(int state, String incomingNumber) {
234             updateNetworkType();
235             updatePhoneState(state);
236         }
237 
238         @Override
239         public void onPreciseCallStateChanged(PreciseCallState preciseState) {
240             updateNetworkType();
241         }
242 
243         @Override
244         public void onCellLocationChanged(CellLocation location) {
245             updateLocation(location);
246         }
247 
248         @Override
249         public void onMessageWaitingIndicatorChanged(boolean mwi) {
250             mMwiValue = mwi;
251             updateMessageWaiting();
252         }
253 
254         @Override
255         public void onCallForwardingIndicatorChanged(boolean cfi) {
256             mCfiValue = cfi;
257             updateCallRedirect();
258         }
259 
260         @Override
261         public void onCellInfoChanged(List<CellInfo> arrayCi) {
262             log("onCellInfoChanged: arrayCi=" + arrayCi);
263             mCellInfoResult = arrayCi;
264             updateCellInfo(mCellInfoResult);
265         }
266 
267         @Override
268         public void onDataConnectionRealTimeInfoChanged(DataConnectionRealTimeInfo dcRtInfo) {
269             log("onDataConnectionRealTimeInfoChanged: dcRtInfo=" + dcRtInfo);
270             updateDcRtInfoTv(dcRtInfo);
271         }
272 
273         @Override
274         public void onSignalStrengthsChanged(SignalStrength signalStrength) {
275             log("onSignalStrengthChanged: SignalStrength=" +signalStrength);
276             updateSignalStrength(signalStrength);
277         }
278 
279         @Override
280         public void onServiceStateChanged(ServiceState serviceState) {
281             log("onServiceStateChanged: ServiceState=" + serviceState);
282             updateServiceState(serviceState);
283             updateRadioPowerState();
284             updateNetworkType();
285             updateImsProvisionedState();
286         }
287     };
288 
updatePreferredNetworkType(int type)289     private void updatePreferredNetworkType(int type) {
290         if (type >= mPreferredNetworkLabels.length || type < 0) {
291             log("EVENT_QUERY_PREFERRED_TYPE_DONE: unknown " +
292                     "type=" + type);
293             type = mPreferredNetworkLabels.length - 1; //set to Unknown
294         }
295         mPreferredNetworkTypeResult = type;
296 
297         preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true);
298     }
299 
300     private Handler mHandler = new Handler() {
301         @Override
302         public void handleMessage(Message msg) {
303             AsyncResult ar;
304             switch (msg.what) {
305                 case EVENT_QUERY_PREFERRED_TYPE_DONE:
306                     ar= (AsyncResult) msg.obj;
307                     if (ar.exception == null && ar.result != null) {
308                         updatePreferredNetworkType(((int[])ar.result)[0]);
309                     } else {
310                         //In case of an exception, we will set this to unknown
311                         updatePreferredNetworkType(mPreferredNetworkLabels.length-1);
312                     }
313                     break;
314                 case EVENT_SET_PREFERRED_TYPE_DONE:
315                     ar= (AsyncResult) msg.obj;
316                     if (ar.exception != null) {
317                         log("Set preferred network type failed.");
318                     }
319                     break;
320                 case EVENT_QUERY_SMSC_DONE:
321                     ar= (AsyncResult) msg.obj;
322                     if (ar.exception != null) {
323                         smsc.setText("refresh error");
324                     } else {
325                         smsc.setText((String)ar.result);
326                     }
327                     break;
328                 case EVENT_UPDATE_SMSC_DONE:
329                     updateSmscButton.setEnabled(true);
330                     ar= (AsyncResult) msg.obj;
331                     if (ar.exception != null) {
332                         smsc.setText("update error");
333                     }
334                     break;
335                 default:
336                     super.handleMessage(msg);
337                     break;
338 
339             }
340         }
341     };
342 
343     @Override
onCreate(Bundle icicle)344     public void onCreate(Bundle icicle) {
345         super.onCreate(icicle);
346 
347         setContentView(R.layout.radio_info);
348 
349         log("Started onCreate");
350 
351         mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
352         phone = PhoneFactory.getDefaultPhone();
353 
354         //TODO: Need to update this if the default phoneId changes?
355         //      Better to have an instance per phone?
356         mImsManager = ImsManager.getInstance(getApplicationContext(),
357                 SubscriptionManager.getDefaultVoicePhoneId());
358 
359         mDeviceId= (TextView) findViewById(R.id.imei);
360         number = (TextView) findViewById(R.id.number);
361         callState = (TextView) findViewById(R.id.call);
362         operatorName = (TextView) findViewById(R.id.operator);
363         roamingState = (TextView) findViewById(R.id.roaming);
364         gsmState = (TextView) findViewById(R.id.gsm);
365         gprsState = (TextView) findViewById(R.id.gprs);
366         voiceNetwork = (TextView) findViewById(R.id.voice_network);
367         dataNetwork = (TextView) findViewById(R.id.data_network);
368         dBm = (TextView) findViewById(R.id.dbm);
369         mMwi = (TextView) findViewById(R.id.mwi);
370         mCfi = (TextView) findViewById(R.id.cfi);
371         mLocation = (TextView) findViewById(R.id.location);
372         mNeighboringCids = (TextView) findViewById(R.id.neighboring);
373         mCellInfo = (TextView) findViewById(R.id.cellinfo);
374         mCellInfo.setTypeface(Typeface.MONOSPACE);
375         mDcRtInfoTv = (TextView) findViewById(R.id.dcrtinfo);
376 
377         sent = (TextView) findViewById(R.id.sent);
378         received = (TextView) findViewById(R.id.received);
379         smsc = (EditText) findViewById(R.id.smsc);
380         dnsCheckState = (TextView) findViewById(R.id.dnsCheckState);
381         mPingHostnameV4 = (TextView) findViewById(R.id.pingHostnameV4);
382         mPingHostnameV6 = (TextView) findViewById(R.id.pingHostnameV6);
383         mHttpClientTest = (TextView) findViewById(R.id.httpClientTest);
384 
385         preferredNetworkType = (Spinner) findViewById(R.id.preferredNetworkType);
386         ArrayAdapter<String> adapter = new ArrayAdapter<String> (this,
387                 android.R.layout.simple_spinner_item, mPreferredNetworkLabels);
388         adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
389         preferredNetworkType.setAdapter(adapter);
390 
391         cellInfoRefreshRateSpinner = (Spinner) findViewById(R.id.cell_info_rate_select);
392         ArrayAdapter<String> cellInfoAdapter = new ArrayAdapter<String>(this,
393                 android.R.layout.simple_spinner_item, mCellInfoRefreshRateLabels);
394         cellInfoAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
395         cellInfoRefreshRateSpinner.setAdapter(cellInfoAdapter);
396 
397         imsVolteProvisionedSwitch = (Switch) findViewById(R.id.volte_provisioned_switch);
398         imsVtProvisionedSwitch = (Switch) findViewById(R.id.vt_provisioned_switch);
399         imsWfcProvisionedSwitch = (Switch) findViewById(R.id.wfc_provisioned_switch);
400 
401         radioPowerOnSwitch = (Switch) findViewById(R.id.radio_power);
402 
403         pingTestButton = (Button) findViewById(R.id.ping_test);
404         pingTestButton.setOnClickListener(mPingButtonHandler);
405         updateSmscButton = (Button) findViewById(R.id.update_smsc);
406         updateSmscButton.setOnClickListener(mUpdateSmscButtonHandler);
407         refreshSmscButton = (Button) findViewById(R.id.refresh_smsc);
408         refreshSmscButton.setOnClickListener(mRefreshSmscButtonHandler);
409         dnsCheckToggleButton = (Button) findViewById(R.id.dns_check_toggle);
410         dnsCheckToggleButton.setOnClickListener(mDnsCheckButtonHandler);
411 
412         oemInfoButton = (Button) findViewById(R.id.oem_info);
413         oemInfoButton.setOnClickListener(mOemInfoButtonHandler);
414         PackageManager pm = getPackageManager();
415         Intent oemInfoIntent = new Intent("com.android.settings.OEM_RADIO_INFO");
416         List<ResolveInfo> oemInfoIntentList = pm.queryIntentActivities(oemInfoIntent, 0);
417         if (oemInfoIntentList.size() == 0) {
418             oemInfoButton.setEnabled(false);
419         }
420 
421         mCellInfoRefreshRateIndex = 0; //disabled
422         mPreferredNetworkTypeResult = mPreferredNetworkLabels.length - 1; //Unknown
423 
424         //FIXME: Replace with TelephonyManager call
425         phone.getPreferredNetworkType(
426                 mHandler.obtainMessage(EVENT_QUERY_PREFERRED_TYPE_DONE));
427 
428         restoreFromBundle(icicle);
429     }
430 
431     @Override
onResume()432     protected void onResume() {
433         super.onResume();
434 
435         log("Started onResume");
436 
437         updateMessageWaiting();
438         updateCallRedirect();
439         updateDataState();
440         updateDataStats2();
441         updateRadioPowerState();
442         updateImsProvisionedState();
443         updateProperties();
444         updateDnsCheckState();
445         updateNetworkType();
446 
447         updateNeighboringCids(mNeighboringCellResult);
448         updateLocation(mCellLocationResult);
449         updateCellInfo(mCellInfoResult);
450 
451         mPingHostnameV4.setText(mPingHostnameResultV4);
452         mPingHostnameV6.setText(mPingHostnameResultV6);
453         mHttpClientTest.setText(mHttpClientTestResult);
454 
455         cellInfoRefreshRateSpinner.setOnItemSelectedListener(mCellInfoRefreshRateHandler);
456         //set selection after registering listener to force update
457         cellInfoRefreshRateSpinner.setSelection(mCellInfoRefreshRateIndex);
458 
459         //set selection before registering to prevent update
460         preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true);
461         preferredNetworkType.setOnItemSelectedListener(mPreferredNetworkHandler);
462 
463         radioPowerOnSwitch.setOnCheckedChangeListener(mRadioPowerOnChangeListener);
464         imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
465         imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
466         imsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
467 
468         mTelephonyManager.listen(mPhoneStateListener,
469                   PhoneStateListener.LISTEN_CALL_STATE
470         //b/27803938 - RadioInfo currently cannot read PRECISE_CALL_STATE
471         //      | PhoneStateListener.LISTEN_PRECISE_CALL_STATE
472                 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
473                 | PhoneStateListener.LISTEN_DATA_ACTIVITY
474                 | PhoneStateListener.LISTEN_CELL_LOCATION
475                 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
476                 | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
477                 | PhoneStateListener.LISTEN_CELL_INFO
478                 | PhoneStateListener.LISTEN_SERVICE_STATE
479                 | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
480                 | PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO);
481 
482         smsc.clearFocus();
483     }
484 
485     @Override
onPause()486     protected void onPause() {
487         super.onPause();
488 
489         log("onPause: unregister phone & data intents");
490 
491         mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
492         phone.setCellInfoListRate(CELL_INFO_LIST_RATE_DISABLED);
493     }
494 
restoreFromBundle(Bundle b)495     private void restoreFromBundle(Bundle b) {
496         if( b == null) {
497             return;
498         }
499 
500         mPingHostnameResultV4 = b.getString("mPingHostnameResultV4","");
501         mPingHostnameResultV6 = b.getString("mPingHostnameResultV6","");
502         mHttpClientTestResult = b.getString("mHttpClientTestResult","");
503 
504         mPingHostnameV4.setText(mPingHostnameResultV4);
505         mPingHostnameV6.setText(mPingHostnameResultV6);
506         mHttpClientTest.setText(mHttpClientTestResult);
507 
508         mPreferredNetworkTypeResult = b.getInt("mPreferredNetworkTypeResult",
509                                                mPreferredNetworkLabels.length - 1);
510 
511         mCellInfoRefreshRateIndex = b.getInt("mCellInfoRefreshRateIndex", 0);
512     }
513 
514     @Override
onSaveInstanceState(Bundle outState)515     protected void onSaveInstanceState(Bundle outState) {
516         outState.putString("mPingHostnameResultV4", mPingHostnameResultV4);
517         outState.putString("mPingHostnameResultV6", mPingHostnameResultV6);
518         outState.putString("mHttpClientTestResult", mHttpClientTestResult);
519 
520         outState.putInt("mPreferredNetworkTypeResult", mPreferredNetworkTypeResult);
521         outState.putInt("mCellInfoRefreshRateIndex", mCellInfoRefreshRateIndex);
522 
523     }
524 
525     @Override
onCreateOptionsMenu(Menu menu)526     public boolean onCreateOptionsMenu(Menu menu) {
527         menu.add(0, MENU_ITEM_SELECT_BAND, 0, R.string.radio_info_band_mode_label)
528                 .setOnMenuItemClickListener(mSelectBandCallback)
529                 .setAlphabeticShortcut('b');
530         menu.add(1, MENU_ITEM_VIEW_ADN, 0,
531                 R.string.radioInfo_menu_viewADN).setOnMenuItemClickListener(mViewADNCallback);
532         menu.add(1, MENU_ITEM_VIEW_FDN, 0,
533                 R.string.radioInfo_menu_viewFDN).setOnMenuItemClickListener(mViewFDNCallback);
534         menu.add(1, MENU_ITEM_VIEW_SDN, 0,
535                 R.string.radioInfo_menu_viewSDN).setOnMenuItemClickListener(mViewSDNCallback);
536         menu.add(1, MENU_ITEM_GET_PDP_LIST,
537                 0, R.string.radioInfo_menu_getPDP).setOnMenuItemClickListener(mGetPdpList);
538         menu.add(1, MENU_ITEM_TOGGLE_DATA,
539                 0, R.string.radio_info_data_connection_disable).setOnMenuItemClickListener(mToggleData);
540         return true;
541     }
542 
543     @Override
onPrepareOptionsMenu(Menu menu)544     public boolean onPrepareOptionsMenu(Menu menu) {
545         // Get the TOGGLE DATA menu item in the right state.
546         MenuItem item = menu.findItem(MENU_ITEM_TOGGLE_DATA);
547         int state = mTelephonyManager.getDataState();
548         boolean visible = true;
549 
550         switch (state) {
551             case TelephonyManager.DATA_CONNECTED:
552             case TelephonyManager.DATA_SUSPENDED:
553                 item.setTitle(R.string.radio_info_data_connection_disable);
554                 break;
555             case TelephonyManager.DATA_DISCONNECTED:
556                 item.setTitle(R.string.radio_info_data_connection_enable);
557                 break;
558             default:
559                 visible = false;
560                 break;
561         }
562         item.setVisible(visible);
563         return true;
564     }
565 
updateDnsCheckState()566     private void updateDnsCheckState() {
567         //FIXME: Replace with a TelephonyManager call
568         dnsCheckState.setText(phone.isDnsCheckDisabled() ?
569                 "0.0.0.0 allowed" :"0.0.0.0 not allowed");
570     }
571 
572     private final void
updateSignalStrength(SignalStrength signalStrength)573     updateSignalStrength(SignalStrength signalStrength) {
574         Resources r = getResources();
575 
576         int signalDbm = signalStrength.getDbm();
577 
578         int signalAsu = signalStrength.getAsuLevel();
579 
580         if (-1 == signalAsu) signalAsu = 0;
581 
582         dBm.setText(String.valueOf(signalDbm) + " "
583             + r.getString(R.string.radioInfo_display_dbm) + "   "
584             + String.valueOf(signalAsu) + " "
585             + r.getString(R.string.radioInfo_display_asu));
586     }
587 
updateLocation(CellLocation location)588     private final void updateLocation(CellLocation location) {
589         Resources r = getResources();
590         if (location instanceof GsmCellLocation) {
591             GsmCellLocation loc = (GsmCellLocation)location;
592             int lac = loc.getLac();
593             int cid = loc.getCid();
594             mLocation.setText(r.getString(R.string.radioInfo_lac) + " = "
595                     + ((lac == -1) ? "unknown" : Integer.toHexString(lac))
596                     + "   "
597                     + r.getString(R.string.radioInfo_cid) + " = "
598                     + ((cid == -1) ? "unknown" : Integer.toHexString(cid)));
599         } else if (location instanceof CdmaCellLocation) {
600             CdmaCellLocation loc = (CdmaCellLocation)location;
601             int bid = loc.getBaseStationId();
602             int sid = loc.getSystemId();
603             int nid = loc.getNetworkId();
604             int lat = loc.getBaseStationLatitude();
605             int lon = loc.getBaseStationLongitude();
606             mLocation.setText("BID = "
607                     + ((bid == -1) ? "unknown" : Integer.toHexString(bid))
608                     + "   "
609                     + "SID = "
610                     + ((sid == -1) ? "unknown" : Integer.toHexString(sid))
611                     + "   "
612                     + "NID = "
613                     + ((nid == -1) ? "unknown" : Integer.toHexString(nid))
614                     + "\n"
615                     + "LAT = "
616                     + ((lat == -1) ? "unknown" : Integer.toHexString(lat))
617                     + "   "
618                     + "LONG = "
619                     + ((lon == -1) ? "unknown" : Integer.toHexString(lon)));
620         } else {
621             mLocation.setText("unknown");
622         }
623 
624 
625     }
626 
updateNeighboringCids(List<NeighboringCellInfo> cids)627     private final void updateNeighboringCids(List<NeighboringCellInfo> cids) {
628         StringBuilder sb = new StringBuilder();
629 
630         if (cids != null) {
631             if ( cids.isEmpty() ) {
632                 sb.append("no neighboring cells");
633             } else {
634                 for (NeighboringCellInfo cell : cids) {
635                     sb.append(cell.toString()).append(" ");
636                 }
637             }
638         } else {
639             sb.append("unknown");
640         }
641         mNeighboringCids.setText(sb.toString());
642     }
643 
getCellInfoDisplayString(int i)644     private final String getCellInfoDisplayString(int i) {
645         return (i != Integer.MAX_VALUE) ? Integer.toString(i) : "";
646     }
647 
getCellInfoDisplayString(long i)648     private final String getCellInfoDisplayString(long i) {
649         return (i != Long.MAX_VALUE) ? Long.toString(i) : "";
650     }
651 
buildCdmaInfoString(CellInfoCdma ci)652     private final String buildCdmaInfoString(CellInfoCdma ci) {
653         CellIdentityCdma cidCdma = ci.getCellIdentity();
654         CellSignalStrengthCdma ssCdma = ci.getCellSignalStrength();
655 
656         return String.format("%-3.3s %-5.5s %-5.5s %-5.5s %-6.6s %-6.6s %-6.6s %-6.6s %-5.5s",
657                 ci.isRegistered() ? "S  " : "   ",
658                 getCellInfoDisplayString(cidCdma.getSystemId()),
659                 getCellInfoDisplayString(cidCdma.getNetworkId()),
660                 getCellInfoDisplayString(cidCdma.getBasestationId()),
661                 getCellInfoDisplayString(ssCdma.getCdmaDbm()),
662                 getCellInfoDisplayString(ssCdma.getCdmaEcio()),
663                 getCellInfoDisplayString(ssCdma.getEvdoDbm()),
664                 getCellInfoDisplayString(ssCdma.getEvdoEcio()),
665                 getCellInfoDisplayString(ssCdma.getEvdoSnr()));
666     }
667 
buildGsmInfoString(CellInfoGsm ci)668     private final String buildGsmInfoString(CellInfoGsm ci) {
669         CellIdentityGsm cidGsm = ci.getCellIdentity();
670         CellSignalStrengthGsm ssGsm = ci.getCellSignalStrength();
671 
672         return String.format("%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-6.6s %-4.4s %-4.4s\n",
673                 ci.isRegistered() ? "S  " : "   ",
674                 getCellInfoDisplayString(cidGsm.getMcc()),
675                 getCellInfoDisplayString(cidGsm.getMnc()),
676                 getCellInfoDisplayString(cidGsm.getLac()),
677                 getCellInfoDisplayString(cidGsm.getCid()),
678                 getCellInfoDisplayString(cidGsm.getArfcn()),
679                 getCellInfoDisplayString(cidGsm.getBsic()),
680                 getCellInfoDisplayString(ssGsm.getDbm()));
681     }
682 
buildLteInfoString(CellInfoLte ci)683     private final String buildLteInfoString(CellInfoLte ci) {
684         CellIdentityLte cidLte = ci.getCellIdentity();
685         CellSignalStrengthLte ssLte = ci.getCellSignalStrength();
686 
687         return String.format(
688                 "%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s %-6.6s %-4.4s %-4.4s %-2.2s\n",
689                 ci.isRegistered() ? "S  " : "   ",
690                 getCellInfoDisplayString(cidLte.getMcc()),
691                 getCellInfoDisplayString(cidLte.getMnc()),
692                 getCellInfoDisplayString(cidLte.getTac()),
693                 getCellInfoDisplayString(cidLte.getCi()),
694                 getCellInfoDisplayString(cidLte.getPci()),
695                 getCellInfoDisplayString(cidLte.getEarfcn()),
696                 getCellInfoDisplayString(ssLte.getDbm()),
697                 getCellInfoDisplayString(ssLte.getRsrq()),
698                 getCellInfoDisplayString(ssLte.getTimingAdvance()));
699     }
700 
buildWcdmaInfoString(CellInfoWcdma ci)701     private final String buildWcdmaInfoString(CellInfoWcdma ci) {
702         CellIdentityWcdma cidWcdma = ci.getCellIdentity();
703         CellSignalStrengthWcdma ssWcdma = ci.getCellSignalStrength();
704 
705         return String.format("%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-6.6s %-3.3s %-4.4s\n",
706                 ci.isRegistered() ? "S  " : "   ",
707                 getCellInfoDisplayString(cidWcdma.getMcc()),
708                 getCellInfoDisplayString(cidWcdma.getMnc()),
709                 getCellInfoDisplayString(cidWcdma.getLac()),
710                 getCellInfoDisplayString(cidWcdma.getCid()),
711                 getCellInfoDisplayString(cidWcdma.getUarfcn()),
712                 getCellInfoDisplayString(cidWcdma.getPsc()),
713                 getCellInfoDisplayString(ssWcdma.getDbm()));
714     }
715 
buildCellInfoString(List<CellInfo> arrayCi)716     private final String buildCellInfoString(List<CellInfo> arrayCi) {
717         String value = new String();
718         StringBuilder cdmaCells = new StringBuilder(),
719                 gsmCells = new StringBuilder(),
720                 lteCells = new StringBuilder(),
721                 wcdmaCells = new StringBuilder();
722 
723         if (arrayCi != null) {
724             for (CellInfo ci : arrayCi) {
725 
726                 if (ci instanceof CellInfoLte) {
727                     lteCells.append(buildLteInfoString((CellInfoLte) ci));
728                 } else if (ci instanceof CellInfoWcdma) {
729                     wcdmaCells.append(buildWcdmaInfoString((CellInfoWcdma) ci));
730                 } else if (ci instanceof CellInfoGsm) {
731                     gsmCells.append(buildGsmInfoString((CellInfoGsm) ci));
732                 } else if (ci instanceof CellInfoCdma) {
733                     cdmaCells.append(buildCdmaInfoString((CellInfoCdma) ci));
734                 }
735             }
736             if (lteCells.length() != 0) {
737                 value += String.format(
738                         "LTE\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s %-6.6s %-4.4s %-4.4s %-2.2s\n",
739                         "SRV", "MCC", "MNC", "TAC", "CID", "PCI", "EARFCN", "RSRP", "RSRQ", "TA");
740                 value += lteCells.toString();
741             }
742             if (wcdmaCells.length() != 0) {
743                 value += String.format("WCDMA\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-6.6s %-3.3s %-4.4s\n",
744                         "SRV", "MCC", "MNC", "LAC", "CID", "UARFCN", "PSC", "RSCP");
745                 value += wcdmaCells.toString();
746             }
747             if (gsmCells.length() != 0) {
748                 value += String.format("GSM\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-6.6s %-4.4s %-4.4s\n",
749                         "SRV", "MCC", "MNC", "LAC", "CID", "ARFCN", "BSIC", "RSSI");
750                 value += gsmCells.toString();
751             }
752             if (cdmaCells.length() != 0) {
753                 value += String.format(
754                         "CDMA/EVDO\n%-3.3s %-5.5s %-5.5s %-5.5s %-6.6s %-6.6s %-6.6s %-6.6s %-5.5s\n",
755                         "SRV", "SID", "NID", "BSID", "C-RSSI", "C-ECIO", "E-RSSI", "E-ECIO", "E-SNR");
756                 value += cdmaCells.toString();
757             }
758         } else {
759             value ="unknown";
760         }
761 
762         return value.toString();
763     }
764 
updateCellInfo(List<CellInfo> arrayCi)765     private final void updateCellInfo(List<CellInfo> arrayCi) {
766         mCellInfo.setText(buildCellInfoString(arrayCi));
767     }
768 
updateDcRtInfoTv(DataConnectionRealTimeInfo dcRtInfo)769     private final void updateDcRtInfoTv(DataConnectionRealTimeInfo dcRtInfo) {
770         mDcRtInfoTv.setText(dcRtInfo.toString());
771     }
772 
773     private final void
updateMessageWaiting()774     updateMessageWaiting() {
775         mMwi.setText(String.valueOf(mMwiValue));
776     }
777 
778     private final void
updateCallRedirect()779     updateCallRedirect() {
780         mCfi.setText(String.valueOf(mCfiValue));
781     }
782 
783 
784     private final void
updateServiceState(ServiceState serviceState)785     updateServiceState(ServiceState serviceState) {
786         int state = serviceState.getState();
787         Resources r = getResources();
788         String display = r.getString(R.string.radioInfo_unknown);
789 
790         switch (state) {
791             case ServiceState.STATE_IN_SERVICE:
792                 display = r.getString(R.string.radioInfo_service_in);
793                 break;
794             case ServiceState.STATE_OUT_OF_SERVICE:
795             case ServiceState.STATE_EMERGENCY_ONLY:
796                 display = r.getString(R.string.radioInfo_service_emergency);
797                 break;
798             case ServiceState.STATE_POWER_OFF:
799                 display = r.getString(R.string.radioInfo_service_off);
800                 break;
801         }
802 
803         gsmState.setText(display);
804 
805         if (serviceState.getRoaming()) {
806             roamingState.setText(R.string.radioInfo_roaming_in);
807         } else {
808             roamingState.setText(R.string.radioInfo_roaming_not);
809         }
810 
811         operatorName.setText(serviceState.getOperatorAlphaLong());
812     }
813 
814     private final void
updatePhoneState(int state)815     updatePhoneState(int state) {
816         Resources r = getResources();
817         String display = r.getString(R.string.radioInfo_unknown);
818 
819         switch (state) {
820             case TelephonyManager.CALL_STATE_IDLE:
821                 display = r.getString(R.string.radioInfo_phone_idle);
822                 break;
823             case TelephonyManager.CALL_STATE_RINGING:
824                 display = r.getString(R.string.radioInfo_phone_ringing);
825                 break;
826             case TelephonyManager.CALL_STATE_OFFHOOK:
827                 display = r.getString(R.string.radioInfo_phone_offhook);
828                 break;
829         }
830 
831         callState.setText(display);
832     }
833 
834     private final void
updateDataState()835     updateDataState() {
836         int state = mTelephonyManager.getDataState();
837         Resources r = getResources();
838         String display = r.getString(R.string.radioInfo_unknown);
839 
840         switch (state) {
841             case TelephonyManager.DATA_CONNECTED:
842                 display = r.getString(R.string.radioInfo_data_connected);
843                 break;
844             case TelephonyManager.DATA_CONNECTING:
845                 display = r.getString(R.string.radioInfo_data_connecting);
846                 break;
847             case TelephonyManager.DATA_DISCONNECTED:
848                 display = r.getString(R.string.radioInfo_data_disconnected);
849                 break;
850             case TelephonyManager.DATA_SUSPENDED:
851                 display = r.getString(R.string.radioInfo_data_suspended);
852                 break;
853         }
854 
855         gprsState.setText(display);
856     }
857 
updateNetworkType()858     private final void updateNetworkType() {
859         if( phone != null ) {
860             ServiceState ss = phone.getServiceState();
861             dataNetwork.setText(ServiceState.rilRadioTechnologyToString(
862                     phone.getServiceState().getRilDataRadioTechnology()));
863             voiceNetwork.setText(ServiceState.rilRadioTechnologyToString(
864                     phone.getServiceState().getRilVoiceRadioTechnology()));
865         }
866     }
867 
868     private final void
updateProperties()869     updateProperties() {
870         String s;
871         Resources r = getResources();
872 
873         s = phone.getDeviceId();
874         if (s == null) s = r.getString(R.string.radioInfo_unknown);
875         mDeviceId.setText(s);
876 
877         //FIXME: Replace with a TelephonyManager call
878         s = phone.getLine1Number();
879         if (s == null) s = r.getString(R.string.radioInfo_unknown);
880         number.setText(s);
881     }
882 
updateDataStats2()883     private final void updateDataStats2() {
884         Resources r = getResources();
885 
886         long txPackets = TrafficStats.getMobileTxPackets();
887         long rxPackets = TrafficStats.getMobileRxPackets();
888         long txBytes   = TrafficStats.getMobileTxBytes();
889         long rxBytes   = TrafficStats.getMobileRxBytes();
890 
891         String packets = r.getString(R.string.radioInfo_display_packets);
892         String bytes   = r.getString(R.string.radioInfo_display_bytes);
893 
894         sent.setText(txPackets + " " + packets + ", " + txBytes + " " + bytes);
895         received.setText(rxPackets + " " + packets + ", " + rxBytes + " " + bytes);
896     }
897 
898     /**
899      *  Ping a host name
900      */
pingHostname()901     private final void pingHostname() {
902         try {
903             try {
904                 Process p4 = Runtime.getRuntime().exec("ping -c 1 www.google.com");
905                 int status4 = p4.waitFor();
906                 if (status4 == 0) {
907                     mPingHostnameResultV4 = "Pass";
908                 } else {
909                     mPingHostnameResultV4 = String.format("Fail(%d)", status4);
910                 }
911             } catch (IOException e) {
912                 mPingHostnameResultV4 = "Fail: IOException";
913             }
914             try {
915                 Process p6 = Runtime.getRuntime().exec("ping6 -c 1 www.google.com");
916                 int status6 = p6.waitFor();
917                 if (status6 == 0) {
918                     mPingHostnameResultV6 = "Pass";
919                 } else {
920                     mPingHostnameResultV6 = String.format("Fail(%d)", status6);
921                 }
922             } catch (IOException e) {
923                 mPingHostnameResultV6 = "Fail: IOException";
924             }
925         } catch (InterruptedException e) {
926             mPingHostnameResultV4 = mPingHostnameResultV6 = "Fail: InterruptedException";
927         }
928     }
929 
930     /**
931      * This function checks for basic functionality of HTTP Client.
932      */
httpClientTest()933     private void httpClientTest() {
934         HttpURLConnection urlConnection = null;
935         try {
936             // TODO: Hardcoded for now, make it UI configurable
937             URL url = new URL("https://www.google.com");
938             urlConnection = (HttpURLConnection) url.openConnection();
939             if (urlConnection.getResponseCode() == 200) {
940                 mHttpClientTestResult = "Pass";
941             } else {
942                 mHttpClientTestResult = "Fail: Code: " + urlConnection.getResponseMessage();
943             }
944         } catch (IOException e) {
945             mHttpClientTestResult = "Fail: IOException";
946         } finally {
947             if (urlConnection != null) {
948                 urlConnection.disconnect();
949             }
950         }
951     }
952 
refreshSmsc()953     private void refreshSmsc() {
954         //FIXME: Replace with a TelephonyManager call
955         phone.getSmscAddress(mHandler.obtainMessage(EVENT_QUERY_SMSC_DONE));
956     }
957 
updateAllCellInfo()958     private final void updateAllCellInfo() {
959 
960         mCellInfo.setText("");
961         mNeighboringCids.setText("");
962         mLocation.setText("");
963 
964         final Runnable updateAllCellInfoResults = new Runnable() {
965             public void run() {
966                 updateNeighboringCids(mNeighboringCellResult);
967                 updateLocation(mCellLocationResult);
968                 updateCellInfo(mCellInfoResult);
969             }
970         };
971 
972         Thread locThread = new Thread() {
973             @Override
974             public void run() {
975                 mCellInfoResult = mTelephonyManager.getAllCellInfo();
976                 mCellLocationResult = mTelephonyManager.getCellLocation();
977                 mNeighboringCellResult = mTelephonyManager.getNeighboringCellInfo();
978 
979                 mHandler.post(updateAllCellInfoResults);
980             }
981         };
982         locThread.start();
983     }
984 
updatePingState()985     private final void updatePingState() {
986         // Set all to unknown since the threads will take a few secs to update.
987         mPingHostnameResultV4 = getResources().getString(R.string.radioInfo_unknown);
988         mPingHostnameResultV6 = getResources().getString(R.string.radioInfo_unknown);
989         mHttpClientTestResult = getResources().getString(R.string.radioInfo_unknown);
990 
991         mPingHostnameV4.setText(mPingHostnameResultV4);
992         mPingHostnameV6.setText(mPingHostnameResultV6);
993         mHttpClientTest.setText(mHttpClientTestResult);
994 
995         final Runnable updatePingResults = new Runnable() {
996             public void run() {
997                 mPingHostnameV4.setText(mPingHostnameResultV4);
998                 mPingHostnameV6.setText(mPingHostnameResultV6);
999                 mHttpClientTest.setText(mHttpClientTestResult);
1000             }
1001         };
1002 
1003         Thread hostname = new Thread() {
1004             @Override
1005             public void run() {
1006                 pingHostname();
1007                 mHandler.post(updatePingResults);
1008             }
1009         };
1010         hostname.start();
1011 
1012         Thread httpClient = new Thread() {
1013             @Override
1014             public void run() {
1015                 httpClientTest();
1016                 mHandler.post(updatePingResults);
1017             }
1018         };
1019         httpClient.start();
1020     }
1021 
1022     private MenuItem.OnMenuItemClickListener mViewADNCallback = new MenuItem.OnMenuItemClickListener() {
1023         public boolean onMenuItemClick(MenuItem item) {
1024             Intent intent = new Intent(Intent.ACTION_VIEW);
1025             // XXX We need to specify the component here because if we don't
1026             // the activity manager will try to resolve the type by calling
1027             // the content provider, which causes it to be loaded in a process
1028             // other than the Dialer process, which causes a lot of stuff to
1029             // break.
1030             intent.setClassName("com.android.phone",
1031                     "com.android.phone.SimContacts");
1032             startActivity(intent);
1033             return true;
1034         }
1035     };
1036 
1037     private MenuItem.OnMenuItemClickListener mViewFDNCallback = new MenuItem.OnMenuItemClickListener() {
1038         public boolean onMenuItemClick(MenuItem item) {
1039             Intent intent = new Intent(Intent.ACTION_VIEW);
1040             // XXX We need to specify the component here because if we don't
1041             // the activity manager will try to resolve the type by calling
1042             // the content provider, which causes it to be loaded in a process
1043             // other than the Dialer process, which causes a lot of stuff to
1044             // break.
1045             intent.setClassName("com.android.phone",
1046                     "com.android.phone.settings.fdn.FdnList");
1047             startActivity(intent);
1048             return true;
1049         }
1050     };
1051 
1052     private MenuItem.OnMenuItemClickListener mViewSDNCallback = new MenuItem.OnMenuItemClickListener() {
1053         public boolean onMenuItemClick(MenuItem item) {
1054             Intent intent = new Intent(
1055                     Intent.ACTION_VIEW, Uri.parse("content://icc/sdn"));
1056             // XXX We need to specify the component here because if we don't
1057             // the activity manager will try to resolve the type by calling
1058             // the content provider, which causes it to be loaded in a process
1059             // other than the Dialer process, which causes a lot of stuff to
1060             // break.
1061             intent.setClassName("com.android.phone",
1062                     "com.android.phone.ADNList");
1063             startActivity(intent);
1064             return true;
1065         }
1066     };
1067 
1068     private MenuItem.OnMenuItemClickListener mGetPdpList = new MenuItem.OnMenuItemClickListener() {
1069         public boolean onMenuItemClick(MenuItem item) {
1070             //FIXME: Replace with a TelephonyManager call
1071             phone.getDataCallList(null);
1072             return true;
1073         }
1074     };
1075 
1076     private MenuItem.OnMenuItemClickListener mSelectBandCallback = new MenuItem.OnMenuItemClickListener() {
1077         public boolean onMenuItemClick(MenuItem item) {
1078             Intent intent = new Intent();
1079             intent.setClass(RadioInfo.this, BandMode.class);
1080             startActivity(intent);
1081             return true;
1082         }
1083     };
1084 
1085     private MenuItem.OnMenuItemClickListener mToggleData = new MenuItem.OnMenuItemClickListener() {
1086         public boolean onMenuItemClick(MenuItem item) {
1087             int state = mTelephonyManager.getDataState();
1088             switch (state) {
1089                 case TelephonyManager.DATA_CONNECTED:
1090                     //FIXME: Replace with a TelephonyManager call
1091                     phone.setDataEnabled(false);
1092                     break;
1093                 case TelephonyManager.DATA_DISCONNECTED:
1094                     //FIXME: Replace with a TelephonyManager call
1095                     phone.setDataEnabled(true);
1096                     break;
1097                 default:
1098                     // do nothing
1099                     break;
1100             }
1101             return true;
1102         }
1103     };
1104 
isRadioOn()1105     private boolean isRadioOn() {
1106         //FIXME: Replace with a TelephonyManager call
1107         return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1108     }
1109 
updateRadioPowerState()1110     private void updateRadioPowerState() {
1111         //delightful hack to prevent on-checked-changed calls from
1112         //actually forcing the radio preference to its transient/current value.
1113         radioPowerOnSwitch.setOnCheckedChangeListener(null);
1114         radioPowerOnSwitch.setChecked(isRadioOn());
1115         radioPowerOnSwitch.setOnCheckedChangeListener(mRadioPowerOnChangeListener);
1116     }
1117 
setImsVolteProvisionedState( boolean state )1118     void setImsVolteProvisionedState( boolean state ) {
1119         Log.d(TAG, "setImsVolteProvisioned state: " + ((state)? "on":"off"));
1120         setImsConfigProvisionedState( IMS_VOLTE_PROVISIONED_CONFIG_ID, state );
1121     }
1122 
setImsVtProvisionedState( boolean state )1123     void setImsVtProvisionedState( boolean state ) {
1124         Log.d(TAG, "setImsVtProvisioned() state: " + ((state)? "on":"off"));
1125         setImsConfigProvisionedState( IMS_VT_PROVISIONED_CONFIG_ID, state );
1126     }
1127 
setImsWfcProvisionedState( boolean state )1128     void setImsWfcProvisionedState( boolean state ) {
1129         Log.d(TAG, "setImsWfcProvisioned() state: " + ((state)? "on":"off"));
1130         setImsConfigProvisionedState( IMS_WFC_PROVISIONED_CONFIG_ID, state );
1131     }
1132 
setImsConfigProvisionedState( int configItem, boolean state )1133     void setImsConfigProvisionedState( int configItem, boolean state ) {
1134         if (phone != null && mImsManager != null) {
1135             QueuedWork.singleThreadExecutor().submit(new Runnable() {
1136                 public void run() {
1137                     try {
1138                         mImsManager.getConfigInterface().setProvisionedValue(
1139                                 configItem,
1140                                 state? 1 : 0);
1141                     } catch (ImsException e) {
1142                         Log.e(TAG, "setImsConfigProvisioned() exception:", e);
1143                     }
1144                 }
1145             });
1146         }
1147     }
1148 
1149     OnCheckedChangeListener mRadioPowerOnChangeListener = new OnCheckedChangeListener() {
1150         @Override
1151         public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1152             log("toggle radio power: currently " + (isRadioOn()?"on":"off"));
1153             phone.setRadioPower(isChecked);
1154        }
1155     };
1156 
isImsVolteProvisioned()1157     private boolean isImsVolteProvisioned() {
1158         if (phone != null && mImsManager != null) {
1159             return mImsManager.isVolteEnabledByPlatform(phone.getContext())
1160                 && mImsManager.isVolteProvisionedOnDevice(phone.getContext());
1161         }
1162         return false;
1163     }
1164 
1165     OnCheckedChangeListener mImsVolteCheckedChangeListener = new OnCheckedChangeListener() {
1166         @Override
1167         public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1168             setImsVolteProvisionedState(isChecked);
1169        }
1170     };
1171 
isImsVtProvisioned()1172     private boolean isImsVtProvisioned() {
1173         if (phone != null && mImsManager != null) {
1174             return mImsManager.isVtEnabledByPlatform(phone.getContext())
1175                 && mImsManager.isVtProvisionedOnDevice(phone.getContext());
1176         }
1177         return false;
1178     }
1179 
1180     OnCheckedChangeListener mImsVtCheckedChangeListener = new OnCheckedChangeListener() {
1181         @Override
1182         public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1183             setImsVtProvisionedState(isChecked);
1184        }
1185     };
1186 
isImsWfcProvisioned()1187     private boolean isImsWfcProvisioned() {
1188         if (phone != null && mImsManager != null) {
1189             return mImsManager.isWfcEnabledByPlatform(phone.getContext())
1190                 && mImsManager.isWfcProvisionedOnDevice(phone.getContext());
1191         }
1192         return false;
1193     }
1194 
1195     OnCheckedChangeListener mImsWfcCheckedChangeListener = new OnCheckedChangeListener() {
1196         @Override
1197         public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1198             setImsWfcProvisionedState(isChecked);
1199        }
1200     };
1201 
updateImsProvisionedState()1202     private void updateImsProvisionedState() {
1203         log("updateImsProvisionedState isImsVolteProvisioned()=" + isImsVolteProvisioned());
1204         //delightful hack to prevent on-checked-changed calls from
1205         //actually forcing the ims provisioning to its transient/current value.
1206         imsVolteProvisionedSwitch.setOnCheckedChangeListener(null);
1207         imsVolteProvisionedSwitch.setChecked(isImsVolteProvisioned());
1208         imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
1209 
1210         imsVtProvisionedSwitch.setOnCheckedChangeListener(null);
1211         imsVtProvisionedSwitch.setChecked(isImsVtProvisioned());
1212         imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
1213 
1214         imsWfcProvisionedSwitch.setOnCheckedChangeListener(null);
1215         imsWfcProvisionedSwitch.setChecked(isImsWfcProvisioned());
1216         imsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
1217     }
1218 
1219     OnClickListener mDnsCheckButtonHandler = new OnClickListener() {
1220         public void onClick(View v) {
1221             //FIXME: Replace with a TelephonyManager call
1222             phone.disableDnsCheck(!phone.isDnsCheckDisabled());
1223             updateDnsCheckState();
1224         }
1225     };
1226 
1227     OnClickListener mOemInfoButtonHandler = new OnClickListener() {
1228         public void onClick(View v) {
1229             Intent intent = new Intent("com.android.settings.OEM_RADIO_INFO");
1230             try {
1231                 startActivity(intent);
1232             } catch (android.content.ActivityNotFoundException ex) {
1233                 log("OEM-specific Info/Settings Activity Not Found : " + ex);
1234                 // If the activity does not exist, there are no OEM
1235                 // settings, and so we can just do nothing...
1236             }
1237         }
1238     };
1239 
1240     OnClickListener mPingButtonHandler = new OnClickListener() {
1241         public void onClick(View v) {
1242             updatePingState();
1243         }
1244     };
1245 
1246     OnClickListener mUpdateSmscButtonHandler = new OnClickListener() {
1247         public void onClick(View v) {
1248             updateSmscButton.setEnabled(false);
1249             phone.setSmscAddress(smsc.getText().toString(),
1250                     mHandler.obtainMessage(EVENT_UPDATE_SMSC_DONE));
1251         }
1252     };
1253 
1254     OnClickListener mRefreshSmscButtonHandler = new OnClickListener() {
1255         public void onClick(View v) {
1256             refreshSmsc();
1257         }
1258     };
1259 
1260     AdapterView.OnItemSelectedListener mPreferredNetworkHandler =
1261             new AdapterView.OnItemSelectedListener() {
1262 
1263         public void onItemSelected(AdapterView parent, View v, int pos, long id) {
1264             if (mPreferredNetworkTypeResult != pos && pos >= 0
1265                     && pos <= mPreferredNetworkLabels.length - 2) {
1266                 mPreferredNetworkTypeResult = pos;
1267                 Message msg = mHandler.obtainMessage(EVENT_SET_PREFERRED_TYPE_DONE);
1268                 phone.setPreferredNetworkType(mPreferredNetworkTypeResult, msg);
1269             }
1270         }
1271 
1272         public void onNothingSelected(AdapterView parent) {
1273         }
1274     };
1275 
1276     AdapterView.OnItemSelectedListener mCellInfoRefreshRateHandler  =
1277             new AdapterView.OnItemSelectedListener() {
1278 
1279         public void onItemSelected(AdapterView parent, View v, int pos, long id) {
1280             mCellInfoRefreshRateIndex = pos;
1281             phone.setCellInfoListRate(mCellInfoRefreshRates[pos]);
1282             updateAllCellInfo();
1283         }
1284 
1285         public void onNothingSelected(AdapterView parent) {
1286         }
1287     };
1288 
1289 }
1290