The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame^] | 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.AlertDialog; |
| 21 | import android.content.DialogInterface; |
| 22 | import android.content.Intent; |
| 23 | import android.content.SharedPreferences; |
| 24 | import android.content.res.Resources; |
| 25 | import android.net.Uri; |
| 26 | import android.os.AsyncResult; |
| 27 | import android.os.Bundle; |
| 28 | import android.os.Handler; |
| 29 | import android.os.INetStatService; |
| 30 | import android.os.Message; |
| 31 | import android.os.RemoteException; |
| 32 | import android.os.ServiceManager; |
| 33 | import android.os.SystemProperties; |
| 34 | import android.pim.DateUtils; |
| 35 | import android.preference.PreferenceManager; |
| 36 | import android.telephony.CellLocation; |
| 37 | import android.telephony.PhoneStateListener; |
| 38 | import android.telephony.ServiceState; |
| 39 | import android.telephony.TelephonyManager; |
| 40 | import android.telephony.gsm.GsmCellLocation; |
| 41 | import android.util.Log; |
| 42 | import android.view.Menu; |
| 43 | import android.view.MenuItem; |
| 44 | import android.view.View; |
| 45 | import android.view.View.OnClickListener; |
| 46 | import android.widget.AdapterView; |
| 47 | import android.widget.ArrayAdapter; |
| 48 | import android.widget.Button; |
| 49 | import android.widget.Spinner; |
| 50 | import android.widget.TextView; |
| 51 | import android.widget.EditText; |
| 52 | |
| 53 | import com.android.internal.telephony.Phone; |
| 54 | import com.android.internal.telephony.PhoneFactory; |
| 55 | import com.android.internal.telephony.PhoneStateIntentReceiver; |
| 56 | import com.android.internal.telephony.TelephonyProperties; |
| 57 | import com.android.internal.telephony.gsm.GSMPhone; |
| 58 | import com.android.internal.telephony.gsm.PdpConnection; |
| 59 | |
| 60 | import org.apache.http.HttpResponse; |
| 61 | import org.apache.http.client.HttpClient; |
| 62 | import org.apache.http.client.methods.HttpGet; |
| 63 | import org.apache.http.impl.client.DefaultHttpClient; |
| 64 | |
| 65 | import java.io.ByteArrayOutputStream; |
| 66 | import java.io.DataOutputStream; |
| 67 | import java.io.IOException; |
| 68 | import java.net.UnknownHostException; |
| 69 | import java.util.List; |
| 70 | |
| 71 | public class RadioInfo extends Activity { |
| 72 | private final String TAG = "phone"; |
| 73 | |
| 74 | private static final int EVENT_PHONE_STATE_CHANGED = 100; |
| 75 | private static final int EVENT_SIGNAL_STRENGTH_CHANGED = 200; |
| 76 | private static final int EVENT_SERVICE_STATE_CHANGED = 300; |
| 77 | private static final int EVENT_CFI_CHANGED = 302; |
| 78 | |
| 79 | private static final int EVENT_QUERY_PREFERRED_TYPE_DONE = 1000; |
| 80 | private static final int EVENT_SET_PREFERRED_TYPE_DONE = 1001; |
| 81 | private static final int EVENT_QUERY_NEIGHBORING_CIDS_DONE = 1002; |
| 82 | private static final int EVENT_SET_QXDMLOG_DONE = 1003; |
| 83 | private static final int EVENT_SET_CIPHER_DONE = 1004; |
| 84 | private static final int EVENT_QUERY_SMSC_DONE = 1005; |
| 85 | private static final int EVENT_UPDATE_SMSC_DONE = 1006; |
| 86 | |
| 87 | private static final int MENU_ITEM_SELECT_BAND = 0; |
| 88 | private static final int MENU_ITEM_VIEW_ADN = 1; |
| 89 | private static final int MENU_ITEM_VIEW_FDN = 2; |
| 90 | private static final int MENU_ITEM_VIEW_SDN = 3; |
| 91 | private static final int MENU_ITEM_GET_PDP_LIST = 4; |
| 92 | private static final int MENU_ITEM_TOGGLE_DATA = 5; |
| 93 | private static final int MENU_ITEM_TOGGLE_DATA_ON_BOOT = 6; |
| 94 | |
| 95 | private TextView mImei; |
| 96 | private TextView mImsi; |
| 97 | private TextView number; |
| 98 | private TextView callState; |
| 99 | private TextView operatorName; |
| 100 | private TextView roamingState; |
| 101 | private TextView gsmState; |
| 102 | private TextView gprsState; |
| 103 | private TextView network; |
| 104 | private TextView dBm; |
| 105 | private TextView mMwi; |
| 106 | private TextView mCfi; |
| 107 | private TextView mLocation; |
| 108 | private TextView mNeighboringCids; |
| 109 | private TextView resets; |
| 110 | private TextView attempts; |
| 111 | private TextView successes; |
| 112 | private TextView disconnects; |
| 113 | private TextView sentSinceReceived; |
| 114 | private TextView sent; |
| 115 | private TextView received; |
| 116 | private TextView mPingIpAddr; |
| 117 | private TextView mPingHostname; |
| 118 | private TextView mHttpClientTest; |
| 119 | private TextView cipherState; |
| 120 | private EditText smsc; |
| 121 | private Button radioPowerButton; |
| 122 | private Button qxdmLogButton; |
| 123 | private Button cipherToggleButton; |
| 124 | private Button pingTestButton; |
| 125 | private Button updateSmscButton; |
| 126 | private Button refreshSmscButton; |
| 127 | private Spinner preferredNetworkType; |
| 128 | |
| 129 | private TelephonyManager mTelephonyManager; |
| 130 | private Phone phone = null; |
| 131 | private PhoneStateIntentReceiver mPhoneStateReceiver; |
| 132 | private INetStatService netstat; |
| 133 | |
| 134 | private OemCommands mOem = null; |
| 135 | private boolean mQxdmLogEnabled; |
| 136 | // The requested cipher state |
| 137 | private boolean mCipherOn; |
| 138 | |
| 139 | private String mPingIpAddrResult; |
| 140 | private String mPingHostnameResult; |
| 141 | private String mHttpClientTestResult; |
| 142 | private boolean mMwiValue = false; |
| 143 | private boolean mCfiValue = false; |
| 144 | |
| 145 | private PhoneStateListener mPhoneStateListener = new PhoneStateListener() { |
| 146 | @Override |
| 147 | public void onDataConnectionStateChanged(int state) { |
| 148 | updateDataState(); |
| 149 | updateDataStats(); |
| 150 | updatePdpList(); |
| 151 | updateNetworkType(); |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public void onDataActivity(int direction) { |
| 156 | updateDataStats2(); |
| 157 | } |
| 158 | |
| 159 | @Override |
| 160 | public void onCellLocationChanged(CellLocation location) { |
| 161 | updateLocation(location); |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public void onMessageWaitingIndicatorChanged(boolean mwi) { |
| 166 | mMwiValue = mwi; |
| 167 | updateMessageWaiting(); |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public void onCallForwardingIndicatorChanged(boolean cfi) { |
| 172 | mCfiValue = cfi; |
| 173 | updateCallRedirect(); |
| 174 | } |
| 175 | }; |
| 176 | |
| 177 | private Handler mHandler = new Handler() { |
| 178 | public void handleMessage(Message msg) { |
| 179 | AsyncResult ar; |
| 180 | switch (msg.what) { |
| 181 | case EVENT_PHONE_STATE_CHANGED: |
| 182 | updatePhoneState(); |
| 183 | break; |
| 184 | |
| 185 | case EVENT_SIGNAL_STRENGTH_CHANGED: |
| 186 | updateSignalStrength(); |
| 187 | break; |
| 188 | |
| 189 | case EVENT_SERVICE_STATE_CHANGED: |
| 190 | updateServiceState(); |
| 191 | updatePowerState(); |
| 192 | break; |
| 193 | |
| 194 | case EVENT_QUERY_PREFERRED_TYPE_DONE: |
| 195 | ar= (AsyncResult) msg.obj; |
| 196 | if (ar.exception == null) { |
| 197 | int type = ((int[])ar.result)[0]; |
| 198 | preferredNetworkType.setSelection(type, true); |
| 199 | } else { |
| 200 | preferredNetworkType.setSelection(3, true); |
| 201 | } |
| 202 | break; |
| 203 | case EVENT_SET_PREFERRED_TYPE_DONE: |
| 204 | ar= (AsyncResult) msg.obj; |
| 205 | if (ar.exception != null) { |
| 206 | phone.getPreferredNetworkType( |
| 207 | obtainMessage(EVENT_QUERY_PREFERRED_TYPE_DONE)); |
| 208 | } |
| 209 | break; |
| 210 | case EVENT_QUERY_NEIGHBORING_CIDS_DONE: |
| 211 | ar= (AsyncResult) msg.obj; |
| 212 | if (ar.exception == null) { |
| 213 | updateNeighboringCids((String[])ar.result); |
| 214 | } else { |
| 215 | mNeighboringCids.setText("unknown"); |
| 216 | } |
| 217 | break; |
| 218 | case EVENT_SET_QXDMLOG_DONE: |
| 219 | ar= (AsyncResult) msg.obj; |
| 220 | if (ar.exception == null) { |
| 221 | mQxdmLogEnabled = !mQxdmLogEnabled; |
| 222 | |
| 223 | updateQxdmState(mQxdmLogEnabled); |
| 224 | displayQxdmEnableResult(); |
| 225 | } |
| 226 | break; |
| 227 | case EVENT_SET_CIPHER_DONE: |
| 228 | ar= (AsyncResult) msg.obj; |
| 229 | if (ar.exception == null) { |
| 230 | setCiphPref(mCipherOn); |
| 231 | } |
| 232 | updateCiphState(); |
| 233 | break; |
| 234 | case EVENT_QUERY_SMSC_DONE: |
| 235 | ar= (AsyncResult) msg.obj; |
| 236 | if (ar.exception != null) { |
| 237 | smsc.setText("refresh error"); |
| 238 | } else { |
| 239 | byte[] buf = (byte[]) ar.result; |
| 240 | smsc.setText(new String(buf)); |
| 241 | } |
| 242 | break; |
| 243 | case EVENT_UPDATE_SMSC_DONE: |
| 244 | updateSmscButton.setEnabled(true); |
| 245 | ar= (AsyncResult) msg.obj; |
| 246 | if (ar.exception != null) { |
| 247 | smsc.setText("update error"); |
| 248 | } |
| 249 | break; |
| 250 | default: |
| 251 | break; |
| 252 | |
| 253 | } |
| 254 | } |
| 255 | }; |
| 256 | |
| 257 | private class OemCommands { |
| 258 | |
| 259 | public final int OEM_QXDM_SDLOG_DEFAULT_FILE_SIZE = 32; |
| 260 | public final int OEM_QXDM_SDLOG_DEFAULT_MASK = 0; |
| 261 | public final int OEM_QXDM_SDLOG_DEFAULT_MAX_INDEX = 8; |
| 262 | |
| 263 | final int SIZE_OF_INT = 4; |
| 264 | final int OEM_FEATURE_ENABLE = 1; |
| 265 | final int OEM_FEATURE_DISABLE = 0; |
| 266 | final int OEM_SIMPE_FEAUTURE_LEN = 1; |
| 267 | |
| 268 | final int OEM_QXDM_SDLOG_FUNCTAG = 0x00010000; |
| 269 | final int OEM_QXDM_SDLOG_LEN = 4; |
| 270 | final int OEM_PS_AUTO_ATTACH_FUNCTAG = 0x00020000; |
| 271 | final int OEM_CIPHERING_FUNCTAG = 0x00020001; |
| 272 | final int OEM_SMSC_UPDATE_FUNCTAG = 0x00020002; |
| 273 | final int OEM_SMSC_QUERY_FUNCTAG = 0x00020003; |
| 274 | final int OEM_SMSC_QUERY_LEN = 0; |
| 275 | |
| 276 | /** |
| 277 | * The OEM interface to store QXDM to SD. |
| 278 | * |
| 279 | * To start/stop logging QXDM logs to SD card, use tag |
| 280 | * OEM_RIL_HOOK_QXDM_SD_LOG_SETUP 0x00010000 |
| 281 | * |
| 282 | * "data" is a const oem_ril_hook_qxdm_sdlog_setup_data_st * |
| 283 | * ((const oem_ril_hook_qxdm_sdlog_setup_data_st *)data)->head.func_tag |
| 284 | * should be OEM_RIL_HOOK_QXDM_SD_LOG_SETUP |
| 285 | * ((const oem_ril_hook_qxdm_sdlog_setup_data_st *)data)->head.len |
| 286 | * should be "sizeof(unsigned int) * 4" |
| 287 | * ((const oem_ril_hook_qxdm_sdlog_setup_data_st *)data)->mode |
| 288 | * could be 0 for 'stop logging', or 1 for 'start logging' |
| 289 | * ((const oem_ril_hook_qxdm_sdlog_setup_data_st *)data)->log_file_size |
| 290 | * will assign the size of each log file, and it could be a value between |
| 291 | * 1 and 512 (in megabytes, default value is recommended to set as 32). |
| 292 | * This value will be ignored when mode == 0. |
| 293 | * ((const oem_ril_hook_qxdm_sdlog_setup_data_st *)data)->log_mask will |
| 294 | * assign the rule to filter logs, and it is a bitmask (bit0 is for MsgAll, |
| 295 | * bit1 is for LogAll, and bit2 is for EventAll) recommended to be set as 0 |
| 296 | * by default. This value will be ignored when mode == 0. |
| 297 | * ((const oem_ril_hook_qxdm_sdlog_setup_data_st *)data)->log_max_fileindex |
| 298 | * set the how many logfiles will storted before roll over. This value will |
| 299 | * be ignored when mode == 0. |
| 300 | * |
| 301 | * "response" is NULL |
| 302 | * |
| 303 | * typedef struct _oem_ril_hook_raw_head_st { |
| 304 | * unsigned int func_tag; |
| 305 | * unsigned int len; |
| 306 | * } oem_ril_hook_raw_head_st; |
| 307 | * |
| 308 | * typedef struct _oem_ril_hook_qxdm_sdlog_setup_data_st { |
| 309 | * oem_ril_hook_raw_head_st head; |
| 310 | * unsigned int mode; |
| 311 | * unsigned int log_file_size; |
| 312 | * unsigned int log_mask; |
| 313 | * unsigned int log_max_fileindex; |
| 314 | * } oem_ril_hook_qxdm_sdlog_setup_data_st; |
| 315 | * |
| 316 | * @param enable set true to start logging QXDM in SD card |
| 317 | * @param fileSize is the log file size in MB |
| 318 | * @param mask is the log mask to filter |
| 319 | * @param maxIndex is the maximum roll-over file number |
| 320 | * @return byteArray to use in RIL RAW command |
| 321 | */ |
| 322 | byte[] getQxdmSdlogData(boolean enable, int fileSize, int mask, int maxIndex) { |
| 323 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
| 324 | DataOutputStream dos = new DataOutputStream(bos); |
| 325 | try { |
| 326 | writeIntLittleEndian(dos, OEM_QXDM_SDLOG_FUNCTAG); |
| 327 | writeIntLittleEndian(dos, OEM_QXDM_SDLOG_LEN * SIZE_OF_INT); |
| 328 | writeIntLittleEndian(dos, enable ? |
| 329 | OEM_FEATURE_ENABLE : OEM_FEATURE_DISABLE); |
| 330 | writeIntLittleEndian(dos, fileSize); |
| 331 | writeIntLittleEndian(dos, mask); |
| 332 | writeIntLittleEndian(dos, maxIndex); |
| 333 | } catch (IOException e) { |
| 334 | return null; |
| 335 | } |
| 336 | return bos.toByteArray(); |
| 337 | } |
| 338 | |
| 339 | byte[] getSmscQueryData() { |
| 340 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
| 341 | DataOutputStream dos = new DataOutputStream(bos); |
| 342 | try { |
| 343 | writeIntLittleEndian(dos, OEM_SMSC_QUERY_FUNCTAG); |
| 344 | writeIntLittleEndian(dos, OEM_SMSC_QUERY_LEN * SIZE_OF_INT); |
| 345 | } catch (IOException e) { |
| 346 | return null; |
| 347 | } |
| 348 | return bos.toByteArray(); |
| 349 | } |
| 350 | |
| 351 | byte[] getSmscUpdateData(String smsc) { |
| 352 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
| 353 | DataOutputStream dos = new DataOutputStream(bos); |
| 354 | try { |
| 355 | byte[] smsc_bytes = smsc.getBytes(); |
| 356 | writeIntLittleEndian(dos, OEM_SMSC_UPDATE_FUNCTAG); |
| 357 | writeIntLittleEndian(dos, smsc_bytes.length); |
| 358 | dos.write(smsc_bytes); |
| 359 | } catch (IOException e) { |
| 360 | return null; |
| 361 | } |
| 362 | return bos.toByteArray(); |
| 363 | } |
| 364 | |
| 365 | byte[] getPsAutoAttachData(boolean enable) { |
| 366 | return getSimpleFeatureData(OEM_PS_AUTO_ATTACH_FUNCTAG, enable); |
| 367 | } |
| 368 | |
| 369 | byte[] getCipheringData(boolean enable) { |
| 370 | return getSimpleFeatureData(OEM_CIPHERING_FUNCTAG, enable); |
| 371 | } |
| 372 | |
| 373 | private byte[] getSimpleFeatureData(int tag, boolean enable) { |
| 374 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
| 375 | DataOutputStream dos = new DataOutputStream(bos); |
| 376 | try { |
| 377 | writeIntLittleEndian(dos, tag); |
| 378 | writeIntLittleEndian(dos, OEM_SIMPE_FEAUTURE_LEN * SIZE_OF_INT); |
| 379 | writeIntLittleEndian(dos, enable ? |
| 380 | OEM_FEATURE_ENABLE : OEM_FEATURE_DISABLE); |
| 381 | } catch (IOException e) { |
| 382 | return null; |
| 383 | } |
| 384 | return bos.toByteArray(); |
| 385 | } |
| 386 | |
| 387 | private void writeIntLittleEndian(DataOutputStream dos, int val) |
| 388 | throws IOException { |
| 389 | dos.writeByte(val); |
| 390 | dos.writeByte(val >> 8); |
| 391 | dos.writeByte(val >> 16); |
| 392 | dos.writeByte(val >> 24); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | @Override |
| 397 | public void onCreate(Bundle icicle) { |
| 398 | super.onCreate(icicle); |
| 399 | |
| 400 | setContentView(R.layout.radio_info); |
| 401 | |
| 402 | mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); |
| 403 | phone = PhoneFactory.getDefaultPhone(); |
| 404 | |
| 405 | mImei = (TextView) findViewById(R.id.imei); |
| 406 | mImsi = (TextView) findViewById(R.id.imsi); |
| 407 | number = (TextView) findViewById(R.id.number); |
| 408 | callState = (TextView) findViewById(R.id.call); |
| 409 | operatorName = (TextView) findViewById(R.id.operator); |
| 410 | roamingState = (TextView) findViewById(R.id.roaming); |
| 411 | gsmState = (TextView) findViewById(R.id.gsm); |
| 412 | gprsState = (TextView) findViewById(R.id.gprs); |
| 413 | network = (TextView) findViewById(R.id.network); |
| 414 | dBm = (TextView) findViewById(R.id.dbm); |
| 415 | mMwi = (TextView) findViewById(R.id.mwi); |
| 416 | mCfi = (TextView) findViewById(R.id.cfi); |
| 417 | mLocation = (TextView) findViewById(R.id.location); |
| 418 | mNeighboringCids = (TextView) findViewById(R.id.neighboring); |
| 419 | |
| 420 | resets = (TextView) findViewById(R.id.resets); |
| 421 | attempts = (TextView) findViewById(R.id.attempts); |
| 422 | successes = (TextView) findViewById(R.id.successes); |
| 423 | disconnects = (TextView) findViewById(R.id.disconnects); |
| 424 | sentSinceReceived = (TextView) findViewById(R.id.sentSinceReceived); |
| 425 | sent = (TextView) findViewById(R.id.sent); |
| 426 | received = (TextView) findViewById(R.id.received); |
| 427 | cipherState = (TextView) findViewById(R.id.ciphState); |
| 428 | smsc = (EditText) findViewById(R.id.smsc); |
| 429 | |
| 430 | mPingIpAddr = (TextView) findViewById(R.id.pingIpAddr); |
| 431 | mPingHostname = (TextView) findViewById(R.id.pingHostname); |
| 432 | mHttpClientTest = (TextView) findViewById(R.id.httpClientTest); |
| 433 | |
| 434 | preferredNetworkType = (Spinner) findViewById(R.id.preferredNetworkType); |
| 435 | ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, |
| 436 | android.R.layout.simple_spinner_item, mPreferredNetworkLabels); |
| 437 | adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
| 438 | preferredNetworkType.setAdapter(adapter); |
| 439 | preferredNetworkType.setOnItemSelectedListener(mPreferredNetworkHandler); |
| 440 | |
| 441 | radioPowerButton = (Button) findViewById(R.id.radio_power); |
| 442 | radioPowerButton.setOnClickListener(mPowerButtonHandler); |
| 443 | |
| 444 | qxdmLogButton = (Button) findViewById(R.id.qxdm_log); |
| 445 | qxdmLogButton.setOnClickListener(mQxdmButtonHandler); |
| 446 | |
| 447 | cipherToggleButton = (Button) findViewById(R.id.ciph_toggle); |
| 448 | cipherToggleButton.setOnClickListener(mCipherButtonHandler); |
| 449 | pingTestButton = (Button) findViewById(R.id.ping_test); |
| 450 | pingTestButton.setOnClickListener(mPingButtonHandler); |
| 451 | updateSmscButton = (Button) findViewById(R.id.update_smsc); |
| 452 | updateSmscButton.setOnClickListener(mUpdateSmscButtonHandler); |
| 453 | refreshSmscButton = (Button) findViewById(R.id.refresh_smsc); |
| 454 | refreshSmscButton.setOnClickListener(mRefreshSmscButtonHandler); |
| 455 | |
| 456 | mPhoneStateReceiver = new PhoneStateIntentReceiver(this, mHandler); |
| 457 | mPhoneStateReceiver.notifySignalStrength(EVENT_SIGNAL_STRENGTH_CHANGED); |
| 458 | mPhoneStateReceiver.notifyServiceState(EVENT_SERVICE_STATE_CHANGED); |
| 459 | mPhoneStateReceiver.notifyPhoneCallState(EVENT_PHONE_STATE_CHANGED); |
| 460 | |
| 461 | updateQxdmState(null); |
| 462 | mOem = new OemCommands(); |
| 463 | |
| 464 | phone.getPreferredNetworkType( |
| 465 | mHandler.obtainMessage(EVENT_QUERY_PREFERRED_TYPE_DONE)); |
| 466 | phone.getNeighboringCids( |
| 467 | mHandler.obtainMessage(EVENT_QUERY_NEIGHBORING_CIDS_DONE)); |
| 468 | |
| 469 | netstat = INetStatService.Stub.asInterface(ServiceManager.getService("netstat")); |
| 470 | |
| 471 | CellLocation.requestLocationUpdate(); |
| 472 | } |
| 473 | |
| 474 | @Override |
| 475 | protected void onResume() { |
| 476 | super.onResume(); |
| 477 | |
| 478 | updatePhoneState(); |
| 479 | updateSignalStrength(); |
| 480 | updateMessageWaiting(); |
| 481 | updateCallRedirect(); |
| 482 | updateServiceState(); |
| 483 | updateLocation(mTelephonyManager.getCellLocation()); |
| 484 | updateDataState(); |
| 485 | updateDataStats(); |
| 486 | updateDataStats2(); |
| 487 | updatePowerState(); |
| 488 | updateQxdmState(null); |
| 489 | updateProperties(); |
| 490 | updateCiphState(); |
| 491 | |
| 492 | Log.i(TAG, "[RadioInfo] onResume: register phone & data intents"); |
| 493 | |
| 494 | mPhoneStateReceiver.registerIntent(); |
| 495 | mTelephonyManager.listen(mPhoneStateListener, |
| 496 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
| 497 | | PhoneStateListener.LISTEN_DATA_ACTIVITY |
| 498 | | PhoneStateListener.LISTEN_CELL_LOCATION |
| 499 | | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
| 500 | | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR); |
| 501 | } |
| 502 | |
| 503 | @Override |
| 504 | public void onPause() { |
| 505 | super.onPause(); |
| 506 | |
| 507 | Log.i(TAG, "[RadioInfo] onPause: unregister phone & data intents"); |
| 508 | |
| 509 | mPhoneStateReceiver.unregisterIntent(); |
| 510 | mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); |
| 511 | } |
| 512 | |
| 513 | @Override |
| 514 | public boolean onCreateOptionsMenu(Menu menu) { |
| 515 | menu.add(0, MENU_ITEM_SELECT_BAND, 0, R.string.radio_info_band_mode_label).setOnMenuItemClickListener(mSelectBandCallback) |
| 516 | .setAlphabeticShortcut('b'); |
| 517 | menu.add(1, MENU_ITEM_VIEW_ADN, 0, |
| 518 | R.string.radioInfo_menu_viewADN).setOnMenuItemClickListener(mViewADNCallback); |
| 519 | menu.add(1, MENU_ITEM_VIEW_FDN, 0, |
| 520 | R.string.radioInfo_menu_viewFDN).setOnMenuItemClickListener(mViewFDNCallback); |
| 521 | menu.add(1, MENU_ITEM_VIEW_SDN, 0, |
| 522 | R.string.radioInfo_menu_viewSDN).setOnMenuItemClickListener(mViewSDNCallback); |
| 523 | menu.add(1, MENU_ITEM_GET_PDP_LIST, |
| 524 | 0, R.string.radioInfo_menu_getPDP).setOnMenuItemClickListener(mGetPdpList); |
| 525 | menu.add(1, MENU_ITEM_TOGGLE_DATA, |
| 526 | 0, R.string.radioInfo_menu_disableData).setOnMenuItemClickListener(mToggleData); |
| 527 | menu.add(1, MENU_ITEM_TOGGLE_DATA_ON_BOOT, |
| 528 | 0, R.string.radioInfo_menu_disableDataOnBoot).setOnMenuItemClickListener(mToggleDataOnBoot); |
| 529 | return true; |
| 530 | } |
| 531 | |
| 532 | |
| 533 | @Override |
| 534 | public boolean onPrepareOptionsMenu(Menu menu) |
| 535 | { |
| 536 | // Get the TOGGLE DATA menu item in the right state. |
| 537 | MenuItem item = menu.findItem(MENU_ITEM_TOGGLE_DATA); |
| 538 | int state = mTelephonyManager.getDataState(); |
| 539 | boolean visible = true; |
| 540 | |
| 541 | switch (state) { |
| 542 | case TelephonyManager.DATA_CONNECTED: |
| 543 | case TelephonyManager.DATA_SUSPENDED: |
| 544 | item.setTitle(R.string.radioInfo_menu_disableData); |
| 545 | break; |
| 546 | case TelephonyManager.DATA_DISCONNECTED: |
| 547 | item.setTitle(R.string.radioInfo_menu_enableData); |
| 548 | break; |
| 549 | default: |
| 550 | visible = false; |
| 551 | break; |
| 552 | } |
| 553 | item.setVisible(visible); |
| 554 | |
| 555 | // Get the toggle-data-on-boot menu item in the right state. |
| 556 | item = menu.findItem(MENU_ITEM_TOGGLE_DATA_ON_BOOT); |
| 557 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this.getApplication()); |
| 558 | boolean value = sp.getBoolean(GSMPhone.DATA_DISABLED_ON_BOOT_KEY, false); |
| 559 | if (value) { |
| 560 | item.setTitle(R.string.radioInfo_menu_enableDataOnBoot); |
| 561 | } else { |
| 562 | item.setTitle(R.string.radioInfo_menu_disableDataOnBoot); |
| 563 | } |
| 564 | return true; |
| 565 | } |
| 566 | |
| 567 | private boolean isRadioOn() { |
| 568 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 569 | } |
| 570 | |
| 571 | private void updatePowerState() { |
| 572 | //log("updatePowerState"); |
| 573 | String buttonText = isRadioOn() ? |
| 574 | getString(R.string.turn_off_radio) : |
| 575 | getString(R.string.turn_on_radio); |
| 576 | radioPowerButton.setText(buttonText); |
| 577 | } |
| 578 | |
| 579 | private void updateQxdmState(Boolean newQxdmStatus) { |
| 580 | SharedPreferences sp = |
| 581 | PreferenceManager.getDefaultSharedPreferences(this.getApplication()); |
| 582 | mQxdmLogEnabled = sp.getBoolean("qxdmstatus", false); |
| 583 | // This is called from onCreate, onResume, and the handler when the status |
| 584 | // is updated. |
| 585 | if (newQxdmStatus != null) { |
| 586 | SharedPreferences.Editor editor = sp.edit(); |
| 587 | editor.putBoolean("qxdmstatus", newQxdmStatus); |
| 588 | editor.commit(); |
| 589 | mQxdmLogEnabled = newQxdmStatus; |
| 590 | } |
| 591 | |
| 592 | String buttonText = mQxdmLogEnabled ? |
| 593 | getString(R.string.turn_off_qxdm) : |
| 594 | getString(R.string.turn_on_qxdm); |
| 595 | qxdmLogButton.setText(buttonText); |
| 596 | } |
| 597 | |
| 598 | private void setCiphPref(boolean value) { |
| 599 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this.getApplication()); |
| 600 | SharedPreferences.Editor editor = sp.edit(); |
| 601 | editor.putBoolean(GSMPhone.CIPHERING_KEY, value); |
| 602 | editor.commit(); |
| 603 | } |
| 604 | |
| 605 | private boolean getCiphPref() { |
| 606 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this.getApplication()); |
| 607 | boolean ret = sp.getBoolean(GSMPhone.CIPHERING_KEY, true); |
| 608 | return ret; |
| 609 | } |
| 610 | |
| 611 | private void updateCiphState() { |
| 612 | cipherState.setText(getCiphPref() ? "Ciphering ON" : "Ciphering OFF"); |
| 613 | } |
| 614 | |
| 615 | private final void |
| 616 | updateSignalStrength() { |
| 617 | int state = |
| 618 | mPhoneStateReceiver.getServiceState().getState(); |
| 619 | Resources r = getResources(); |
| 620 | |
| 621 | if ((ServiceState.STATE_OUT_OF_SERVICE == state) || |
| 622 | (ServiceState.STATE_POWER_OFF == state)) { |
| 623 | dBm.setText("0"); |
| 624 | } |
| 625 | |
| 626 | int signalDbm = mPhoneStateReceiver.getSignalStrengthDbm(); |
| 627 | |
| 628 | if (-1 == signalDbm) signalDbm = 0; |
| 629 | |
| 630 | int signalAsu = mPhoneStateReceiver.getSignalStrength(); |
| 631 | |
| 632 | if (-1 == signalAsu) signalAsu = 0; |
| 633 | |
| 634 | dBm.setText(String.valueOf(signalDbm) + " " |
| 635 | + r.getString(R.string.radioInfo_display_dbm) + " " |
| 636 | + String.valueOf(signalAsu) + " " |
| 637 | + r.getString(R.string.radioInfo_display_asu)); |
| 638 | } |
| 639 | |
| 640 | private final void updateLocation(CellLocation location) { |
| 641 | GsmCellLocation loc = (GsmCellLocation)location; |
| 642 | Resources r = getResources(); |
| 643 | |
| 644 | int lac = loc.getLac(); |
| 645 | int cid = loc.getCid(); |
| 646 | |
| 647 | mLocation.setText(r.getString(R.string.radioInfo_lac) + " = " |
| 648 | + ((lac == -1) ? "unknown" : Integer.toHexString(lac)) |
| 649 | + " " |
| 650 | + r.getString(R.string.radioInfo_cid) + " = " |
| 651 | + ((cid == -1) ? "unknown" : Integer.toHexString(cid))); |
| 652 | } |
| 653 | |
| 654 | private final void updateNeighboringCids(String[] cids) { |
| 655 | if (cids != null && cids.length > 0 && cids[0] != null) { |
| 656 | int size = Integer.parseInt(cids[0]); |
| 657 | String neiborings; |
| 658 | if (size > 0) { |
| 659 | neiborings = "{"; |
| 660 | for (int i=1; i<=size; i++) { |
| 661 | neiborings += cids[i] + ", "; |
| 662 | } |
| 663 | neiborings += "}"; |
| 664 | } else { |
| 665 | neiborings = "none"; |
| 666 | } |
| 667 | mNeighboringCids.setText(neiborings); |
| 668 | } else { |
| 669 | mNeighboringCids.setText("unknown"); |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | private final void |
| 674 | updateMessageWaiting() { |
| 675 | mMwi.setText(String.valueOf(mMwiValue)); |
| 676 | } |
| 677 | |
| 678 | private final void |
| 679 | updateCallRedirect() { |
| 680 | mCfi.setText(String.valueOf(mCfiValue)); |
| 681 | } |
| 682 | |
| 683 | |
| 684 | private final void |
| 685 | updateServiceState() { |
| 686 | ServiceState serviceState = mPhoneStateReceiver.getServiceState(); |
| 687 | int state = serviceState.getState(); |
| 688 | Resources r = getResources(); |
| 689 | String display = r.getString(R.string.radioInfo_unknown); |
| 690 | |
| 691 | switch (state) { |
| 692 | case ServiceState.STATE_IN_SERVICE: |
| 693 | display = r.getString(R.string.radioInfo_service_in); |
| 694 | break; |
| 695 | case ServiceState.STATE_OUT_OF_SERVICE: |
| 696 | case ServiceState.STATE_EMERGENCY_ONLY: |
| 697 | display = r.getString(R.string.radioInfo_service_emergency); |
| 698 | break; |
| 699 | case ServiceState.STATE_POWER_OFF: |
| 700 | display = r.getString(R.string.radioInfo_service_off); |
| 701 | break; |
| 702 | } |
| 703 | |
| 704 | gsmState.setText(display); |
| 705 | |
| 706 | if (serviceState.getRoaming()) { |
| 707 | roamingState.setText(R.string.radioInfo_roaming_in); |
| 708 | } else { |
| 709 | roamingState.setText(R.string.radioInfo_roaming_not); |
| 710 | } |
| 711 | |
| 712 | operatorName.setText(serviceState.getOperatorAlphaLong()); |
| 713 | } |
| 714 | |
| 715 | private final void |
| 716 | updatePhoneState() { |
| 717 | Phone.State state = mPhoneStateReceiver.getPhoneState(); |
| 718 | Resources r = getResources(); |
| 719 | String display = r.getString(R.string.radioInfo_unknown); |
| 720 | |
| 721 | switch (state) { |
| 722 | case IDLE: |
| 723 | display = r.getString(R.string.radioInfo_phone_idle); |
| 724 | break; |
| 725 | case RINGING: |
| 726 | display = r.getString(R.string.radioInfo_phone_ringing); |
| 727 | break; |
| 728 | case OFFHOOK: |
| 729 | display = r.getString(R.string.radioInfo_phone_offhook); |
| 730 | break; |
| 731 | } |
| 732 | |
| 733 | callState.setText(display); |
| 734 | } |
| 735 | |
| 736 | private final void |
| 737 | updateDataState() { |
| 738 | int state = mTelephonyManager.getDataState(); |
| 739 | Resources r = getResources(); |
| 740 | String display = r.getString(R.string.radioInfo_unknown); |
| 741 | |
| 742 | switch (state) { |
| 743 | case TelephonyManager.DATA_CONNECTED: |
| 744 | display = r.getString(R.string.radioInfo_data_connected); |
| 745 | break; |
| 746 | case TelephonyManager.DATA_CONNECTING: |
| 747 | display = r.getString(R.string.radioInfo_data_connecting); |
| 748 | break; |
| 749 | case TelephonyManager.DATA_DISCONNECTED: |
| 750 | display = r.getString(R.string.radioInfo_data_disconnected); |
| 751 | break; |
| 752 | case TelephonyManager.DATA_SUSPENDED: |
| 753 | display = r.getString(R.string.radioInfo_data_suspended); |
| 754 | break; |
| 755 | } |
| 756 | |
| 757 | gprsState.setText(display); |
| 758 | } |
| 759 | |
| 760 | private final void updateNetworkType() { |
| 761 | Resources r = getResources(); |
| 762 | String display = SystemProperties.get(TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, |
| 763 | r.getString(R.string.radioInfo_unknown)); |
| 764 | |
| 765 | network.setText(display); |
| 766 | } |
| 767 | |
| 768 | private final void |
| 769 | updateProperties() { |
| 770 | String s; |
| 771 | Resources r = getResources(); |
| 772 | |
| 773 | s = phone.getDeviceId(); |
| 774 | if (s == null) s = r.getString(R.string.radioInfo_unknown); |
| 775 | mImei.setText(s); |
| 776 | |
| 777 | s = phone.getSubscriberId(); |
| 778 | if (s == null) s = r.getString(R.string.radioInfo_unknown); |
| 779 | mImsi.setText(s); |
| 780 | |
| 781 | s = phone.getLine1Number(); |
| 782 | if (s == null) s = r.getString(R.string.radioInfo_unknown); |
| 783 | number.setText(s); |
| 784 | } |
| 785 | |
| 786 | private final void updateDataStats() { |
| 787 | String s; |
| 788 | |
| 789 | s = SystemProperties.get("net.gsm.radio-reset", "0"); |
| 790 | resets.setText(s); |
| 791 | |
| 792 | s = SystemProperties.get("net.gsm.attempt-gprs", "0"); |
| 793 | attempts.setText(s); |
| 794 | |
| 795 | s = SystemProperties.get("net.gsm.succeed-gprs", "0"); |
| 796 | successes.setText(s); |
| 797 | |
| 798 | //s = SystemProperties.get("net.gsm.disconnect", "0"); |
| 799 | //disconnects.setText(s); |
| 800 | |
| 801 | s = SystemProperties.get("net.ppp.reset-by-timeout", "0"); |
| 802 | sentSinceReceived.setText(s); |
| 803 | } |
| 804 | |
| 805 | private final void updateDataStats2() { |
| 806 | Resources r = getResources(); |
| 807 | |
| 808 | try { |
| 809 | int txPackets = netstat.getTxPackets(); |
| 810 | int rxPackets = netstat.getRxPackets(); |
| 811 | int txBytes = netstat.getTxBytes(); |
| 812 | int rxBytes = netstat.getRxBytes(); |
| 813 | |
| 814 | String packets = r.getString(R.string.radioInfo_display_packets); |
| 815 | String bytes = r.getString(R.string.radioInfo_display_bytes); |
| 816 | |
| 817 | sent.setText(txPackets + " " + packets + ", " + txBytes + " " + bytes); |
| 818 | received.setText(rxPackets + " " + packets + ", " + rxBytes + " " + bytes); |
| 819 | } catch (RemoteException e) { |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | /** |
| 824 | * Ping a IP address. |
| 825 | */ |
| 826 | private final void pingIpAddr() { |
| 827 | try { |
| 828 | // This is hardcoded IP addr. This is for testing purposes. |
| 829 | // We would need to get rid of this before release. |
| 830 | String ipAddress = "74.125.47.104"; |
| 831 | Process p = Runtime.getRuntime().exec("ping -c 1 " + ipAddress); |
| 832 | int status = p.waitFor(); |
| 833 | if (status == 0) { |
| 834 | mPingIpAddrResult = "Pass"; |
| 835 | } else { |
| 836 | mPingIpAddrResult = "Fail: IP addr not reachable"; |
| 837 | } |
| 838 | } catch (IOException e) { |
| 839 | mPingIpAddrResult = "Fail: IOException"; |
| 840 | } catch (InterruptedException e) { |
| 841 | mPingIpAddrResult = "Fail: InterruptedException"; |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | /** |
| 846 | * Ping a host name |
| 847 | */ |
| 848 | private final void pingHostname() { |
| 849 | try { |
| 850 | Process p = Runtime.getRuntime().exec("ping -c 1 www.google.com"); |
| 851 | int status = p.waitFor(); |
| 852 | if (status == 0) { |
| 853 | mPingHostnameResult = "Pass"; |
| 854 | } else { |
| 855 | mPingHostnameResult = "Fail: Host unreachable"; |
| 856 | } |
| 857 | } catch (UnknownHostException e) { |
| 858 | mPingHostnameResult = "Fail: Unknown Host"; |
| 859 | } catch (IOException e) { |
| 860 | mPingHostnameResult= "Fail: IOException"; |
| 861 | } catch (InterruptedException e) { |
| 862 | mPingHostnameResult = "Fail: InterruptedException"; |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | /** |
| 867 | * This function checks for basic functionality of HTTP Client. |
| 868 | */ |
| 869 | private void httpClientTest() { |
| 870 | HttpClient client = new DefaultHttpClient(); |
| 871 | try { |
| 872 | HttpGet request = new HttpGet("http://www.google.com"); |
| 873 | HttpResponse response = client.execute(request); |
| 874 | if (response.getStatusLine().getStatusCode() == 200) { |
| 875 | mHttpClientTestResult = "Pass"; |
| 876 | } else { |
| 877 | mHttpClientTestResult = "Fail: Code: " + String.valueOf(response); |
| 878 | } |
| 879 | request.abort(); |
| 880 | } catch (IOException e) { |
| 881 | mHttpClientTestResult = "Fail: IOException"; |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | private void refreshSmsc() { |
| 886 | byte[] data = mOem.getSmscQueryData(); |
| 887 | if (data == null) return; |
| 888 | phone.invokeOemRilRequestRaw(data, |
| 889 | mHandler.obtainMessage(EVENT_QUERY_SMSC_DONE)); |
| 890 | } |
| 891 | |
| 892 | private final void updatePingState() { |
| 893 | final Handler handler = new Handler(); |
| 894 | // Set all to unknown since the threads will take a few secs to update. |
| 895 | mPingIpAddrResult = getResources().getString(R.string.radioInfo_unknown); |
| 896 | mPingHostnameResult = getResources().getString(R.string.radioInfo_unknown); |
| 897 | mHttpClientTestResult = getResources().getString(R.string.radioInfo_unknown); |
| 898 | |
| 899 | mPingIpAddr.setText(mPingIpAddrResult); |
| 900 | mPingHostname.setText(mPingHostnameResult); |
| 901 | mHttpClientTest.setText(mHttpClientTestResult); |
| 902 | |
| 903 | final Runnable updatePingResults = new Runnable() { |
| 904 | public void run() { |
| 905 | mPingIpAddr.setText(mPingIpAddrResult); |
| 906 | mPingHostname.setText(mPingHostnameResult); |
| 907 | mHttpClientTest.setText(mHttpClientTestResult); |
| 908 | } |
| 909 | }; |
| 910 | Thread ipAddr = new Thread() { |
| 911 | @Override |
| 912 | public void run() { |
| 913 | pingIpAddr(); |
| 914 | handler.post(updatePingResults); |
| 915 | } |
| 916 | }; |
| 917 | ipAddr.start(); |
| 918 | |
| 919 | Thread hostname = new Thread() { |
| 920 | @Override |
| 921 | public void run() { |
| 922 | pingHostname(); |
| 923 | handler.post(updatePingResults); |
| 924 | } |
| 925 | }; |
| 926 | hostname.start(); |
| 927 | |
| 928 | Thread httpClient = new Thread() { |
| 929 | @Override |
| 930 | public void run() { |
| 931 | httpClientTest(); |
| 932 | handler.post(updatePingResults); |
| 933 | } |
| 934 | }; |
| 935 | httpClient.start(); |
| 936 | } |
| 937 | |
| 938 | private final void updatePdpList() { |
| 939 | StringBuilder sb = new StringBuilder("========DATA=======\n"); |
| 940 | |
| 941 | List<PdpConnection> pdps = phone.getCurrentPdpList(); |
| 942 | |
| 943 | for (PdpConnection pdp : pdps) { |
| 944 | sb.append(" State: ").append(pdp.getState().toString()).append("\n"); |
| 945 | if (pdp.getState().isActive()) { |
| 946 | long timeElapsed = |
| 947 | (System.currentTimeMillis() - pdp.getConnectionTime())/1000; |
| 948 | sb.append(" connected at ") |
| 949 | .append(DateUtils.timeString(pdp.getConnectionTime())) |
| 950 | .append(" and elapsed ") |
| 951 | .append(DateUtils.formatElapsedTime(timeElapsed)) |
| 952 | .append("\n to ") |
| 953 | .append(pdp.getApn().toString()) |
| 954 | .append("\ninterface: ") |
| 955 | .append(phone.getInterfaceName(phone.getActiveApn())) |
| 956 | .append("\naddress: ") |
| 957 | .append(phone.getIpAddress(phone.getActiveApn())) |
| 958 | .append("\ngateway: ") |
| 959 | .append(phone.getGateway(phone.getActiveApn())); |
| 960 | String[] dns = phone.getDnsServers(phone.getActiveApn()); |
| 961 | sb.append("\ndns: ").append(dns[0]).append(", ").append(dns[1]); |
| 962 | } else if (pdp.getState().isInactive()) { |
| 963 | sb.append(" disconnected with last try at ") |
| 964 | .append(DateUtils.timeString(pdp.getLastFailTime())) |
| 965 | .append("\n fail because ") |
| 966 | .append(pdp.getLastFailCause().toString()); |
| 967 | } else { |
| 968 | sb.append(" is connecting to ") |
| 969 | .append(pdp.getApn().toString()); |
| 970 | } |
| 971 | sb.append("\n==================="); |
| 972 | } |
| 973 | |
| 974 | |
| 975 | disconnects.setText(sb.toString()); |
| 976 | } |
| 977 | |
| 978 | private void displayQxdmEnableResult() { |
| 979 | String status = mQxdmLogEnabled ? "Start QXDM Log" : "Stop QXDM Log"; |
| 980 | |
| 981 | DialogInterface mProgressPanel = new AlertDialog. |
| 982 | Builder(this).setMessage(status).show(); |
| 983 | |
| 984 | mHandler.postDelayed( |
| 985 | new Runnable() { |
| 986 | public void run() { |
| 987 | finish(); |
| 988 | } |
| 989 | }, 2000); |
| 990 | } |
| 991 | |
| 992 | private MenuItem.OnMenuItemClickListener mViewADNCallback = new MenuItem.OnMenuItemClickListener() { |
| 993 | public boolean onMenuItemClick(MenuItem item) { |
| 994 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 995 | // XXX We need to specify the component here because if we don't |
| 996 | // the activity manager will try to resolve the type by calling |
| 997 | // the content provider, which causes it to be loaded in a process |
| 998 | // other than the Dialer process, which causes a lot of stuff to |
| 999 | // break. |
| 1000 | intent.setClassName("com.android.phone", |
| 1001 | "com.android.phone.SimContacts"); |
| 1002 | startActivity(intent); |
| 1003 | return true; |
| 1004 | } |
| 1005 | }; |
| 1006 | |
| 1007 | private MenuItem.OnMenuItemClickListener mViewFDNCallback = new MenuItem.OnMenuItemClickListener() { |
| 1008 | public boolean onMenuItemClick(MenuItem item) { |
| 1009 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 1010 | // XXX We need to specify the component here because if we don't |
| 1011 | // the activity manager will try to resolve the type by calling |
| 1012 | // the content provider, which causes it to be loaded in a process |
| 1013 | // other than the Dialer process, which causes a lot of stuff to |
| 1014 | // break. |
| 1015 | intent.setClassName("com.android.phone", |
| 1016 | "com.android.phone.FdnList"); |
| 1017 | startActivity(intent); |
| 1018 | return true; |
| 1019 | } |
| 1020 | }; |
| 1021 | |
| 1022 | private MenuItem.OnMenuItemClickListener mViewSDNCallback = new MenuItem.OnMenuItemClickListener() { |
| 1023 | public boolean onMenuItemClick(MenuItem item) { |
| 1024 | Intent intent = new Intent( |
| 1025 | Intent.ACTION_VIEW, Uri.parse("content://sim/sdn")); |
| 1026 | // XXX We need to specify the component here because if we don't |
| 1027 | // the activity manager will try to resolve the type by calling |
| 1028 | // the content provider, which causes it to be loaded in a process |
| 1029 | // other than the Dialer process, which causes a lot of stuff to |
| 1030 | // break. |
| 1031 | intent.setClassName("com.android.phone", |
| 1032 | "com.android.phone.ADNList"); |
| 1033 | startActivity(intent); |
| 1034 | return true; |
| 1035 | } |
| 1036 | }; |
| 1037 | |
| 1038 | private void toggleDataDisabledOnBoot() { |
| 1039 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this.getApplication()); |
| 1040 | SharedPreferences.Editor editor = sp.edit(); |
| 1041 | boolean value = sp.getBoolean(GSMPhone.DATA_DISABLED_ON_BOOT_KEY, false); |
| 1042 | editor.putBoolean(GSMPhone.DATA_DISABLED_ON_BOOT_KEY, !value); |
| 1043 | byte[] data = mOem.getPsAutoAttachData(value); |
| 1044 | if (data == null) { |
| 1045 | // don't commit |
| 1046 | return; |
| 1047 | } |
| 1048 | |
| 1049 | editor.commit(); |
| 1050 | phone.invokeOemRilRequestRaw(data, null); |
| 1051 | } |
| 1052 | |
| 1053 | private MenuItem.OnMenuItemClickListener mToggleDataOnBoot = new MenuItem.OnMenuItemClickListener() { |
| 1054 | public boolean onMenuItemClick(MenuItem item) { |
| 1055 | toggleDataDisabledOnBoot(); |
| 1056 | return true; |
| 1057 | } |
| 1058 | }; |
| 1059 | |
| 1060 | private MenuItem.OnMenuItemClickListener mToggleData = new MenuItem.OnMenuItemClickListener() { |
| 1061 | public boolean onMenuItemClick(MenuItem item) { |
| 1062 | int state = mTelephonyManager.getDataState(); |
| 1063 | switch (state) { |
| 1064 | case TelephonyManager.DATA_CONNECTED: |
| 1065 | phone.disableDataConnectivity(); |
| 1066 | break; |
| 1067 | case TelephonyManager.DATA_DISCONNECTED: |
| 1068 | phone.enableDataConnectivity(); |
| 1069 | break; |
| 1070 | default: |
| 1071 | // do nothing |
| 1072 | break; |
| 1073 | } |
| 1074 | return true; |
| 1075 | } |
| 1076 | }; |
| 1077 | |
| 1078 | private MenuItem.OnMenuItemClickListener mGetPdpList = new MenuItem.OnMenuItemClickListener() { |
| 1079 | public boolean onMenuItemClick(MenuItem item) { |
| 1080 | phone.getPdpContextList(null); |
| 1081 | return true; |
| 1082 | } |
| 1083 | }; |
| 1084 | |
| 1085 | private MenuItem.OnMenuItemClickListener mSelectBandCallback = new MenuItem.OnMenuItemClickListener() { |
| 1086 | public boolean onMenuItemClick(MenuItem item) { |
| 1087 | Intent intent = new Intent(); |
| 1088 | intent.setClass(RadioInfo.this, BandMode.class); |
| 1089 | startActivity(intent); |
| 1090 | return true; |
| 1091 | } |
| 1092 | }; |
| 1093 | |
| 1094 | OnClickListener mPowerButtonHandler = new OnClickListener() { |
| 1095 | public void onClick(View v) { |
| 1096 | //log("toggle radio power: currently " + (isRadioOn()?"on":"off")); |
| 1097 | phone.setRadioPower(!isRadioOn()); |
| 1098 | } |
| 1099 | }; |
| 1100 | |
| 1101 | OnClickListener mCipherButtonHandler = new OnClickListener() { |
| 1102 | public void onClick(View v) { |
| 1103 | mCipherOn = !getCiphPref(); |
| 1104 | byte[] data = mOem.getCipheringData(mCipherOn); |
| 1105 | |
| 1106 | if (data == null) |
| 1107 | return; |
| 1108 | |
| 1109 | cipherState.setText("Setting..."); |
| 1110 | phone.invokeOemRilRequestRaw(data, |
| 1111 | mHandler.obtainMessage(EVENT_SET_CIPHER_DONE)); |
| 1112 | } |
| 1113 | }; |
| 1114 | |
| 1115 | OnClickListener mPingButtonHandler = new OnClickListener() { |
| 1116 | public void onClick(View v) { |
| 1117 | updatePingState(); |
| 1118 | } |
| 1119 | }; |
| 1120 | |
| 1121 | OnClickListener mUpdateSmscButtonHandler = new OnClickListener() { |
| 1122 | public void onClick(View v) { |
| 1123 | updateSmscButton.setEnabled(false); |
| 1124 | byte[] data = mOem.getSmscUpdateData(smsc.getText().toString()); |
| 1125 | if (data == null) return; |
| 1126 | phone.invokeOemRilRequestRaw(data, |
| 1127 | mHandler.obtainMessage(EVENT_UPDATE_SMSC_DONE)); |
| 1128 | } |
| 1129 | }; |
| 1130 | |
| 1131 | OnClickListener mRefreshSmscButtonHandler = new OnClickListener() { |
| 1132 | public void onClick(View v) { |
| 1133 | refreshSmsc(); |
| 1134 | } |
| 1135 | }; |
| 1136 | |
| 1137 | OnClickListener mQxdmButtonHandler = new OnClickListener() { |
| 1138 | public void onClick(View v) { |
| 1139 | byte[] data = mOem.getQxdmSdlogData( |
| 1140 | !mQxdmLogEnabled, |
| 1141 | mOem.OEM_QXDM_SDLOG_DEFAULT_FILE_SIZE, |
| 1142 | mOem.OEM_QXDM_SDLOG_DEFAULT_MASK, |
| 1143 | mOem.OEM_QXDM_SDLOG_DEFAULT_MAX_INDEX); |
| 1144 | |
| 1145 | if (data == null) |
| 1146 | return; |
| 1147 | |
| 1148 | phone.invokeOemRilRequestRaw(data, |
| 1149 | mHandler.obtainMessage(EVENT_SET_QXDMLOG_DONE)); |
| 1150 | } |
| 1151 | }; |
| 1152 | |
| 1153 | AdapterView.OnItemSelectedListener |
| 1154 | mPreferredNetworkHandler = new AdapterView.OnItemSelectedListener() { |
| 1155 | public void onItemSelected(AdapterView parent, View v, int pos, long id) { |
| 1156 | Message msg = mHandler.obtainMessage(EVENT_SET_PREFERRED_TYPE_DONE); |
| 1157 | if (pos>=0 && pos<=2) { |
| 1158 | phone.setPreferredNetworkType(pos, msg); |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | public void onNothingSelected(AdapterView parent) { |
| 1163 | } |
| 1164 | }; |
| 1165 | |
| 1166 | private String[] mPreferredNetworkLabels = { |
| 1167 | "WCDMA preferred", "GSM only", "WCDMA only", "Unknown"}; |
| 1168 | } |