blob: 4c861440d17ea26b53d37b6806f84fb34ba056b9 [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001/*
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
17package com.android.settings;
18
19import android.app.Activity;
Robert Greenwalt99be5002010-11-24 17:20:59 -080020import android.content.Context;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080021import android.content.Intent;
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +080022import android.content.pm.PackageManager;
23import android.content.pm.ResolveInfo;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080024import android.content.res.Resources;
Robert Greenwalt99be5002010-11-24 17:20:59 -080025import android.net.ConnectivityManager;
Jeff Sharkey93029862011-05-27 18:26:15 -070026import android.net.TrafficStats;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080027import android.net.Uri;
28import android.os.AsyncResult;
29import android.os.Bundle;
30import android.os.Handler;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080031import android.os.Message;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080032import android.os.SystemProperties;
Wink Saville79bff2a2012-06-01 14:37:21 -070033import android.telephony.CellInfo;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080034import android.telephony.CellLocation;
Wink Saville4f0d8812014-04-15 22:05:24 -070035import android.telephony.DataConnectionRealTimeInfo;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080036import android.telephony.PhoneStateListener;
37import android.telephony.ServiceState;
38import android.telephony.TelephonyManager;
39import android.telephony.NeighboringCellInfo;
jsh534f5ae2009-09-24 09:19:22 -070040import android.telephony.cdma.CdmaCellLocation;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080041import android.telephony.gsm.GsmCellLocation;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080042import android.util.Log;
43import android.view.Menu;
44import android.view.MenuItem;
45import android.view.View;
46import android.view.View.OnClickListener;
47import android.widget.AdapterView;
48import android.widget.ArrayAdapter;
49import android.widget.Button;
50import android.widget.Spinner;
51import android.widget.TextView;
52import android.widget.EditText;
53
54import com.android.internal.telephony.Phone;
Wink Saville55434042012-06-14 12:33:43 -070055import com.android.internal.telephony.PhoneConstants;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080056import com.android.internal.telephony.PhoneFactory;
57import com.android.internal.telephony.PhoneStateIntentReceiver;
58import com.android.internal.telephony.TelephonyProperties;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080059import org.apache.http.HttpResponse;
60import org.apache.http.client.HttpClient;
61import org.apache.http.client.methods.HttpGet;
62import org.apache.http.impl.client.DefaultHttpClient;
63
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080064import java.io.IOException;
65import java.net.UnknownHostException;
66import java.util.ArrayList;
67import java.util.List;
68
69public class RadioInfo extends Activity {
70 private final String TAG = "phone";
johnwang342101a2009-09-23 16:22:34 -070071
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080072 private static final int EVENT_PHONE_STATE_CHANGED = 100;
73 private static final int EVENT_SIGNAL_STRENGTH_CHANGED = 200;
74 private static final int EVENT_SERVICE_STATE_CHANGED = 300;
75 private static final int EVENT_CFI_CHANGED = 302;
76
77 private static final int EVENT_QUERY_PREFERRED_TYPE_DONE = 1000;
78 private static final int EVENT_SET_PREFERRED_TYPE_DONE = 1001;
79 private static final int EVENT_QUERY_NEIGHBORING_CIDS_DONE = 1002;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080080 private static final int EVENT_QUERY_SMSC_DONE = 1005;
81 private static final int EVENT_UPDATE_SMSC_DONE = 1006;
82
83 private static final int MENU_ITEM_SELECT_BAND = 0;
84 private static final int MENU_ITEM_VIEW_ADN = 1;
85 private static final int MENU_ITEM_VIEW_FDN = 2;
86 private static final int MENU_ITEM_VIEW_SDN = 3;
87 private static final int MENU_ITEM_GET_PDP_LIST = 4;
88 private static final int MENU_ITEM_TOGGLE_DATA = 5;
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +080089
90 static final String ENABLE_DATA_STR = "Enable data connection";
91 static final String DISABLE_DATA_STR = "Disable data connection";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080092
Wink Savillec3886682009-04-02 11:00:56 -070093 private TextView mDeviceId; //DeviceId is the IMEI in GSM and the MEID in CDMA
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080094 private TextView number;
95 private TextView callState;
96 private TextView operatorName;
97 private TextView roamingState;
98 private TextView gsmState;
99 private TextView gprsState;
100 private TextView network;
101 private TextView dBm;
102 private TextView mMwi;
103 private TextView mCfi;
104 private TextView mLocation;
105 private TextView mNeighboringCids;
Wink Saville79bff2a2012-06-01 14:37:21 -0700106 private TextView mCellInfo;
Wink Saville4f0d8812014-04-15 22:05:24 -0700107 private TextView mDcRtInfoTv;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800108 private TextView resets;
109 private TextView attempts;
110 private TextView successes;
111 private TextView disconnects;
112 private TextView sentSinceReceived;
113 private TextView sent;
114 private TextView received;
115 private TextView mPingIpAddr;
116 private TextView mPingHostname;
117 private TextView mHttpClientTest;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800118 private TextView dnsCheckState;
119 private EditText smsc;
120 private Button radioPowerButton;
Wink Savillebf471282013-04-05 15:04:05 -0700121 private Button cellInfoListRateButton;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800122 private Button dnsCheckToggleButton;
123 private Button pingTestButton;
124 private Button updateSmscButton;
125 private Button refreshSmscButton;
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800126 private Button oemInfoButton;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800127 private Spinner preferredNetworkType;
128
129 private TelephonyManager mTelephonyManager;
130 private Phone phone = null;
131 private PhoneStateIntentReceiver mPhoneStateReceiver;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800132
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800133 private String mPingIpAddrResult;
134 private String mPingHostnameResult;
135 private String mHttpClientTestResult;
136 private boolean mMwiValue = false;
137 private boolean mCfiValue = false;
Wink Saville79bff2a2012-06-01 14:37:21 -0700138 private List<CellInfo> mCellInfoValue;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800139
140 private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
141 @Override
142 public void onDataConnectionStateChanged(int state) {
143 updateDataState();
144 updateDataStats();
145 updatePdpList();
146 updateNetworkType();
147 }
148
149 @Override
150 public void onDataActivity(int direction) {
151 updateDataStats2();
152 }
153
154 @Override
155 public void onCellLocationChanged(CellLocation location) {
156 updateLocation(location);
157 }
158
159 @Override
160 public void onMessageWaitingIndicatorChanged(boolean mwi) {
161 mMwiValue = mwi;
162 updateMessageWaiting();
163 }
164
165 @Override
166 public void onCallForwardingIndicatorChanged(boolean cfi) {
167 mCfiValue = cfi;
168 updateCallRedirect();
169 }
Wink Saville79bff2a2012-06-01 14:37:21 -0700170
171 @Override
172 public void onCellInfoChanged(List<CellInfo> arrayCi) {
Wink Savillebf471282013-04-05 15:04:05 -0700173 log("onCellInfoChanged: arrayCi=" + arrayCi);
174 updateCellInfoTv(arrayCi);
Wink Saville79bff2a2012-06-01 14:37:21 -0700175 }
Wink Saville4f0d8812014-04-15 22:05:24 -0700176
177 @Override
178 public void onDataConnectionRealTimeInfoChanged(DataConnectionRealTimeInfo dcRtInfo) {
179 log("onDataConnectionRealTimeInfoChanged: dcRtInfo=" + dcRtInfo);
180 updateDcRtInfoTv(dcRtInfo);
181 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800182 };
183
184 private Handler mHandler = new Handler() {
185 public void handleMessage(Message msg) {
186 AsyncResult ar;
187 switch (msg.what) {
188 case EVENT_PHONE_STATE_CHANGED:
189 updatePhoneState();
190 break;
191
192 case EVENT_SIGNAL_STRENGTH_CHANGED:
193 updateSignalStrength();
194 break;
195
196 case EVENT_SERVICE_STATE_CHANGED:
197 updateServiceState();
198 updatePowerState();
199 break;
200
201 case EVENT_QUERY_PREFERRED_TYPE_DONE:
202 ar= (AsyncResult) msg.obj;
203 if (ar.exception == null) {
204 int type = ((int[])ar.result)[0];
Ricardo Cerqueira32310ee2012-04-12 23:34:38 +0100205 if (type >= mPreferredNetworkLabels.length) {
Wink Savillebf471282013-04-05 15:04:05 -0700206 log("EVENT_QUERY_PREFERRED_TYPE_DONE: unknown " +
Ricardo Cerqueira32310ee2012-04-12 23:34:38 +0100207 "type=" + type);
208 type = mPreferredNetworkLabels.length - 1;
209 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800210 preferredNetworkType.setSelection(type, true);
211 } else {
Ricardo Cerqueira32310ee2012-04-12 23:34:38 +0100212 preferredNetworkType.setSelection(mPreferredNetworkLabels.length - 1, true);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800213 }
214 break;
215 case EVENT_SET_PREFERRED_TYPE_DONE:
216 ar= (AsyncResult) msg.obj;
217 if (ar.exception != null) {
218 phone.getPreferredNetworkType(
219 obtainMessage(EVENT_QUERY_PREFERRED_TYPE_DONE));
220 }
221 break;
222 case EVENT_QUERY_NEIGHBORING_CIDS_DONE:
223 ar= (AsyncResult) msg.obj;
224 if (ar.exception == null) {
225 updateNeighboringCids((ArrayList<NeighboringCellInfo>)ar.result);
226 } else {
227 mNeighboringCids.setText("unknown");
228 }
229 break;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800230 case EVENT_QUERY_SMSC_DONE:
231 ar= (AsyncResult) msg.obj;
232 if (ar.exception != null) {
233 smsc.setText("refresh error");
234 } else {
jsh21dd4072009-05-12 11:26:55 -0700235 smsc.setText((String)ar.result);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800236 }
237 break;
238 case EVENT_UPDATE_SMSC_DONE:
239 updateSmscButton.setEnabled(true);
240 ar= (AsyncResult) msg.obj;
241 if (ar.exception != null) {
242 smsc.setText("update error");
243 }
244 break;
245 default:
246 break;
247
248 }
249 }
250 };
251
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800252 @Override
253 public void onCreate(Bundle icicle) {
254 super.onCreate(icicle);
255
256 setContentView(R.layout.radio_info);
257
258 mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
259 phone = PhoneFactory.getDefaultPhone();
260
Wink Savillec3886682009-04-02 11:00:56 -0700261 mDeviceId= (TextView) findViewById(R.id.imei);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800262 number = (TextView) findViewById(R.id.number);
263 callState = (TextView) findViewById(R.id.call);
264 operatorName = (TextView) findViewById(R.id.operator);
265 roamingState = (TextView) findViewById(R.id.roaming);
266 gsmState = (TextView) findViewById(R.id.gsm);
267 gprsState = (TextView) findViewById(R.id.gprs);
268 network = (TextView) findViewById(R.id.network);
269 dBm = (TextView) findViewById(R.id.dbm);
270 mMwi = (TextView) findViewById(R.id.mwi);
271 mCfi = (TextView) findViewById(R.id.cfi);
272 mLocation = (TextView) findViewById(R.id.location);
273 mNeighboringCids = (TextView) findViewById(R.id.neighboring);
Wink Saville79bff2a2012-06-01 14:37:21 -0700274 mCellInfo = (TextView) findViewById(R.id.cellinfo);
Wink Saville4f0d8812014-04-15 22:05:24 -0700275 mDcRtInfoTv = (TextView) findViewById(R.id.dcrtinfo);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800276
277 resets = (TextView) findViewById(R.id.resets);
278 attempts = (TextView) findViewById(R.id.attempts);
279 successes = (TextView) findViewById(R.id.successes);
280 disconnects = (TextView) findViewById(R.id.disconnects);
281 sentSinceReceived = (TextView) findViewById(R.id.sentSinceReceived);
282 sent = (TextView) findViewById(R.id.sent);
283 received = (TextView) findViewById(R.id.received);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800284 smsc = (EditText) findViewById(R.id.smsc);
285 dnsCheckState = (TextView) findViewById(R.id.dnsCheckState);
286
287 mPingIpAddr = (TextView) findViewById(R.id.pingIpAddr);
288 mPingHostname = (TextView) findViewById(R.id.pingHostname);
289 mHttpClientTest = (TextView) findViewById(R.id.httpClientTest);
290
291 preferredNetworkType = (Spinner) findViewById(R.id.preferredNetworkType);
292 ArrayAdapter<String> adapter = new ArrayAdapter<String> (this,
293 android.R.layout.simple_spinner_item, mPreferredNetworkLabels);
johnwang342101a2009-09-23 16:22:34 -0700294 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800295 preferredNetworkType.setAdapter(adapter);
296 preferredNetworkType.setOnItemSelectedListener(mPreferredNetworkHandler);
297
298 radioPowerButton = (Button) findViewById(R.id.radio_power);
299 radioPowerButton.setOnClickListener(mPowerButtonHandler);
300
Wink Savillebf471282013-04-05 15:04:05 -0700301 cellInfoListRateButton = (Button) findViewById(R.id.cell_info_list_rate);
302 cellInfoListRateButton.setOnClickListener(mCellInfoListRateHandler);
303
Wink Saville1e596f32011-09-19 14:24:39 -0700304 imsRegRequiredButton = (Button) findViewById(R.id.ims_reg_required);
305 imsRegRequiredButton.setOnClickListener(mImsRegRequiredHandler);
306
Wink Saville382a75b2011-09-22 15:17:00 -0700307 smsOverImsButton = (Button) findViewById(R.id.sms_over_ims);
308 smsOverImsButton.setOnClickListener(mSmsOverImsHandler);
309
Wink Saville426fc662011-09-25 14:39:02 -0700310 lteRamDumpButton = (Button) findViewById(R.id.lte_ram_dump);
311 lteRamDumpButton.setOnClickListener(mLteRamDumpHandler);
312
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800313 pingTestButton = (Button) findViewById(R.id.ping_test);
314 pingTestButton.setOnClickListener(mPingButtonHandler);
315 updateSmscButton = (Button) findViewById(R.id.update_smsc);
316 updateSmscButton.setOnClickListener(mUpdateSmscButtonHandler);
317 refreshSmscButton = (Button) findViewById(R.id.refresh_smsc);
318 refreshSmscButton.setOnClickListener(mRefreshSmscButtonHandler);
319 dnsCheckToggleButton = (Button) findViewById(R.id.dns_check_toggle);
320 dnsCheckToggleButton.setOnClickListener(mDnsCheckButtonHandler);
johnwang342101a2009-09-23 16:22:34 -0700321
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800322 oemInfoButton = (Button) findViewById(R.id.oem_info);
323 oemInfoButton.setOnClickListener(mOemInfoButtonHandler);
324 PackageManager pm = getPackageManager();
325 Intent oemInfoIntent = new Intent("com.android.settings.OEM_RADIO_INFO");
326 List<ResolveInfo> oemInfoIntentList = pm.queryIntentActivities(oemInfoIntent, 0);
327 if (oemInfoIntentList.size() == 0) {
328 oemInfoButton.setEnabled(false);
329 }
330
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800331 mPhoneStateReceiver = new PhoneStateIntentReceiver(this, mHandler);
332 mPhoneStateReceiver.notifySignalStrength(EVENT_SIGNAL_STRENGTH_CHANGED);
333 mPhoneStateReceiver.notifyServiceState(EVENT_SERVICE_STATE_CHANGED);
334 mPhoneStateReceiver.notifyPhoneCallState(EVENT_PHONE_STATE_CHANGED);
johnwang342101a2009-09-23 16:22:34 -0700335
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800336 phone.getPreferredNetworkType(
337 mHandler.obtainMessage(EVENT_QUERY_PREFERRED_TYPE_DONE));
338 phone.getNeighboringCids(
339 mHandler.obtainMessage(EVENT_QUERY_NEIGHBORING_CIDS_DONE));
340
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800341 CellLocation.requestLocationUpdate();
Wink Saville79bff2a2012-06-01 14:37:21 -0700342
343 // Get current cell info
344 mCellInfoValue = mTelephonyManager.getAllCellInfo();
Wink Savillebf471282013-04-05 15:04:05 -0700345 log("onCreate: mCellInfoValue=" + mCellInfoValue);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800346 }
347
348 @Override
349 protected void onResume() {
350 super.onResume();
351
352 updatePhoneState();
353 updateSignalStrength();
354 updateMessageWaiting();
355 updateCallRedirect();
356 updateServiceState();
357 updateLocation(mTelephonyManager.getCellLocation());
358 updateDataState();
359 updateDataStats();
360 updateDataStats2();
361 updatePowerState();
Wink Savillebf471282013-04-05 15:04:05 -0700362 updateCellInfoListRate();
Wink Saville1e596f32011-09-19 14:24:39 -0700363 updateImsRegRequiredState();
Wink Saville382a75b2011-09-22 15:17:00 -0700364 updateSmsOverImsState();
Wink Saville426fc662011-09-25 14:39:02 -0700365 updateLteRamDumpState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800366 updateProperties();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800367 updateDnsCheckState();
368
Wink Savillebf471282013-04-05 15:04:05 -0700369 log("onResume: register phone & data intents");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800370
371 mPhoneStateReceiver.registerIntent();
372 mTelephonyManager.listen(mPhoneStateListener,
373 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
374 | PhoneStateListener.LISTEN_DATA_ACTIVITY
375 | PhoneStateListener.LISTEN_CELL_LOCATION
376 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
Wink Saville79bff2a2012-06-01 14:37:21 -0700377 | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
Wink Saville4f0d8812014-04-15 22:05:24 -0700378 | PhoneStateListener.LISTEN_CELL_INFO
379 | PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800380 }
381
382 @Override
383 public void onPause() {
384 super.onPause();
385
Wink Savillebf471282013-04-05 15:04:05 -0700386 log("onPause: unregister phone & data intents");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800387
388 mPhoneStateReceiver.unregisterIntent();
389 mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
390 }
391
392 @Override
393 public boolean onCreateOptionsMenu(Menu menu) {
Wink Savillec3886682009-04-02 11:00:56 -0700394 menu.add(0, MENU_ITEM_SELECT_BAND, 0, R.string.radio_info_band_mode_label)
395 .setOnMenuItemClickListener(mSelectBandCallback)
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800396 .setAlphabeticShortcut('b');
397 menu.add(1, MENU_ITEM_VIEW_ADN, 0,
398 R.string.radioInfo_menu_viewADN).setOnMenuItemClickListener(mViewADNCallback);
399 menu.add(1, MENU_ITEM_VIEW_FDN, 0,
400 R.string.radioInfo_menu_viewFDN).setOnMenuItemClickListener(mViewFDNCallback);
401 menu.add(1, MENU_ITEM_VIEW_SDN, 0,
402 R.string.radioInfo_menu_viewSDN).setOnMenuItemClickListener(mViewSDNCallback);
403 menu.add(1, MENU_ITEM_GET_PDP_LIST,
404 0, R.string.radioInfo_menu_getPDP).setOnMenuItemClickListener(mGetPdpList);
405 menu.add(1, MENU_ITEM_TOGGLE_DATA,
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800406 0, DISABLE_DATA_STR).setOnMenuItemClickListener(mToggleData);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800407 return true;
408 }
409
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800410 @Override
Wink Savillec3886682009-04-02 11:00:56 -0700411 public boolean onPrepareOptionsMenu(Menu menu) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800412 // Get the TOGGLE DATA menu item in the right state.
413 MenuItem item = menu.findItem(MENU_ITEM_TOGGLE_DATA);
414 int state = mTelephonyManager.getDataState();
415 boolean visible = true;
416
417 switch (state) {
418 case TelephonyManager.DATA_CONNECTED:
419 case TelephonyManager.DATA_SUSPENDED:
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800420 item.setTitle(DISABLE_DATA_STR);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800421 break;
422 case TelephonyManager.DATA_DISCONNECTED:
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800423 item.setTitle(ENABLE_DATA_STR);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800424 break;
425 default:
426 visible = false;
427 break;
428 }
429 item.setVisible(visible);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800430 return true;
431 }
432
433 private boolean isRadioOn() {
434 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
435 }
johnwang342101a2009-09-23 16:22:34 -0700436
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800437 private void updatePowerState() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800438 String buttonText = isRadioOn() ?
439 getString(R.string.turn_off_radio) :
440 getString(R.string.turn_on_radio);
Wink Savillec3886682009-04-02 11:00:56 -0700441 radioPowerButton.setText(buttonText);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800442 }
443
Wink Savillebf471282013-04-05 15:04:05 -0700444 private void updateCellInfoListRate() {
445 cellInfoListRateButton.setText("CellInfoListRate " + mCellInfoListRateHandler.getRate());
446 updateCellInfoTv(mTelephonyManager.getAllCellInfo());
447 }
448
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800449 private void updateDnsCheckState() {
Mike Lockwood5304c7e2009-04-05 11:37:45 -0700450 dnsCheckState.setText(phone.isDnsCheckDisabled() ?
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800451 "0.0.0.0 allowed" :"0.0.0.0 not allowed");
452 }
Wink Savillee2a14e32009-05-29 14:06:30 -0700453
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800454 private final void
455 updateSignalStrength() {
Wink Savillee2a14e32009-05-29 14:06:30 -0700456 // TODO PhoneStateIntentReceiver is deprecated and PhoneStateListener
457 // should probably used instead.
458 int state = mPhoneStateReceiver.getServiceState().getState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800459 Resources r = getResources();
460
461 if ((ServiceState.STATE_OUT_OF_SERVICE == state) ||
462 (ServiceState.STATE_POWER_OFF == state)) {
463 dBm.setText("0");
464 }
Wink Savillee2a14e32009-05-29 14:06:30 -0700465
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800466 int signalDbm = mPhoneStateReceiver.getSignalStrengthDbm();
Wink Savillee2a14e32009-05-29 14:06:30 -0700467
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800468 if (-1 == signalDbm) signalDbm = 0;
469
Wink Saville882c74a2011-02-17 12:00:03 -0800470 int signalAsu = mPhoneStateReceiver.getSignalStrengthLevelAsu();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800471
472 if (-1 == signalAsu) signalAsu = 0;
473
474 dBm.setText(String.valueOf(signalDbm) + " "
475 + r.getString(R.string.radioInfo_display_dbm) + " "
476 + String.valueOf(signalAsu) + " "
477 + r.getString(R.string.radioInfo_display_asu));
478 }
479
480 private final void updateLocation(CellLocation location) {
jsh534f5ae2009-09-24 09:19:22 -0700481 Resources r = getResources();
Wink Savillec3886682009-04-02 11:00:56 -0700482 if (location instanceof GsmCellLocation) {
483 GsmCellLocation loc = (GsmCellLocation)location;
jsh534f5ae2009-09-24 09:19:22 -0700484 int lac = loc.getLac();
485 int cid = loc.getCid();
486 mLocation.setText(r.getString(R.string.radioInfo_lac) + " = "
487 + ((lac == -1) ? "unknown" : Integer.toHexString(lac))
488 + " "
489 + r.getString(R.string.radioInfo_cid) + " = "
490 + ((cid == -1) ? "unknown" : Integer.toHexString(cid)));
491 } else if (location instanceof CdmaCellLocation) {
492 CdmaCellLocation loc = (CdmaCellLocation)location;
493 int bid = loc.getBaseStationId();
494 int sid = loc.getSystemId();
495 int nid = loc.getNetworkId();
496 int lat = loc.getBaseStationLatitude();
497 int lon = loc.getBaseStationLongitude();
498 mLocation.setText("BID = "
499 + ((bid == -1) ? "unknown" : Integer.toHexString(bid))
500 + " "
501 + "SID = "
502 + ((sid == -1) ? "unknown" : Integer.toHexString(sid))
503 + " "
504 + "NID = "
505 + ((nid == -1) ? "unknown" : Integer.toHexString(nid))
506 + "\n"
507 + "LAT = "
508 + ((lat == -1) ? "unknown" : Integer.toHexString(lat))
509 + " "
510 + "LONG = "
511 + ((lon == -1) ? "unknown" : Integer.toHexString(lon)));
512 } else {
513 mLocation.setText("unknown");
Wink Savillec3886682009-04-02 11:00:56 -0700514 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800515
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800516
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800517 }
518
519 private final void updateNeighboringCids(ArrayList<NeighboringCellInfo> cids) {
johnwangf02c65f2009-09-25 17:26:54 -0700520 StringBuilder sb = new StringBuilder();
521
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800522 if (cids != null) {
523 if ( cids.isEmpty() ) {
johnwangf02c65f2009-09-25 17:26:54 -0700524 sb.append("no neighboring cells");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800525 } else {
526 for (NeighboringCellInfo cell : cids) {
johnwangf02c65f2009-09-25 17:26:54 -0700527 sb.append(cell.toString()).append(" ");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800528 }
529 }
530 } else {
johnwangf02c65f2009-09-25 17:26:54 -0700531 sb.append("unknown");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800532 }
johnwangf02c65f2009-09-25 17:26:54 -0700533 mNeighboringCids.setText(sb.toString());
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800534 }
535
Wink Savillebf471282013-04-05 15:04:05 -0700536 private final void updateCellInfoTv(List<CellInfo> arrayCi) {
537 mCellInfoValue = arrayCi;
Wink Saville79bff2a2012-06-01 14:37:21 -0700538 StringBuilder value = new StringBuilder();
539 if (mCellInfoValue != null) {
540 int index = 0;
541 for (CellInfo ci : mCellInfoValue) {
542 value.append('[');
543 value.append(index);
544 value.append("]=");
545 value.append(ci.toString());
546 if (++index < mCellInfoValue.size()) {
547 value.append("\n");
548 }
549 }
550 }
551 mCellInfo.setText(value.toString());
552 }
553
Wink Saville4f0d8812014-04-15 22:05:24 -0700554 private final void updateDcRtInfoTv(DataConnectionRealTimeInfo dcRtInfo) {
555 mDcRtInfoTv.setText(dcRtInfo.toString());
556 }
557
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800558 private final void
559 updateMessageWaiting() {
560 mMwi.setText(String.valueOf(mMwiValue));
561 }
562
563 private final void
564 updateCallRedirect() {
565 mCfi.setText(String.valueOf(mCfiValue));
566 }
567
568
569 private final void
570 updateServiceState() {
571 ServiceState serviceState = mPhoneStateReceiver.getServiceState();
572 int state = serviceState.getState();
573 Resources r = getResources();
574 String display = r.getString(R.string.radioInfo_unknown);
johnwang342101a2009-09-23 16:22:34 -0700575
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800576 switch (state) {
577 case ServiceState.STATE_IN_SERVICE:
578 display = r.getString(R.string.radioInfo_service_in);
579 break;
580 case ServiceState.STATE_OUT_OF_SERVICE:
581 case ServiceState.STATE_EMERGENCY_ONLY:
582 display = r.getString(R.string.radioInfo_service_emergency);
583 break;
584 case ServiceState.STATE_POWER_OFF:
585 display = r.getString(R.string.radioInfo_service_off);
586 break;
587 }
johnwang342101a2009-09-23 16:22:34 -0700588
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800589 gsmState.setText(display);
johnwang342101a2009-09-23 16:22:34 -0700590
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800591 if (serviceState.getRoaming()) {
592 roamingState.setText(R.string.radioInfo_roaming_in);
593 } else {
594 roamingState.setText(R.string.radioInfo_roaming_not);
595 }
596
597 operatorName.setText(serviceState.getOperatorAlphaLong());
598 }
599
600 private final void
601 updatePhoneState() {
Wink Saville55434042012-06-14 12:33:43 -0700602 PhoneConstants.State state = mPhoneStateReceiver.getPhoneState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800603 Resources r = getResources();
604 String display = r.getString(R.string.radioInfo_unknown);
605
606 switch (state) {
607 case IDLE:
608 display = r.getString(R.string.radioInfo_phone_idle);
609 break;
610 case RINGING:
611 display = r.getString(R.string.radioInfo_phone_ringing);
612 break;
613 case OFFHOOK:
614 display = r.getString(R.string.radioInfo_phone_offhook);
615 break;
616 }
617
618 callState.setText(display);
619 }
620
621 private final void
622 updateDataState() {
623 int state = mTelephonyManager.getDataState();
624 Resources r = getResources();
625 String display = r.getString(R.string.radioInfo_unknown);
626
627 switch (state) {
628 case TelephonyManager.DATA_CONNECTED:
629 display = r.getString(R.string.radioInfo_data_connected);
630 break;
631 case TelephonyManager.DATA_CONNECTING:
632 display = r.getString(R.string.radioInfo_data_connecting);
633 break;
634 case TelephonyManager.DATA_DISCONNECTED:
635 display = r.getString(R.string.radioInfo_data_disconnected);
636 break;
637 case TelephonyManager.DATA_SUSPENDED:
638 display = r.getString(R.string.radioInfo_data_suspended);
639 break;
640 }
johnwang342101a2009-09-23 16:22:34 -0700641
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800642 gprsState.setText(display);
643 }
644
645 private final void updateNetworkType() {
646 Resources r = getResources();
647 String display = SystemProperties.get(TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE,
648 r.getString(R.string.radioInfo_unknown));
649
650 network.setText(display);
651 }
652
653 private final void
654 updateProperties() {
655 String s;
656 Resources r = getResources();
657
658 s = phone.getDeviceId();
johnwang342101a2009-09-23 16:22:34 -0700659 if (s == null) s = r.getString(R.string.radioInfo_unknown);
Wink Savillec3886682009-04-02 11:00:56 -0700660 mDeviceId.setText(s);
johnwang342101a2009-09-23 16:22:34 -0700661
Wink Savillec3886682009-04-02 11:00:56 -0700662
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800663 s = phone.getLine1Number();
johnwang342101a2009-09-23 16:22:34 -0700664 if (s == null) s = r.getString(R.string.radioInfo_unknown);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800665 number.setText(s);
666 }
667
668 private final void updateDataStats() {
669 String s;
670
671 s = SystemProperties.get("net.gsm.radio-reset", "0");
672 resets.setText(s);
673
674 s = SystemProperties.get("net.gsm.attempt-gprs", "0");
675 attempts.setText(s);
676
677 s = SystemProperties.get("net.gsm.succeed-gprs", "0");
678 successes.setText(s);
679
680 //s = SystemProperties.get("net.gsm.disconnect", "0");
681 //disconnects.setText(s);
682
683 s = SystemProperties.get("net.ppp.reset-by-timeout", "0");
684 sentSinceReceived.setText(s);
685 }
686
687 private final void updateDataStats2() {
688 Resources r = getResources();
689
Jeff Sharkey93029862011-05-27 18:26:15 -0700690 long txPackets = TrafficStats.getMobileTxPackets();
691 long rxPackets = TrafficStats.getMobileRxPackets();
692 long txBytes = TrafficStats.getMobileTxBytes();
693 long rxBytes = TrafficStats.getMobileRxBytes();
johnwang342101a2009-09-23 16:22:34 -0700694
Jeff Sharkey93029862011-05-27 18:26:15 -0700695 String packets = r.getString(R.string.radioInfo_display_packets);
696 String bytes = r.getString(R.string.radioInfo_display_bytes);
johnwang342101a2009-09-23 16:22:34 -0700697
Jeff Sharkey93029862011-05-27 18:26:15 -0700698 sent.setText(txPackets + " " + packets + ", " + txBytes + " " + bytes);
699 received.setText(rxPackets + " " + packets + ", " + rxBytes + " " + bytes);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800700 }
701
702 /**
703 * Ping a IP address.
704 */
705 private final void pingIpAddr() {
706 try {
707 // This is hardcoded IP addr. This is for testing purposes.
708 // We would need to get rid of this before release.
709 String ipAddress = "74.125.47.104";
710 Process p = Runtime.getRuntime().exec("ping -c 1 " + ipAddress);
711 int status = p.waitFor();
712 if (status == 0) {
713 mPingIpAddrResult = "Pass";
714 } else {
715 mPingIpAddrResult = "Fail: IP addr not reachable";
716 }
717 } catch (IOException e) {
718 mPingIpAddrResult = "Fail: IOException";
719 } catch (InterruptedException e) {
720 mPingIpAddrResult = "Fail: InterruptedException";
721 }
722 }
723
724 /**
725 * Ping a host name
726 */
727 private final void pingHostname() {
728 try {
johnwang342101a2009-09-23 16:22:34 -0700729 Process p = Runtime.getRuntime().exec("ping -c 1 www.google.com");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800730 int status = p.waitFor();
731 if (status == 0) {
732 mPingHostnameResult = "Pass";
733 } else {
734 mPingHostnameResult = "Fail: Host unreachable";
735 }
736 } catch (UnknownHostException e) {
737 mPingHostnameResult = "Fail: Unknown Host";
738 } catch (IOException e) {
739 mPingHostnameResult= "Fail: IOException";
740 } catch (InterruptedException e) {
741 mPingHostnameResult = "Fail: InterruptedException";
742 }
743 }
744
745 /**
746 * This function checks for basic functionality of HTTP Client.
747 */
748 private void httpClientTest() {
749 HttpClient client = new DefaultHttpClient();
750 try {
751 HttpGet request = new HttpGet("http://www.google.com");
752 HttpResponse response = client.execute(request);
753 if (response.getStatusLine().getStatusCode() == 200) {
754 mHttpClientTestResult = "Pass";
755 } else {
756 mHttpClientTestResult = "Fail: Code: " + String.valueOf(response);
757 }
758 request.abort();
759 } catch (IOException e) {
760 mHttpClientTestResult = "Fail: IOException";
761 }
762 }
763
764 private void refreshSmsc() {
jsh21dd4072009-05-12 11:26:55 -0700765 phone.getSmscAddress(mHandler.obtainMessage(EVENT_QUERY_SMSC_DONE));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800766 }
767
768 private final void updatePingState() {
769 final Handler handler = new Handler();
770 // Set all to unknown since the threads will take a few secs to update.
771 mPingIpAddrResult = getResources().getString(R.string.radioInfo_unknown);
772 mPingHostnameResult = getResources().getString(R.string.radioInfo_unknown);
773 mHttpClientTestResult = getResources().getString(R.string.radioInfo_unknown);
774
775 mPingIpAddr.setText(mPingIpAddrResult);
776 mPingHostname.setText(mPingHostnameResult);
777 mHttpClientTest.setText(mHttpClientTestResult);
778
779 final Runnable updatePingResults = new Runnable() {
780 public void run() {
781 mPingIpAddr.setText(mPingIpAddrResult);
782 mPingHostname.setText(mPingHostnameResult);
783 mHttpClientTest.setText(mHttpClientTestResult);
784 }
785 };
786 Thread ipAddr = new Thread() {
787 @Override
788 public void run() {
789 pingIpAddr();
790 handler.post(updatePingResults);
791 }
792 };
793 ipAddr.start();
794
795 Thread hostname = new Thread() {
796 @Override
797 public void run() {
798 pingHostname();
799 handler.post(updatePingResults);
800 }
801 };
802 hostname.start();
803
804 Thread httpClient = new Thread() {
805 @Override
806 public void run() {
807 httpClientTest();
808 handler.post(updatePingResults);
809 }
810 };
811 httpClient.start();
812 }
813
814 private final void updatePdpList() {
815 StringBuilder sb = new StringBuilder("========DATA=======\n");
816
Wink Saville2c3ec092011-04-20 10:24:36 -0700817// List<DataConnection> dcs = phone.getCurrentDataConnectionList();
818//
819// for (DataConnection dc : dcs) {
820// sb.append(" State=").append(dc.getStateAsString()).append("\n");
821// if (dc.isActive()) {
822// long timeElapsed =
823// (System.currentTimeMillis() - dc.getConnectionTime())/1000;
824// sb.append(" connected at ")
825// .append(DateUtils.timeString(dc.getConnectionTime()))
826// .append(" and elapsed ")
827// .append(DateUtils.formatElapsedTime(timeElapsed));
828//
829// if (dc instanceof GsmDataConnection) {
830// GsmDataConnection pdp = (GsmDataConnection)dc;
831// sb.append("\n to ")
832// .append(pdp.getApn().toString());
833// }
834// sb.append("\nLinkProperties: ");
835// sb.append(phone.getLinkProperties(phone.getActiveApnTypes()[0]).toString());
836// } else if (dc.isInactive()) {
837// sb.append(" disconnected with last try at ")
838// .append(DateUtils.timeString(dc.getLastFailTime()))
839// .append("\n fail because ")
840// .append(dc.getLastFailCause().toString());
841// } else {
842// if (dc instanceof GsmDataConnection) {
843// GsmDataConnection pdp = (GsmDataConnection)dc;
844// sb.append(" is connecting to ")
845// .append(pdp.getApn().toString());
846// } else {
847// sb.append(" is connecting");
848// }
849// }
850// sb.append("\n===================");
851// }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800852
853 disconnects.setText(sb.toString());
854 }
855
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800856 private MenuItem.OnMenuItemClickListener mViewADNCallback = new MenuItem.OnMenuItemClickListener() {
857 public boolean onMenuItemClick(MenuItem item) {
858 Intent intent = new Intent(Intent.ACTION_VIEW);
859 // XXX We need to specify the component here because if we don't
860 // the activity manager will try to resolve the type by calling
861 // the content provider, which causes it to be loaded in a process
862 // other than the Dialer process, which causes a lot of stuff to
863 // break.
864 intent.setClassName("com.android.phone",
865 "com.android.phone.SimContacts");
866 startActivity(intent);
867 return true;
868 }
869 };
870
871 private MenuItem.OnMenuItemClickListener mViewFDNCallback = new MenuItem.OnMenuItemClickListener() {
872 public boolean onMenuItemClick(MenuItem item) {
873 Intent intent = new Intent(Intent.ACTION_VIEW);
874 // XXX We need to specify the component here because if we don't
875 // the activity manager will try to resolve the type by calling
876 // the content provider, which causes it to be loaded in a process
877 // other than the Dialer process, which causes a lot of stuff to
878 // break.
879 intent.setClassName("com.android.phone",
880 "com.android.phone.FdnList");
881 startActivity(intent);
882 return true;
883 }
884 };
885
886 private MenuItem.OnMenuItemClickListener mViewSDNCallback = new MenuItem.OnMenuItemClickListener() {
887 public boolean onMenuItemClick(MenuItem item) {
888 Intent intent = new Intent(
Wink Savillec3886682009-04-02 11:00:56 -0700889 Intent.ACTION_VIEW, Uri.parse("content://icc/sdn"));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800890 // XXX We need to specify the component here because if we don't
891 // the activity manager will try to resolve the type by calling
892 // the content provider, which causes it to be loaded in a process
893 // other than the Dialer process, which causes a lot of stuff to
894 // break.
895 intent.setClassName("com.android.phone",
896 "com.android.phone.ADNList");
897 startActivity(intent);
898 return true;
899 }
900 };
901
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800902 private MenuItem.OnMenuItemClickListener mGetPdpList = new MenuItem.OnMenuItemClickListener() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800903 public boolean onMenuItemClick(MenuItem item) {
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800904 phone.getDataCallList(null);
905 return true;
906 }
907 };
908
909 private MenuItem.OnMenuItemClickListener mSelectBandCallback = new MenuItem.OnMenuItemClickListener() {
910 public boolean onMenuItemClick(MenuItem item) {
911 Intent intent = new Intent();
912 intent.setClass(RadioInfo.this, BandMode.class);
913 startActivity(intent);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800914 return true;
915 }
916 };
johnwang342101a2009-09-23 16:22:34 -0700917
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800918 private MenuItem.OnMenuItemClickListener mToggleData = new MenuItem.OnMenuItemClickListener() {
919 public boolean onMenuItemClick(MenuItem item) {
Robert Greenwalt99be5002010-11-24 17:20:59 -0800920 ConnectivityManager cm =
921 (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800922 int state = mTelephonyManager.getDataState();
923 switch (state) {
924 case TelephonyManager.DATA_CONNECTED:
Robert Greenwalt99be5002010-11-24 17:20:59 -0800925 cm.setMobileDataEnabled(false);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800926 break;
927 case TelephonyManager.DATA_DISCONNECTED:
Robert Greenwalt99be5002010-11-24 17:20:59 -0800928 cm.setMobileDataEnabled(true);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800929 break;
930 default:
931 // do nothing
932 break;
933 }
934 return true;
935 }
936 };
937
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800938 OnClickListener mPowerButtonHandler = new OnClickListener() {
939 public void onClick(View v) {
940 //log("toggle radio power: currently " + (isRadioOn()?"on":"off"));
941 phone.setRadioPower(!isRadioOn());
942 }
943 };
944
Wink Savillebf471282013-04-05 15:04:05 -0700945 class CellInfoListRateHandler implements OnClickListener {
946 int rates[] = {Integer.MAX_VALUE, 0, 1000};
947 int index = 0;
948
949 public int getRate() {
950 return rates[index];
951 }
952
953 @Override
954 public void onClick(View v) {
955 index += 1;
956 if (index >= rates.length) {
957 index = 0;
958 }
959 phone.setCellInfoListRate(rates[index]);
960 updateCellInfoListRate();
961 }
962 }
963 CellInfoListRateHandler mCellInfoListRateHandler = new CellInfoListRateHandler();
964
Wink Saville426fc662011-09-25 14:39:02 -0700965 private Button imsRegRequiredButton;
966 static final String PROPERTY_IMS_REG_REQUIRED = "persist.radio.imsregrequired";
Wink Saville1e596f32011-09-19 14:24:39 -0700967 OnClickListener mImsRegRequiredHandler = new OnClickListener() {
968 @Override
969 public void onClick(View v) {
Wink Savillebf471282013-04-05 15:04:05 -0700970 log(String.format("toggle %s: currently %s",
Wink Saville426fc662011-09-25 14:39:02 -0700971 PROPERTY_IMS_REG_REQUIRED, (isImsRegRequired() ? "on":"off")));
Wink Saville1e596f32011-09-19 14:24:39 -0700972 boolean newValue = !isImsRegRequired();
Wink Saville426fc662011-09-25 14:39:02 -0700973 SystemProperties.set(PROPERTY_IMS_REG_REQUIRED,
Wink Saville1e596f32011-09-19 14:24:39 -0700974 newValue ? "1":"0");
975 updateImsRegRequiredState();
976 }
977 };
978
Wink Saville426fc662011-09-25 14:39:02 -0700979 private boolean isImsRegRequired() {
980 return SystemProperties.getBoolean(PROPERTY_IMS_REG_REQUIRED, false);
981 }
982
983 private void updateImsRegRequiredState() {
Wink Savillebf471282013-04-05 15:04:05 -0700984 log("updateImsRegRequiredState isImsRegRequired()=" + isImsRegRequired());
Wink Saville426fc662011-09-25 14:39:02 -0700985 String buttonText = isImsRegRequired() ?
986 getString(R.string.ims_reg_required_off) :
987 getString(R.string.ims_reg_required_on);
988 imsRegRequiredButton.setText(buttonText);
989 }
990
991 private Button smsOverImsButton;
Wink Saville382a75b2011-09-22 15:17:00 -0700992 static final String PROPERTY_SMS_OVER_IMS = "persist.radio.imsallowmtsms";
993 OnClickListener mSmsOverImsHandler = new OnClickListener() {
994 @Override
995 public void onClick(View v) {
Wink Savillebf471282013-04-05 15:04:05 -0700996 log(String.format("toggle %s: currently %s",
Wink Saville382a75b2011-09-22 15:17:00 -0700997 PROPERTY_SMS_OVER_IMS, (isSmsOverImsEnabled() ? "on":"off")));
998 boolean newValue = !isSmsOverImsEnabled();
999 SystemProperties.set(PROPERTY_SMS_OVER_IMS, newValue ? "1":"0");
1000 updateSmsOverImsState();
1001 }
1002 };
1003
Wink Saville426fc662011-09-25 14:39:02 -07001004 private boolean isSmsOverImsEnabled() {
1005 return SystemProperties.getBoolean(PROPERTY_SMS_OVER_IMS, false);
1006 }
1007
1008 private void updateSmsOverImsState() {
Wink Savillebf471282013-04-05 15:04:05 -07001009 log("updateSmsOverImsState isSmsOverImsEnabled()=" + isSmsOverImsEnabled());
Wink Saville426fc662011-09-25 14:39:02 -07001010 String buttonText = isSmsOverImsEnabled() ?
1011 getString(R.string.sms_over_ims_off) :
1012 getString(R.string.sms_over_ims_on);
1013 smsOverImsButton.setText(buttonText);
1014 }
1015
1016 private Button lteRamDumpButton;
1017 static final String PROPERTY_LTE_RAM_DUMP = "persist.radio.ramdump";
1018 OnClickListener mLteRamDumpHandler = new OnClickListener() {
1019 @Override
1020 public void onClick(View v) {
Wink Savillebf471282013-04-05 15:04:05 -07001021 log(String.format("toggle %s: currently %s",
Wink Saville426fc662011-09-25 14:39:02 -07001022 PROPERTY_LTE_RAM_DUMP, (isSmsOverImsEnabled() ? "on":"off")));
1023 boolean newValue = !isLteRamDumpEnabled();
1024 SystemProperties.set(PROPERTY_LTE_RAM_DUMP, newValue ? "1":"0");
1025 updateLteRamDumpState();
1026 }
1027 };
1028
1029 private boolean isLteRamDumpEnabled() {
1030 return SystemProperties.getBoolean(PROPERTY_LTE_RAM_DUMP, false);
1031 }
1032
1033 private void updateLteRamDumpState() {
Wink Savillebf471282013-04-05 15:04:05 -07001034 log("updateLteRamDumpState isLteRamDumpEnabled()=" + isLteRamDumpEnabled());
Wink Saville426fc662011-09-25 14:39:02 -07001035 String buttonText = isLteRamDumpEnabled() ?
1036 getString(R.string.lte_ram_dump_off) :
1037 getString(R.string.lte_ram_dump_on);
1038 lteRamDumpButton.setText(buttonText);
1039 }
1040
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001041 OnClickListener mDnsCheckButtonHandler = new OnClickListener() {
1042 public void onClick(View v) {
Wink Savillec3886682009-04-02 11:00:56 -07001043 phone.disableDnsCheck(!phone.isDnsCheckDisabled());
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001044 updateDnsCheckState();
1045 }
1046 };
johnwang342101a2009-09-23 16:22:34 -07001047
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001048 OnClickListener mOemInfoButtonHandler = new OnClickListener() {
1049 public void onClick(View v) {
1050 Intent intent = new Intent("com.android.settings.OEM_RADIO_INFO");
1051 try {
1052 startActivity(intent);
1053 } catch (android.content.ActivityNotFoundException ex) {
Wink Savillebf471282013-04-05 15:04:05 -07001054 log("OEM-specific Info/Settings Activity Not Found : " + ex);
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001055 // If the activity does not exist, there are no OEM
1056 // settings, and so we can just do nothing...
1057 }
1058 }
1059 };
1060
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001061 OnClickListener mPingButtonHandler = new OnClickListener() {
1062 public void onClick(View v) {
1063 updatePingState();
1064 }
1065 };
1066
1067 OnClickListener mUpdateSmscButtonHandler = new OnClickListener() {
1068 public void onClick(View v) {
1069 updateSmscButton.setEnabled(false);
jsh21dd4072009-05-12 11:26:55 -07001070 phone.setSmscAddress(smsc.getText().toString(),
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001071 mHandler.obtainMessage(EVENT_UPDATE_SMSC_DONE));
1072 }
1073 };
1074
1075 OnClickListener mRefreshSmscButtonHandler = new OnClickListener() {
1076 public void onClick(View v) {
1077 refreshSmsc();
1078 }
1079 };
1080
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001081 AdapterView.OnItemSelectedListener
1082 mPreferredNetworkHandler = new AdapterView.OnItemSelectedListener() {
1083 public void onItemSelected(AdapterView parent, View v, int pos, long id) {
1084 Message msg = mHandler.obtainMessage(EVENT_SET_PREFERRED_TYPE_DONE);
Ricardo Cerqueira32310ee2012-04-12 23:34:38 +01001085 if (pos>=0 && pos<=(mPreferredNetworkLabels.length - 2)) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001086 phone.setPreferredNetworkType(pos, msg);
1087 }
1088 }
1089
1090 public void onNothingSelected(AdapterView parent) {
1091 }
1092 };
1093
1094 private String[] mPreferredNetworkLabels = {
jsh87fa11b2009-08-18 18:00:15 -07001095 "WCDMA preferred",
1096 "GSM only",
1097 "WCDMA only",
1098 "GSM auto (PRL)",
1099 "CDMA auto (PRL)",
1100 "CDMA only",
1101 "EvDo only",
1102 "GSM/CDMA auto (PRL)",
Ricardo Cerqueira32310ee2012-04-12 23:34:38 +01001103 "LTE/CDMA auto (PRL)",
1104 "LTE/GSM auto (PRL)",
1105 "LTE/GSM/CDMA auto (PRL)",
1106 "LTE only",
jsh87fa11b2009-08-18 18:00:15 -07001107 "Unknown"};
Wink Savillebf471282013-04-05 15:04:05 -07001108
1109 private void log(String s) {
1110 Log.d(TAG, "[RadioInfo] " + s);
1111 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001112}