blob: 91d319c42ec5d36e75972e446fc0c3ba247f6587 [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings;
18
19import android.app.Activity;
Nathan Harolde272c202016-10-27 13:45:00 -070020import android.app.AlertDialog;
21import android.app.Dialog;
Pavel Zhamaitsiakcb267a62015-01-21 18:25:14 -080022import android.app.QueuedWork;
Youhan Wangfd781e92016-12-16 15:53:16 -080023import android.content.ComponentName;
Meng Wang586741c2017-04-26 15:02:51 -070024import android.content.Context;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080025import android.content.Intent;
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +080026import android.content.pm.PackageManager;
27import android.content.pm.ResolveInfo;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080028import android.content.res.Resources;
Nathan Haroldcea413a2015-11-23 15:48:10 -080029import android.graphics.Typeface;
Jeff Sharkey93029862011-05-27 18:26:15 -070030import android.net.TrafficStats;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080031import android.net.Uri;
32import android.os.AsyncResult;
33import android.os.Bundle;
34import android.os.Handler;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080035import android.os.Message;
Meng Wang586741c2017-04-26 15:02:51 -070036import android.telephony.CarrierConfigManager;
Wink Saville79bff2a2012-06-01 14:37:21 -070037import android.telephony.CellInfo;
Nathan Haroldcea413a2015-11-23 15:48:10 -080038import android.telephony.CellInfoCdma;
39import android.telephony.CellInfoGsm;
40import android.telephony.CellInfoLte;
41import android.telephony.CellInfoWcdma;
42import android.telephony.CellIdentityCdma;
43import android.telephony.CellIdentityGsm;
44import android.telephony.CellIdentityLte;
45import android.telephony.CellIdentityWcdma;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080046import android.telephony.CellLocation;
Nathan Haroldcea413a2015-11-23 15:48:10 -080047import android.telephony.CellSignalStrengthCdma;
48import android.telephony.CellSignalStrengthGsm;
49import android.telephony.CellSignalStrengthLte;
50import android.telephony.CellSignalStrengthWcdma;
Wink Saville4f0d8812014-04-15 22:05:24 -070051import android.telephony.DataConnectionRealTimeInfo;
Jason Monk39b46742015-09-10 15:52:51 -040052import android.telephony.NeighboringCellInfo;
Nathan Harold2b77d742016-03-19 13:22:10 -070053import android.telephony.PreciseCallState;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080054import android.telephony.PhoneStateListener;
55import android.telephony.ServiceState;
Nathan Harold2b77d742016-03-19 13:22:10 -070056import android.telephony.SignalStrength;
Nathan Haroldcea413a2015-11-23 15:48:10 -080057import android.telephony.SubscriptionManager;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080058import android.telephony.TelephonyManager;
jsh534f5ae2009-09-24 09:19:22 -070059import android.telephony.cdma.CdmaCellLocation;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080060import android.telephony.gsm.GsmCellLocation;
Nathan Harold6e16fdf2018-04-17 17:01:32 -070061import android.text.TextUtils;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080062import android.util.Log;
63import android.view.Menu;
64import android.view.MenuItem;
65import android.view.View;
66import android.view.View.OnClickListener;
67import android.widget.AdapterView;
68import android.widget.ArrayAdapter;
69import android.widget.Button;
Nathan Harold2b77d742016-03-19 13:22:10 -070070import android.widget.CompoundButton;
71import android.widget.CompoundButton.OnCheckedChangeListener;
Jason Monk39b46742015-09-10 15:52:51 -040072import android.widget.EditText;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080073import android.widget.Spinner;
Nathan Harold2b77d742016-03-19 13:22:10 -070074import android.widget.Switch;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080075import android.widget.TextView;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080076
Jason Monk39b46742015-09-10 15:52:51 -040077import com.android.ims.ImsConfig;
78import com.android.ims.ImsException;
79import com.android.ims.ImsManager;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080080import com.android.internal.telephony.Phone;
Wink Saville55434042012-06-14 12:33:43 -070081import com.android.internal.telephony.PhoneConstants;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080082import com.android.internal.telephony.PhoneFactory;
Nathan Haroldcea413a2015-11-23 15:48:10 -080083import com.android.internal.telephony.RILConstants;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080084import com.android.internal.telephony.TelephonyProperties;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080085
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080086import java.io.IOException;
Jason Monk39b46742015-09-10 15:52:51 -040087import java.net.HttpURLConnection;
88import java.net.URL;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080089import java.net.UnknownHostException;
90import java.util.ArrayList;
91import java.util.List;
92
93public class RadioInfo extends Activity {
Nathan Harold2b77d742016-03-19 13:22:10 -070094 private static final String TAG = "RadioInfo";
johnwang342101a2009-09-23 16:22:34 -070095
Nathan Harold2b77d742016-03-19 13:22:10 -070096 private static final String[] mPreferredNetworkLabels = {
97 "WCDMA preferred",
98 "GSM only",
99 "WCDMA only",
100 "GSM auto (PRL)",
101 "CDMA auto (PRL)",
102 "CDMA only",
103 "EvDo only",
104 "Global auto (PRL)",
105 "LTE/CDMA auto (PRL)",
106 "LTE/UMTS auto (PRL)",
107 "LTE/CDMA/UMTS auto (PRL)",
108 "LTE only",
109 "LTE/WCDMA",
110 "TD-SCDMA only",
111 "TD-SCDMA/WCDMA",
112 "LTE/TD-SCDMA",
113 "TD-SCDMA/GSM",
114 "TD-SCDMA/UMTS",
115 "LTE/TD-SCDMA/WCDMA",
116 "LTE/TD-SCDMA/UMTS",
117 "TD-SCDMA/CDMA/UMTS",
118 "Global/TD-SCDMA",
119 "Unknown"
120 };
121
122
123 private static final int CELL_INFO_LIST_RATE_DISABLED = Integer.MAX_VALUE;
124 private static final int CELL_INFO_LIST_RATE_MAX = 0;
125
Nathan Harold12e1f552016-06-17 13:55:38 -0700126
127 private static final int IMS_VOLTE_PROVISIONED_CONFIG_ID =
128 ImsConfig.ConfigConstants.VLT_SETTING_ENABLED;
129
130 private static final int IMS_VT_PROVISIONED_CONFIG_ID =
131 ImsConfig.ConfigConstants.LVC_SETTING_ENABLED;
132
133 private static final int IMS_WFC_PROVISIONED_CONFIG_ID =
134 ImsConfig.ConfigConstants.VOICE_OVER_WIFI_SETTING_ENABLED;
135
Meng Wang586741c2017-04-26 15:02:51 -0700136 private static final int EAB_PROVISIONED_CONFIG_ID =
137 ImsConfig.ConfigConstants.EAB_SETTING_ENABLED;
138
Nathan Harold2b77d742016-03-19 13:22:10 -0700139 //Values in must match mCellInfoRefreshRates
140 private static final String[] mCellInfoRefreshRateLabels = {
141 "Disabled",
142 "Immediate",
143 "Min 5s",
144 "Min 10s",
145 "Min 60s"
146 };
147
148 //Values in seconds, must match mCellInfoRefreshRateLabels
149 private static final int mCellInfoRefreshRates[] = {
150 CELL_INFO_LIST_RATE_DISABLED,
151 CELL_INFO_LIST_RATE_MAX,
152 5000,
153 10000,
154 60000
155 };
156
157 private void log(String s) {
158 Log.d(TAG, s);
159 }
160
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800161 private static final int EVENT_CFI_CHANGED = 302;
162
163 private static final int EVENT_QUERY_PREFERRED_TYPE_DONE = 1000;
164 private static final int EVENT_SET_PREFERRED_TYPE_DONE = 1001;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800165 private static final int EVENT_QUERY_SMSC_DONE = 1005;
166 private static final int EVENT_UPDATE_SMSC_DONE = 1006;
167
168 private static final int MENU_ITEM_SELECT_BAND = 0;
169 private static final int MENU_ITEM_VIEW_ADN = 1;
170 private static final int MENU_ITEM_VIEW_FDN = 2;
171 private static final int MENU_ITEM_VIEW_SDN = 3;
Nathan Harolde272c202016-10-27 13:45:00 -0700172 private static final int MENU_ITEM_GET_IMS_STATUS = 4;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800173 private static final int MENU_ITEM_TOGGLE_DATA = 5;
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800174
Wink Savillec3886682009-04-02 11:00:56 -0700175 private TextView mDeviceId; //DeviceId is the IMEI in GSM and the MEID in CDMA
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800176 private TextView number;
Meng Wang9053f172017-06-23 16:02:14 -0700177 private TextView mSubscriberId;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800178 private TextView callState;
179 private TextView operatorName;
180 private TextView roamingState;
181 private TextView gsmState;
182 private TextView gprsState;
Nathan Harold2b77d742016-03-19 13:22:10 -0700183 private TextView voiceNetwork;
184 private TextView dataNetwork;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800185 private TextView dBm;
186 private TextView mMwi;
187 private TextView mCfi;
188 private TextView mLocation;
189 private TextView mNeighboringCids;
Wink Saville79bff2a2012-06-01 14:37:21 -0700190 private TextView mCellInfo;
Wink Saville4f0d8812014-04-15 22:05:24 -0700191 private TextView mDcRtInfoTv;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800192 private TextView sent;
193 private TextView received;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800194 private TextView mPingHostnameV4;
195 private TextView mPingHostnameV6;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800196 private TextView mHttpClientTest;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800197 private TextView dnsCheckState;
198 private EditText smsc;
Nathan Harold2b77d742016-03-19 13:22:10 -0700199 private Switch radioPowerOnSwitch;
200 private Button cellInfoRefreshRateButton;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800201 private Button dnsCheckToggleButton;
202 private Button pingTestButton;
203 private Button updateSmscButton;
204 private Button refreshSmscButton;
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800205 private Button oemInfoButton;
Youhan Wangfd781e92016-12-16 15:53:16 -0800206 private Button carrierProvisioningButton;
207 private Button triggercarrierProvisioningButton;
Nathan Harold12e1f552016-06-17 13:55:38 -0700208 private Switch imsVolteProvisionedSwitch;
209 private Switch imsVtProvisionedSwitch;
210 private Switch imsWfcProvisionedSwitch;
Meng Wang586741c2017-04-26 15:02:51 -0700211 private Switch eabProvisionedSwitch;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800212 private Spinner preferredNetworkType;
Nathan Harold2b77d742016-03-19 13:22:10 -0700213 private Spinner cellInfoRefreshRateSpinner;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800214
215 private TelephonyManager mTelephonyManager;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800216 private ImsManager mImsManager = null;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800217 private Phone phone = null;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800218
Nathan Haroldcea413a2015-11-23 15:48:10 -0800219 private String mPingHostnameResultV4;
220 private String mPingHostnameResultV6;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800221 private String mHttpClientTestResult;
222 private boolean mMwiValue = false;
223 private boolean mCfiValue = false;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800224
225 private List<CellInfo> mCellInfoResult = null;
226 private CellLocation mCellLocationResult = null;
227 private List<NeighboringCellInfo> mNeighboringCellResult = null;
228
229 private int mPreferredNetworkTypeResult;
Nathan Harold2b77d742016-03-19 13:22:10 -0700230 private int mCellInfoRefreshRateIndex;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800231
Nathan Harold2b77d742016-03-19 13:22:10 -0700232 private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800233 @Override
234 public void onDataConnectionStateChanged(int state) {
235 updateDataState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800236 updateNetworkType();
237 }
238
239 @Override
240 public void onDataActivity(int direction) {
241 updateDataStats2();
242 }
243
244 @Override
Nathan Harold2b77d742016-03-19 13:22:10 -0700245 public void onCallStateChanged(int state, String incomingNumber) {
246 updateNetworkType();
247 updatePhoneState(state);
248 }
249
250 @Override
251 public void onPreciseCallStateChanged(PreciseCallState preciseState) {
252 updateNetworkType();
253 }
254
255 @Override
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800256 public void onCellLocationChanged(CellLocation location) {
257 updateLocation(location);
258 }
259
260 @Override
261 public void onMessageWaitingIndicatorChanged(boolean mwi) {
262 mMwiValue = mwi;
263 updateMessageWaiting();
264 }
265
266 @Override
267 public void onCallForwardingIndicatorChanged(boolean cfi) {
268 mCfiValue = cfi;
269 updateCallRedirect();
270 }
Wink Saville79bff2a2012-06-01 14:37:21 -0700271
272 @Override
273 public void onCellInfoChanged(List<CellInfo> arrayCi) {
Wink Savillebf471282013-04-05 15:04:05 -0700274 log("onCellInfoChanged: arrayCi=" + arrayCi);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800275 mCellInfoResult = arrayCi;
276 updateCellInfo(mCellInfoResult);
Wink Saville79bff2a2012-06-01 14:37:21 -0700277 }
Wink Saville4f0d8812014-04-15 22:05:24 -0700278
279 @Override
280 public void onDataConnectionRealTimeInfoChanged(DataConnectionRealTimeInfo dcRtInfo) {
281 log("onDataConnectionRealTimeInfoChanged: dcRtInfo=" + dcRtInfo);
282 updateDcRtInfoTv(dcRtInfo);
283 }
Nathan Harold2b77d742016-03-19 13:22:10 -0700284
285 @Override
286 public void onSignalStrengthsChanged(SignalStrength signalStrength) {
287 log("onSignalStrengthChanged: SignalStrength=" +signalStrength);
288 updateSignalStrength(signalStrength);
289 }
290
291 @Override
292 public void onServiceStateChanged(ServiceState serviceState) {
293 log("onServiceStateChanged: ServiceState=" + serviceState);
294 updateServiceState(serviceState);
295 updateRadioPowerState();
296 updateNetworkType();
Nathan Harold12e1f552016-06-17 13:55:38 -0700297 updateImsProvisionedState();
Nathan Harold2b77d742016-03-19 13:22:10 -0700298 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800299 };
300
Nathan Haroldcea413a2015-11-23 15:48:10 -0800301 private void updatePreferredNetworkType(int type) {
302 if (type >= mPreferredNetworkLabels.length || type < 0) {
303 log("EVENT_QUERY_PREFERRED_TYPE_DONE: unknown " +
304 "type=" + type);
305 type = mPreferredNetworkLabels.length - 1; //set to Unknown
306 }
307 mPreferredNetworkTypeResult = type;
308
309 preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true);
310 }
311
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800312 private Handler mHandler = new Handler() {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800313 @Override
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800314 public void handleMessage(Message msg) {
315 AsyncResult ar;
316 switch (msg.what) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800317 case EVENT_QUERY_PREFERRED_TYPE_DONE:
318 ar= (AsyncResult) msg.obj;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800319 if (ar.exception == null && ar.result != null) {
320 updatePreferredNetworkType(((int[])ar.result)[0]);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800321 } else {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800322 //In case of an exception, we will set this to unknown
323 updatePreferredNetworkType(mPreferredNetworkLabels.length-1);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800324 }
325 break;
326 case EVENT_SET_PREFERRED_TYPE_DONE:
327 ar= (AsyncResult) msg.obj;
328 if (ar.exception != null) {
Nathan Harolded38afa2016-04-13 00:29:30 -0700329 log("Set preferred network type failed.");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800330 }
331 break;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800332 case EVENT_QUERY_SMSC_DONE:
333 ar= (AsyncResult) msg.obj;
334 if (ar.exception != null) {
335 smsc.setText("refresh error");
336 } else {
jsh21dd4072009-05-12 11:26:55 -0700337 smsc.setText((String)ar.result);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800338 }
339 break;
340 case EVENT_UPDATE_SMSC_DONE:
341 updateSmscButton.setEnabled(true);
342 ar= (AsyncResult) msg.obj;
343 if (ar.exception != null) {
344 smsc.setText("update error");
345 }
346 break;
347 default:
Nathan Haroldcea413a2015-11-23 15:48:10 -0800348 super.handleMessage(msg);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800349 break;
350
351 }
352 }
353 };
354
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800355 @Override
356 public void onCreate(Bundle icicle) {
357 super.onCreate(icicle);
fionaxub54cb2d2016-09-22 15:01:05 -0700358 if (!android.os.Process.myUserHandle().isSystem()) {
359 Log.e(TAG, "Not run from system user, don't do anything.");
360 finish();
361 return;
362 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800363
364 setContentView(R.layout.radio_info);
365
Nathan Haroldcea413a2015-11-23 15:48:10 -0800366 log("Started onCreate");
367
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800368 mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
369 phone = PhoneFactory.getDefaultPhone();
370
Nathan Haroldcea413a2015-11-23 15:48:10 -0800371 //TODO: Need to update this if the default phoneId changes?
372 // Better to have an instance per phone?
373 mImsManager = ImsManager.getInstance(getApplicationContext(),
374 SubscriptionManager.getDefaultVoicePhoneId());
375
Meng Wang9053f172017-06-23 16:02:14 -0700376 mDeviceId = (TextView) findViewById(R.id.imei);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800377 number = (TextView) findViewById(R.id.number);
Meng Wang9053f172017-06-23 16:02:14 -0700378 mSubscriberId = (TextView) findViewById(R.id.imsi);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800379 callState = (TextView) findViewById(R.id.call);
380 operatorName = (TextView) findViewById(R.id.operator);
381 roamingState = (TextView) findViewById(R.id.roaming);
382 gsmState = (TextView) findViewById(R.id.gsm);
383 gprsState = (TextView) findViewById(R.id.gprs);
Nathan Harold2b77d742016-03-19 13:22:10 -0700384 voiceNetwork = (TextView) findViewById(R.id.voice_network);
385 dataNetwork = (TextView) findViewById(R.id.data_network);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800386 dBm = (TextView) findViewById(R.id.dbm);
387 mMwi = (TextView) findViewById(R.id.mwi);
388 mCfi = (TextView) findViewById(R.id.cfi);
389 mLocation = (TextView) findViewById(R.id.location);
390 mNeighboringCids = (TextView) findViewById(R.id.neighboring);
Wink Saville79bff2a2012-06-01 14:37:21 -0700391 mCellInfo = (TextView) findViewById(R.id.cellinfo);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800392 mCellInfo.setTypeface(Typeface.MONOSPACE);
Wink Saville4f0d8812014-04-15 22:05:24 -0700393 mDcRtInfoTv = (TextView) findViewById(R.id.dcrtinfo);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800394
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800395 sent = (TextView) findViewById(R.id.sent);
396 received = (TextView) findViewById(R.id.received);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800397 smsc = (EditText) findViewById(R.id.smsc);
398 dnsCheckState = (TextView) findViewById(R.id.dnsCheckState);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800399 mPingHostnameV4 = (TextView) findViewById(R.id.pingHostnameV4);
400 mPingHostnameV6 = (TextView) findViewById(R.id.pingHostnameV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800401 mHttpClientTest = (TextView) findViewById(R.id.httpClientTest);
402
403 preferredNetworkType = (Spinner) findViewById(R.id.preferredNetworkType);
404 ArrayAdapter<String> adapter = new ArrayAdapter<String> (this,
405 android.R.layout.simple_spinner_item, mPreferredNetworkLabels);
johnwang342101a2009-09-23 16:22:34 -0700406 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800407 preferredNetworkType.setAdapter(adapter);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800408
Nathan Harold2b77d742016-03-19 13:22:10 -0700409 cellInfoRefreshRateSpinner = (Spinner) findViewById(R.id.cell_info_rate_select);
410 ArrayAdapter<String> cellInfoAdapter = new ArrayAdapter<String>(this,
411 android.R.layout.simple_spinner_item, mCellInfoRefreshRateLabels);
412 cellInfoAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
413 cellInfoRefreshRateSpinner.setAdapter(cellInfoAdapter);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800414
Nathan Harold12e1f552016-06-17 13:55:38 -0700415 imsVolteProvisionedSwitch = (Switch) findViewById(R.id.volte_provisioned_switch);
416 imsVtProvisionedSwitch = (Switch) findViewById(R.id.vt_provisioned_switch);
417 imsWfcProvisionedSwitch = (Switch) findViewById(R.id.wfc_provisioned_switch);
Meng Wang69439b52017-05-01 08:31:14 -0700418 eabProvisionedSwitch = (Switch) findViewById(R.id.eab_provisioned_switch);
Wink Savillebf471282013-04-05 15:04:05 -0700419
Nathan Harold2b77d742016-03-19 13:22:10 -0700420 radioPowerOnSwitch = (Switch) findViewById(R.id.radio_power);
Wink Saville426fc662011-09-25 14:39:02 -0700421
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800422 pingTestButton = (Button) findViewById(R.id.ping_test);
423 pingTestButton.setOnClickListener(mPingButtonHandler);
424 updateSmscButton = (Button) findViewById(R.id.update_smsc);
425 updateSmscButton.setOnClickListener(mUpdateSmscButtonHandler);
426 refreshSmscButton = (Button) findViewById(R.id.refresh_smsc);
427 refreshSmscButton.setOnClickListener(mRefreshSmscButtonHandler);
428 dnsCheckToggleButton = (Button) findViewById(R.id.dns_check_toggle);
429 dnsCheckToggleButton.setOnClickListener(mDnsCheckButtonHandler);
Youhan Wangfd781e92016-12-16 15:53:16 -0800430 carrierProvisioningButton = (Button) findViewById(R.id.carrier_provisioning);
431 carrierProvisioningButton.setOnClickListener(mCarrierProvisioningButtonHandler);
432 triggercarrierProvisioningButton = (Button) findViewById(R.id.trigger_carrier_provisioning);
433 triggercarrierProvisioningButton.setOnClickListener(
434 mTriggerCarrierProvisioningButtonHandler);
johnwang342101a2009-09-23 16:22:34 -0700435
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800436 oemInfoButton = (Button) findViewById(R.id.oem_info);
437 oemInfoButton.setOnClickListener(mOemInfoButtonHandler);
438 PackageManager pm = getPackageManager();
439 Intent oemInfoIntent = new Intent("com.android.settings.OEM_RADIO_INFO");
440 List<ResolveInfo> oemInfoIntentList = pm.queryIntentActivities(oemInfoIntent, 0);
441 if (oemInfoIntentList.size() == 0) {
442 oemInfoButton.setEnabled(false);
443 }
444
Nathan Harolded38afa2016-04-13 00:29:30 -0700445 mCellInfoRefreshRateIndex = 0; //disabled
Nathan Haroldcea413a2015-11-23 15:48:10 -0800446 mPreferredNetworkTypeResult = mPreferredNetworkLabels.length - 1; //Unknown
447
448 //FIXME: Replace with TelephonyManager call
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800449 phone.getPreferredNetworkType(
450 mHandler.obtainMessage(EVENT_QUERY_PREFERRED_TYPE_DONE));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800451
Nathan Haroldcea413a2015-11-23 15:48:10 -0800452 restoreFromBundle(icicle);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800453 }
454
455 @Override
456 protected void onResume() {
457 super.onResume();
458
Nathan Haroldcea413a2015-11-23 15:48:10 -0800459 log("Started onResume");
460
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800461 updateMessageWaiting();
462 updateCallRedirect();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800463 updateDataState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800464 updateDataStats2();
Nathan Harold2b77d742016-03-19 13:22:10 -0700465 updateRadioPowerState();
Nathan Harold12e1f552016-06-17 13:55:38 -0700466 updateImsProvisionedState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800467 updateProperties();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800468 updateDnsCheckState();
Nathan Harold2b77d742016-03-19 13:22:10 -0700469 updateNetworkType();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800470
Nathan Haroldcea413a2015-11-23 15:48:10 -0800471 updateNeighboringCids(mNeighboringCellResult);
472 updateLocation(mCellLocationResult);
473 updateCellInfo(mCellInfoResult);
474
475 mPingHostnameV4.setText(mPingHostnameResultV4);
476 mPingHostnameV6.setText(mPingHostnameResultV6);
477 mHttpClientTest.setText(mHttpClientTestResult);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800478
Nathan Harold2b77d742016-03-19 13:22:10 -0700479 cellInfoRefreshRateSpinner.setOnItemSelectedListener(mCellInfoRefreshRateHandler);
Nathan Harolded38afa2016-04-13 00:29:30 -0700480 //set selection after registering listener to force update
481 cellInfoRefreshRateSpinner.setSelection(mCellInfoRefreshRateIndex);
482
483 //set selection before registering to prevent update
484 preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true);
Nathan Harold2b77d742016-03-19 13:22:10 -0700485 preferredNetworkType.setOnItemSelectedListener(mPreferredNetworkHandler);
Nathan Harolded38afa2016-04-13 00:29:30 -0700486
Nathan Harold2b77d742016-03-19 13:22:10 -0700487 radioPowerOnSwitch.setOnCheckedChangeListener(mRadioPowerOnChangeListener);
Nathan Harold12e1f552016-06-17 13:55:38 -0700488 imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
489 imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
490 imsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
Meng Wang586741c2017-04-26 15:02:51 -0700491 eabProvisionedSwitch.setOnCheckedChangeListener(mEabCheckedChangeListener);
Nathan Harold2b77d742016-03-19 13:22:10 -0700492
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800493 mTelephonyManager.listen(mPhoneStateListener,
Nathan Harold2b77d742016-03-19 13:22:10 -0700494 PhoneStateListener.LISTEN_CALL_STATE
495 //b/27803938 - RadioInfo currently cannot read PRECISE_CALL_STATE
496 // | PhoneStateListener.LISTEN_PRECISE_CALL_STATE
497 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800498 | PhoneStateListener.LISTEN_DATA_ACTIVITY
499 | PhoneStateListener.LISTEN_CELL_LOCATION
500 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
Wink Saville79bff2a2012-06-01 14:37:21 -0700501 | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
Wink Saville4f0d8812014-04-15 22:05:24 -0700502 | PhoneStateListener.LISTEN_CELL_INFO
Nathan Harold2b77d742016-03-19 13:22:10 -0700503 | PhoneStateListener.LISTEN_SERVICE_STATE
504 | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
Wink Saville4f0d8812014-04-15 22:05:24 -0700505 | PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO);
Nathan Harolded38afa2016-04-13 00:29:30 -0700506
507 smsc.clearFocus();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800508 }
509
510 @Override
Nathan Haroldcea413a2015-11-23 15:48:10 -0800511 protected void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800512 super.onPause();
513
Wink Savillebf471282013-04-05 15:04:05 -0700514 log("onPause: unregister phone & data intents");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800515
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800516 mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
Sooraj Sasindran5cce06b2016-08-18 15:49:49 -0700517 mTelephonyManager.setCellInfoListRate(CELL_INFO_LIST_RATE_DISABLED);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800518 }
519
Nathan Haroldcea413a2015-11-23 15:48:10 -0800520 private void restoreFromBundle(Bundle b) {
Nathan Harolde272c202016-10-27 13:45:00 -0700521 if(b == null) {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800522 return;
523 }
524
525 mPingHostnameResultV4 = b.getString("mPingHostnameResultV4","");
526 mPingHostnameResultV6 = b.getString("mPingHostnameResultV6","");
527 mHttpClientTestResult = b.getString("mHttpClientTestResult","");
528
529 mPingHostnameV4.setText(mPingHostnameResultV4);
530 mPingHostnameV6.setText(mPingHostnameResultV6);
531 mHttpClientTest.setText(mHttpClientTestResult);
532
Nathan Harold2b77d742016-03-19 13:22:10 -0700533 mPreferredNetworkTypeResult = b.getInt("mPreferredNetworkTypeResult",
534 mPreferredNetworkLabels.length - 1);
535
536 mCellInfoRefreshRateIndex = b.getInt("mCellInfoRefreshRateIndex", 0);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800537 }
538
539 @Override
540 protected void onSaveInstanceState(Bundle outState) {
541 outState.putString("mPingHostnameResultV4", mPingHostnameResultV4);
542 outState.putString("mPingHostnameResultV6", mPingHostnameResultV6);
543 outState.putString("mHttpClientTestResult", mHttpClientTestResult);
Nathan Harold2b77d742016-03-19 13:22:10 -0700544
Nathan Haroldcea413a2015-11-23 15:48:10 -0800545 outState.putInt("mPreferredNetworkTypeResult", mPreferredNetworkTypeResult);
Nathan Harold2b77d742016-03-19 13:22:10 -0700546 outState.putInt("mCellInfoRefreshRateIndex", mCellInfoRefreshRateIndex);
547
Nathan Haroldcea413a2015-11-23 15:48:10 -0800548 }
549
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800550 @Override
551 public boolean onCreateOptionsMenu(Menu menu) {
Wink Savillec3886682009-04-02 11:00:56 -0700552 menu.add(0, MENU_ITEM_SELECT_BAND, 0, R.string.radio_info_band_mode_label)
553 .setOnMenuItemClickListener(mSelectBandCallback)
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800554 .setAlphabeticShortcut('b');
555 menu.add(1, MENU_ITEM_VIEW_ADN, 0,
556 R.string.radioInfo_menu_viewADN).setOnMenuItemClickListener(mViewADNCallback);
557 menu.add(1, MENU_ITEM_VIEW_FDN, 0,
558 R.string.radioInfo_menu_viewFDN).setOnMenuItemClickListener(mViewFDNCallback);
559 menu.add(1, MENU_ITEM_VIEW_SDN, 0,
560 R.string.radioInfo_menu_viewSDN).setOnMenuItemClickListener(mViewSDNCallback);
Nathan Harolde272c202016-10-27 13:45:00 -0700561 menu.add(1, MENU_ITEM_GET_IMS_STATUS,
562 0, R.string.radioInfo_menu_getIMS).setOnMenuItemClickListener(mGetImsStatus);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800563 menu.add(1, MENU_ITEM_TOGGLE_DATA,
Nathan Harold2b77d742016-03-19 13:22:10 -0700564 0, R.string.radio_info_data_connection_disable).setOnMenuItemClickListener(mToggleData);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800565 return true;
566 }
567
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800568 @Override
Wink Savillec3886682009-04-02 11:00:56 -0700569 public boolean onPrepareOptionsMenu(Menu menu) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800570 // Get the TOGGLE DATA menu item in the right state.
571 MenuItem item = menu.findItem(MENU_ITEM_TOGGLE_DATA);
572 int state = mTelephonyManager.getDataState();
573 boolean visible = true;
574
575 switch (state) {
576 case TelephonyManager.DATA_CONNECTED:
577 case TelephonyManager.DATA_SUSPENDED:
Nathan Harold2b77d742016-03-19 13:22:10 -0700578 item.setTitle(R.string.radio_info_data_connection_disable);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800579 break;
580 case TelephonyManager.DATA_DISCONNECTED:
Nathan Harold2b77d742016-03-19 13:22:10 -0700581 item.setTitle(R.string.radio_info_data_connection_enable);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800582 break;
583 default:
584 visible = false;
585 break;
586 }
587 item.setVisible(visible);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800588 return true;
589 }
590
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800591 private void updateDnsCheckState() {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800592 //FIXME: Replace with a TelephonyManager call
Mike Lockwood5304c7e2009-04-05 11:37:45 -0700593 dnsCheckState.setText(phone.isDnsCheckDisabled() ?
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800594 "0.0.0.0 allowed" :"0.0.0.0 not allowed");
595 }
Wink Savillee2a14e32009-05-29 14:06:30 -0700596
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800597 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -0700598 updateSignalStrength(SignalStrength signalStrength) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800599 Resources r = getResources();
600
Nathan Harold2b77d742016-03-19 13:22:10 -0700601 int signalDbm = signalStrength.getDbm();
Wink Savillee2a14e32009-05-29 14:06:30 -0700602
Nathan Harold2b77d742016-03-19 13:22:10 -0700603 int signalAsu = signalStrength.getAsuLevel();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800604
605 if (-1 == signalAsu) signalAsu = 0;
606
607 dBm.setText(String.valueOf(signalDbm) + " "
608 + r.getString(R.string.radioInfo_display_dbm) + " "
609 + String.valueOf(signalAsu) + " "
610 + r.getString(R.string.radioInfo_display_asu));
611 }
612
613 private final void updateLocation(CellLocation location) {
jsh534f5ae2009-09-24 09:19:22 -0700614 Resources r = getResources();
Wink Savillec3886682009-04-02 11:00:56 -0700615 if (location instanceof GsmCellLocation) {
616 GsmCellLocation loc = (GsmCellLocation)location;
jsh534f5ae2009-09-24 09:19:22 -0700617 int lac = loc.getLac();
618 int cid = loc.getCid();
619 mLocation.setText(r.getString(R.string.radioInfo_lac) + " = "
620 + ((lac == -1) ? "unknown" : Integer.toHexString(lac))
621 + " "
622 + r.getString(R.string.radioInfo_cid) + " = "
623 + ((cid == -1) ? "unknown" : Integer.toHexString(cid)));
624 } else if (location instanceof CdmaCellLocation) {
625 CdmaCellLocation loc = (CdmaCellLocation)location;
626 int bid = loc.getBaseStationId();
627 int sid = loc.getSystemId();
628 int nid = loc.getNetworkId();
629 int lat = loc.getBaseStationLatitude();
630 int lon = loc.getBaseStationLongitude();
631 mLocation.setText("BID = "
632 + ((bid == -1) ? "unknown" : Integer.toHexString(bid))
633 + " "
634 + "SID = "
635 + ((sid == -1) ? "unknown" : Integer.toHexString(sid))
636 + " "
637 + "NID = "
638 + ((nid == -1) ? "unknown" : Integer.toHexString(nid))
639 + "\n"
640 + "LAT = "
641 + ((lat == -1) ? "unknown" : Integer.toHexString(lat))
642 + " "
643 + "LONG = "
644 + ((lon == -1) ? "unknown" : Integer.toHexString(lon)));
645 } else {
646 mLocation.setText("unknown");
Wink Savillec3886682009-04-02 11:00:56 -0700647 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800648
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800649
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800650 }
651
Nathan Haroldcea413a2015-11-23 15:48:10 -0800652 private final void updateNeighboringCids(List<NeighboringCellInfo> cids) {
johnwangf02c65f2009-09-25 17:26:54 -0700653 StringBuilder sb = new StringBuilder();
654
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800655 if (cids != null) {
Nathan Harolde272c202016-10-27 13:45:00 -0700656 if (cids.isEmpty()) {
johnwangf02c65f2009-09-25 17:26:54 -0700657 sb.append("no neighboring cells");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800658 } else {
659 for (NeighboringCellInfo cell : cids) {
johnwangf02c65f2009-09-25 17:26:54 -0700660 sb.append(cell.toString()).append(" ");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800661 }
662 }
663 } else {
johnwangf02c65f2009-09-25 17:26:54 -0700664 sb.append("unknown");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800665 }
johnwangf02c65f2009-09-25 17:26:54 -0700666 mNeighboringCids.setText(sb.toString());
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800667 }
668
Nathan Haroldcea413a2015-11-23 15:48:10 -0800669 private final String getCellInfoDisplayString(int i) {
670 return (i != Integer.MAX_VALUE) ? Integer.toString(i) : "";
671 }
672
673 private final String getCellInfoDisplayString(long i) {
674 return (i != Long.MAX_VALUE) ? Long.toString(i) : "";
675 }
676
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700677 private final String getConnectionStatusString(CellInfo ci) {
678 String regStr = "";
679 String connStatStr = "";
680 String connector = "";
681
682 if (ci.isRegistered()) {
683 regStr = "R";
684 }
685 switch (ci.getCellConnectionStatus()) {
686 case CellInfo.CONNECTION_PRIMARY_SERVING: connStatStr = "P"; break;
687 case CellInfo.CONNECTION_SECONDARY_SERVING: connStatStr = "S"; break;
688 case CellInfo.CONNECTION_NONE: connStatStr = "N"; break;
689 case CellInfo.CONNECTION_UNKNOWN: /* Field is unsupported */ break;
690 default: break;
691 }
692 if (!TextUtils.isEmpty(regStr) && !TextUtils.isEmpty(connStatStr)) {
693 connector = "+";
694 }
695
696 return regStr + connector + connStatStr;
697 }
698
Nathan Haroldcea413a2015-11-23 15:48:10 -0800699 private final String buildCdmaInfoString(CellInfoCdma ci) {
700 CellIdentityCdma cidCdma = ci.getCellIdentity();
701 CellSignalStrengthCdma ssCdma = ci.getCellSignalStrength();
702
703 return String.format("%-3.3s %-5.5s %-5.5s %-5.5s %-6.6s %-6.6s %-6.6s %-6.6s %-5.5s",
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700704 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800705 getCellInfoDisplayString(cidCdma.getSystemId()),
706 getCellInfoDisplayString(cidCdma.getNetworkId()),
707 getCellInfoDisplayString(cidCdma.getBasestationId()),
708 getCellInfoDisplayString(ssCdma.getCdmaDbm()),
709 getCellInfoDisplayString(ssCdma.getCdmaEcio()),
710 getCellInfoDisplayString(ssCdma.getEvdoDbm()),
711 getCellInfoDisplayString(ssCdma.getEvdoEcio()),
712 getCellInfoDisplayString(ssCdma.getEvdoSnr()));
713 }
714
715 private final String buildGsmInfoString(CellInfoGsm ci) {
716 CellIdentityGsm cidGsm = ci.getCellIdentity();
717 CellSignalStrengthGsm ssGsm = ci.getCellSignalStrength();
718
Nathan Harold2b77d742016-03-19 13:22:10 -0700719 return String.format("%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-6.6s %-4.4s %-4.4s\n",
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700720 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800721 getCellInfoDisplayString(cidGsm.getMcc()),
722 getCellInfoDisplayString(cidGsm.getMnc()),
723 getCellInfoDisplayString(cidGsm.getLac()),
724 getCellInfoDisplayString(cidGsm.getCid()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700725 getCellInfoDisplayString(cidGsm.getArfcn()),
726 getCellInfoDisplayString(cidGsm.getBsic()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800727 getCellInfoDisplayString(ssGsm.getDbm()));
728 }
729
730 private final String buildLteInfoString(CellInfoLte ci) {
731 CellIdentityLte cidLte = ci.getCellIdentity();
732 CellSignalStrengthLte ssLte = ci.getCellSignalStrength();
733
734 return String.format(
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700735 "%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s %-6.6s %-2.2s %-4.4s %-4.4s %-2.2s\n",
736 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800737 getCellInfoDisplayString(cidLte.getMcc()),
738 getCellInfoDisplayString(cidLte.getMnc()),
739 getCellInfoDisplayString(cidLte.getTac()),
740 getCellInfoDisplayString(cidLte.getCi()),
741 getCellInfoDisplayString(cidLte.getPci()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700742 getCellInfoDisplayString(cidLte.getEarfcn()),
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700743 getCellInfoDisplayString(cidLte.getBandwidth()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800744 getCellInfoDisplayString(ssLte.getDbm()),
745 getCellInfoDisplayString(ssLte.getRsrq()),
746 getCellInfoDisplayString(ssLte.getTimingAdvance()));
747 }
748
749 private final String buildWcdmaInfoString(CellInfoWcdma ci) {
750 CellIdentityWcdma cidWcdma = ci.getCellIdentity();
751 CellSignalStrengthWcdma ssWcdma = ci.getCellSignalStrength();
752
Nathan Harold2b77d742016-03-19 13:22:10 -0700753 return String.format("%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-6.6s %-3.3s %-4.4s\n",
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700754 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800755 getCellInfoDisplayString(cidWcdma.getMcc()),
756 getCellInfoDisplayString(cidWcdma.getMnc()),
757 getCellInfoDisplayString(cidWcdma.getLac()),
758 getCellInfoDisplayString(cidWcdma.getCid()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700759 getCellInfoDisplayString(cidWcdma.getUarfcn()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800760 getCellInfoDisplayString(cidWcdma.getPsc()),
761 getCellInfoDisplayString(ssWcdma.getDbm()));
762 }
763
764 private final String buildCellInfoString(List<CellInfo> arrayCi) {
765 String value = new String();
766 StringBuilder cdmaCells = new StringBuilder(),
767 gsmCells = new StringBuilder(),
768 lteCells = new StringBuilder(),
769 wcdmaCells = new StringBuilder();
770
771 if (arrayCi != null) {
772 for (CellInfo ci : arrayCi) {
773
774 if (ci instanceof CellInfoLte) {
775 lteCells.append(buildLteInfoString((CellInfoLte) ci));
776 } else if (ci instanceof CellInfoWcdma) {
777 wcdmaCells.append(buildWcdmaInfoString((CellInfoWcdma) ci));
778 } else if (ci instanceof CellInfoGsm) {
779 gsmCells.append(buildGsmInfoString((CellInfoGsm) ci));
780 } else if (ci instanceof CellInfoCdma) {
781 cdmaCells.append(buildCdmaInfoString((CellInfoCdma) ci));
Wink Saville79bff2a2012-06-01 14:37:21 -0700782 }
783 }
Nathan Haroldcea413a2015-11-23 15:48:10 -0800784 if (lteCells.length() != 0) {
785 value += String.format(
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700786 "LTE\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s"
787 + " %-6.6s %-2.2s %-4.4s %-4.4s %-2.2s\n",
788 "SRV", "MCC", "MNC", "TAC", "CID", "PCI",
789 "EARFCN", "BW", "RSRP", "RSRQ", "TA");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800790 value += lteCells.toString();
791 }
792 if (wcdmaCells.length() != 0) {
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700793 value += String.format(
794 "WCDMA\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-6.6s %-3.3s %-4.4s\n",
Nathan Harold2b77d742016-03-19 13:22:10 -0700795 "SRV", "MCC", "MNC", "LAC", "CID", "UARFCN", "PSC", "RSCP");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800796 value += wcdmaCells.toString();
797 }
798 if (gsmCells.length() != 0) {
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700799 value += String.format(
800 "GSM\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-6.6s %-4.4s %-4.4s\n",
Nathan Harold2b77d742016-03-19 13:22:10 -0700801 "SRV", "MCC", "MNC", "LAC", "CID", "ARFCN", "BSIC", "RSSI");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800802 value += gsmCells.toString();
803 }
804 if (cdmaCells.length() != 0) {
805 value += String.format(
806 "CDMA/EVDO\n%-3.3s %-5.5s %-5.5s %-5.5s %-6.6s %-6.6s %-6.6s %-6.6s %-5.5s\n",
807 "SRV", "SID", "NID", "BSID", "C-RSSI", "C-ECIO", "E-RSSI", "E-ECIO", "E-SNR");
808 value += cdmaCells.toString();
809 }
810 } else {
811 value ="unknown";
Wink Saville79bff2a2012-06-01 14:37:21 -0700812 }
Nathan Haroldcea413a2015-11-23 15:48:10 -0800813
814 return value.toString();
815 }
816
817 private final void updateCellInfo(List<CellInfo> arrayCi) {
818 mCellInfo.setText(buildCellInfoString(arrayCi));
Wink Saville79bff2a2012-06-01 14:37:21 -0700819 }
820
Wink Saville4f0d8812014-04-15 22:05:24 -0700821 private final void updateDcRtInfoTv(DataConnectionRealTimeInfo dcRtInfo) {
822 mDcRtInfoTv.setText(dcRtInfo.toString());
823 }
824
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800825 private final void
826 updateMessageWaiting() {
827 mMwi.setText(String.valueOf(mMwiValue));
828 }
829
830 private final void
831 updateCallRedirect() {
832 mCfi.setText(String.valueOf(mCfiValue));
833 }
834
835
836 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -0700837 updateServiceState(ServiceState serviceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800838 int state = serviceState.getState();
839 Resources r = getResources();
840 String display = r.getString(R.string.radioInfo_unknown);
johnwang342101a2009-09-23 16:22:34 -0700841
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800842 switch (state) {
843 case ServiceState.STATE_IN_SERVICE:
844 display = r.getString(R.string.radioInfo_service_in);
845 break;
846 case ServiceState.STATE_OUT_OF_SERVICE:
847 case ServiceState.STATE_EMERGENCY_ONLY:
848 display = r.getString(R.string.radioInfo_service_emergency);
849 break;
850 case ServiceState.STATE_POWER_OFF:
851 display = r.getString(R.string.radioInfo_service_off);
852 break;
853 }
johnwang342101a2009-09-23 16:22:34 -0700854
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800855 gsmState.setText(display);
johnwang342101a2009-09-23 16:22:34 -0700856
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800857 if (serviceState.getRoaming()) {
858 roamingState.setText(R.string.radioInfo_roaming_in);
859 } else {
860 roamingState.setText(R.string.radioInfo_roaming_not);
861 }
862
863 operatorName.setText(serviceState.getOperatorAlphaLong());
864 }
865
866 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -0700867 updatePhoneState(int state) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800868 Resources r = getResources();
869 String display = r.getString(R.string.radioInfo_unknown);
870
871 switch (state) {
Nathan Harold2b77d742016-03-19 13:22:10 -0700872 case TelephonyManager.CALL_STATE_IDLE:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800873 display = r.getString(R.string.radioInfo_phone_idle);
874 break;
Nathan Harold2b77d742016-03-19 13:22:10 -0700875 case TelephonyManager.CALL_STATE_RINGING:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800876 display = r.getString(R.string.radioInfo_phone_ringing);
877 break;
Nathan Harold2b77d742016-03-19 13:22:10 -0700878 case TelephonyManager.CALL_STATE_OFFHOOK:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800879 display = r.getString(R.string.radioInfo_phone_offhook);
880 break;
881 }
882
883 callState.setText(display);
884 }
885
886 private final void
887 updateDataState() {
888 int state = mTelephonyManager.getDataState();
889 Resources r = getResources();
890 String display = r.getString(R.string.radioInfo_unknown);
891
892 switch (state) {
893 case TelephonyManager.DATA_CONNECTED:
894 display = r.getString(R.string.radioInfo_data_connected);
895 break;
896 case TelephonyManager.DATA_CONNECTING:
897 display = r.getString(R.string.radioInfo_data_connecting);
898 break;
899 case TelephonyManager.DATA_DISCONNECTED:
900 display = r.getString(R.string.radioInfo_data_disconnected);
901 break;
902 case TelephonyManager.DATA_SUSPENDED:
903 display = r.getString(R.string.radioInfo_data_suspended);
904 break;
905 }
johnwang342101a2009-09-23 16:22:34 -0700906
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800907 gprsState.setText(display);
908 }
909
910 private final void updateNetworkType() {
Nathan Harolde272c202016-10-27 13:45:00 -0700911 if(phone != null) {
Nathan Harold2b77d742016-03-19 13:22:10 -0700912 ServiceState ss = phone.getServiceState();
913 dataNetwork.setText(ServiceState.rilRadioTechnologyToString(
914 phone.getServiceState().getRilDataRadioTechnology()));
915 voiceNetwork.setText(ServiceState.rilRadioTechnologyToString(
916 phone.getServiceState().getRilVoiceRadioTechnology()));
917 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800918 }
919
920 private final void
921 updateProperties() {
922 String s;
923 Resources r = getResources();
924
925 s = phone.getDeviceId();
johnwang342101a2009-09-23 16:22:34 -0700926 if (s == null) s = r.getString(R.string.radioInfo_unknown);
Wink Savillec3886682009-04-02 11:00:56 -0700927 mDeviceId.setText(s);
johnwang342101a2009-09-23 16:22:34 -0700928
Meng Wang9053f172017-06-23 16:02:14 -0700929 s = phone.getSubscriberId();
930 if (s == null) s = r.getString(R.string.radioInfo_unknown);
931 mSubscriberId.setText(s);
932
Nathan Haroldcea413a2015-11-23 15:48:10 -0800933 //FIXME: Replace with a TelephonyManager call
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800934 s = phone.getLine1Number();
johnwang342101a2009-09-23 16:22:34 -0700935 if (s == null) s = r.getString(R.string.radioInfo_unknown);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800936 number.setText(s);
937 }
938
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800939 private final void updateDataStats2() {
940 Resources r = getResources();
941
Jeff Sharkey93029862011-05-27 18:26:15 -0700942 long txPackets = TrafficStats.getMobileTxPackets();
943 long rxPackets = TrafficStats.getMobileRxPackets();
944 long txBytes = TrafficStats.getMobileTxBytes();
945 long rxBytes = TrafficStats.getMobileRxBytes();
johnwang342101a2009-09-23 16:22:34 -0700946
Jeff Sharkey93029862011-05-27 18:26:15 -0700947 String packets = r.getString(R.string.radioInfo_display_packets);
948 String bytes = r.getString(R.string.radioInfo_display_bytes);
johnwang342101a2009-09-23 16:22:34 -0700949
Jeff Sharkey93029862011-05-27 18:26:15 -0700950 sent.setText(txPackets + " " + packets + ", " + txBytes + " " + bytes);
951 received.setText(rxPackets + " " + packets + ", " + rxBytes + " " + bytes);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800952 }
953
954 /**
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800955 * Ping a host name
956 */
957 private final void pingHostname() {
958 try {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800959 try {
960 Process p4 = Runtime.getRuntime().exec("ping -c 1 www.google.com");
961 int status4 = p4.waitFor();
962 if (status4 == 0) {
963 mPingHostnameResultV4 = "Pass";
964 } else {
965 mPingHostnameResultV4 = String.format("Fail(%d)", status4);
966 }
967 } catch (IOException e) {
968 mPingHostnameResultV4 = "Fail: IOException";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800969 }
Nathan Haroldcea413a2015-11-23 15:48:10 -0800970 try {
971 Process p6 = Runtime.getRuntime().exec("ping6 -c 1 www.google.com");
972 int status6 = p6.waitFor();
973 if (status6 == 0) {
974 mPingHostnameResultV6 = "Pass";
975 } else {
976 mPingHostnameResultV6 = String.format("Fail(%d)", status6);
977 }
978 } catch (IOException e) {
979 mPingHostnameResultV6 = "Fail: IOException";
980 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800981 } catch (InterruptedException e) {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800982 mPingHostnameResultV4 = mPingHostnameResultV6 = "Fail: InterruptedException";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800983 }
984 }
985
986 /**
987 * This function checks for basic functionality of HTTP Client.
988 */
989 private void httpClientTest() {
Narayan Kamathf25627c2014-12-12 13:53:28 +0000990 HttpURLConnection urlConnection = null;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800991 try {
Narayan Kamathf25627c2014-12-12 13:53:28 +0000992 // TODO: Hardcoded for now, make it UI configurable
Alex Klyubinb0090232015-04-02 11:08:51 -0700993 URL url = new URL("https://www.google.com");
Narayan Kamathf25627c2014-12-12 13:53:28 +0000994 urlConnection = (HttpURLConnection) url.openConnection();
995 if (urlConnection.getResponseCode() == 200) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800996 mHttpClientTestResult = "Pass";
997 } else {
Narayan Kamathf25627c2014-12-12 13:53:28 +0000998 mHttpClientTestResult = "Fail: Code: " + urlConnection.getResponseMessage();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800999 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001000 } catch (IOException e) {
1001 mHttpClientTestResult = "Fail: IOException";
Narayan Kamathf25627c2014-12-12 13:53:28 +00001002 } finally {
1003 if (urlConnection != null) {
1004 urlConnection.disconnect();
1005 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001006 }
1007 }
1008
1009 private void refreshSmsc() {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001010 //FIXME: Replace with a TelephonyManager call
jsh21dd4072009-05-12 11:26:55 -07001011 phone.getSmscAddress(mHandler.obtainMessage(EVENT_QUERY_SMSC_DONE));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001012 }
1013
Nathan Haroldcea413a2015-11-23 15:48:10 -08001014 private final void updateAllCellInfo() {
1015
1016 mCellInfo.setText("");
1017 mNeighboringCids.setText("");
1018 mLocation.setText("");
1019
1020 final Runnable updateAllCellInfoResults = new Runnable() {
1021 public void run() {
1022 updateNeighboringCids(mNeighboringCellResult);
1023 updateLocation(mCellLocationResult);
1024 updateCellInfo(mCellInfoResult);
1025 }
1026 };
1027
1028 Thread locThread = new Thread() {
1029 @Override
1030 public void run() {
1031 mCellInfoResult = mTelephonyManager.getAllCellInfo();
1032 mCellLocationResult = mTelephonyManager.getCellLocation();
1033 mNeighboringCellResult = mTelephonyManager.getNeighboringCellInfo();
1034
1035 mHandler.post(updateAllCellInfoResults);
1036 }
1037 };
1038 locThread.start();
1039 }
1040
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001041 private final void updatePingState() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001042 // Set all to unknown since the threads will take a few secs to update.
Nathan Haroldcea413a2015-11-23 15:48:10 -08001043 mPingHostnameResultV4 = getResources().getString(R.string.radioInfo_unknown);
1044 mPingHostnameResultV6 = getResources().getString(R.string.radioInfo_unknown);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001045 mHttpClientTestResult = getResources().getString(R.string.radioInfo_unknown);
1046
Nathan Haroldcea413a2015-11-23 15:48:10 -08001047 mPingHostnameV4.setText(mPingHostnameResultV4);
1048 mPingHostnameV6.setText(mPingHostnameResultV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001049 mHttpClientTest.setText(mHttpClientTestResult);
1050
1051 final Runnable updatePingResults = new Runnable() {
1052 public void run() {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001053 mPingHostnameV4.setText(mPingHostnameResultV4);
1054 mPingHostnameV6.setText(mPingHostnameResultV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001055 mHttpClientTest.setText(mHttpClientTestResult);
1056 }
1057 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001058
1059 Thread hostname = new Thread() {
1060 @Override
1061 public void run() {
1062 pingHostname();
Nathan Haroldcea413a2015-11-23 15:48:10 -08001063 mHandler.post(updatePingResults);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001064 }
1065 };
1066 hostname.start();
1067
1068 Thread httpClient = new Thread() {
1069 @Override
1070 public void run() {
1071 httpClientTest();
Nathan Haroldcea413a2015-11-23 15:48:10 -08001072 mHandler.post(updatePingResults);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001073 }
1074 };
1075 httpClient.start();
1076 }
1077
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001078 private MenuItem.OnMenuItemClickListener mViewADNCallback = new MenuItem.OnMenuItemClickListener() {
1079 public boolean onMenuItemClick(MenuItem item) {
1080 Intent intent = new Intent(Intent.ACTION_VIEW);
1081 // XXX We need to specify the component here because if we don't
1082 // the activity manager will try to resolve the type by calling
1083 // the content provider, which causes it to be loaded in a process
1084 // other than the Dialer process, which causes a lot of stuff to
1085 // break.
1086 intent.setClassName("com.android.phone",
1087 "com.android.phone.SimContacts");
1088 startActivity(intent);
1089 return true;
1090 }
1091 };
1092
1093 private MenuItem.OnMenuItemClickListener mViewFDNCallback = new MenuItem.OnMenuItemClickListener() {
1094 public boolean onMenuItemClick(MenuItem item) {
1095 Intent intent = new Intent(Intent.ACTION_VIEW);
1096 // XXX We need to specify the component here because if we don't
1097 // the activity manager will try to resolve the type by calling
1098 // the content provider, which causes it to be loaded in a process
1099 // other than the Dialer process, which causes a lot of stuff to
1100 // break.
1101 intent.setClassName("com.android.phone",
Andrew Leeda90d682014-10-31 13:12:20 -07001102 "com.android.phone.settings.fdn.FdnList");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001103 startActivity(intent);
1104 return true;
1105 }
1106 };
1107
1108 private MenuItem.OnMenuItemClickListener mViewSDNCallback = new MenuItem.OnMenuItemClickListener() {
1109 public boolean onMenuItemClick(MenuItem item) {
1110 Intent intent = new Intent(
Wink Savillec3886682009-04-02 11:00:56 -07001111 Intent.ACTION_VIEW, Uri.parse("content://icc/sdn"));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001112 // XXX We need to specify the component here because if we don't
1113 // the activity manager will try to resolve the type by calling
1114 // the content provider, which causes it to be loaded in a process
1115 // other than the Dialer process, which causes a lot of stuff to
1116 // break.
1117 intent.setClassName("com.android.phone",
1118 "com.android.phone.ADNList");
1119 startActivity(intent);
1120 return true;
1121 }
1122 };
1123
Nathan Harolde272c202016-10-27 13:45:00 -07001124 private MenuItem.OnMenuItemClickListener mGetImsStatus = new MenuItem.OnMenuItemClickListener() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001125 public boolean onMenuItemClick(MenuItem item) {
Nathan Harolde272c202016-10-27 13:45:00 -07001126 boolean isImsRegistered = phone.isImsRegistered();
1127 boolean availableVolte = phone.isVolteEnabled();
1128 boolean availableWfc = phone.isWifiCallingEnabled();
1129 boolean availableVt = phone.isVideoEnabled();
1130 boolean availableUt = phone.isUtEnabled();
1131
1132 final String imsRegString = isImsRegistered ?
1133 getString(R.string.radio_info_ims_reg_status_registered) :
1134 getString(R.string.radio_info_ims_reg_status_not_registered);
1135
1136 final String available = getString(R.string.radio_info_ims_feature_status_available);
1137 final String unavailable = getString(
1138 R.string.radio_info_ims_feature_status_unavailable);
1139
1140 String imsStatus = getString(R.string.radio_info_ims_reg_status,
1141 imsRegString,
1142 availableVolte ? available : unavailable,
1143 availableWfc ? available : unavailable,
1144 availableVt ? available : unavailable,
1145 availableUt ? available : unavailable);
1146
1147 AlertDialog imsDialog = new AlertDialog.Builder(RadioInfo.this)
1148 .setMessage(imsStatus)
1149 .setTitle(getString(R.string.radio_info_ims_reg_status_title))
1150 .create();
1151
1152 imsDialog.show();
1153
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001154 return true;
1155 }
1156 };
1157
1158 private MenuItem.OnMenuItemClickListener mSelectBandCallback = new MenuItem.OnMenuItemClickListener() {
1159 public boolean onMenuItemClick(MenuItem item) {
1160 Intent intent = new Intent();
1161 intent.setClass(RadioInfo.this, BandMode.class);
1162 startActivity(intent);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001163 return true;
1164 }
1165 };
johnwang342101a2009-09-23 16:22:34 -07001166
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001167 private MenuItem.OnMenuItemClickListener mToggleData = new MenuItem.OnMenuItemClickListener() {
1168 public boolean onMenuItemClick(MenuItem item) {
1169 int state = mTelephonyManager.getDataState();
1170 switch (state) {
1171 case TelephonyManager.DATA_CONNECTED:
Nathan Haroldcea413a2015-11-23 15:48:10 -08001172 //FIXME: Replace with a TelephonyManager call
Malcolm Chenf612f592017-11-29 18:01:25 -08001173 phone.setUserDataEnabled(false);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001174 break;
1175 case TelephonyManager.DATA_DISCONNECTED:
Nathan Haroldcea413a2015-11-23 15:48:10 -08001176 //FIXME: Replace with a TelephonyManager call
Malcolm Chenf612f592017-11-29 18:01:25 -08001177 phone.setUserDataEnabled(true);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001178 break;
1179 default:
1180 // do nothing
1181 break;
1182 }
1183 return true;
1184 }
1185 };
1186
Nathan Harold2b77d742016-03-19 13:22:10 -07001187 private boolean isRadioOn() {
1188 //FIXME: Replace with a TelephonyManager call
1189 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1190 }
1191
1192 private void updateRadioPowerState() {
1193 //delightful hack to prevent on-checked-changed calls from
1194 //actually forcing the radio preference to its transient/current value.
1195 radioPowerOnSwitch.setOnCheckedChangeListener(null);
1196 radioPowerOnSwitch.setChecked(isRadioOn());
1197 radioPowerOnSwitch.setOnCheckedChangeListener(mRadioPowerOnChangeListener);
1198 }
1199
Nathan Harolde272c202016-10-27 13:45:00 -07001200 void setImsVolteProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001201 Log.d(TAG, "setImsVolteProvisioned state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001202 setImsConfigProvisionedState(IMS_VOLTE_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001203 }
1204
Nathan Harolde272c202016-10-27 13:45:00 -07001205 void setImsVtProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001206 Log.d(TAG, "setImsVtProvisioned() state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001207 setImsConfigProvisionedState(IMS_VT_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001208 }
1209
Nathan Harolde272c202016-10-27 13:45:00 -07001210 void setImsWfcProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001211 Log.d(TAG, "setImsWfcProvisioned() state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001212 setImsConfigProvisionedState(IMS_WFC_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001213 }
1214
Meng Wang586741c2017-04-26 15:02:51 -07001215 void setEabProvisionedState(boolean state) {
1216 Log.d(TAG, "setEabProvisioned() state: " + ((state)? "on":"off"));
1217 setImsConfigProvisionedState(EAB_PROVISIONED_CONFIG_ID, state);
1218 }
1219
Nathan Harolde272c202016-10-27 13:45:00 -07001220 void setImsConfigProvisionedState(int configItem, boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001221 if (phone != null && mImsManager != null) {
Philip P. Moltmann5c449ae2017-02-14 12:43:02 -08001222 QueuedWork.queue(new Runnable() {
Nathan Harold12e1f552016-06-17 13:55:38 -07001223 public void run() {
1224 try {
1225 mImsManager.getConfigInterface().setProvisionedValue(
1226 configItem,
1227 state? 1 : 0);
1228 } catch (ImsException e) {
1229 Log.e(TAG, "setImsConfigProvisioned() exception:", e);
1230 }
1231 }
Philip P. Moltmann5c449ae2017-02-14 12:43:02 -08001232 }, false);
Nathan Harold12e1f552016-06-17 13:55:38 -07001233 }
1234 }
1235
Nathan Harold2b77d742016-03-19 13:22:10 -07001236 OnCheckedChangeListener mRadioPowerOnChangeListener = new OnCheckedChangeListener() {
1237 @Override
1238 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1239 log("toggle radio power: currently " + (isRadioOn()?"on":"off"));
1240 phone.setRadioPower(isChecked);
1241 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001242 };
1243
Nathan Harold12e1f552016-06-17 13:55:38 -07001244 private boolean isImsVolteProvisioned() {
Nathan Harold2b77d742016-03-19 13:22:10 -07001245 if (phone != null && mImsManager != null) {
1246 return mImsManager.isVolteEnabledByPlatform(phone.getContext())
1247 && mImsManager.isVolteProvisionedOnDevice(phone.getContext());
Pavel Zhamaitsiakcb267a62015-01-21 18:25:14 -08001248 }
1249 return false;
1250 }
1251
Nathan Harold12e1f552016-06-17 13:55:38 -07001252 OnCheckedChangeListener mImsVolteCheckedChangeListener = new OnCheckedChangeListener() {
Wink Saville426fc662011-09-25 14:39:02 -07001253 @Override
Nathan Harold2b77d742016-03-19 13:22:10 -07001254 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001255 setImsVolteProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001256 }
Wink Saville426fc662011-09-25 14:39:02 -07001257 };
1258
Nathan Harold12e1f552016-06-17 13:55:38 -07001259 private boolean isImsVtProvisioned() {
1260 if (phone != null && mImsManager != null) {
1261 return mImsManager.isVtEnabledByPlatform(phone.getContext())
1262 && mImsManager.isVtProvisionedOnDevice(phone.getContext());
1263 }
1264 return false;
1265 }
1266
1267 OnCheckedChangeListener mImsVtCheckedChangeListener = new OnCheckedChangeListener() {
1268 @Override
1269 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1270 setImsVtProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001271 }
Nathan Harold12e1f552016-06-17 13:55:38 -07001272 };
1273
1274 private boolean isImsWfcProvisioned() {
1275 if (phone != null && mImsManager != null) {
1276 return mImsManager.isWfcEnabledByPlatform(phone.getContext())
1277 && mImsManager.isWfcProvisionedOnDevice(phone.getContext());
1278 }
1279 return false;
1280 }
1281
1282 OnCheckedChangeListener mImsWfcCheckedChangeListener = new OnCheckedChangeListener() {
1283 @Override
1284 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1285 setImsWfcProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001286 }
Nathan Harold12e1f552016-06-17 13:55:38 -07001287 };
1288
Meng Wang586741c2017-04-26 15:02:51 -07001289 private boolean isEabProvisioned() {
1290 return isFeatureProvisioned(EAB_PROVISIONED_CONFIG_ID, false);
1291 }
1292
1293 OnCheckedChangeListener mEabCheckedChangeListener = new OnCheckedChangeListener() {
1294 @Override
1295 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1296 setEabProvisionedState(isChecked);
1297 }
1298 };
1299
1300 private boolean isFeatureProvisioned(int featureId, boolean defaultValue) {
1301 boolean provisioned = defaultValue;
1302 if (mImsManager != null) {
1303 try {
1304 ImsConfig imsConfig = mImsManager.getConfigInterface();
1305 if (imsConfig != null) {
1306 provisioned =
1307 (imsConfig.getProvisionedValue(featureId)
1308 == ImsConfig.FeatureValueConstants.ON);
1309 }
1310 } catch (ImsException ex) {
1311 Log.e(TAG, "isFeatureProvisioned() exception:", ex);
1312 }
1313 }
1314
1315 log("isFeatureProvisioned() featureId=" + featureId + " provisioned=" + provisioned);
1316 return provisioned;
1317 }
1318
1319 private static boolean isEabEnabledByPlatform(Context context) {
1320 if (context != null) {
1321 CarrierConfigManager configManager = (CarrierConfigManager)
1322 context.getSystemService(Context.CARRIER_CONFIG_SERVICE);
1323 if (configManager != null && configManager.getConfig().getBoolean(
1324 CarrierConfigManager.KEY_USE_RCS_PRESENCE_BOOL)) {
1325 return true;
1326 }
1327 }
1328 return false;
1329 }
1330
Nathan Harold12e1f552016-06-17 13:55:38 -07001331 private void updateImsProvisionedState() {
1332 log("updateImsProvisionedState isImsVolteProvisioned()=" + isImsVolteProvisioned());
Nathan Harold2b77d742016-03-19 13:22:10 -07001333 //delightful hack to prevent on-checked-changed calls from
1334 //actually forcing the ims provisioning to its transient/current value.
Nathan Harold12e1f552016-06-17 13:55:38 -07001335 imsVolteProvisionedSwitch.setOnCheckedChangeListener(null);
1336 imsVolteProvisionedSwitch.setChecked(isImsVolteProvisioned());
1337 imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
Nathan Harold6dc15e92016-10-28 11:45:59 -07001338 imsVolteProvisionedSwitch.setEnabled(
1339 mImsManager.isVolteEnabledByPlatform(phone.getContext()));
Nathan Harold12e1f552016-06-17 13:55:38 -07001340
1341 imsVtProvisionedSwitch.setOnCheckedChangeListener(null);
1342 imsVtProvisionedSwitch.setChecked(isImsVtProvisioned());
1343 imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
Nathan Harold6dc15e92016-10-28 11:45:59 -07001344 imsVtProvisionedSwitch.setEnabled(
1345 mImsManager.isVtEnabledByPlatform(phone.getContext()));
Nathan Harold12e1f552016-06-17 13:55:38 -07001346
1347 imsWfcProvisionedSwitch.setOnCheckedChangeListener(null);
1348 imsWfcProvisionedSwitch.setChecked(isImsWfcProvisioned());
1349 imsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
Nathan Harold6dc15e92016-10-28 11:45:59 -07001350 imsWfcProvisionedSwitch.setEnabled(
1351 mImsManager.isWfcEnabledByPlatform(phone.getContext()));
Meng Wang586741c2017-04-26 15:02:51 -07001352
1353 eabProvisionedSwitch.setOnCheckedChangeListener(null);
1354 eabProvisionedSwitch.setChecked(isEabProvisioned());
1355 eabProvisionedSwitch.setOnCheckedChangeListener(mEabCheckedChangeListener);
1356 eabProvisionedSwitch.setEnabled(isEabEnabledByPlatform(phone.getContext()));
Wink Saville426fc662011-09-25 14:39:02 -07001357 }
1358
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001359 OnClickListener mDnsCheckButtonHandler = new OnClickListener() {
1360 public void onClick(View v) {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001361 //FIXME: Replace with a TelephonyManager call
Wink Savillec3886682009-04-02 11:00:56 -07001362 phone.disableDnsCheck(!phone.isDnsCheckDisabled());
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001363 updateDnsCheckState();
1364 }
1365 };
johnwang342101a2009-09-23 16:22:34 -07001366
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001367 OnClickListener mOemInfoButtonHandler = new OnClickListener() {
1368 public void onClick(View v) {
1369 Intent intent = new Intent("com.android.settings.OEM_RADIO_INFO");
1370 try {
1371 startActivity(intent);
1372 } catch (android.content.ActivityNotFoundException ex) {
Wink Savillebf471282013-04-05 15:04:05 -07001373 log("OEM-specific Info/Settings Activity Not Found : " + ex);
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001374 // If the activity does not exist, there are no OEM
1375 // settings, and so we can just do nothing...
1376 }
1377 }
1378 };
1379
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001380 OnClickListener mPingButtonHandler = new OnClickListener() {
1381 public void onClick(View v) {
1382 updatePingState();
1383 }
1384 };
1385
1386 OnClickListener mUpdateSmscButtonHandler = new OnClickListener() {
1387 public void onClick(View v) {
1388 updateSmscButton.setEnabled(false);
jsh21dd4072009-05-12 11:26:55 -07001389 phone.setSmscAddress(smsc.getText().toString(),
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001390 mHandler.obtainMessage(EVENT_UPDATE_SMSC_DONE));
1391 }
1392 };
1393
1394 OnClickListener mRefreshSmscButtonHandler = new OnClickListener() {
1395 public void onClick(View v) {
1396 refreshSmsc();
1397 }
1398 };
1399
Youhan Wangfd781e92016-12-16 15:53:16 -08001400 OnClickListener mCarrierProvisioningButtonHandler = new OnClickListener() {
1401 public void onClick(View v) {
Meng Wanga04449b2017-08-03 14:34:35 -07001402 final Intent intent = new Intent("com.android.settings.CARRIER_PROVISIONING");
1403 final ComponentName serviceComponent = ComponentName.unflattenFromString(
1404 "com.android.omadm.service/.DMIntentReceiver");
Youhan Wangfd781e92016-12-16 15:53:16 -08001405 intent.setComponent(serviceComponent);
Meng Wanga04449b2017-08-03 14:34:35 -07001406 sendBroadcast(intent);
Youhan Wangfd781e92016-12-16 15:53:16 -08001407 }
1408 };
1409
1410 OnClickListener mTriggerCarrierProvisioningButtonHandler = new OnClickListener() {
1411 public void onClick(View v) {
Meng Wanga04449b2017-08-03 14:34:35 -07001412 final Intent intent = new Intent("com.android.settings.TRIGGER_CARRIER_PROVISIONING");
1413 final ComponentName serviceComponent = ComponentName.unflattenFromString(
1414 "com.android.omadm.service/.DMIntentReceiver");
Youhan Wangfd781e92016-12-16 15:53:16 -08001415 intent.setComponent(serviceComponent);
Meng Wanga04449b2017-08-03 14:34:35 -07001416 sendBroadcast(intent);
Youhan Wangfd781e92016-12-16 15:53:16 -08001417 }
1418 };
1419
Nathan Haroldcea413a2015-11-23 15:48:10 -08001420 AdapterView.OnItemSelectedListener mPreferredNetworkHandler =
1421 new AdapterView.OnItemSelectedListener() {
1422
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001423 public void onItemSelected(AdapterView parent, View v, int pos, long id) {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001424 if (mPreferredNetworkTypeResult != pos && pos >= 0
1425 && pos <= mPreferredNetworkLabels.length - 2) {
1426 mPreferredNetworkTypeResult = pos;
1427 Message msg = mHandler.obtainMessage(EVENT_SET_PREFERRED_TYPE_DONE);
1428 phone.setPreferredNetworkType(mPreferredNetworkTypeResult, msg);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001429 }
1430 }
1431
1432 public void onNothingSelected(AdapterView parent) {
1433 }
1434 };
1435
Nathan Harold2b77d742016-03-19 13:22:10 -07001436 AdapterView.OnItemSelectedListener mCellInfoRefreshRateHandler =
1437 new AdapterView.OnItemSelectedListener() {
Wink Savillebf471282013-04-05 15:04:05 -07001438
Nathan Harold2b77d742016-03-19 13:22:10 -07001439 public void onItemSelected(AdapterView parent, View v, int pos, long id) {
1440 mCellInfoRefreshRateIndex = pos;
Sooraj Sasindran5cce06b2016-08-18 15:49:49 -07001441 mTelephonyManager.setCellInfoListRate(mCellInfoRefreshRates[pos]);
Nathan Harold2b77d742016-03-19 13:22:10 -07001442 updateAllCellInfo();
1443 }
1444
1445 public void onNothingSelected(AdapterView parent) {
1446 }
1447 };
1448
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001449}