The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [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; |
Robert Greenwalt | 99be500 | 2010-11-24 17:20:59 -0800 | [diff] [blame] | 20 | import android.content.Context; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 21 | import android.content.Intent; |
Tammo Spalink | a5f4c8f | 2009-10-15 20:08:58 +0800 | [diff] [blame] | 22 | import android.content.pm.PackageManager; |
| 23 | import android.content.pm.ResolveInfo; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 24 | import android.content.res.Resources; |
Robert Greenwalt | 99be500 | 2010-11-24 17:20:59 -0800 | [diff] [blame] | 25 | import android.net.ConnectivityManager; |
Robert Greenwalt | ae04c1a | 2010-08-30 15:33:28 -0700 | [diff] [blame] | 26 | import android.net.LinkProperties; |
Jeff Sharkey | 9302986 | 2011-05-27 18:26:15 -0700 | [diff] [blame] | 27 | import android.net.TrafficStats; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 28 | import android.net.Uri; |
| 29 | import android.os.AsyncResult; |
| 30 | import android.os.Bundle; |
| 31 | import android.os.Handler; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 32 | import android.os.Message; |
| 33 | import android.os.RemoteException; |
| 34 | import android.os.ServiceManager; |
| 35 | import android.os.SystemProperties; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 36 | import android.telephony.CellLocation; |
| 37 | import android.telephony.PhoneStateListener; |
| 38 | import android.telephony.ServiceState; |
| 39 | import android.telephony.TelephonyManager; |
| 40 | import android.telephony.NeighboringCellInfo; |
jsh | 534f5ae | 2009-09-24 09:19:22 -0700 | [diff] [blame] | 41 | import android.telephony.cdma.CdmaCellLocation; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 42 | import android.telephony.gsm.GsmCellLocation; |
| 43 | import android.text.format.DateUtils; |
| 44 | import android.util.Log; |
| 45 | import android.view.Menu; |
| 46 | import android.view.MenuItem; |
| 47 | import android.view.View; |
| 48 | import android.view.View.OnClickListener; |
| 49 | import android.widget.AdapterView; |
| 50 | import android.widget.ArrayAdapter; |
| 51 | import android.widget.Button; |
| 52 | import android.widget.Spinner; |
| 53 | import android.widget.TextView; |
| 54 | import android.widget.EditText; |
| 55 | |
jsh | 87fa11b | 2009-08-18 18:00:15 -0700 | [diff] [blame] | 56 | import com.android.internal.telephony.DataConnection; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 57 | import com.android.internal.telephony.Phone; |
Wink Saville | 5543404 | 2012-06-14 12:33:43 -0700 | [diff] [blame] | 58 | import com.android.internal.telephony.PhoneConstants; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 59 | import com.android.internal.telephony.PhoneFactory; |
| 60 | import com.android.internal.telephony.PhoneStateIntentReceiver; |
| 61 | import com.android.internal.telephony.TelephonyProperties; |
Wink Saville | 0d93697 | 2009-12-22 14:36:47 -0800 | [diff] [blame] | 62 | import com.android.internal.telephony.gsm.GsmDataConnection; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 63 | |
| 64 | import org.apache.http.HttpResponse; |
| 65 | import org.apache.http.client.HttpClient; |
| 66 | import org.apache.http.client.methods.HttpGet; |
| 67 | import org.apache.http.impl.client.DefaultHttpClient; |
| 68 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 69 | import java.io.IOException; |
Wink Saville | a9f1637 | 2010-08-27 13:53:26 -0700 | [diff] [blame] | 70 | import java.net.InetAddress; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 71 | import java.net.UnknownHostException; |
| 72 | import java.util.ArrayList; |
| 73 | import java.util.List; |
| 74 | |
Tammo Spalink | a5f4c8f | 2009-10-15 20:08:58 +0800 | [diff] [blame] | 75 | import android.util.Log; |
| 76 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 77 | public class RadioInfo extends Activity { |
| 78 | private final String TAG = "phone"; |
johnwang | 342101a | 2009-09-23 16:22:34 -0700 | [diff] [blame] | 79 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 80 | private static final int EVENT_PHONE_STATE_CHANGED = 100; |
| 81 | private static final int EVENT_SIGNAL_STRENGTH_CHANGED = 200; |
| 82 | private static final int EVENT_SERVICE_STATE_CHANGED = 300; |
| 83 | private static final int EVENT_CFI_CHANGED = 302; |
| 84 | |
| 85 | private static final int EVENT_QUERY_PREFERRED_TYPE_DONE = 1000; |
| 86 | private static final int EVENT_SET_PREFERRED_TYPE_DONE = 1001; |
| 87 | private static final int EVENT_QUERY_NEIGHBORING_CIDS_DONE = 1002; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 88 | private static final int EVENT_QUERY_SMSC_DONE = 1005; |
| 89 | private static final int EVENT_UPDATE_SMSC_DONE = 1006; |
| 90 | |
| 91 | private static final int MENU_ITEM_SELECT_BAND = 0; |
| 92 | private static final int MENU_ITEM_VIEW_ADN = 1; |
| 93 | private static final int MENU_ITEM_VIEW_FDN = 2; |
| 94 | private static final int MENU_ITEM_VIEW_SDN = 3; |
| 95 | private static final int MENU_ITEM_GET_PDP_LIST = 4; |
| 96 | private static final int MENU_ITEM_TOGGLE_DATA = 5; |
Tammo Spalink | a5f4c8f | 2009-10-15 20:08:58 +0800 | [diff] [blame] | 97 | |
| 98 | static final String ENABLE_DATA_STR = "Enable data connection"; |
| 99 | static final String DISABLE_DATA_STR = "Disable data connection"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 100 | |
Wink Saville | c388668 | 2009-04-02 11:00:56 -0700 | [diff] [blame] | 101 | private TextView mDeviceId; //DeviceId is the IMEI in GSM and the MEID in CDMA |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 102 | private TextView number; |
| 103 | private TextView callState; |
| 104 | private TextView operatorName; |
| 105 | private TextView roamingState; |
| 106 | private TextView gsmState; |
| 107 | private TextView gprsState; |
| 108 | private TextView network; |
| 109 | private TextView dBm; |
| 110 | private TextView mMwi; |
| 111 | private TextView mCfi; |
| 112 | private TextView mLocation; |
| 113 | private TextView mNeighboringCids; |
| 114 | private TextView resets; |
| 115 | private TextView attempts; |
| 116 | private TextView successes; |
| 117 | private TextView disconnects; |
| 118 | private TextView sentSinceReceived; |
| 119 | private TextView sent; |
| 120 | private TextView received; |
| 121 | private TextView mPingIpAddr; |
| 122 | private TextView mPingHostname; |
| 123 | private TextView mHttpClientTest; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 124 | private TextView dnsCheckState; |
| 125 | private EditText smsc; |
| 126 | private Button radioPowerButton; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 127 | private Button dnsCheckToggleButton; |
| 128 | private Button pingTestButton; |
| 129 | private Button updateSmscButton; |
| 130 | private Button refreshSmscButton; |
Tammo Spalink | a5f4c8f | 2009-10-15 20:08:58 +0800 | [diff] [blame] | 131 | private Button oemInfoButton; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 132 | private Spinner preferredNetworkType; |
| 133 | |
| 134 | private TelephonyManager mTelephonyManager; |
| 135 | private Phone phone = null; |
| 136 | private PhoneStateIntentReceiver mPhoneStateReceiver; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 137 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 138 | private String mPingIpAddrResult; |
| 139 | private String mPingHostnameResult; |
| 140 | private String mHttpClientTestResult; |
| 141 | private boolean mMwiValue = false; |
| 142 | private boolean mCfiValue = false; |
| 143 | |
| 144 | private PhoneStateListener mPhoneStateListener = new PhoneStateListener() { |
| 145 | @Override |
| 146 | public void onDataConnectionStateChanged(int state) { |
| 147 | updateDataState(); |
| 148 | updateDataStats(); |
| 149 | updatePdpList(); |
| 150 | updateNetworkType(); |
| 151 | } |
| 152 | |
| 153 | @Override |
| 154 | public void onDataActivity(int direction) { |
| 155 | updateDataStats2(); |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | public void onCellLocationChanged(CellLocation location) { |
| 160 | updateLocation(location); |
| 161 | } |
| 162 | |
| 163 | @Override |
| 164 | public void onMessageWaitingIndicatorChanged(boolean mwi) { |
| 165 | mMwiValue = mwi; |
| 166 | updateMessageWaiting(); |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public void onCallForwardingIndicatorChanged(boolean cfi) { |
| 171 | mCfiValue = cfi; |
| 172 | updateCallRedirect(); |
| 173 | } |
| 174 | }; |
| 175 | |
| 176 | private Handler mHandler = new Handler() { |
| 177 | public void handleMessage(Message msg) { |
| 178 | AsyncResult ar; |
| 179 | switch (msg.what) { |
| 180 | case EVENT_PHONE_STATE_CHANGED: |
| 181 | updatePhoneState(); |
| 182 | break; |
| 183 | |
| 184 | case EVENT_SIGNAL_STRENGTH_CHANGED: |
| 185 | updateSignalStrength(); |
| 186 | break; |
| 187 | |
| 188 | case EVENT_SERVICE_STATE_CHANGED: |
| 189 | updateServiceState(); |
| 190 | updatePowerState(); |
| 191 | break; |
| 192 | |
| 193 | case EVENT_QUERY_PREFERRED_TYPE_DONE: |
| 194 | ar= (AsyncResult) msg.obj; |
| 195 | if (ar.exception == null) { |
| 196 | int type = ((int[])ar.result)[0]; |
Ricardo Cerqueira | 32310ee | 2012-04-12 23:34:38 +0100 | [diff] [blame] | 197 | if (type >= mPreferredNetworkLabels.length) { |
| 198 | Log.e(TAG, "[RadioInfo] EVENT_QUERY_PREFERRED_TYPE_DONE: unknown " + |
| 199 | "type=" + type); |
| 200 | type = mPreferredNetworkLabels.length - 1; |
| 201 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 202 | preferredNetworkType.setSelection(type, true); |
| 203 | } else { |
Ricardo Cerqueira | 32310ee | 2012-04-12 23:34:38 +0100 | [diff] [blame] | 204 | preferredNetworkType.setSelection(mPreferredNetworkLabels.length - 1, true); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 205 | } |
| 206 | break; |
| 207 | case EVENT_SET_PREFERRED_TYPE_DONE: |
| 208 | ar= (AsyncResult) msg.obj; |
| 209 | if (ar.exception != null) { |
| 210 | phone.getPreferredNetworkType( |
| 211 | obtainMessage(EVENT_QUERY_PREFERRED_TYPE_DONE)); |
| 212 | } |
| 213 | break; |
| 214 | case EVENT_QUERY_NEIGHBORING_CIDS_DONE: |
| 215 | ar= (AsyncResult) msg.obj; |
| 216 | if (ar.exception == null) { |
| 217 | updateNeighboringCids((ArrayList<NeighboringCellInfo>)ar.result); |
| 218 | } else { |
| 219 | mNeighboringCids.setText("unknown"); |
| 220 | } |
| 221 | break; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 222 | case EVENT_QUERY_SMSC_DONE: |
| 223 | ar= (AsyncResult) msg.obj; |
| 224 | if (ar.exception != null) { |
| 225 | smsc.setText("refresh error"); |
| 226 | } else { |
jsh | 21dd407 | 2009-05-12 11:26:55 -0700 | [diff] [blame] | 227 | smsc.setText((String)ar.result); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 228 | } |
| 229 | break; |
| 230 | case EVENT_UPDATE_SMSC_DONE: |
| 231 | updateSmscButton.setEnabled(true); |
| 232 | ar= (AsyncResult) msg.obj; |
| 233 | if (ar.exception != null) { |
| 234 | smsc.setText("update error"); |
| 235 | } |
| 236 | break; |
| 237 | default: |
| 238 | break; |
| 239 | |
| 240 | } |
| 241 | } |
| 242 | }; |
| 243 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 244 | @Override |
| 245 | public void onCreate(Bundle icicle) { |
| 246 | super.onCreate(icicle); |
| 247 | |
| 248 | setContentView(R.layout.radio_info); |
| 249 | |
| 250 | mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); |
| 251 | phone = PhoneFactory.getDefaultPhone(); |
| 252 | |
Wink Saville | c388668 | 2009-04-02 11:00:56 -0700 | [diff] [blame] | 253 | mDeviceId= (TextView) findViewById(R.id.imei); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 254 | number = (TextView) findViewById(R.id.number); |
| 255 | callState = (TextView) findViewById(R.id.call); |
| 256 | operatorName = (TextView) findViewById(R.id.operator); |
| 257 | roamingState = (TextView) findViewById(R.id.roaming); |
| 258 | gsmState = (TextView) findViewById(R.id.gsm); |
| 259 | gprsState = (TextView) findViewById(R.id.gprs); |
| 260 | network = (TextView) findViewById(R.id.network); |
| 261 | dBm = (TextView) findViewById(R.id.dbm); |
| 262 | mMwi = (TextView) findViewById(R.id.mwi); |
| 263 | mCfi = (TextView) findViewById(R.id.cfi); |
| 264 | mLocation = (TextView) findViewById(R.id.location); |
| 265 | mNeighboringCids = (TextView) findViewById(R.id.neighboring); |
| 266 | |
| 267 | resets = (TextView) findViewById(R.id.resets); |
| 268 | attempts = (TextView) findViewById(R.id.attempts); |
| 269 | successes = (TextView) findViewById(R.id.successes); |
| 270 | disconnects = (TextView) findViewById(R.id.disconnects); |
| 271 | sentSinceReceived = (TextView) findViewById(R.id.sentSinceReceived); |
| 272 | sent = (TextView) findViewById(R.id.sent); |
| 273 | received = (TextView) findViewById(R.id.received); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 274 | smsc = (EditText) findViewById(R.id.smsc); |
| 275 | dnsCheckState = (TextView) findViewById(R.id.dnsCheckState); |
| 276 | |
| 277 | mPingIpAddr = (TextView) findViewById(R.id.pingIpAddr); |
| 278 | mPingHostname = (TextView) findViewById(R.id.pingHostname); |
| 279 | mHttpClientTest = (TextView) findViewById(R.id.httpClientTest); |
| 280 | |
| 281 | preferredNetworkType = (Spinner) findViewById(R.id.preferredNetworkType); |
| 282 | ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, |
| 283 | android.R.layout.simple_spinner_item, mPreferredNetworkLabels); |
johnwang | 342101a | 2009-09-23 16:22:34 -0700 | [diff] [blame] | 284 | adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 285 | preferredNetworkType.setAdapter(adapter); |
| 286 | preferredNetworkType.setOnItemSelectedListener(mPreferredNetworkHandler); |
| 287 | |
| 288 | radioPowerButton = (Button) findViewById(R.id.radio_power); |
| 289 | radioPowerButton.setOnClickListener(mPowerButtonHandler); |
| 290 | |
Wink Saville | 1e596f3 | 2011-09-19 14:24:39 -0700 | [diff] [blame] | 291 | imsRegRequiredButton = (Button) findViewById(R.id.ims_reg_required); |
| 292 | imsRegRequiredButton.setOnClickListener(mImsRegRequiredHandler); |
| 293 | |
Wink Saville | 382a75b | 2011-09-22 15:17:00 -0700 | [diff] [blame] | 294 | smsOverImsButton = (Button) findViewById(R.id.sms_over_ims); |
| 295 | smsOverImsButton.setOnClickListener(mSmsOverImsHandler); |
| 296 | |
Wink Saville | 426fc66 | 2011-09-25 14:39:02 -0700 | [diff] [blame] | 297 | lteRamDumpButton = (Button) findViewById(R.id.lte_ram_dump); |
| 298 | lteRamDumpButton.setOnClickListener(mLteRamDumpHandler); |
| 299 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 300 | pingTestButton = (Button) findViewById(R.id.ping_test); |
| 301 | pingTestButton.setOnClickListener(mPingButtonHandler); |
| 302 | updateSmscButton = (Button) findViewById(R.id.update_smsc); |
| 303 | updateSmscButton.setOnClickListener(mUpdateSmscButtonHandler); |
| 304 | refreshSmscButton = (Button) findViewById(R.id.refresh_smsc); |
| 305 | refreshSmscButton.setOnClickListener(mRefreshSmscButtonHandler); |
| 306 | dnsCheckToggleButton = (Button) findViewById(R.id.dns_check_toggle); |
| 307 | dnsCheckToggleButton.setOnClickListener(mDnsCheckButtonHandler); |
johnwang | 342101a | 2009-09-23 16:22:34 -0700 | [diff] [blame] | 308 | |
Tammo Spalink | a5f4c8f | 2009-10-15 20:08:58 +0800 | [diff] [blame] | 309 | oemInfoButton = (Button) findViewById(R.id.oem_info); |
| 310 | oemInfoButton.setOnClickListener(mOemInfoButtonHandler); |
| 311 | PackageManager pm = getPackageManager(); |
| 312 | Intent oemInfoIntent = new Intent("com.android.settings.OEM_RADIO_INFO"); |
| 313 | List<ResolveInfo> oemInfoIntentList = pm.queryIntentActivities(oemInfoIntent, 0); |
| 314 | if (oemInfoIntentList.size() == 0) { |
| 315 | oemInfoButton.setEnabled(false); |
| 316 | } |
| 317 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 318 | mPhoneStateReceiver = new PhoneStateIntentReceiver(this, mHandler); |
| 319 | mPhoneStateReceiver.notifySignalStrength(EVENT_SIGNAL_STRENGTH_CHANGED); |
| 320 | mPhoneStateReceiver.notifyServiceState(EVENT_SERVICE_STATE_CHANGED); |
| 321 | mPhoneStateReceiver.notifyPhoneCallState(EVENT_PHONE_STATE_CHANGED); |
johnwang | 342101a | 2009-09-23 16:22:34 -0700 | [diff] [blame] | 322 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 323 | phone.getPreferredNetworkType( |
| 324 | mHandler.obtainMessage(EVENT_QUERY_PREFERRED_TYPE_DONE)); |
| 325 | phone.getNeighboringCids( |
| 326 | mHandler.obtainMessage(EVENT_QUERY_NEIGHBORING_CIDS_DONE)); |
| 327 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 328 | CellLocation.requestLocationUpdate(); |
| 329 | } |
| 330 | |
| 331 | @Override |
| 332 | protected void onResume() { |
| 333 | super.onResume(); |
| 334 | |
| 335 | updatePhoneState(); |
| 336 | updateSignalStrength(); |
| 337 | updateMessageWaiting(); |
| 338 | updateCallRedirect(); |
| 339 | updateServiceState(); |
| 340 | updateLocation(mTelephonyManager.getCellLocation()); |
| 341 | updateDataState(); |
| 342 | updateDataStats(); |
| 343 | updateDataStats2(); |
| 344 | updatePowerState(); |
Wink Saville | 1e596f3 | 2011-09-19 14:24:39 -0700 | [diff] [blame] | 345 | updateImsRegRequiredState(); |
Wink Saville | 382a75b | 2011-09-22 15:17:00 -0700 | [diff] [blame] | 346 | updateSmsOverImsState(); |
Wink Saville | 426fc66 | 2011-09-25 14:39:02 -0700 | [diff] [blame] | 347 | updateLteRamDumpState(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 348 | updateProperties(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 349 | updateDnsCheckState(); |
| 350 | |
| 351 | Log.i(TAG, "[RadioInfo] onResume: register phone & data intents"); |
| 352 | |
| 353 | mPhoneStateReceiver.registerIntent(); |
| 354 | mTelephonyManager.listen(mPhoneStateListener, |
| 355 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
| 356 | | PhoneStateListener.LISTEN_DATA_ACTIVITY |
| 357 | | PhoneStateListener.LISTEN_CELL_LOCATION |
| 358 | | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
| 359 | | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR); |
| 360 | } |
| 361 | |
| 362 | @Override |
| 363 | public void onPause() { |
| 364 | super.onPause(); |
| 365 | |
| 366 | Log.i(TAG, "[RadioInfo] onPause: unregister phone & data intents"); |
| 367 | |
| 368 | mPhoneStateReceiver.unregisterIntent(); |
| 369 | mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); |
| 370 | } |
| 371 | |
| 372 | @Override |
| 373 | public boolean onCreateOptionsMenu(Menu menu) { |
Wink Saville | c388668 | 2009-04-02 11:00:56 -0700 | [diff] [blame] | 374 | menu.add(0, MENU_ITEM_SELECT_BAND, 0, R.string.radio_info_band_mode_label) |
| 375 | .setOnMenuItemClickListener(mSelectBandCallback) |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 376 | .setAlphabeticShortcut('b'); |
| 377 | menu.add(1, MENU_ITEM_VIEW_ADN, 0, |
| 378 | R.string.radioInfo_menu_viewADN).setOnMenuItemClickListener(mViewADNCallback); |
| 379 | menu.add(1, MENU_ITEM_VIEW_FDN, 0, |
| 380 | R.string.radioInfo_menu_viewFDN).setOnMenuItemClickListener(mViewFDNCallback); |
| 381 | menu.add(1, MENU_ITEM_VIEW_SDN, 0, |
| 382 | R.string.radioInfo_menu_viewSDN).setOnMenuItemClickListener(mViewSDNCallback); |
| 383 | menu.add(1, MENU_ITEM_GET_PDP_LIST, |
| 384 | 0, R.string.radioInfo_menu_getPDP).setOnMenuItemClickListener(mGetPdpList); |
| 385 | menu.add(1, MENU_ITEM_TOGGLE_DATA, |
Tammo Spalink | a5f4c8f | 2009-10-15 20:08:58 +0800 | [diff] [blame] | 386 | 0, DISABLE_DATA_STR).setOnMenuItemClickListener(mToggleData); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 387 | return true; |
| 388 | } |
| 389 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 390 | @Override |
Wink Saville | c388668 | 2009-04-02 11:00:56 -0700 | [diff] [blame] | 391 | public boolean onPrepareOptionsMenu(Menu menu) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 392 | // Get the TOGGLE DATA menu item in the right state. |
| 393 | MenuItem item = menu.findItem(MENU_ITEM_TOGGLE_DATA); |
| 394 | int state = mTelephonyManager.getDataState(); |
| 395 | boolean visible = true; |
| 396 | |
| 397 | switch (state) { |
| 398 | case TelephonyManager.DATA_CONNECTED: |
| 399 | case TelephonyManager.DATA_SUSPENDED: |
Tammo Spalink | a5f4c8f | 2009-10-15 20:08:58 +0800 | [diff] [blame] | 400 | item.setTitle(DISABLE_DATA_STR); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 401 | break; |
| 402 | case TelephonyManager.DATA_DISCONNECTED: |
Tammo Spalink | a5f4c8f | 2009-10-15 20:08:58 +0800 | [diff] [blame] | 403 | item.setTitle(ENABLE_DATA_STR); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 404 | break; |
| 405 | default: |
| 406 | visible = false; |
| 407 | break; |
| 408 | } |
| 409 | item.setVisible(visible); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 410 | return true; |
| 411 | } |
| 412 | |
| 413 | private boolean isRadioOn() { |
| 414 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 415 | } |
johnwang | 342101a | 2009-09-23 16:22:34 -0700 | [diff] [blame] | 416 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 417 | private void updatePowerState() { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 418 | String buttonText = isRadioOn() ? |
| 419 | getString(R.string.turn_off_radio) : |
| 420 | getString(R.string.turn_on_radio); |
Wink Saville | c388668 | 2009-04-02 11:00:56 -0700 | [diff] [blame] | 421 | radioPowerButton.setText(buttonText); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 422 | } |
| 423 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 424 | private void updateDnsCheckState() { |
Mike Lockwood | 5304c7e | 2009-04-05 11:37:45 -0700 | [diff] [blame] | 425 | dnsCheckState.setText(phone.isDnsCheckDisabled() ? |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 426 | "0.0.0.0 allowed" :"0.0.0.0 not allowed"); |
| 427 | } |
Wink Saville | e2a14e3 | 2009-05-29 14:06:30 -0700 | [diff] [blame] | 428 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 429 | private final void |
| 430 | updateSignalStrength() { |
Wink Saville | e2a14e3 | 2009-05-29 14:06:30 -0700 | [diff] [blame] | 431 | // TODO PhoneStateIntentReceiver is deprecated and PhoneStateListener |
| 432 | // should probably used instead. |
| 433 | int state = mPhoneStateReceiver.getServiceState().getState(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 434 | Resources r = getResources(); |
| 435 | |
| 436 | if ((ServiceState.STATE_OUT_OF_SERVICE == state) || |
| 437 | (ServiceState.STATE_POWER_OFF == state)) { |
| 438 | dBm.setText("0"); |
| 439 | } |
Wink Saville | e2a14e3 | 2009-05-29 14:06:30 -0700 | [diff] [blame] | 440 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 441 | int signalDbm = mPhoneStateReceiver.getSignalStrengthDbm(); |
Wink Saville | e2a14e3 | 2009-05-29 14:06:30 -0700 | [diff] [blame] | 442 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 443 | if (-1 == signalDbm) signalDbm = 0; |
| 444 | |
Wink Saville | 882c74a | 2011-02-17 12:00:03 -0800 | [diff] [blame] | 445 | int signalAsu = mPhoneStateReceiver.getSignalStrengthLevelAsu(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 446 | |
| 447 | if (-1 == signalAsu) signalAsu = 0; |
| 448 | |
| 449 | dBm.setText(String.valueOf(signalDbm) + " " |
| 450 | + r.getString(R.string.radioInfo_display_dbm) + " " |
| 451 | + String.valueOf(signalAsu) + " " |
| 452 | + r.getString(R.string.radioInfo_display_asu)); |
| 453 | } |
| 454 | |
| 455 | private final void updateLocation(CellLocation location) { |
jsh | 534f5ae | 2009-09-24 09:19:22 -0700 | [diff] [blame] | 456 | Resources r = getResources(); |
Wink Saville | c388668 | 2009-04-02 11:00:56 -0700 | [diff] [blame] | 457 | if (location instanceof GsmCellLocation) { |
| 458 | GsmCellLocation loc = (GsmCellLocation)location; |
jsh | 534f5ae | 2009-09-24 09:19:22 -0700 | [diff] [blame] | 459 | int lac = loc.getLac(); |
| 460 | int cid = loc.getCid(); |
| 461 | mLocation.setText(r.getString(R.string.radioInfo_lac) + " = " |
| 462 | + ((lac == -1) ? "unknown" : Integer.toHexString(lac)) |
| 463 | + " " |
| 464 | + r.getString(R.string.radioInfo_cid) + " = " |
| 465 | + ((cid == -1) ? "unknown" : Integer.toHexString(cid))); |
| 466 | } else if (location instanceof CdmaCellLocation) { |
| 467 | CdmaCellLocation loc = (CdmaCellLocation)location; |
| 468 | int bid = loc.getBaseStationId(); |
| 469 | int sid = loc.getSystemId(); |
| 470 | int nid = loc.getNetworkId(); |
| 471 | int lat = loc.getBaseStationLatitude(); |
| 472 | int lon = loc.getBaseStationLongitude(); |
| 473 | mLocation.setText("BID = " |
| 474 | + ((bid == -1) ? "unknown" : Integer.toHexString(bid)) |
| 475 | + " " |
| 476 | + "SID = " |
| 477 | + ((sid == -1) ? "unknown" : Integer.toHexString(sid)) |
| 478 | + " " |
| 479 | + "NID = " |
| 480 | + ((nid == -1) ? "unknown" : Integer.toHexString(nid)) |
| 481 | + "\n" |
| 482 | + "LAT = " |
| 483 | + ((lat == -1) ? "unknown" : Integer.toHexString(lat)) |
| 484 | + " " |
| 485 | + "LONG = " |
| 486 | + ((lon == -1) ? "unknown" : Integer.toHexString(lon))); |
| 487 | } else { |
| 488 | mLocation.setText("unknown"); |
Wink Saville | c388668 | 2009-04-02 11:00:56 -0700 | [diff] [blame] | 489 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 490 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 491 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | private final void updateNeighboringCids(ArrayList<NeighboringCellInfo> cids) { |
johnwang | f02c65f | 2009-09-25 17:26:54 -0700 | [diff] [blame] | 495 | StringBuilder sb = new StringBuilder(); |
| 496 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 497 | if (cids != null) { |
| 498 | if ( cids.isEmpty() ) { |
johnwang | f02c65f | 2009-09-25 17:26:54 -0700 | [diff] [blame] | 499 | sb.append("no neighboring cells"); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 500 | } else { |
| 501 | for (NeighboringCellInfo cell : cids) { |
johnwang | f02c65f | 2009-09-25 17:26:54 -0700 | [diff] [blame] | 502 | sb.append(cell.toString()).append(" "); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | } else { |
johnwang | f02c65f | 2009-09-25 17:26:54 -0700 | [diff] [blame] | 506 | sb.append("unknown"); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 507 | } |
johnwang | f02c65f | 2009-09-25 17:26:54 -0700 | [diff] [blame] | 508 | mNeighboringCids.setText(sb.toString()); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | private final void |
| 512 | updateMessageWaiting() { |
| 513 | mMwi.setText(String.valueOf(mMwiValue)); |
| 514 | } |
| 515 | |
| 516 | private final void |
| 517 | updateCallRedirect() { |
| 518 | mCfi.setText(String.valueOf(mCfiValue)); |
| 519 | } |
| 520 | |
| 521 | |
| 522 | private final void |
| 523 | updateServiceState() { |
| 524 | ServiceState serviceState = mPhoneStateReceiver.getServiceState(); |
| 525 | int state = serviceState.getState(); |
| 526 | Resources r = getResources(); |
| 527 | String display = r.getString(R.string.radioInfo_unknown); |
johnwang | 342101a | 2009-09-23 16:22:34 -0700 | [diff] [blame] | 528 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 529 | switch (state) { |
| 530 | case ServiceState.STATE_IN_SERVICE: |
| 531 | display = r.getString(R.string.radioInfo_service_in); |
| 532 | break; |
| 533 | case ServiceState.STATE_OUT_OF_SERVICE: |
| 534 | case ServiceState.STATE_EMERGENCY_ONLY: |
| 535 | display = r.getString(R.string.radioInfo_service_emergency); |
| 536 | break; |
| 537 | case ServiceState.STATE_POWER_OFF: |
| 538 | display = r.getString(R.string.radioInfo_service_off); |
| 539 | break; |
| 540 | } |
johnwang | 342101a | 2009-09-23 16:22:34 -0700 | [diff] [blame] | 541 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 542 | gsmState.setText(display); |
johnwang | 342101a | 2009-09-23 16:22:34 -0700 | [diff] [blame] | 543 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 544 | if (serviceState.getRoaming()) { |
| 545 | roamingState.setText(R.string.radioInfo_roaming_in); |
| 546 | } else { |
| 547 | roamingState.setText(R.string.radioInfo_roaming_not); |
| 548 | } |
| 549 | |
| 550 | operatorName.setText(serviceState.getOperatorAlphaLong()); |
| 551 | } |
| 552 | |
| 553 | private final void |
| 554 | updatePhoneState() { |
Wink Saville | 5543404 | 2012-06-14 12:33:43 -0700 | [diff] [blame] | 555 | PhoneConstants.State state = mPhoneStateReceiver.getPhoneState(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 556 | Resources r = getResources(); |
| 557 | String display = r.getString(R.string.radioInfo_unknown); |
| 558 | |
| 559 | switch (state) { |
| 560 | case IDLE: |
| 561 | display = r.getString(R.string.radioInfo_phone_idle); |
| 562 | break; |
| 563 | case RINGING: |
| 564 | display = r.getString(R.string.radioInfo_phone_ringing); |
| 565 | break; |
| 566 | case OFFHOOK: |
| 567 | display = r.getString(R.string.radioInfo_phone_offhook); |
| 568 | break; |
| 569 | } |
| 570 | |
| 571 | callState.setText(display); |
| 572 | } |
| 573 | |
| 574 | private final void |
| 575 | updateDataState() { |
| 576 | int state = mTelephonyManager.getDataState(); |
| 577 | Resources r = getResources(); |
| 578 | String display = r.getString(R.string.radioInfo_unknown); |
| 579 | |
| 580 | switch (state) { |
| 581 | case TelephonyManager.DATA_CONNECTED: |
| 582 | display = r.getString(R.string.radioInfo_data_connected); |
| 583 | break; |
| 584 | case TelephonyManager.DATA_CONNECTING: |
| 585 | display = r.getString(R.string.radioInfo_data_connecting); |
| 586 | break; |
| 587 | case TelephonyManager.DATA_DISCONNECTED: |
| 588 | display = r.getString(R.string.radioInfo_data_disconnected); |
| 589 | break; |
| 590 | case TelephonyManager.DATA_SUSPENDED: |
| 591 | display = r.getString(R.string.radioInfo_data_suspended); |
| 592 | break; |
| 593 | } |
johnwang | 342101a | 2009-09-23 16:22:34 -0700 | [diff] [blame] | 594 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 595 | gprsState.setText(display); |
| 596 | } |
| 597 | |
| 598 | private final void updateNetworkType() { |
| 599 | Resources r = getResources(); |
| 600 | String display = SystemProperties.get(TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, |
| 601 | r.getString(R.string.radioInfo_unknown)); |
| 602 | |
| 603 | network.setText(display); |
| 604 | } |
| 605 | |
| 606 | private final void |
| 607 | updateProperties() { |
| 608 | String s; |
| 609 | Resources r = getResources(); |
| 610 | |
| 611 | s = phone.getDeviceId(); |
johnwang | 342101a | 2009-09-23 16:22:34 -0700 | [diff] [blame] | 612 | if (s == null) s = r.getString(R.string.radioInfo_unknown); |
Wink Saville | c388668 | 2009-04-02 11:00:56 -0700 | [diff] [blame] | 613 | mDeviceId.setText(s); |
johnwang | 342101a | 2009-09-23 16:22:34 -0700 | [diff] [blame] | 614 | |
Wink Saville | c388668 | 2009-04-02 11:00:56 -0700 | [diff] [blame] | 615 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 616 | s = phone.getLine1Number(); |
johnwang | 342101a | 2009-09-23 16:22:34 -0700 | [diff] [blame] | 617 | if (s == null) s = r.getString(R.string.radioInfo_unknown); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 618 | number.setText(s); |
| 619 | } |
| 620 | |
| 621 | private final void updateDataStats() { |
| 622 | String s; |
| 623 | |
| 624 | s = SystemProperties.get("net.gsm.radio-reset", "0"); |
| 625 | resets.setText(s); |
| 626 | |
| 627 | s = SystemProperties.get("net.gsm.attempt-gprs", "0"); |
| 628 | attempts.setText(s); |
| 629 | |
| 630 | s = SystemProperties.get("net.gsm.succeed-gprs", "0"); |
| 631 | successes.setText(s); |
| 632 | |
| 633 | //s = SystemProperties.get("net.gsm.disconnect", "0"); |
| 634 | //disconnects.setText(s); |
| 635 | |
| 636 | s = SystemProperties.get("net.ppp.reset-by-timeout", "0"); |
| 637 | sentSinceReceived.setText(s); |
| 638 | } |
| 639 | |
| 640 | private final void updateDataStats2() { |
| 641 | Resources r = getResources(); |
| 642 | |
Jeff Sharkey | 9302986 | 2011-05-27 18:26:15 -0700 | [diff] [blame] | 643 | long txPackets = TrafficStats.getMobileTxPackets(); |
| 644 | long rxPackets = TrafficStats.getMobileRxPackets(); |
| 645 | long txBytes = TrafficStats.getMobileTxBytes(); |
| 646 | long rxBytes = TrafficStats.getMobileRxBytes(); |
johnwang | 342101a | 2009-09-23 16:22:34 -0700 | [diff] [blame] | 647 | |
Jeff Sharkey | 9302986 | 2011-05-27 18:26:15 -0700 | [diff] [blame] | 648 | String packets = r.getString(R.string.radioInfo_display_packets); |
| 649 | String bytes = r.getString(R.string.radioInfo_display_bytes); |
johnwang | 342101a | 2009-09-23 16:22:34 -0700 | [diff] [blame] | 650 | |
Jeff Sharkey | 9302986 | 2011-05-27 18:26:15 -0700 | [diff] [blame] | 651 | sent.setText(txPackets + " " + packets + ", " + txBytes + " " + bytes); |
| 652 | received.setText(rxPackets + " " + packets + ", " + rxBytes + " " + bytes); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | /** |
| 656 | * Ping a IP address. |
| 657 | */ |
| 658 | private final void pingIpAddr() { |
| 659 | try { |
| 660 | // This is hardcoded IP addr. This is for testing purposes. |
| 661 | // We would need to get rid of this before release. |
| 662 | String ipAddress = "74.125.47.104"; |
| 663 | Process p = Runtime.getRuntime().exec("ping -c 1 " + ipAddress); |
| 664 | int status = p.waitFor(); |
| 665 | if (status == 0) { |
| 666 | mPingIpAddrResult = "Pass"; |
| 667 | } else { |
| 668 | mPingIpAddrResult = "Fail: IP addr not reachable"; |
| 669 | } |
| 670 | } catch (IOException e) { |
| 671 | mPingIpAddrResult = "Fail: IOException"; |
| 672 | } catch (InterruptedException e) { |
| 673 | mPingIpAddrResult = "Fail: InterruptedException"; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | /** |
| 678 | * Ping a host name |
| 679 | */ |
| 680 | private final void pingHostname() { |
| 681 | try { |
johnwang | 342101a | 2009-09-23 16:22:34 -0700 | [diff] [blame] | 682 | Process p = Runtime.getRuntime().exec("ping -c 1 www.google.com"); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 683 | int status = p.waitFor(); |
| 684 | if (status == 0) { |
| 685 | mPingHostnameResult = "Pass"; |
| 686 | } else { |
| 687 | mPingHostnameResult = "Fail: Host unreachable"; |
| 688 | } |
| 689 | } catch (UnknownHostException e) { |
| 690 | mPingHostnameResult = "Fail: Unknown Host"; |
| 691 | } catch (IOException e) { |
| 692 | mPingHostnameResult= "Fail: IOException"; |
| 693 | } catch (InterruptedException e) { |
| 694 | mPingHostnameResult = "Fail: InterruptedException"; |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | /** |
| 699 | * This function checks for basic functionality of HTTP Client. |
| 700 | */ |
| 701 | private void httpClientTest() { |
| 702 | HttpClient client = new DefaultHttpClient(); |
| 703 | try { |
| 704 | HttpGet request = new HttpGet("http://www.google.com"); |
| 705 | HttpResponse response = client.execute(request); |
| 706 | if (response.getStatusLine().getStatusCode() == 200) { |
| 707 | mHttpClientTestResult = "Pass"; |
| 708 | } else { |
| 709 | mHttpClientTestResult = "Fail: Code: " + String.valueOf(response); |
| 710 | } |
| 711 | request.abort(); |
| 712 | } catch (IOException e) { |
| 713 | mHttpClientTestResult = "Fail: IOException"; |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | private void refreshSmsc() { |
jsh | 21dd407 | 2009-05-12 11:26:55 -0700 | [diff] [blame] | 718 | phone.getSmscAddress(mHandler.obtainMessage(EVENT_QUERY_SMSC_DONE)); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | private final void updatePingState() { |
| 722 | final Handler handler = new Handler(); |
| 723 | // Set all to unknown since the threads will take a few secs to update. |
| 724 | mPingIpAddrResult = getResources().getString(R.string.radioInfo_unknown); |
| 725 | mPingHostnameResult = getResources().getString(R.string.radioInfo_unknown); |
| 726 | mHttpClientTestResult = getResources().getString(R.string.radioInfo_unknown); |
| 727 | |
| 728 | mPingIpAddr.setText(mPingIpAddrResult); |
| 729 | mPingHostname.setText(mPingHostnameResult); |
| 730 | mHttpClientTest.setText(mHttpClientTestResult); |
| 731 | |
| 732 | final Runnable updatePingResults = new Runnable() { |
| 733 | public void run() { |
| 734 | mPingIpAddr.setText(mPingIpAddrResult); |
| 735 | mPingHostname.setText(mPingHostnameResult); |
| 736 | mHttpClientTest.setText(mHttpClientTestResult); |
| 737 | } |
| 738 | }; |
| 739 | Thread ipAddr = new Thread() { |
| 740 | @Override |
| 741 | public void run() { |
| 742 | pingIpAddr(); |
| 743 | handler.post(updatePingResults); |
| 744 | } |
| 745 | }; |
| 746 | ipAddr.start(); |
| 747 | |
| 748 | Thread hostname = new Thread() { |
| 749 | @Override |
| 750 | public void run() { |
| 751 | pingHostname(); |
| 752 | handler.post(updatePingResults); |
| 753 | } |
| 754 | }; |
| 755 | hostname.start(); |
| 756 | |
| 757 | Thread httpClient = new Thread() { |
| 758 | @Override |
| 759 | public void run() { |
| 760 | httpClientTest(); |
| 761 | handler.post(updatePingResults); |
| 762 | } |
| 763 | }; |
| 764 | httpClient.start(); |
| 765 | } |
| 766 | |
| 767 | private final void updatePdpList() { |
| 768 | StringBuilder sb = new StringBuilder("========DATA=======\n"); |
| 769 | |
Wink Saville | 2c3ec09 | 2011-04-20 10:24:36 -0700 | [diff] [blame] | 770 | // List<DataConnection> dcs = phone.getCurrentDataConnectionList(); |
| 771 | // |
| 772 | // for (DataConnection dc : dcs) { |
| 773 | // sb.append(" State=").append(dc.getStateAsString()).append("\n"); |
| 774 | // if (dc.isActive()) { |
| 775 | // long timeElapsed = |
| 776 | // (System.currentTimeMillis() - dc.getConnectionTime())/1000; |
| 777 | // sb.append(" connected at ") |
| 778 | // .append(DateUtils.timeString(dc.getConnectionTime())) |
| 779 | // .append(" and elapsed ") |
| 780 | // .append(DateUtils.formatElapsedTime(timeElapsed)); |
| 781 | // |
| 782 | // if (dc instanceof GsmDataConnection) { |
| 783 | // GsmDataConnection pdp = (GsmDataConnection)dc; |
| 784 | // sb.append("\n to ") |
| 785 | // .append(pdp.getApn().toString()); |
| 786 | // } |
| 787 | // sb.append("\nLinkProperties: "); |
| 788 | // sb.append(phone.getLinkProperties(phone.getActiveApnTypes()[0]).toString()); |
| 789 | // } else if (dc.isInactive()) { |
| 790 | // sb.append(" disconnected with last try at ") |
| 791 | // .append(DateUtils.timeString(dc.getLastFailTime())) |
| 792 | // .append("\n fail because ") |
| 793 | // .append(dc.getLastFailCause().toString()); |
| 794 | // } else { |
| 795 | // if (dc instanceof GsmDataConnection) { |
| 796 | // GsmDataConnection pdp = (GsmDataConnection)dc; |
| 797 | // sb.append(" is connecting to ") |
| 798 | // .append(pdp.getApn().toString()); |
| 799 | // } else { |
| 800 | // sb.append(" is connecting"); |
| 801 | // } |
| 802 | // } |
| 803 | // sb.append("\n==================="); |
| 804 | // } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 805 | |
| 806 | disconnects.setText(sb.toString()); |
| 807 | } |
| 808 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 809 | private MenuItem.OnMenuItemClickListener mViewADNCallback = new MenuItem.OnMenuItemClickListener() { |
| 810 | public boolean onMenuItemClick(MenuItem item) { |
| 811 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 812 | // XXX We need to specify the component here because if we don't |
| 813 | // the activity manager will try to resolve the type by calling |
| 814 | // the content provider, which causes it to be loaded in a process |
| 815 | // other than the Dialer process, which causes a lot of stuff to |
| 816 | // break. |
| 817 | intent.setClassName("com.android.phone", |
| 818 | "com.android.phone.SimContacts"); |
| 819 | startActivity(intent); |
| 820 | return true; |
| 821 | } |
| 822 | }; |
| 823 | |
| 824 | private MenuItem.OnMenuItemClickListener mViewFDNCallback = new MenuItem.OnMenuItemClickListener() { |
| 825 | public boolean onMenuItemClick(MenuItem item) { |
| 826 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 827 | // XXX We need to specify the component here because if we don't |
| 828 | // the activity manager will try to resolve the type by calling |
| 829 | // the content provider, which causes it to be loaded in a process |
| 830 | // other than the Dialer process, which causes a lot of stuff to |
| 831 | // break. |
| 832 | intent.setClassName("com.android.phone", |
| 833 | "com.android.phone.FdnList"); |
| 834 | startActivity(intent); |
| 835 | return true; |
| 836 | } |
| 837 | }; |
| 838 | |
| 839 | private MenuItem.OnMenuItemClickListener mViewSDNCallback = new MenuItem.OnMenuItemClickListener() { |
| 840 | public boolean onMenuItemClick(MenuItem item) { |
| 841 | Intent intent = new Intent( |
Wink Saville | c388668 | 2009-04-02 11:00:56 -0700 | [diff] [blame] | 842 | Intent.ACTION_VIEW, Uri.parse("content://icc/sdn")); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 843 | // XXX We need to specify the component here because if we don't |
| 844 | // the activity manager will try to resolve the type by calling |
| 845 | // the content provider, which causes it to be loaded in a process |
| 846 | // other than the Dialer process, which causes a lot of stuff to |
| 847 | // break. |
| 848 | intent.setClassName("com.android.phone", |
| 849 | "com.android.phone.ADNList"); |
| 850 | startActivity(intent); |
| 851 | return true; |
| 852 | } |
| 853 | }; |
| 854 | |
Tammo Spalink | a5f4c8f | 2009-10-15 20:08:58 +0800 | [diff] [blame] | 855 | private MenuItem.OnMenuItemClickListener mGetPdpList = new MenuItem.OnMenuItemClickListener() { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 856 | public boolean onMenuItemClick(MenuItem item) { |
Tammo Spalink | a5f4c8f | 2009-10-15 20:08:58 +0800 | [diff] [blame] | 857 | phone.getDataCallList(null); |
| 858 | return true; |
| 859 | } |
| 860 | }; |
| 861 | |
| 862 | private MenuItem.OnMenuItemClickListener mSelectBandCallback = new MenuItem.OnMenuItemClickListener() { |
| 863 | public boolean onMenuItemClick(MenuItem item) { |
| 864 | Intent intent = new Intent(); |
| 865 | intent.setClass(RadioInfo.this, BandMode.class); |
| 866 | startActivity(intent); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 867 | return true; |
| 868 | } |
| 869 | }; |
johnwang | 342101a | 2009-09-23 16:22:34 -0700 | [diff] [blame] | 870 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 871 | private MenuItem.OnMenuItemClickListener mToggleData = new MenuItem.OnMenuItemClickListener() { |
| 872 | public boolean onMenuItemClick(MenuItem item) { |
Robert Greenwalt | 99be500 | 2010-11-24 17:20:59 -0800 | [diff] [blame] | 873 | ConnectivityManager cm = |
| 874 | (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 875 | int state = mTelephonyManager.getDataState(); |
| 876 | switch (state) { |
| 877 | case TelephonyManager.DATA_CONNECTED: |
Robert Greenwalt | 99be500 | 2010-11-24 17:20:59 -0800 | [diff] [blame] | 878 | cm.setMobileDataEnabled(false); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 879 | break; |
| 880 | case TelephonyManager.DATA_DISCONNECTED: |
Robert Greenwalt | 99be500 | 2010-11-24 17:20:59 -0800 | [diff] [blame] | 881 | cm.setMobileDataEnabled(true); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 882 | break; |
| 883 | default: |
| 884 | // do nothing |
| 885 | break; |
| 886 | } |
| 887 | return true; |
| 888 | } |
| 889 | }; |
| 890 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 891 | OnClickListener mPowerButtonHandler = new OnClickListener() { |
| 892 | public void onClick(View v) { |
| 893 | //log("toggle radio power: currently " + (isRadioOn()?"on":"off")); |
| 894 | phone.setRadioPower(!isRadioOn()); |
| 895 | } |
| 896 | }; |
| 897 | |
Wink Saville | 426fc66 | 2011-09-25 14:39:02 -0700 | [diff] [blame] | 898 | private Button imsRegRequiredButton; |
| 899 | static final String PROPERTY_IMS_REG_REQUIRED = "persist.radio.imsregrequired"; |
Wink Saville | 1e596f3 | 2011-09-19 14:24:39 -0700 | [diff] [blame] | 900 | OnClickListener mImsRegRequiredHandler = new OnClickListener() { |
| 901 | @Override |
| 902 | public void onClick(View v) { |
| 903 | Log.d(TAG, String.format("toggle %s: currently %s", |
Wink Saville | 426fc66 | 2011-09-25 14:39:02 -0700 | [diff] [blame] | 904 | PROPERTY_IMS_REG_REQUIRED, (isImsRegRequired() ? "on":"off"))); |
Wink Saville | 1e596f3 | 2011-09-19 14:24:39 -0700 | [diff] [blame] | 905 | boolean newValue = !isImsRegRequired(); |
Wink Saville | 426fc66 | 2011-09-25 14:39:02 -0700 | [diff] [blame] | 906 | SystemProperties.set(PROPERTY_IMS_REG_REQUIRED, |
Wink Saville | 1e596f3 | 2011-09-19 14:24:39 -0700 | [diff] [blame] | 907 | newValue ? "1":"0"); |
| 908 | updateImsRegRequiredState(); |
| 909 | } |
| 910 | }; |
| 911 | |
Wink Saville | 426fc66 | 2011-09-25 14:39:02 -0700 | [diff] [blame] | 912 | private boolean isImsRegRequired() { |
| 913 | return SystemProperties.getBoolean(PROPERTY_IMS_REG_REQUIRED, false); |
| 914 | } |
| 915 | |
| 916 | private void updateImsRegRequiredState() { |
| 917 | Log.d(TAG, "updateImsRegRequiredState isImsRegRequired()=" + isImsRegRequired()); |
| 918 | String buttonText = isImsRegRequired() ? |
| 919 | getString(R.string.ims_reg_required_off) : |
| 920 | getString(R.string.ims_reg_required_on); |
| 921 | imsRegRequiredButton.setText(buttonText); |
| 922 | } |
| 923 | |
| 924 | private Button smsOverImsButton; |
Wink Saville | 382a75b | 2011-09-22 15:17:00 -0700 | [diff] [blame] | 925 | static final String PROPERTY_SMS_OVER_IMS = "persist.radio.imsallowmtsms"; |
| 926 | OnClickListener mSmsOverImsHandler = new OnClickListener() { |
| 927 | @Override |
| 928 | public void onClick(View v) { |
| 929 | Log.d(TAG, String.format("toggle %s: currently %s", |
| 930 | PROPERTY_SMS_OVER_IMS, (isSmsOverImsEnabled() ? "on":"off"))); |
| 931 | boolean newValue = !isSmsOverImsEnabled(); |
| 932 | SystemProperties.set(PROPERTY_SMS_OVER_IMS, newValue ? "1":"0"); |
| 933 | updateSmsOverImsState(); |
| 934 | } |
| 935 | }; |
| 936 | |
Wink Saville | 426fc66 | 2011-09-25 14:39:02 -0700 | [diff] [blame] | 937 | private boolean isSmsOverImsEnabled() { |
| 938 | return SystemProperties.getBoolean(PROPERTY_SMS_OVER_IMS, false); |
| 939 | } |
| 940 | |
| 941 | private void updateSmsOverImsState() { |
| 942 | Log.d(TAG, "updateSmsOverImsState isSmsOverImsEnabled()=" + isSmsOverImsEnabled()); |
| 943 | String buttonText = isSmsOverImsEnabled() ? |
| 944 | getString(R.string.sms_over_ims_off) : |
| 945 | getString(R.string.sms_over_ims_on); |
| 946 | smsOverImsButton.setText(buttonText); |
| 947 | } |
| 948 | |
| 949 | private Button lteRamDumpButton; |
| 950 | static final String PROPERTY_LTE_RAM_DUMP = "persist.radio.ramdump"; |
| 951 | OnClickListener mLteRamDumpHandler = new OnClickListener() { |
| 952 | @Override |
| 953 | public void onClick(View v) { |
| 954 | Log.d(TAG, String.format("toggle %s: currently %s", |
| 955 | PROPERTY_LTE_RAM_DUMP, (isSmsOverImsEnabled() ? "on":"off"))); |
| 956 | boolean newValue = !isLteRamDumpEnabled(); |
| 957 | SystemProperties.set(PROPERTY_LTE_RAM_DUMP, newValue ? "1":"0"); |
| 958 | updateLteRamDumpState(); |
| 959 | } |
| 960 | }; |
| 961 | |
| 962 | private boolean isLteRamDumpEnabled() { |
| 963 | return SystemProperties.getBoolean(PROPERTY_LTE_RAM_DUMP, false); |
| 964 | } |
| 965 | |
| 966 | private void updateLteRamDumpState() { |
| 967 | Log.d(TAG, "updateLteRamDumpState isLteRamDumpEnabled()=" + isLteRamDumpEnabled()); |
| 968 | String buttonText = isLteRamDumpEnabled() ? |
| 969 | getString(R.string.lte_ram_dump_off) : |
| 970 | getString(R.string.lte_ram_dump_on); |
| 971 | lteRamDumpButton.setText(buttonText); |
| 972 | } |
| 973 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 974 | OnClickListener mDnsCheckButtonHandler = new OnClickListener() { |
| 975 | public void onClick(View v) { |
Wink Saville | c388668 | 2009-04-02 11:00:56 -0700 | [diff] [blame] | 976 | phone.disableDnsCheck(!phone.isDnsCheckDisabled()); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 977 | updateDnsCheckState(); |
| 978 | } |
| 979 | }; |
johnwang | 342101a | 2009-09-23 16:22:34 -0700 | [diff] [blame] | 980 | |
Tammo Spalink | a5f4c8f | 2009-10-15 20:08:58 +0800 | [diff] [blame] | 981 | OnClickListener mOemInfoButtonHandler = new OnClickListener() { |
| 982 | public void onClick(View v) { |
| 983 | Intent intent = new Intent("com.android.settings.OEM_RADIO_INFO"); |
| 984 | try { |
| 985 | startActivity(intent); |
| 986 | } catch (android.content.ActivityNotFoundException ex) { |
| 987 | Log.d(TAG, "OEM-specific Info/Settings Activity Not Found : " + ex); |
| 988 | // If the activity does not exist, there are no OEM |
| 989 | // settings, and so we can just do nothing... |
| 990 | } |
| 991 | } |
| 992 | }; |
| 993 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 994 | OnClickListener mPingButtonHandler = new OnClickListener() { |
| 995 | public void onClick(View v) { |
| 996 | updatePingState(); |
| 997 | } |
| 998 | }; |
| 999 | |
| 1000 | OnClickListener mUpdateSmscButtonHandler = new OnClickListener() { |
| 1001 | public void onClick(View v) { |
| 1002 | updateSmscButton.setEnabled(false); |
jsh | 21dd407 | 2009-05-12 11:26:55 -0700 | [diff] [blame] | 1003 | phone.setSmscAddress(smsc.getText().toString(), |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1004 | mHandler.obtainMessage(EVENT_UPDATE_SMSC_DONE)); |
| 1005 | } |
| 1006 | }; |
| 1007 | |
| 1008 | OnClickListener mRefreshSmscButtonHandler = new OnClickListener() { |
| 1009 | public void onClick(View v) { |
| 1010 | refreshSmsc(); |
| 1011 | } |
| 1012 | }; |
| 1013 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1014 | AdapterView.OnItemSelectedListener |
| 1015 | mPreferredNetworkHandler = new AdapterView.OnItemSelectedListener() { |
| 1016 | public void onItemSelected(AdapterView parent, View v, int pos, long id) { |
| 1017 | Message msg = mHandler.obtainMessage(EVENT_SET_PREFERRED_TYPE_DONE); |
Ricardo Cerqueira | 32310ee | 2012-04-12 23:34:38 +0100 | [diff] [blame] | 1018 | if (pos>=0 && pos<=(mPreferredNetworkLabels.length - 2)) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1019 | phone.setPreferredNetworkType(pos, msg); |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | public void onNothingSelected(AdapterView parent) { |
| 1024 | } |
| 1025 | }; |
| 1026 | |
| 1027 | private String[] mPreferredNetworkLabels = { |
jsh | 87fa11b | 2009-08-18 18:00:15 -0700 | [diff] [blame] | 1028 | "WCDMA preferred", |
| 1029 | "GSM only", |
| 1030 | "WCDMA only", |
| 1031 | "GSM auto (PRL)", |
| 1032 | "CDMA auto (PRL)", |
| 1033 | "CDMA only", |
| 1034 | "EvDo only", |
| 1035 | "GSM/CDMA auto (PRL)", |
Ricardo Cerqueira | 32310ee | 2012-04-12 23:34:38 +0100 | [diff] [blame] | 1036 | "LTE/CDMA auto (PRL)", |
| 1037 | "LTE/GSM auto (PRL)", |
| 1038 | "LTE/GSM/CDMA auto (PRL)", |
| 1039 | "LTE only", |
jsh | 87fa11b | 2009-08-18 18:00:15 -0700 | [diff] [blame] | 1040 | "Unknown"}; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1041 | } |