blob: 5c0e87dadc03385e8b7ac5b29c9597b0223d22b3 [file] [log] [blame]
Jordan Liu4cb626c2019-04-11 21:53:13 +00001/*
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08002 * 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
Nathan Haroldf10ea322018-04-24 13:31:07 -070019import static android.net.ConnectivityManager.NetworkCallback;
Nathan Harolddaea8be2018-06-05 14:02:35 -070020import static android.provider.Settings.Global.PREFERRED_NETWORK_MODE;
Nathan Haroldf10ea322018-04-24 13:31:07 -070021
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080022import android.app.Activity;
Pavel Zhamaitsiakcb267a62015-01-21 18:25:14 -080023import android.app.QueuedWork;
Youhan Wangfd781e92016-12-16 15:53:16 -080024import android.content.ComponentName;
Meng Wang586741c2017-04-26 15:02:51 -070025import android.content.Context;
Pengquan Meng7f602c72019-01-28 19:12:18 -080026import android.content.DialogInterface;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080027import android.content.Intent;
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +080028import android.content.pm.PackageManager;
29import android.content.pm.ResolveInfo;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080030import android.content.res.Resources;
Nathan Haroldcea413a2015-11-23 15:48:10 -080031import android.graphics.Typeface;
Nathan Haroldf10ea322018-04-24 13:31:07 -070032import android.net.ConnectivityManager;
33import android.net.Network;
34import android.net.NetworkCapabilities;
35import android.net.NetworkRequest;
Jeff Sharkey93029862011-05-27 18:26:15 -070036import android.net.TrafficStats;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080037import android.net.Uri;
38import android.os.AsyncResult;
Sreekanth Badidac888e192018-02-05 17:18:40 +010039import android.os.Build;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080040import android.os.Bundle;
41import android.os.Handler;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080042import android.os.Message;
Nathan Harolddaea8be2018-06-05 14:02:35 -070043import android.provider.Settings;
Meng Wang586741c2017-04-26 15:02:51 -070044import android.telephony.CarrierConfigManager;
Fan Zhangc7162cd2018-06-18 15:21:41 -070045import android.telephony.CellIdentityCdma;
46import android.telephony.CellIdentityGsm;
47import android.telephony.CellIdentityLte;
48import android.telephony.CellIdentityWcdma;
Wink Saville79bff2a2012-06-01 14:37:21 -070049import android.telephony.CellInfo;
Nathan Haroldcea413a2015-11-23 15:48:10 -080050import android.telephony.CellInfoCdma;
51import android.telephony.CellInfoGsm;
52import android.telephony.CellInfoLte;
53import android.telephony.CellInfoWcdma;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080054import android.telephony.CellLocation;
Nathan Haroldcea413a2015-11-23 15:48:10 -080055import android.telephony.CellSignalStrengthCdma;
56import android.telephony.CellSignalStrengthGsm;
57import android.telephony.CellSignalStrengthLte;
58import android.telephony.CellSignalStrengthWcdma;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080059import android.telephony.PhoneStateListener;
Nathan Harold433ca442018-04-23 18:20:43 -070060import android.telephony.PhysicalChannelConfig;
Fan Zhangc7162cd2018-06-18 15:21:41 -070061import android.telephony.PreciseCallState;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080062import android.telephony.ServiceState;
Nathan Harold2b77d742016-03-19 13:22:10 -070063import android.telephony.SignalStrength;
Nathan Haroldcea413a2015-11-23 15:48:10 -080064import android.telephony.SubscriptionManager;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080065import android.telephony.TelephonyManager;
jsh534f5ae2009-09-24 09:19:22 -070066import android.telephony.cdma.CdmaCellLocation;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080067import android.telephony.gsm.GsmCellLocation;
Nathan Harold6e16fdf2018-04-17 17:01:32 -070068import android.text.TextUtils;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080069import android.util.Log;
70import android.view.Menu;
71import android.view.MenuItem;
72import android.view.View;
73import android.view.View.OnClickListener;
74import android.widget.AdapterView;
75import android.widget.ArrayAdapter;
76import android.widget.Button;
Nathan Harold2b77d742016-03-19 13:22:10 -070077import android.widget.CompoundButton;
78import android.widget.CompoundButton.OnCheckedChangeListener;
Jason Monk39b46742015-09-10 15:52:51 -040079import android.widget.EditText;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080080import android.widget.Spinner;
Nathan Harold2b77d742016-03-19 13:22:10 -070081import android.widget.Switch;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080082import android.widget.TextView;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080083
Fan Zhang23f8d592018-08-28 15:11:40 -070084import androidx.appcompat.app.AlertDialog;
Pengquan Meng7f602c72019-01-28 19:12:18 -080085import androidx.appcompat.app.AlertDialog.Builder;
Fan Zhang23f8d592018-08-28 15:11:40 -070086
Jason Monk39b46742015-09-10 15:52:51 -040087import com.android.ims.ImsConfig;
88import com.android.ims.ImsException;
89import com.android.ims.ImsManager;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080090import com.android.internal.telephony.Phone;
91import com.android.internal.telephony.PhoneFactory;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080092
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080093import java.io.IOException;
Jason Monk39b46742015-09-10 15:52:51 -040094import java.net.HttpURLConnection;
95import java.net.URL;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080096import java.util.List;
97
Pengquan Meng7f602c72019-01-28 19:12:18 -080098// TODO(b/123598192) consider to move this activity to telephony package.
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080099public class RadioInfo extends Activity {
Nathan Harold2b77d742016-03-19 13:22:10 -0700100 private static final String TAG = "RadioInfo";
johnwang342101a2009-09-23 16:22:34 -0700101
Nathan Harold2b77d742016-03-19 13:22:10 -0700102 private static final String[] mPreferredNetworkLabels = {
103 "WCDMA preferred",
104 "GSM only",
105 "WCDMA only",
106 "GSM auto (PRL)",
107 "CDMA auto (PRL)",
108 "CDMA only",
109 "EvDo only",
110 "Global auto (PRL)",
111 "LTE/CDMA auto (PRL)",
112 "LTE/UMTS auto (PRL)",
113 "LTE/CDMA/UMTS auto (PRL)",
114 "LTE only",
115 "LTE/WCDMA",
116 "TD-SCDMA only",
117 "TD-SCDMA/WCDMA",
118 "LTE/TD-SCDMA",
119 "TD-SCDMA/GSM",
120 "TD-SCDMA/UMTS",
121 "LTE/TD-SCDMA/WCDMA",
122 "LTE/TD-SCDMA/UMTS",
123 "TD-SCDMA/CDMA/UMTS",
124 "Global/TD-SCDMA",
125 "Unknown"
126 };
127
Jordan Liub69e8f22019-04-02 12:13:31 -0700128 private static String[] mPhoneIndexLabels;
Nathan Harold2b77d742016-03-19 13:22:10 -0700129
130 private static final int CELL_INFO_LIST_RATE_DISABLED = Integer.MAX_VALUE;
131 private static final int CELL_INFO_LIST_RATE_MAX = 0;
132
Nathan Harold12e1f552016-06-17 13:55:38 -0700133
134 private static final int IMS_VOLTE_PROVISIONED_CONFIG_ID =
135 ImsConfig.ConfigConstants.VLT_SETTING_ENABLED;
136
137 private static final int IMS_VT_PROVISIONED_CONFIG_ID =
138 ImsConfig.ConfigConstants.LVC_SETTING_ENABLED;
139
140 private static final int IMS_WFC_PROVISIONED_CONFIG_ID =
141 ImsConfig.ConfigConstants.VOICE_OVER_WIFI_SETTING_ENABLED;
142
Meng Wang586741c2017-04-26 15:02:51 -0700143 private static final int EAB_PROVISIONED_CONFIG_ID =
144 ImsConfig.ConfigConstants.EAB_SETTING_ENABLED;
145
Nathan Harold2b77d742016-03-19 13:22:10 -0700146 //Values in must match mCellInfoRefreshRates
147 private static final String[] mCellInfoRefreshRateLabels = {
148 "Disabled",
149 "Immediate",
150 "Min 5s",
151 "Min 10s",
152 "Min 60s"
153 };
154
155 //Values in seconds, must match mCellInfoRefreshRateLabels
156 private static final int mCellInfoRefreshRates[] = {
157 CELL_INFO_LIST_RATE_DISABLED,
158 CELL_INFO_LIST_RATE_MAX,
159 5000,
160 10000,
161 60000
162 };
163
Jordan Liub69e8f22019-04-02 12:13:31 -0700164 private static void log(String s) {
Nathan Harold2b77d742016-03-19 13:22:10 -0700165 Log.d(TAG, s);
166 }
167
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800168 private static final int EVENT_CFI_CHANGED = 302;
169
170 private static final int EVENT_QUERY_PREFERRED_TYPE_DONE = 1000;
171 private static final int EVENT_SET_PREFERRED_TYPE_DONE = 1001;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800172 private static final int EVENT_QUERY_SMSC_DONE = 1005;
173 private static final int EVENT_UPDATE_SMSC_DONE = 1006;
174
Jordan Liub69e8f22019-04-02 12:13:31 -0700175 private static final int MENU_ITEM_SELECT_BAND = 0;
176 private static final int MENU_ITEM_VIEW_ADN = 1;
177 private static final int MENU_ITEM_VIEW_FDN = 2;
178 private static final int MENU_ITEM_VIEW_SDN = 3;
179 private static final int MENU_ITEM_GET_IMS_STATUS = 4;
180 private static final int MENU_ITEM_TOGGLE_DATA = 5;
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800181
Wink Savillec3886682009-04-02 11:00:56 -0700182 private TextView mDeviceId; //DeviceId is the IMEI in GSM and the MEID in CDMA
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800183 private TextView number;
Jordan Liub69e8f22019-04-02 12:13:31 -0700184 private TextView mSubscriptionId;
185 private TextView mDds;
Meng Wang9053f172017-06-23 16:02:14 -0700186 private TextView mSubscriberId;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800187 private TextView callState;
188 private TextView operatorName;
189 private TextView roamingState;
190 private TextView gsmState;
191 private TextView gprsState;
Nathan Harold2b77d742016-03-19 13:22:10 -0700192 private TextView voiceNetwork;
193 private TextView dataNetwork;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800194 private TextView dBm;
195 private TextView mMwi;
196 private TextView mCfi;
197 private TextView mLocation;
Wink Saville79bff2a2012-06-01 14:37:21 -0700198 private TextView mCellInfo;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800199 private TextView sent;
200 private TextView received;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800201 private TextView mPingHostnameV4;
202 private TextView mPingHostnameV6;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800203 private TextView mHttpClientTest;
Nathan Harold433ca442018-04-23 18:20:43 -0700204 private TextView mPhyChanConfig;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800205 private TextView dnsCheckState;
Nathan Haroldf10ea322018-04-24 13:31:07 -0700206 private TextView mDownlinkKbps;
207 private TextView mUplinkKbps;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800208 private EditText smsc;
Nathan Harold2b77d742016-03-19 13:22:10 -0700209 private Switch radioPowerOnSwitch;
210 private Button cellInfoRefreshRateButton;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800211 private Button dnsCheckToggleButton;
212 private Button pingTestButton;
213 private Button updateSmscButton;
214 private Button refreshSmscButton;
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800215 private Button oemInfoButton;
Youhan Wangfd781e92016-12-16 15:53:16 -0800216 private Button carrierProvisioningButton;
217 private Button triggercarrierProvisioningButton;
Nathan Harold12e1f552016-06-17 13:55:38 -0700218 private Switch imsVolteProvisionedSwitch;
219 private Switch imsVtProvisionedSwitch;
220 private Switch imsWfcProvisionedSwitch;
Meng Wang586741c2017-04-26 15:02:51 -0700221 private Switch eabProvisionedSwitch;
Naina Nallurid1b57f62019-01-08 15:19:58 -0800222 private Switch cbrsDataSwitch;
Pengquan Meng7f602c72019-01-28 19:12:18 -0800223 private Switch dsdsSwitch;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800224 private Spinner preferredNetworkType;
Jordan Liub69e8f22019-04-02 12:13:31 -0700225 private Spinner mSelectPhoneIndex;
Nathan Harold2b77d742016-03-19 13:22:10 -0700226 private Spinner cellInfoRefreshRateSpinner;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800227
Nathan Haroldf10ea322018-04-24 13:31:07 -0700228 private ConnectivityManager mConnectivityManager;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800229 private TelephonyManager mTelephonyManager;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800230 private ImsManager mImsManager = null;
Jordan Liu84deb0a2019-04-05 14:39:41 -0700231 private Phone mPhone = null;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800232
Nathan Haroldcea413a2015-11-23 15:48:10 -0800233 private String mPingHostnameResultV4;
234 private String mPingHostnameResultV6;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800235 private String mHttpClientTestResult;
236 private boolean mMwiValue = false;
237 private boolean mCfiValue = false;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800238
239 private List<CellInfo> mCellInfoResult = null;
240 private CellLocation mCellLocationResult = null;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800241
242 private int mPreferredNetworkTypeResult;
Nathan Harold2b77d742016-03-19 13:22:10 -0700243 private int mCellInfoRefreshRateIndex;
Jordan Liub69e8f22019-04-02 12:13:31 -0700244 private int mSelectedPhoneIndex;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800245
Nathan Haroldf10ea322018-04-24 13:31:07 -0700246 private final NetworkRequest mDefaultNetworkRequest = new NetworkRequest.Builder()
247 .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
248 .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
249 .build();
250
251 private final NetworkCallback mNetworkCallback = new NetworkCallback() {
252 public void onCapabilitiesChanged(Network n, NetworkCapabilities nc) {
253 int dlbw = nc.getLinkDownstreamBandwidthKbps();
254 int ulbw = nc.getLinkUpstreamBandwidthKbps();
255 updateBandwidths(dlbw, ulbw);
256 }
257 };
258
Jordan Liu84deb0a2019-04-05 14:39:41 -0700259 // not final because we need to recreate this object to register on a new subId (b/117555407)
260 private PhoneStateListener mPhoneStateListener = new RadioInfoPhoneStateListener();
261 private class RadioInfoPhoneStateListener extends PhoneStateListener {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800262 @Override
263 public void onDataConnectionStateChanged(int state) {
264 updateDataState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800265 updateNetworkType();
266 }
267
268 @Override
269 public void onDataActivity(int direction) {
270 updateDataStats2();
271 }
272
273 @Override
Nathan Harold2b77d742016-03-19 13:22:10 -0700274 public void onCallStateChanged(int state, String incomingNumber) {
275 updateNetworkType();
276 updatePhoneState(state);
277 }
278
279 @Override
280 public void onPreciseCallStateChanged(PreciseCallState preciseState) {
281 updateNetworkType();
282 }
283
284 @Override
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800285 public void onCellLocationChanged(CellLocation location) {
286 updateLocation(location);
287 }
288
289 @Override
290 public void onMessageWaitingIndicatorChanged(boolean mwi) {
291 mMwiValue = mwi;
292 updateMessageWaiting();
293 }
294
295 @Override
296 public void onCallForwardingIndicatorChanged(boolean cfi) {
297 mCfiValue = cfi;
298 updateCallRedirect();
299 }
Wink Saville79bff2a2012-06-01 14:37:21 -0700300
301 @Override
302 public void onCellInfoChanged(List<CellInfo> arrayCi) {
Wink Savillebf471282013-04-05 15:04:05 -0700303 log("onCellInfoChanged: arrayCi=" + arrayCi);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800304 mCellInfoResult = arrayCi;
305 updateCellInfo(mCellInfoResult);
Wink Saville79bff2a2012-06-01 14:37:21 -0700306 }
Wink Saville4f0d8812014-04-15 22:05:24 -0700307
308 @Override
Nathan Harold2b77d742016-03-19 13:22:10 -0700309 public void onSignalStrengthsChanged(SignalStrength signalStrength) {
310 log("onSignalStrengthChanged: SignalStrength=" +signalStrength);
311 updateSignalStrength(signalStrength);
312 }
313
314 @Override
315 public void onServiceStateChanged(ServiceState serviceState) {
316 log("onServiceStateChanged: ServiceState=" + serviceState);
317 updateServiceState(serviceState);
318 updateRadioPowerState();
319 updateNetworkType();
Nathan Harold12e1f552016-06-17 13:55:38 -0700320 updateImsProvisionedState();
Nathan Harold2b77d742016-03-19 13:22:10 -0700321 }
Nathan Harold433ca442018-04-23 18:20:43 -0700322
323 @Override
324 public void onPhysicalChannelConfigurationChanged(
325 List<PhysicalChannelConfig> configs) {
326 updatePhysicalChannelConfiguration(configs);
327 }
328
Jordan Liu84deb0a2019-04-05 14:39:41 -0700329 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800330
Nathan Harold433ca442018-04-23 18:20:43 -0700331 private void updatePhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
332 StringBuilder sb = new StringBuilder();
333 String div = "";
334 sb.append("{");
335 if (configs != null) {
336 for(PhysicalChannelConfig c : configs) {
337 sb.append(div).append(c);
338 div = ",";
339 }
340 }
341 sb.append("}");
342 mPhyChanConfig.setText(sb.toString());
343 }
344
Nathan Haroldcea413a2015-11-23 15:48:10 -0800345 private void updatePreferredNetworkType(int type) {
346 if (type >= mPreferredNetworkLabels.length || type < 0) {
347 log("EVENT_QUERY_PREFERRED_TYPE_DONE: unknown " +
348 "type=" + type);
349 type = mPreferredNetworkLabels.length - 1; //set to Unknown
350 }
351 mPreferredNetworkTypeResult = type;
352
353 preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true);
354 }
355
Jordan Liub69e8f22019-04-02 12:13:31 -0700356 private void updatePhoneIndex(int phoneIndex, int subId) {
357 // unregister listeners on the old subId
Jordan Liu84deb0a2019-04-05 14:39:41 -0700358 unregisterPhoneStateListener();
Jordan Liub69e8f22019-04-02 12:13:31 -0700359 mTelephonyManager.setCellInfoListRate(CELL_INFO_LIST_RATE_DISABLED);
360
361 // update the subId
362 mTelephonyManager = mTelephonyManager.createForSubscriptionId(subId);
Jordan Liub69e8f22019-04-02 12:13:31 -0700363
364 // update the phoneId
Jordan Liu84deb0a2019-04-05 14:39:41 -0700365 mImsManager = ImsManager.getInstance(getApplicationContext(), phoneIndex);
366 mPhone = PhoneFactory.getPhone(phoneIndex);
Jordan Liub69e8f22019-04-02 12:13:31 -0700367
368 updateAllFields();
369 }
370
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800371 private Handler mHandler = new Handler() {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800372 @Override
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800373 public void handleMessage(Message msg) {
374 AsyncResult ar;
375 switch (msg.what) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800376 case EVENT_QUERY_PREFERRED_TYPE_DONE:
377 ar= (AsyncResult) msg.obj;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800378 if (ar.exception == null && ar.result != null) {
379 updatePreferredNetworkType(((int[])ar.result)[0]);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800380 } else {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800381 //In case of an exception, we will set this to unknown
382 updatePreferredNetworkType(mPreferredNetworkLabels.length-1);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800383 }
384 break;
385 case EVENT_SET_PREFERRED_TYPE_DONE:
386 ar= (AsyncResult) msg.obj;
387 if (ar.exception != null) {
Nathan Harolded38afa2016-04-13 00:29:30 -0700388 log("Set preferred network type failed.");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800389 }
390 break;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800391 case EVENT_QUERY_SMSC_DONE:
392 ar= (AsyncResult) msg.obj;
393 if (ar.exception != null) {
394 smsc.setText("refresh error");
395 } else {
jsh21dd4072009-05-12 11:26:55 -0700396 smsc.setText((String)ar.result);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800397 }
398 break;
399 case EVENT_UPDATE_SMSC_DONE:
400 updateSmscButton.setEnabled(true);
401 ar= (AsyncResult) msg.obj;
402 if (ar.exception != null) {
403 smsc.setText("update error");
404 }
405 break;
406 default:
Nathan Haroldcea413a2015-11-23 15:48:10 -0800407 super.handleMessage(msg);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800408 break;
409
410 }
411 }
412 };
413
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800414 @Override
415 public void onCreate(Bundle icicle) {
416 super.onCreate(icicle);
fionaxub54cb2d2016-09-22 15:01:05 -0700417 if (!android.os.Process.myUserHandle().isSystem()) {
418 Log.e(TAG, "Not run from system user, don't do anything.");
419 finish();
420 return;
421 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800422
423 setContentView(R.layout.radio_info);
424
Nathan Haroldcea413a2015-11-23 15:48:10 -0800425 log("Started onCreate");
426
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800427 mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
Nathan Haroldf10ea322018-04-24 13:31:07 -0700428 mConnectivityManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
Jordan Liu84deb0a2019-04-05 14:39:41 -0700429 mPhone = PhoneFactory.getDefaultPhone();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800430
Nathan Haroldcea413a2015-11-23 15:48:10 -0800431 mImsManager = ImsManager.getInstance(getApplicationContext(),
432 SubscriptionManager.getDefaultVoicePhoneId());
433
Jordan Liub69e8f22019-04-02 12:13:31 -0700434 mPhoneIndexLabels = getPhoneIndexLabels(mTelephonyManager);
435
Meng Wang9053f172017-06-23 16:02:14 -0700436 mDeviceId = (TextView) findViewById(R.id.imei);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800437 number = (TextView) findViewById(R.id.number);
Jordan Liub69e8f22019-04-02 12:13:31 -0700438 mSubscriptionId = (TextView) findViewById(R.id.subid);
439 mDds = (TextView) findViewById(R.id.dds);
Meng Wang9053f172017-06-23 16:02:14 -0700440 mSubscriberId = (TextView) findViewById(R.id.imsi);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800441 callState = (TextView) findViewById(R.id.call);
442 operatorName = (TextView) findViewById(R.id.operator);
443 roamingState = (TextView) findViewById(R.id.roaming);
444 gsmState = (TextView) findViewById(R.id.gsm);
445 gprsState = (TextView) findViewById(R.id.gprs);
Nathan Harold2b77d742016-03-19 13:22:10 -0700446 voiceNetwork = (TextView) findViewById(R.id.voice_network);
447 dataNetwork = (TextView) findViewById(R.id.data_network);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800448 dBm = (TextView) findViewById(R.id.dbm);
449 mMwi = (TextView) findViewById(R.id.mwi);
450 mCfi = (TextView) findViewById(R.id.cfi);
451 mLocation = (TextView) findViewById(R.id.location);
Wink Saville79bff2a2012-06-01 14:37:21 -0700452 mCellInfo = (TextView) findViewById(R.id.cellinfo);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800453 mCellInfo.setTypeface(Typeface.MONOSPACE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800454
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800455 sent = (TextView) findViewById(R.id.sent);
456 received = (TextView) findViewById(R.id.received);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800457 smsc = (EditText) findViewById(R.id.smsc);
458 dnsCheckState = (TextView) findViewById(R.id.dnsCheckState);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800459 mPingHostnameV4 = (TextView) findViewById(R.id.pingHostnameV4);
460 mPingHostnameV6 = (TextView) findViewById(R.id.pingHostnameV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800461 mHttpClientTest = (TextView) findViewById(R.id.httpClientTest);
462
Nathan Harold433ca442018-04-23 18:20:43 -0700463 mPhyChanConfig = (TextView) findViewById(R.id.phy_chan_config);
464
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800465 preferredNetworkType = (Spinner) findViewById(R.id.preferredNetworkType);
Jordan Liub69e8f22019-04-02 12:13:31 -0700466 ArrayAdapter<String> preferredNetworkTypeAdapter = new ArrayAdapter<String> (this,
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800467 android.R.layout.simple_spinner_item, mPreferredNetworkLabels);
Jordan Liub69e8f22019-04-02 12:13:31 -0700468 preferredNetworkTypeAdapter
469 .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
470 preferredNetworkType.setAdapter(preferredNetworkTypeAdapter);
471
472 mSelectPhoneIndex = (Spinner) findViewById(R.id.phoneIndex);
473 ArrayAdapter<String> phoneIndexAdapter = new ArrayAdapter<String> (this,
474 android.R.layout.simple_spinner_item, mPhoneIndexLabels);
475 phoneIndexAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
476 mSelectPhoneIndex.setAdapter(phoneIndexAdapter);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800477
Nathan Harold2b77d742016-03-19 13:22:10 -0700478 cellInfoRefreshRateSpinner = (Spinner) findViewById(R.id.cell_info_rate_select);
479 ArrayAdapter<String> cellInfoAdapter = new ArrayAdapter<String>(this,
480 android.R.layout.simple_spinner_item, mCellInfoRefreshRateLabels);
481 cellInfoAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
482 cellInfoRefreshRateSpinner.setAdapter(cellInfoAdapter);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800483
Nathan Harold12e1f552016-06-17 13:55:38 -0700484 imsVolteProvisionedSwitch = (Switch) findViewById(R.id.volte_provisioned_switch);
485 imsVtProvisionedSwitch = (Switch) findViewById(R.id.vt_provisioned_switch);
486 imsWfcProvisionedSwitch = (Switch) findViewById(R.id.wfc_provisioned_switch);
Meng Wang69439b52017-05-01 08:31:14 -0700487 eabProvisionedSwitch = (Switch) findViewById(R.id.eab_provisioned_switch);
Wink Savillebf471282013-04-05 15:04:05 -0700488
Jordan Liu84deb0a2019-04-05 14:39:41 -0700489 if (!ImsManager.isImsSupportedOnDevice(mPhone.getContext())) {
Brad Ebinger5dfe7f82019-03-11 17:33:53 -0700490 imsVolteProvisionedSwitch.setVisibility(View.GONE);
491 imsVtProvisionedSwitch.setVisibility(View.GONE);
492 imsWfcProvisionedSwitch.setVisibility(View.GONE);
493 eabProvisionedSwitch.setVisibility(View.GONE);
494 }
495
Naina Nallurid1b57f62019-01-08 15:19:58 -0800496 cbrsDataSwitch = (Switch) findViewById(R.id.cbrs_data_switch);
497 cbrsDataSwitch.setVisibility(isCbrsSupported() ? View.VISIBLE : View.GONE);
498
Pengquan Meng7f602c72019-01-28 19:12:18 -0800499 dsdsSwitch = findViewById(R.id.dsds_switch);
500 if (isDsdsSupported()) {
501 dsdsSwitch.setVisibility(View.VISIBLE);
502 dsdsSwitch.setOnClickListener(v -> {
chen xu4f379d22019-04-03 10:31:19 -0700503 if (mTelephonyManager.doesSwitchMultiSimConfigTriggerReboot()) {
Pengquan Meng7f602c72019-01-28 19:12:18 -0800504 // Undo the click action until user clicks the confirm dialog.
505 dsdsSwitch.toggle();
506 showDsdsChangeDialog();
507 } else {
508 performDsdsSwitch();
509 }
510 });
511 dsdsSwitch.setChecked(isDsdsEnabled());
512 } else {
513 dsdsSwitch.setVisibility(View.GONE);
514 }
515
Nathan Harold2b77d742016-03-19 13:22:10 -0700516 radioPowerOnSwitch = (Switch) findViewById(R.id.radio_power);
Wink Saville426fc662011-09-25 14:39:02 -0700517
Nathan Haroldf10ea322018-04-24 13:31:07 -0700518 mDownlinkKbps = (TextView) findViewById(R.id.dl_kbps);
519 mUplinkKbps = (TextView) findViewById(R.id.ul_kbps);
520 updateBandwidths(0, 0);
521
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800522 pingTestButton = (Button) findViewById(R.id.ping_test);
523 pingTestButton.setOnClickListener(mPingButtonHandler);
524 updateSmscButton = (Button) findViewById(R.id.update_smsc);
525 updateSmscButton.setOnClickListener(mUpdateSmscButtonHandler);
526 refreshSmscButton = (Button) findViewById(R.id.refresh_smsc);
527 refreshSmscButton.setOnClickListener(mRefreshSmscButtonHandler);
528 dnsCheckToggleButton = (Button) findViewById(R.id.dns_check_toggle);
529 dnsCheckToggleButton.setOnClickListener(mDnsCheckButtonHandler);
Youhan Wangfd781e92016-12-16 15:53:16 -0800530 carrierProvisioningButton = (Button) findViewById(R.id.carrier_provisioning);
531 carrierProvisioningButton.setOnClickListener(mCarrierProvisioningButtonHandler);
532 triggercarrierProvisioningButton = (Button) findViewById(R.id.trigger_carrier_provisioning);
533 triggercarrierProvisioningButton.setOnClickListener(
534 mTriggerCarrierProvisioningButtonHandler);
johnwang342101a2009-09-23 16:22:34 -0700535
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800536 oemInfoButton = (Button) findViewById(R.id.oem_info);
537 oemInfoButton.setOnClickListener(mOemInfoButtonHandler);
538 PackageManager pm = getPackageManager();
539 Intent oemInfoIntent = new Intent("com.android.settings.OEM_RADIO_INFO");
540 List<ResolveInfo> oemInfoIntentList = pm.queryIntentActivities(oemInfoIntent, 0);
541 if (oemInfoIntentList.size() == 0) {
542 oemInfoButton.setEnabled(false);
543 }
544
Nathan Harolded38afa2016-04-13 00:29:30 -0700545 mCellInfoRefreshRateIndex = 0; //disabled
Nathan Haroldcea413a2015-11-23 15:48:10 -0800546 mPreferredNetworkTypeResult = mPreferredNetworkLabels.length - 1; //Unknown
Jordan Liub69e8f22019-04-02 12:13:31 -0700547 mSelectedPhoneIndex = 0; //phone 0
Nathan Haroldcea413a2015-11-23 15:48:10 -0800548
549 //FIXME: Replace with TelephonyManager call
Jordan Liu84deb0a2019-04-05 14:39:41 -0700550 mPhone.getPreferredNetworkType(
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800551 mHandler.obtainMessage(EVENT_QUERY_PREFERRED_TYPE_DONE));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800552
Nathan Haroldcea413a2015-11-23 15:48:10 -0800553 restoreFromBundle(icicle);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800554 }
555
556 @Override
557 protected void onResume() {
558 super.onResume();
559
Nathan Haroldcea413a2015-11-23 15:48:10 -0800560 log("Started onResume");
561
Jordan Liub69e8f22019-04-02 12:13:31 -0700562 updateAllFields();
563 }
564
565 private void updateAllFields() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800566 updateMessageWaiting();
567 updateCallRedirect();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800568 updateDataState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800569 updateDataStats2();
Nathan Harold2b77d742016-03-19 13:22:10 -0700570 updateRadioPowerState();
Nathan Harold12e1f552016-06-17 13:55:38 -0700571 updateImsProvisionedState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800572 updateProperties();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800573 updateDnsCheckState();
Nathan Harold2b77d742016-03-19 13:22:10 -0700574 updateNetworkType();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800575
Nathan Haroldcea413a2015-11-23 15:48:10 -0800576 updateLocation(mCellLocationResult);
577 updateCellInfo(mCellInfoResult);
Jordan Liub69e8f22019-04-02 12:13:31 -0700578 updateSubscriptionIds();
Nathan Haroldcea413a2015-11-23 15:48:10 -0800579
580 mPingHostnameV4.setText(mPingHostnameResultV4);
581 mPingHostnameV6.setText(mPingHostnameResultV6);
582 mHttpClientTest.setText(mHttpClientTestResult);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800583
Nathan Harold2b77d742016-03-19 13:22:10 -0700584 cellInfoRefreshRateSpinner.setOnItemSelectedListener(mCellInfoRefreshRateHandler);
Nathan Harolded38afa2016-04-13 00:29:30 -0700585 //set selection after registering listener to force update
586 cellInfoRefreshRateSpinner.setSelection(mCellInfoRefreshRateIndex);
587
588 //set selection before registering to prevent update
589 preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true);
Nathan Harold2b77d742016-03-19 13:22:10 -0700590 preferredNetworkType.setOnItemSelectedListener(mPreferredNetworkHandler);
Nathan Harolded38afa2016-04-13 00:29:30 -0700591
Jordan Liub69e8f22019-04-02 12:13:31 -0700592 // set phone index
593 mSelectPhoneIndex.setSelection(mSelectedPhoneIndex, true);
594 mSelectPhoneIndex.setOnItemSelectedListener(mSelectPhoneIndexHandler);
595
Nathan Harold2b77d742016-03-19 13:22:10 -0700596 radioPowerOnSwitch.setOnCheckedChangeListener(mRadioPowerOnChangeListener);
Nathan Harold12e1f552016-06-17 13:55:38 -0700597 imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
598 imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
599 imsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
Meng Wang586741c2017-04-26 15:02:51 -0700600 eabProvisionedSwitch.setOnCheckedChangeListener(mEabCheckedChangeListener);
Nathan Harold2b77d742016-03-19 13:22:10 -0700601
Naina Nallurid1b57f62019-01-08 15:19:58 -0800602 if (isCbrsSupported()) {
603 cbrsDataSwitch.setChecked(getCbrsDataState());
604 cbrsDataSwitch.setOnCheckedChangeListener(mCbrsDataSwitchChangeListener);
605 }
606
Jordan Liu84deb0a2019-04-05 14:39:41 -0700607 unregisterPhoneStateListener();
Jordan Liub69e8f22019-04-02 12:13:31 -0700608 registerPhoneStateListener();
Nathan Harolded38afa2016-04-13 00:29:30 -0700609
Nathan Haroldf10ea322018-04-24 13:31:07 -0700610 mConnectivityManager.registerNetworkCallback(
611 mDefaultNetworkRequest, mNetworkCallback, mHandler);
612
Nathan Harolded38afa2016-04-13 00:29:30 -0700613 smsc.clearFocus();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800614 }
615
616 @Override
Nathan Haroldcea413a2015-11-23 15:48:10 -0800617 protected void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800618 super.onPause();
619
Wink Savillebf471282013-04-05 15:04:05 -0700620 log("onPause: unregister phone & data intents");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800621
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800622 mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
Sooraj Sasindran5cce06b2016-08-18 15:49:49 -0700623 mTelephonyManager.setCellInfoListRate(CELL_INFO_LIST_RATE_DISABLED);
Nathan Haroldf10ea322018-04-24 13:31:07 -0700624 mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
625
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800626 }
627
Nathan Haroldcea413a2015-11-23 15:48:10 -0800628 private void restoreFromBundle(Bundle b) {
Nathan Harolde272c202016-10-27 13:45:00 -0700629 if(b == null) {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800630 return;
631 }
632
633 mPingHostnameResultV4 = b.getString("mPingHostnameResultV4","");
634 mPingHostnameResultV6 = b.getString("mPingHostnameResultV6","");
635 mHttpClientTestResult = b.getString("mHttpClientTestResult","");
636
637 mPingHostnameV4.setText(mPingHostnameResultV4);
638 mPingHostnameV6.setText(mPingHostnameResultV6);
639 mHttpClientTest.setText(mHttpClientTestResult);
640
Nathan Harold2b77d742016-03-19 13:22:10 -0700641 mPreferredNetworkTypeResult = b.getInt("mPreferredNetworkTypeResult",
642 mPreferredNetworkLabels.length - 1);
643
Jordan Liub69e8f22019-04-02 12:13:31 -0700644 mSelectedPhoneIndex = b.getInt("mSelectedPhoneIndex", 0);
645
Nathan Harold2b77d742016-03-19 13:22:10 -0700646 mCellInfoRefreshRateIndex = b.getInt("mCellInfoRefreshRateIndex", 0);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800647 }
648
649 @Override
650 protected void onSaveInstanceState(Bundle outState) {
651 outState.putString("mPingHostnameResultV4", mPingHostnameResultV4);
652 outState.putString("mPingHostnameResultV6", mPingHostnameResultV6);
653 outState.putString("mHttpClientTestResult", mHttpClientTestResult);
Nathan Harold2b77d742016-03-19 13:22:10 -0700654
Nathan Haroldcea413a2015-11-23 15:48:10 -0800655 outState.putInt("mPreferredNetworkTypeResult", mPreferredNetworkTypeResult);
Jordan Liub69e8f22019-04-02 12:13:31 -0700656 outState.putInt("mSelectedPhoneIndex", mSelectedPhoneIndex);
Nathan Harold2b77d742016-03-19 13:22:10 -0700657 outState.putInt("mCellInfoRefreshRateIndex", mCellInfoRefreshRateIndex);
658
Nathan Haroldcea413a2015-11-23 15:48:10 -0800659 }
660
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800661 @Override
662 public boolean onCreateOptionsMenu(Menu menu) {
Wink Savillec3886682009-04-02 11:00:56 -0700663 menu.add(0, MENU_ITEM_SELECT_BAND, 0, R.string.radio_info_band_mode_label)
664 .setOnMenuItemClickListener(mSelectBandCallback)
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800665 .setAlphabeticShortcut('b');
666 menu.add(1, MENU_ITEM_VIEW_ADN, 0,
667 R.string.radioInfo_menu_viewADN).setOnMenuItemClickListener(mViewADNCallback);
668 menu.add(1, MENU_ITEM_VIEW_FDN, 0,
669 R.string.radioInfo_menu_viewFDN).setOnMenuItemClickListener(mViewFDNCallback);
670 menu.add(1, MENU_ITEM_VIEW_SDN, 0,
671 R.string.radioInfo_menu_viewSDN).setOnMenuItemClickListener(mViewSDNCallback);
Jordan Liu84deb0a2019-04-05 14:39:41 -0700672 if (ImsManager.isImsSupportedOnDevice(mPhone.getContext())) {
Brad Ebinger5dfe7f82019-03-11 17:33:53 -0700673 menu.add(1, MENU_ITEM_GET_IMS_STATUS,
674 0, R.string.radioInfo_menu_getIMS).setOnMenuItemClickListener(mGetImsStatus);
675 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800676 menu.add(1, MENU_ITEM_TOGGLE_DATA,
Nathan Harold2b77d742016-03-19 13:22:10 -0700677 0, R.string.radio_info_data_connection_disable).setOnMenuItemClickListener(mToggleData);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800678 return true;
679 }
680
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800681 @Override
Wink Savillec3886682009-04-02 11:00:56 -0700682 public boolean onPrepareOptionsMenu(Menu menu) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800683 // Get the TOGGLE DATA menu item in the right state.
684 MenuItem item = menu.findItem(MENU_ITEM_TOGGLE_DATA);
685 int state = mTelephonyManager.getDataState();
686 boolean visible = true;
687
688 switch (state) {
689 case TelephonyManager.DATA_CONNECTED:
690 case TelephonyManager.DATA_SUSPENDED:
Nathan Harold2b77d742016-03-19 13:22:10 -0700691 item.setTitle(R.string.radio_info_data_connection_disable);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800692 break;
693 case TelephonyManager.DATA_DISCONNECTED:
Nathan Harold2b77d742016-03-19 13:22:10 -0700694 item.setTitle(R.string.radio_info_data_connection_enable);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800695 break;
696 default:
697 visible = false;
698 break;
699 }
700 item.setVisible(visible);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800701 return true;
702 }
703
Jordan Liub69e8f22019-04-02 12:13:31 -0700704 // returns array of string labels for each phone index. The array index is equal to the phone
705 // index.
706 private static String[] getPhoneIndexLabels(TelephonyManager tm) {
707 int phones = tm.getPhoneCount();
708 String[] labels = new String[phones];
709 for (int i = 0; i < phones; i++) {
710 labels[i] = "Phone " + i;
711 }
712 return labels;
713 }
714
Jordan Liu84deb0a2019-04-05 14:39:41 -0700715 private void unregisterPhoneStateListener() {
716 mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
717
718 // clear all fields so they are blank until the next listener event occurs
719 operatorName.setText("");
720 gprsState.setText("");
721 dataNetwork.setText("");
722 voiceNetwork.setText("");
723 sent.setText("");
724 received.setText("");
725 callState.setText("");
726 mLocation.setText("");
727 mMwiValue = false;
728 mMwi.setText("");
729 mCfiValue = false;
730 mCfi.setText("");
731 mCellInfo.setText("");
732 dBm.setText("");
733 gsmState.setText("");
734 roamingState.setText("");
735 mPhyChanConfig.setText("");
736 }
737
Jordan Liub69e8f22019-04-02 12:13:31 -0700738 // register mPhoneStateListener for relevant fields using the current TelephonyManager
739 private void registerPhoneStateListener() {
Jordan Liu84deb0a2019-04-05 14:39:41 -0700740 mPhoneStateListener = new RadioInfoPhoneStateListener();
Jordan Liub69e8f22019-04-02 12:13:31 -0700741 mTelephonyManager.listen(mPhoneStateListener,
742 PhoneStateListener.LISTEN_CALL_STATE
743 //b/27803938 - RadioInfo currently cannot read PRECISE_CALL_STATE
744 // | PhoneStateListener.LISTEN_PRECISE_CALL_STATE
745 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
746 | PhoneStateListener.LISTEN_DATA_ACTIVITY
747 | PhoneStateListener.LISTEN_CELL_LOCATION
748 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
749 | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
750 | PhoneStateListener.LISTEN_CELL_INFO
751 | PhoneStateListener.LISTEN_SERVICE_STATE
752 | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
753 | PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION);
754 }
755
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800756 private void updateDnsCheckState() {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800757 //FIXME: Replace with a TelephonyManager call
Jordan Liu84deb0a2019-04-05 14:39:41 -0700758 dnsCheckState.setText(mPhone.isDnsCheckDisabled() ?
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800759 "0.0.0.0 allowed" :"0.0.0.0 not allowed");
760 }
Wink Savillee2a14e32009-05-29 14:06:30 -0700761
Nathan Haroldf10ea322018-04-24 13:31:07 -0700762 private void updateBandwidths(int dlbw, int ulbw) {
763 dlbw = (dlbw < 0 || dlbw == Integer.MAX_VALUE) ? -1 : dlbw;
764 ulbw = (ulbw < 0 || ulbw == Integer.MAX_VALUE) ? -1 : ulbw;
765 mDownlinkKbps.setText(String.format("%-5d", dlbw));
766 mUplinkKbps.setText(String.format("%-5d", ulbw));
767 }
768
769
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800770 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -0700771 updateSignalStrength(SignalStrength signalStrength) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800772 Resources r = getResources();
773
Nathan Harold2b77d742016-03-19 13:22:10 -0700774 int signalDbm = signalStrength.getDbm();
Wink Savillee2a14e32009-05-29 14:06:30 -0700775
Nathan Harold2b77d742016-03-19 13:22:10 -0700776 int signalAsu = signalStrength.getAsuLevel();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800777
778 if (-1 == signalAsu) signalAsu = 0;
779
780 dBm.setText(String.valueOf(signalDbm) + " "
781 + r.getString(R.string.radioInfo_display_dbm) + " "
782 + String.valueOf(signalAsu) + " "
783 + r.getString(R.string.radioInfo_display_asu));
784 }
785
786 private final void updateLocation(CellLocation location) {
jsh534f5ae2009-09-24 09:19:22 -0700787 Resources r = getResources();
Wink Savillec3886682009-04-02 11:00:56 -0700788 if (location instanceof GsmCellLocation) {
789 GsmCellLocation loc = (GsmCellLocation)location;
jsh534f5ae2009-09-24 09:19:22 -0700790 int lac = loc.getLac();
791 int cid = loc.getCid();
792 mLocation.setText(r.getString(R.string.radioInfo_lac) + " = "
793 + ((lac == -1) ? "unknown" : Integer.toHexString(lac))
794 + " "
795 + r.getString(R.string.radioInfo_cid) + " = "
796 + ((cid == -1) ? "unknown" : Integer.toHexString(cid)));
797 } else if (location instanceof CdmaCellLocation) {
798 CdmaCellLocation loc = (CdmaCellLocation)location;
799 int bid = loc.getBaseStationId();
800 int sid = loc.getSystemId();
801 int nid = loc.getNetworkId();
802 int lat = loc.getBaseStationLatitude();
803 int lon = loc.getBaseStationLongitude();
804 mLocation.setText("BID = "
805 + ((bid == -1) ? "unknown" : Integer.toHexString(bid))
806 + " "
807 + "SID = "
808 + ((sid == -1) ? "unknown" : Integer.toHexString(sid))
809 + " "
810 + "NID = "
811 + ((nid == -1) ? "unknown" : Integer.toHexString(nid))
812 + "\n"
813 + "LAT = "
814 + ((lat == -1) ? "unknown" : Integer.toHexString(lat))
815 + " "
816 + "LONG = "
817 + ((lon == -1) ? "unknown" : Integer.toHexString(lon)));
818 } else {
819 mLocation.setText("unknown");
Wink Savillec3886682009-04-02 11:00:56 -0700820 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800821
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800822
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800823 }
824
Nathan Haroldcea413a2015-11-23 15:48:10 -0800825 private final String getCellInfoDisplayString(int i) {
826 return (i != Integer.MAX_VALUE) ? Integer.toString(i) : "";
827 }
828
829 private final String getCellInfoDisplayString(long i) {
830 return (i != Long.MAX_VALUE) ? Long.toString(i) : "";
831 }
832
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700833 private final String getConnectionStatusString(CellInfo ci) {
834 String regStr = "";
835 String connStatStr = "";
836 String connector = "";
837
838 if (ci.isRegistered()) {
839 regStr = "R";
840 }
841 switch (ci.getCellConnectionStatus()) {
842 case CellInfo.CONNECTION_PRIMARY_SERVING: connStatStr = "P"; break;
843 case CellInfo.CONNECTION_SECONDARY_SERVING: connStatStr = "S"; break;
844 case CellInfo.CONNECTION_NONE: connStatStr = "N"; break;
845 case CellInfo.CONNECTION_UNKNOWN: /* Field is unsupported */ break;
846 default: break;
847 }
848 if (!TextUtils.isEmpty(regStr) && !TextUtils.isEmpty(connStatStr)) {
849 connector = "+";
850 }
851
852 return regStr + connector + connStatStr;
853 }
854
Nathan Haroldcea413a2015-11-23 15:48:10 -0800855 private final String buildCdmaInfoString(CellInfoCdma ci) {
856 CellIdentityCdma cidCdma = ci.getCellIdentity();
857 CellSignalStrengthCdma ssCdma = ci.getCellSignalStrength();
858
859 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 -0700860 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800861 getCellInfoDisplayString(cidCdma.getSystemId()),
862 getCellInfoDisplayString(cidCdma.getNetworkId()),
863 getCellInfoDisplayString(cidCdma.getBasestationId()),
864 getCellInfoDisplayString(ssCdma.getCdmaDbm()),
865 getCellInfoDisplayString(ssCdma.getCdmaEcio()),
866 getCellInfoDisplayString(ssCdma.getEvdoDbm()),
867 getCellInfoDisplayString(ssCdma.getEvdoEcio()),
868 getCellInfoDisplayString(ssCdma.getEvdoSnr()));
869 }
870
871 private final String buildGsmInfoString(CellInfoGsm ci) {
872 CellIdentityGsm cidGsm = ci.getCellIdentity();
873 CellSignalStrengthGsm ssGsm = ci.getCellSignalStrength();
874
Nathan Harold2b77d742016-03-19 13:22:10 -0700875 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 -0700876 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800877 getCellInfoDisplayString(cidGsm.getMcc()),
878 getCellInfoDisplayString(cidGsm.getMnc()),
879 getCellInfoDisplayString(cidGsm.getLac()),
880 getCellInfoDisplayString(cidGsm.getCid()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700881 getCellInfoDisplayString(cidGsm.getArfcn()),
882 getCellInfoDisplayString(cidGsm.getBsic()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800883 getCellInfoDisplayString(ssGsm.getDbm()));
884 }
885
886 private final String buildLteInfoString(CellInfoLte ci) {
887 CellIdentityLte cidLte = ci.getCellIdentity();
888 CellSignalStrengthLte ssLte = ci.getCellSignalStrength();
889
890 return String.format(
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700891 "%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s %-6.6s %-2.2s %-4.4s %-4.4s %-2.2s\n",
892 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800893 getCellInfoDisplayString(cidLte.getMcc()),
894 getCellInfoDisplayString(cidLte.getMnc()),
895 getCellInfoDisplayString(cidLte.getTac()),
896 getCellInfoDisplayString(cidLte.getCi()),
897 getCellInfoDisplayString(cidLte.getPci()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700898 getCellInfoDisplayString(cidLte.getEarfcn()),
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700899 getCellInfoDisplayString(cidLte.getBandwidth()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800900 getCellInfoDisplayString(ssLte.getDbm()),
901 getCellInfoDisplayString(ssLte.getRsrq()),
902 getCellInfoDisplayString(ssLte.getTimingAdvance()));
903 }
904
905 private final String buildWcdmaInfoString(CellInfoWcdma ci) {
906 CellIdentityWcdma cidWcdma = ci.getCellIdentity();
907 CellSignalStrengthWcdma ssWcdma = ci.getCellSignalStrength();
908
Nathan Harold2b77d742016-03-19 13:22:10 -0700909 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 -0700910 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800911 getCellInfoDisplayString(cidWcdma.getMcc()),
912 getCellInfoDisplayString(cidWcdma.getMnc()),
913 getCellInfoDisplayString(cidWcdma.getLac()),
914 getCellInfoDisplayString(cidWcdma.getCid()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700915 getCellInfoDisplayString(cidWcdma.getUarfcn()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800916 getCellInfoDisplayString(cidWcdma.getPsc()),
917 getCellInfoDisplayString(ssWcdma.getDbm()));
918 }
919
920 private final String buildCellInfoString(List<CellInfo> arrayCi) {
921 String value = new String();
922 StringBuilder cdmaCells = new StringBuilder(),
923 gsmCells = new StringBuilder(),
924 lteCells = new StringBuilder(),
925 wcdmaCells = new StringBuilder();
926
927 if (arrayCi != null) {
928 for (CellInfo ci : arrayCi) {
929
930 if (ci instanceof CellInfoLte) {
931 lteCells.append(buildLteInfoString((CellInfoLte) ci));
932 } else if (ci instanceof CellInfoWcdma) {
933 wcdmaCells.append(buildWcdmaInfoString((CellInfoWcdma) ci));
934 } else if (ci instanceof CellInfoGsm) {
935 gsmCells.append(buildGsmInfoString((CellInfoGsm) ci));
936 } else if (ci instanceof CellInfoCdma) {
937 cdmaCells.append(buildCdmaInfoString((CellInfoCdma) ci));
Wink Saville79bff2a2012-06-01 14:37:21 -0700938 }
939 }
Nathan Haroldcea413a2015-11-23 15:48:10 -0800940 if (lteCells.length() != 0) {
941 value += String.format(
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700942 "LTE\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s"
943 + " %-6.6s %-2.2s %-4.4s %-4.4s %-2.2s\n",
944 "SRV", "MCC", "MNC", "TAC", "CID", "PCI",
945 "EARFCN", "BW", "RSRP", "RSRQ", "TA");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800946 value += lteCells.toString();
947 }
948 if (wcdmaCells.length() != 0) {
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700949 value += String.format(
950 "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 -0700951 "SRV", "MCC", "MNC", "LAC", "CID", "UARFCN", "PSC", "RSCP");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800952 value += wcdmaCells.toString();
953 }
954 if (gsmCells.length() != 0) {
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700955 value += String.format(
956 "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 -0700957 "SRV", "MCC", "MNC", "LAC", "CID", "ARFCN", "BSIC", "RSSI");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800958 value += gsmCells.toString();
959 }
960 if (cdmaCells.length() != 0) {
961 value += String.format(
962 "CDMA/EVDO\n%-3.3s %-5.5s %-5.5s %-5.5s %-6.6s %-6.6s %-6.6s %-6.6s %-5.5s\n",
963 "SRV", "SID", "NID", "BSID", "C-RSSI", "C-ECIO", "E-RSSI", "E-ECIO", "E-SNR");
964 value += cdmaCells.toString();
965 }
966 } else {
967 value ="unknown";
Wink Saville79bff2a2012-06-01 14:37:21 -0700968 }
Nathan Haroldcea413a2015-11-23 15:48:10 -0800969
970 return value.toString();
971 }
972
973 private final void updateCellInfo(List<CellInfo> arrayCi) {
974 mCellInfo.setText(buildCellInfoString(arrayCi));
Wink Saville79bff2a2012-06-01 14:37:21 -0700975 }
976
Jordan Liub69e8f22019-04-02 12:13:31 -0700977 private final void updateSubscriptionIds() {
Jordan Liu84deb0a2019-04-05 14:39:41 -0700978 mSubscriptionId.setText(Integer.toString(mPhone.getSubId()));
Jordan Liub69e8f22019-04-02 12:13:31 -0700979 mDds.setText(Integer.toString(SubscriptionManager.getDefaultDataSubscriptionId()));
980 }
981
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800982 private final void
983 updateMessageWaiting() {
984 mMwi.setText(String.valueOf(mMwiValue));
985 }
986
987 private final void
988 updateCallRedirect() {
989 mCfi.setText(String.valueOf(mCfiValue));
990 }
991
992
993 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -0700994 updateServiceState(ServiceState serviceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800995 int state = serviceState.getState();
996 Resources r = getResources();
997 String display = r.getString(R.string.radioInfo_unknown);
johnwang342101a2009-09-23 16:22:34 -0700998
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800999 switch (state) {
1000 case ServiceState.STATE_IN_SERVICE:
1001 display = r.getString(R.string.radioInfo_service_in);
1002 break;
1003 case ServiceState.STATE_OUT_OF_SERVICE:
1004 case ServiceState.STATE_EMERGENCY_ONLY:
1005 display = r.getString(R.string.radioInfo_service_emergency);
1006 break;
1007 case ServiceState.STATE_POWER_OFF:
1008 display = r.getString(R.string.radioInfo_service_off);
1009 break;
1010 }
johnwang342101a2009-09-23 16:22:34 -07001011
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001012 gsmState.setText(display);
johnwang342101a2009-09-23 16:22:34 -07001013
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001014 if (serviceState.getRoaming()) {
1015 roamingState.setText(R.string.radioInfo_roaming_in);
1016 } else {
1017 roamingState.setText(R.string.radioInfo_roaming_not);
1018 }
1019
1020 operatorName.setText(serviceState.getOperatorAlphaLong());
1021 }
1022
1023 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -07001024 updatePhoneState(int state) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001025 Resources r = getResources();
1026 String display = r.getString(R.string.radioInfo_unknown);
1027
1028 switch (state) {
Nathan Harold2b77d742016-03-19 13:22:10 -07001029 case TelephonyManager.CALL_STATE_IDLE:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001030 display = r.getString(R.string.radioInfo_phone_idle);
1031 break;
Nathan Harold2b77d742016-03-19 13:22:10 -07001032 case TelephonyManager.CALL_STATE_RINGING:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001033 display = r.getString(R.string.radioInfo_phone_ringing);
1034 break;
Nathan Harold2b77d742016-03-19 13:22:10 -07001035 case TelephonyManager.CALL_STATE_OFFHOOK:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001036 display = r.getString(R.string.radioInfo_phone_offhook);
1037 break;
1038 }
1039
1040 callState.setText(display);
1041 }
1042
1043 private final void
1044 updateDataState() {
1045 int state = mTelephonyManager.getDataState();
1046 Resources r = getResources();
1047 String display = r.getString(R.string.radioInfo_unknown);
1048
1049 switch (state) {
1050 case TelephonyManager.DATA_CONNECTED:
1051 display = r.getString(R.string.radioInfo_data_connected);
1052 break;
1053 case TelephonyManager.DATA_CONNECTING:
1054 display = r.getString(R.string.radioInfo_data_connecting);
1055 break;
1056 case TelephonyManager.DATA_DISCONNECTED:
1057 display = r.getString(R.string.radioInfo_data_disconnected);
1058 break;
1059 case TelephonyManager.DATA_SUSPENDED:
1060 display = r.getString(R.string.radioInfo_data_suspended);
1061 break;
1062 }
johnwang342101a2009-09-23 16:22:34 -07001063
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001064 gprsState.setText(display);
1065 }
1066
1067 private final void updateNetworkType() {
Jordan Liu84deb0a2019-04-05 14:39:41 -07001068 if(mPhone != null) {
1069 ServiceState ss = mPhone.getServiceState();
Nathan Harold2b77d742016-03-19 13:22:10 -07001070 dataNetwork.setText(ServiceState.rilRadioTechnologyToString(
Jordan Liu84deb0a2019-04-05 14:39:41 -07001071 mPhone.getServiceState().getRilDataRadioTechnology()));
Nathan Harold2b77d742016-03-19 13:22:10 -07001072 voiceNetwork.setText(ServiceState.rilRadioTechnologyToString(
Jordan Liu84deb0a2019-04-05 14:39:41 -07001073 mPhone.getServiceState().getRilVoiceRadioTechnology()));
Nathan Harold2b77d742016-03-19 13:22:10 -07001074 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001075 }
1076
1077 private final void
1078 updateProperties() {
1079 String s;
1080 Resources r = getResources();
1081
Jordan Liu84deb0a2019-04-05 14:39:41 -07001082 s = mPhone.getDeviceId();
johnwang342101a2009-09-23 16:22:34 -07001083 if (s == null) s = r.getString(R.string.radioInfo_unknown);
Wink Savillec3886682009-04-02 11:00:56 -07001084 mDeviceId.setText(s);
johnwang342101a2009-09-23 16:22:34 -07001085
Jordan Liu84deb0a2019-04-05 14:39:41 -07001086 s = mPhone.getSubscriberId();
Meng Wang9053f172017-06-23 16:02:14 -07001087 if (s == null) s = r.getString(R.string.radioInfo_unknown);
1088 mSubscriberId.setText(s);
1089
Nathan Haroldcea413a2015-11-23 15:48:10 -08001090 //FIXME: Replace with a TelephonyManager call
Jordan Liu84deb0a2019-04-05 14:39:41 -07001091 s = mPhone.getLine1Number();
johnwang342101a2009-09-23 16:22:34 -07001092 if (s == null) s = r.getString(R.string.radioInfo_unknown);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001093 number.setText(s);
1094 }
1095
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001096 private final void updateDataStats2() {
1097 Resources r = getResources();
1098
Jeff Sharkey93029862011-05-27 18:26:15 -07001099 long txPackets = TrafficStats.getMobileTxPackets();
1100 long rxPackets = TrafficStats.getMobileRxPackets();
1101 long txBytes = TrafficStats.getMobileTxBytes();
1102 long rxBytes = TrafficStats.getMobileRxBytes();
johnwang342101a2009-09-23 16:22:34 -07001103
Jeff Sharkey93029862011-05-27 18:26:15 -07001104 String packets = r.getString(R.string.radioInfo_display_packets);
1105 String bytes = r.getString(R.string.radioInfo_display_bytes);
johnwang342101a2009-09-23 16:22:34 -07001106
Jeff Sharkey93029862011-05-27 18:26:15 -07001107 sent.setText(txPackets + " " + packets + ", " + txBytes + " " + bytes);
1108 received.setText(rxPackets + " " + packets + ", " + rxBytes + " " + bytes);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001109 }
1110
1111 /**
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001112 * Ping a host name
1113 */
1114 private final void pingHostname() {
1115 try {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001116 try {
1117 Process p4 = Runtime.getRuntime().exec("ping -c 1 www.google.com");
1118 int status4 = p4.waitFor();
1119 if (status4 == 0) {
1120 mPingHostnameResultV4 = "Pass";
1121 } else {
1122 mPingHostnameResultV4 = String.format("Fail(%d)", status4);
1123 }
1124 } catch (IOException e) {
1125 mPingHostnameResultV4 = "Fail: IOException";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001126 }
Nathan Haroldcea413a2015-11-23 15:48:10 -08001127 try {
1128 Process p6 = Runtime.getRuntime().exec("ping6 -c 1 www.google.com");
1129 int status6 = p6.waitFor();
1130 if (status6 == 0) {
1131 mPingHostnameResultV6 = "Pass";
1132 } else {
1133 mPingHostnameResultV6 = String.format("Fail(%d)", status6);
1134 }
1135 } catch (IOException e) {
1136 mPingHostnameResultV6 = "Fail: IOException";
1137 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001138 } catch (InterruptedException e) {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001139 mPingHostnameResultV4 = mPingHostnameResultV6 = "Fail: InterruptedException";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001140 }
1141 }
1142
1143 /**
1144 * This function checks for basic functionality of HTTP Client.
1145 */
1146 private void httpClientTest() {
Narayan Kamathf25627c2014-12-12 13:53:28 +00001147 HttpURLConnection urlConnection = null;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001148 try {
Narayan Kamathf25627c2014-12-12 13:53:28 +00001149 // TODO: Hardcoded for now, make it UI configurable
Alex Klyubinb0090232015-04-02 11:08:51 -07001150 URL url = new URL("https://www.google.com");
Narayan Kamathf25627c2014-12-12 13:53:28 +00001151 urlConnection = (HttpURLConnection) url.openConnection();
1152 if (urlConnection.getResponseCode() == 200) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001153 mHttpClientTestResult = "Pass";
1154 } else {
Narayan Kamathf25627c2014-12-12 13:53:28 +00001155 mHttpClientTestResult = "Fail: Code: " + urlConnection.getResponseMessage();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001156 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001157 } catch (IOException e) {
1158 mHttpClientTestResult = "Fail: IOException";
Narayan Kamathf25627c2014-12-12 13:53:28 +00001159 } finally {
1160 if (urlConnection != null) {
1161 urlConnection.disconnect();
1162 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001163 }
1164 }
1165
1166 private void refreshSmsc() {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001167 //FIXME: Replace with a TelephonyManager call
Jordan Liu84deb0a2019-04-05 14:39:41 -07001168 mPhone.getSmscAddress(mHandler.obtainMessage(EVENT_QUERY_SMSC_DONE));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001169 }
1170
Nathan Haroldcea413a2015-11-23 15:48:10 -08001171 private final void updateAllCellInfo() {
1172
1173 mCellInfo.setText("");
Nathan Haroldcea413a2015-11-23 15:48:10 -08001174 mLocation.setText("");
1175
1176 final Runnable updateAllCellInfoResults = new Runnable() {
1177 public void run() {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001178 updateLocation(mCellLocationResult);
1179 updateCellInfo(mCellInfoResult);
1180 }
1181 };
1182
1183 Thread locThread = new Thread() {
1184 @Override
1185 public void run() {
1186 mCellInfoResult = mTelephonyManager.getAllCellInfo();
1187 mCellLocationResult = mTelephonyManager.getCellLocation();
Nathan Haroldcea413a2015-11-23 15:48:10 -08001188
1189 mHandler.post(updateAllCellInfoResults);
1190 }
1191 };
1192 locThread.start();
1193 }
1194
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001195 private final void updatePingState() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001196 // Set all to unknown since the threads will take a few secs to update.
Nathan Haroldcea413a2015-11-23 15:48:10 -08001197 mPingHostnameResultV4 = getResources().getString(R.string.radioInfo_unknown);
1198 mPingHostnameResultV6 = getResources().getString(R.string.radioInfo_unknown);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001199 mHttpClientTestResult = getResources().getString(R.string.radioInfo_unknown);
1200
Nathan Haroldcea413a2015-11-23 15:48:10 -08001201 mPingHostnameV4.setText(mPingHostnameResultV4);
1202 mPingHostnameV6.setText(mPingHostnameResultV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001203 mHttpClientTest.setText(mHttpClientTestResult);
1204
1205 final Runnable updatePingResults = new Runnable() {
1206 public void run() {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001207 mPingHostnameV4.setText(mPingHostnameResultV4);
1208 mPingHostnameV6.setText(mPingHostnameResultV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001209 mHttpClientTest.setText(mHttpClientTestResult);
1210 }
1211 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001212
1213 Thread hostname = new Thread() {
1214 @Override
1215 public void run() {
1216 pingHostname();
Nathan Haroldcea413a2015-11-23 15:48:10 -08001217 mHandler.post(updatePingResults);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001218 }
1219 };
1220 hostname.start();
1221
1222 Thread httpClient = new Thread() {
1223 @Override
1224 public void run() {
1225 httpClientTest();
Nathan Haroldcea413a2015-11-23 15:48:10 -08001226 mHandler.post(updatePingResults);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001227 }
1228 };
1229 httpClient.start();
1230 }
1231
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001232 private MenuItem.OnMenuItemClickListener mViewADNCallback = new MenuItem.OnMenuItemClickListener() {
1233 public boolean onMenuItemClick(MenuItem item) {
1234 Intent intent = new Intent(Intent.ACTION_VIEW);
1235 // XXX We need to specify the component here because if we don't
1236 // the activity manager will try to resolve the type by calling
1237 // the content provider, which causes it to be loaded in a process
1238 // other than the Dialer process, which causes a lot of stuff to
1239 // break.
Jordan Liu84deb0a2019-04-05 14:39:41 -07001240 intent.setClassName("com.android.phone", "com.android.phone.SimContacts");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001241 startActivity(intent);
1242 return true;
1243 }
1244 };
1245
1246 private MenuItem.OnMenuItemClickListener mViewFDNCallback = new MenuItem.OnMenuItemClickListener() {
1247 public boolean onMenuItemClick(MenuItem item) {
1248 Intent intent = new Intent(Intent.ACTION_VIEW);
1249 // XXX We need to specify the component here because if we don't
1250 // the activity manager will try to resolve the type by calling
1251 // the content provider, which causes it to be loaded in a process
1252 // other than the Dialer process, which causes a lot of stuff to
1253 // break.
Jordan Liu84deb0a2019-04-05 14:39:41 -07001254 intent.setClassName("com.android.phone", "com.android.phone.settings.fdn.FdnList");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001255 startActivity(intent);
1256 return true;
1257 }
1258 };
1259
1260 private MenuItem.OnMenuItemClickListener mViewSDNCallback = new MenuItem.OnMenuItemClickListener() {
1261 public boolean onMenuItemClick(MenuItem item) {
1262 Intent intent = new Intent(
Wink Savillec3886682009-04-02 11:00:56 -07001263 Intent.ACTION_VIEW, Uri.parse("content://icc/sdn"));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001264 // XXX We need to specify the component here because if we don't
1265 // the activity manager will try to resolve the type by calling
1266 // the content provider, which causes it to be loaded in a process
1267 // other than the Dialer process, which causes a lot of stuff to
1268 // break.
Jordan Liu84deb0a2019-04-05 14:39:41 -07001269 intent.setClassName("com.android.phone", "com.android.phone.ADNList");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001270 startActivity(intent);
1271 return true;
1272 }
1273 };
1274
Nathan Harolde272c202016-10-27 13:45:00 -07001275 private MenuItem.OnMenuItemClickListener mGetImsStatus = new MenuItem.OnMenuItemClickListener() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001276 public boolean onMenuItemClick(MenuItem item) {
Jordan Liu84deb0a2019-04-05 14:39:41 -07001277 boolean isImsRegistered = mPhone.isImsRegistered();
1278 boolean availableVolte = mPhone.isVolteEnabled();
1279 boolean availableWfc = mPhone.isWifiCallingEnabled();
1280 boolean availableVt = mPhone.isVideoEnabled();
1281 boolean availableUt = mPhone.isUtEnabled();
Nathan Harolde272c202016-10-27 13:45:00 -07001282
1283 final String imsRegString = isImsRegistered ?
1284 getString(R.string.radio_info_ims_reg_status_registered) :
1285 getString(R.string.radio_info_ims_reg_status_not_registered);
1286
1287 final String available = getString(R.string.radio_info_ims_feature_status_available);
1288 final String unavailable = getString(
1289 R.string.radio_info_ims_feature_status_unavailable);
1290
1291 String imsStatus = getString(R.string.radio_info_ims_reg_status,
1292 imsRegString,
1293 availableVolte ? available : unavailable,
1294 availableWfc ? available : unavailable,
1295 availableVt ? available : unavailable,
1296 availableUt ? available : unavailable);
1297
1298 AlertDialog imsDialog = new AlertDialog.Builder(RadioInfo.this)
1299 .setMessage(imsStatus)
1300 .setTitle(getString(R.string.radio_info_ims_reg_status_title))
1301 .create();
1302
1303 imsDialog.show();
1304
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001305 return true;
1306 }
1307 };
1308
1309 private MenuItem.OnMenuItemClickListener mSelectBandCallback = new MenuItem.OnMenuItemClickListener() {
1310 public boolean onMenuItemClick(MenuItem item) {
1311 Intent intent = new Intent();
1312 intent.setClass(RadioInfo.this, BandMode.class);
1313 startActivity(intent);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001314 return true;
1315 }
1316 };
johnwang342101a2009-09-23 16:22:34 -07001317
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001318 private MenuItem.OnMenuItemClickListener mToggleData = new MenuItem.OnMenuItemClickListener() {
1319 public boolean onMenuItemClick(MenuItem item) {
1320 int state = mTelephonyManager.getDataState();
1321 switch (state) {
1322 case TelephonyManager.DATA_CONNECTED:
Jack Yu50972ed2018-12-13 11:51:20 -08001323 mTelephonyManager.setDataEnabled(false);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001324 break;
1325 case TelephonyManager.DATA_DISCONNECTED:
Jack Yu50972ed2018-12-13 11:51:20 -08001326 mTelephonyManager.setDataEnabled(true);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001327 break;
1328 default:
1329 // do nothing
1330 break;
1331 }
1332 return true;
1333 }
1334 };
1335
Nathan Harold2b77d742016-03-19 13:22:10 -07001336 private boolean isRadioOn() {
1337 //FIXME: Replace with a TelephonyManager call
Jordan Liu84deb0a2019-04-05 14:39:41 -07001338 return mPhone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
Nathan Harold2b77d742016-03-19 13:22:10 -07001339 }
1340
1341 private void updateRadioPowerState() {
1342 //delightful hack to prevent on-checked-changed calls from
1343 //actually forcing the radio preference to its transient/current value.
1344 radioPowerOnSwitch.setOnCheckedChangeListener(null);
1345 radioPowerOnSwitch.setChecked(isRadioOn());
1346 radioPowerOnSwitch.setOnCheckedChangeListener(mRadioPowerOnChangeListener);
1347 }
1348
Nathan Harolde272c202016-10-27 13:45:00 -07001349 void setImsVolteProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001350 Log.d(TAG, "setImsVolteProvisioned state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001351 setImsConfigProvisionedState(IMS_VOLTE_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001352 }
1353
Nathan Harolde272c202016-10-27 13:45:00 -07001354 void setImsVtProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001355 Log.d(TAG, "setImsVtProvisioned() state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001356 setImsConfigProvisionedState(IMS_VT_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001357 }
1358
Nathan Harolde272c202016-10-27 13:45:00 -07001359 void setImsWfcProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001360 Log.d(TAG, "setImsWfcProvisioned() state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001361 setImsConfigProvisionedState(IMS_WFC_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001362 }
1363
Meng Wang586741c2017-04-26 15:02:51 -07001364 void setEabProvisionedState(boolean state) {
1365 Log.d(TAG, "setEabProvisioned() state: " + ((state)? "on":"off"));
1366 setImsConfigProvisionedState(EAB_PROVISIONED_CONFIG_ID, state);
1367 }
1368
Nathan Harolde272c202016-10-27 13:45:00 -07001369 void setImsConfigProvisionedState(int configItem, boolean state) {
Jordan Liu84deb0a2019-04-05 14:39:41 -07001370 if (mPhone != null && mImsManager != null) {
Philip P. Moltmann5c449ae2017-02-14 12:43:02 -08001371 QueuedWork.queue(new Runnable() {
Nathan Harold12e1f552016-06-17 13:55:38 -07001372 public void run() {
1373 try {
1374 mImsManager.getConfigInterface().setProvisionedValue(
1375 configItem,
1376 state? 1 : 0);
1377 } catch (ImsException e) {
1378 Log.e(TAG, "setImsConfigProvisioned() exception:", e);
1379 }
1380 }
Philip P. Moltmann5c449ae2017-02-14 12:43:02 -08001381 }, false);
Nathan Harold12e1f552016-06-17 13:55:38 -07001382 }
1383 }
1384
Nathan Harold2b77d742016-03-19 13:22:10 -07001385 OnCheckedChangeListener mRadioPowerOnChangeListener = new OnCheckedChangeListener() {
1386 @Override
1387 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1388 log("toggle radio power: currently " + (isRadioOn()?"on":"off"));
Jordan Liu84deb0a2019-04-05 14:39:41 -07001389 mPhone.setRadioPower(isChecked);
Nathan Harold2b77d742016-03-19 13:22:10 -07001390 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001391 };
1392
Nathan Harold12e1f552016-06-17 13:55:38 -07001393 private boolean isImsVolteProvisioned() {
Jordan Liu84deb0a2019-04-05 14:39:41 -07001394 if (mPhone != null && mImsManager != null) {
1395 return mImsManager.isVolteEnabledByPlatform(mPhone.getContext())
1396 && mImsManager.isVolteProvisionedOnDevice(mPhone.getContext());
Pavel Zhamaitsiakcb267a62015-01-21 18:25:14 -08001397 }
1398 return false;
1399 }
1400
Nathan Harold12e1f552016-06-17 13:55:38 -07001401 OnCheckedChangeListener mImsVolteCheckedChangeListener = new OnCheckedChangeListener() {
Wink Saville426fc662011-09-25 14:39:02 -07001402 @Override
Nathan Harold2b77d742016-03-19 13:22:10 -07001403 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001404 setImsVolteProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001405 }
Wink Saville426fc662011-09-25 14:39:02 -07001406 };
1407
Nathan Harold12e1f552016-06-17 13:55:38 -07001408 private boolean isImsVtProvisioned() {
Jordan Liu84deb0a2019-04-05 14:39:41 -07001409 if (mPhone != null && mImsManager != null) {
1410 return mImsManager.isVtEnabledByPlatform(mPhone.getContext())
1411 && mImsManager.isVtProvisionedOnDevice(mPhone.getContext());
Nathan Harold12e1f552016-06-17 13:55:38 -07001412 }
1413 return false;
1414 }
1415
1416 OnCheckedChangeListener mImsVtCheckedChangeListener = new OnCheckedChangeListener() {
1417 @Override
1418 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1419 setImsVtProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001420 }
Nathan Harold12e1f552016-06-17 13:55:38 -07001421 };
1422
1423 private boolean isImsWfcProvisioned() {
Jordan Liu84deb0a2019-04-05 14:39:41 -07001424 if (mPhone != null && mImsManager != null) {
1425 return mImsManager.isWfcEnabledByPlatform(mPhone.getContext())
1426 && mImsManager.isWfcProvisionedOnDevice(mPhone.getContext());
Nathan Harold12e1f552016-06-17 13:55:38 -07001427 }
1428 return false;
1429 }
1430
1431 OnCheckedChangeListener mImsWfcCheckedChangeListener = new OnCheckedChangeListener() {
1432 @Override
1433 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1434 setImsWfcProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001435 }
Nathan Harold12e1f552016-06-17 13:55:38 -07001436 };
1437
Meng Wang586741c2017-04-26 15:02:51 -07001438 private boolean isEabProvisioned() {
1439 return isFeatureProvisioned(EAB_PROVISIONED_CONFIG_ID, false);
1440 }
1441
1442 OnCheckedChangeListener mEabCheckedChangeListener = new OnCheckedChangeListener() {
1443 @Override
1444 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1445 setEabProvisionedState(isChecked);
1446 }
1447 };
1448
1449 private boolean isFeatureProvisioned(int featureId, boolean defaultValue) {
1450 boolean provisioned = defaultValue;
1451 if (mImsManager != null) {
1452 try {
1453 ImsConfig imsConfig = mImsManager.getConfigInterface();
1454 if (imsConfig != null) {
1455 provisioned =
1456 (imsConfig.getProvisionedValue(featureId)
1457 == ImsConfig.FeatureValueConstants.ON);
1458 }
1459 } catch (ImsException ex) {
1460 Log.e(TAG, "isFeatureProvisioned() exception:", ex);
1461 }
1462 }
1463
1464 log("isFeatureProvisioned() featureId=" + featureId + " provisioned=" + provisioned);
1465 return provisioned;
1466 }
1467
1468 private static boolean isEabEnabledByPlatform(Context context) {
1469 if (context != null) {
1470 CarrierConfigManager configManager = (CarrierConfigManager)
1471 context.getSystemService(Context.CARRIER_CONFIG_SERVICE);
1472 if (configManager != null && configManager.getConfig().getBoolean(
1473 CarrierConfigManager.KEY_USE_RCS_PRESENCE_BOOL)) {
1474 return true;
1475 }
1476 }
1477 return false;
1478 }
1479
Nathan Harold12e1f552016-06-17 13:55:38 -07001480 private void updateImsProvisionedState() {
Jordan Liu84deb0a2019-04-05 14:39:41 -07001481 if (!ImsManager.isImsSupportedOnDevice(mPhone.getContext())) {
Brad Ebinger5dfe7f82019-03-11 17:33:53 -07001482 return;
1483 }
Nathan Harold12e1f552016-06-17 13:55:38 -07001484 log("updateImsProvisionedState isImsVolteProvisioned()=" + isImsVolteProvisioned());
Nathan Harold2b77d742016-03-19 13:22:10 -07001485 //delightful hack to prevent on-checked-changed calls from
1486 //actually forcing the ims provisioning to its transient/current value.
Nathan Harold12e1f552016-06-17 13:55:38 -07001487 imsVolteProvisionedSwitch.setOnCheckedChangeListener(null);
1488 imsVolteProvisionedSwitch.setChecked(isImsVolteProvisioned());
1489 imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
Sreekanth Badidac888e192018-02-05 17:18:40 +01001490 imsVolteProvisionedSwitch.setEnabled(!Build.IS_USER
Jordan Liu84deb0a2019-04-05 14:39:41 -07001491 && mImsManager.isVolteEnabledByPlatform(mPhone.getContext()));
Nathan Harold12e1f552016-06-17 13:55:38 -07001492
1493 imsVtProvisionedSwitch.setOnCheckedChangeListener(null);
1494 imsVtProvisionedSwitch.setChecked(isImsVtProvisioned());
1495 imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
Sreekanth Badidac888e192018-02-05 17:18:40 +01001496 imsVtProvisionedSwitch.setEnabled(!Build.IS_USER
Jordan Liu84deb0a2019-04-05 14:39:41 -07001497 && mImsManager.isVtEnabledByPlatform(mPhone.getContext()));
Nathan Harold12e1f552016-06-17 13:55:38 -07001498
1499 imsWfcProvisionedSwitch.setOnCheckedChangeListener(null);
1500 imsWfcProvisionedSwitch.setChecked(isImsWfcProvisioned());
1501 imsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
Sreekanth Badidac888e192018-02-05 17:18:40 +01001502 imsWfcProvisionedSwitch.setEnabled(!Build.IS_USER
Jordan Liu84deb0a2019-04-05 14:39:41 -07001503 && mImsManager.isWfcEnabledByPlatform(mPhone.getContext()));
Meng Wang586741c2017-04-26 15:02:51 -07001504
1505 eabProvisionedSwitch.setOnCheckedChangeListener(null);
1506 eabProvisionedSwitch.setChecked(isEabProvisioned());
1507 eabProvisionedSwitch.setOnCheckedChangeListener(mEabCheckedChangeListener);
Sreekanth Badidac888e192018-02-05 17:18:40 +01001508 eabProvisionedSwitch.setEnabled(!Build.IS_USER
Jordan Liu84deb0a2019-04-05 14:39:41 -07001509 && isEabEnabledByPlatform(mPhone.getContext()));
Wink Saville426fc662011-09-25 14:39:02 -07001510 }
1511
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001512 OnClickListener mDnsCheckButtonHandler = new OnClickListener() {
1513 public void onClick(View v) {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001514 //FIXME: Replace with a TelephonyManager call
Jordan Liu84deb0a2019-04-05 14:39:41 -07001515 mPhone.disableDnsCheck(!mPhone.isDnsCheckDisabled());
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001516 updateDnsCheckState();
1517 }
1518 };
johnwang342101a2009-09-23 16:22:34 -07001519
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001520 OnClickListener mOemInfoButtonHandler = new OnClickListener() {
1521 public void onClick(View v) {
1522 Intent intent = new Intent("com.android.settings.OEM_RADIO_INFO");
1523 try {
1524 startActivity(intent);
1525 } catch (android.content.ActivityNotFoundException ex) {
Wink Savillebf471282013-04-05 15:04:05 -07001526 log("OEM-specific Info/Settings Activity Not Found : " + ex);
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001527 // If the activity does not exist, there are no OEM
1528 // settings, and so we can just do nothing...
1529 }
1530 }
1531 };
1532
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001533 OnClickListener mPingButtonHandler = new OnClickListener() {
1534 public void onClick(View v) {
1535 updatePingState();
1536 }
1537 };
1538
1539 OnClickListener mUpdateSmscButtonHandler = new OnClickListener() {
1540 public void onClick(View v) {
1541 updateSmscButton.setEnabled(false);
Jordan Liu84deb0a2019-04-05 14:39:41 -07001542 mPhone.setSmscAddress(smsc.getText().toString(),
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001543 mHandler.obtainMessage(EVENT_UPDATE_SMSC_DONE));
1544 }
1545 };
1546
1547 OnClickListener mRefreshSmscButtonHandler = new OnClickListener() {
1548 public void onClick(View v) {
1549 refreshSmsc();
1550 }
1551 };
1552
Youhan Wangfd781e92016-12-16 15:53:16 -08001553 OnClickListener mCarrierProvisioningButtonHandler = new OnClickListener() {
1554 public void onClick(View v) {
Meng Wanga04449b2017-08-03 14:34:35 -07001555 final Intent intent = new Intent("com.android.settings.CARRIER_PROVISIONING");
1556 final ComponentName serviceComponent = ComponentName.unflattenFromString(
1557 "com.android.omadm.service/.DMIntentReceiver");
Youhan Wangfd781e92016-12-16 15:53:16 -08001558 intent.setComponent(serviceComponent);
Meng Wanga04449b2017-08-03 14:34:35 -07001559 sendBroadcast(intent);
Youhan Wangfd781e92016-12-16 15:53:16 -08001560 }
1561 };
1562
1563 OnClickListener mTriggerCarrierProvisioningButtonHandler = new OnClickListener() {
1564 public void onClick(View v) {
Meng Wanga04449b2017-08-03 14:34:35 -07001565 final Intent intent = new Intent("com.android.settings.TRIGGER_CARRIER_PROVISIONING");
1566 final ComponentName serviceComponent = ComponentName.unflattenFromString(
1567 "com.android.omadm.service/.DMIntentReceiver");
Youhan Wangfd781e92016-12-16 15:53:16 -08001568 intent.setComponent(serviceComponent);
Meng Wanga04449b2017-08-03 14:34:35 -07001569 sendBroadcast(intent);
Youhan Wangfd781e92016-12-16 15:53:16 -08001570 }
1571 };
1572
Nathan Haroldcea413a2015-11-23 15:48:10 -08001573 AdapterView.OnItemSelectedListener mPreferredNetworkHandler =
1574 new AdapterView.OnItemSelectedListener() {
1575
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001576 public void onItemSelected(AdapterView parent, View v, int pos, long id) {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001577 if (mPreferredNetworkTypeResult != pos && pos >= 0
1578 && pos <= mPreferredNetworkLabels.length - 2) {
1579 mPreferredNetworkTypeResult = pos;
Nathan Harolddaea8be2018-06-05 14:02:35 -07001580
1581 // TODO: Possibly migrate this to TelephonyManager.setPreferredNetworkType()
1582 // which today still has some issues (mostly that the "set" is conditional
1583 // on a successful modem call, which is not what we want). Instead we always
1584 // want this setting to be set, so that if the radio hiccups and this setting
1585 // is for some reason unsuccessful, future calls to the radio will reflect
1586 // the users's preference which is set here.
Jordan Liu84deb0a2019-04-05 14:39:41 -07001587 final int subId = mPhone.getSubId();
Nathan Harolddaea8be2018-06-05 14:02:35 -07001588 if (SubscriptionManager.isUsableSubIdValue(subId)) {
Jordan Liu84deb0a2019-04-05 14:39:41 -07001589 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Nathan Harolddaea8be2018-06-05 14:02:35 -07001590 PREFERRED_NETWORK_MODE + subId, mPreferredNetworkTypeResult);
1591 }
1592 log("Calling setPreferredNetworkType(" + mPreferredNetworkTypeResult + ")");
Nathan Haroldcea413a2015-11-23 15:48:10 -08001593 Message msg = mHandler.obtainMessage(EVENT_SET_PREFERRED_TYPE_DONE);
Jordan Liu84deb0a2019-04-05 14:39:41 -07001594 mPhone.setPreferredNetworkType(mPreferredNetworkTypeResult, msg);
1595 }
1596 }
1597
1598 public void onNothingSelected(AdapterView parent) {
1599 }
1600 };
1601
1602 AdapterView.OnItemSelectedListener mSelectPhoneIndexHandler =
1603 new AdapterView.OnItemSelectedListener() {
1604
1605 public void onItemSelected(AdapterView parent, View v, int pos, long id) {
1606 if (pos >= 0 && pos <= mPhoneIndexLabels.length - 1) {
1607 // the array position is equal to the phone index
1608 int phoneIndex = pos;
1609 Phone[] phones = PhoneFactory.getPhones();
1610 if (phones == null || phones.length <= phoneIndex) {
1611 return;
1612 }
1613 // getSubId says it takes a slotIndex, but it actually takes a phone index
1614 int[] subIds = SubscriptionManager.getSubId(phoneIndex);
1615 if (subIds == null || subIds.length < 1) {
1616 return;
1617 }
1618 mSelectedPhoneIndex = phoneIndex;
1619
1620 updatePhoneIndex(phoneIndex, subIds[0]);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001621 }
1622 }
1623
1624 public void onNothingSelected(AdapterView parent) {
1625 }
1626 };
1627
Jordan Liub69e8f22019-04-02 12:13:31 -07001628 AdapterView.OnItemSelectedListener mSelectPhoneIndexHandler =
1629 new AdapterView.OnItemSelectedListener() {
1630
1631 public void onItemSelected(AdapterView parent, View v, int pos, long id) {
1632 if (pos >= 0 && pos <= mPhoneIndexLabels.length - 1) {
1633 // the array position is equal to the phone index
1634 int phoneIndex = pos;
1635 Phone[] phones = PhoneFactory.getPhones();
1636 if (phones == null || phones.length <= phoneIndex) {
1637 log("phoneIndex " + phoneIndex + " is invalid");
1638 return;
1639 }
1640 log("switching to phone " + phoneIndex);
1641 // getSubId says it takes a slotIndex, but it actually takes a phone index
1642 int[] subIds = SubscriptionManager.getSubId(phoneIndex);
1643 if (subIds == null || subIds.length < 1) {
1644 log("no subscription found for phoneIndex " + phoneIndex);
1645 return;
1646 }
1647 mSelectedPhoneIndex = phoneIndex;
1648
1649 updatePhoneIndex(phoneIndex, subIds[0]);
1650 }
1651 }
1652
1653 public void onNothingSelected(AdapterView parent) {
1654 }
1655 };
1656
Nathan Harold2b77d742016-03-19 13:22:10 -07001657 AdapterView.OnItemSelectedListener mCellInfoRefreshRateHandler =
1658 new AdapterView.OnItemSelectedListener() {
Wink Savillebf471282013-04-05 15:04:05 -07001659
Nathan Harold2b77d742016-03-19 13:22:10 -07001660 public void onItemSelected(AdapterView parent, View v, int pos, long id) {
1661 mCellInfoRefreshRateIndex = pos;
Sooraj Sasindran5cce06b2016-08-18 15:49:49 -07001662 mTelephonyManager.setCellInfoListRate(mCellInfoRefreshRates[pos]);
Nathan Harold2b77d742016-03-19 13:22:10 -07001663 updateAllCellInfo();
1664 }
1665
1666 public void onNothingSelected(AdapterView parent) {
1667 }
1668 };
1669
Naina Nallurid1b57f62019-01-08 15:19:58 -08001670 boolean isCbrsSupported() {
1671 return getResources().getBoolean(
1672 com.android.internal.R.bool.config_cbrs_supported);
1673 }
1674
1675 void updateCbrsDataState(boolean state) {
1676 Log.d(TAG, "setCbrsDataSwitchState() state:" + ((state)? "on":"off"));
1677 if (mTelephonyManager != null) {
1678 QueuedWork.queue(new Runnable() {
1679 public void run() {
1680 mTelephonyManager.setOpportunisticNetworkState(state);
1681 cbrsDataSwitch.setChecked(getCbrsDataState());
1682 }
1683 }, false);
1684 }
1685 }
1686
1687 boolean getCbrsDataState() {
1688 boolean state = false;
1689 if (mTelephonyManager != null) {
1690 state = mTelephonyManager.isOpportunisticNetworkEnabled();
1691 }
1692 Log.d(TAG, "getCbrsDataState() state:" +((state)? "on":"off"));
1693 return state;
1694 }
1695
1696 OnCheckedChangeListener mCbrsDataSwitchChangeListener = new OnCheckedChangeListener() {
1697 @Override
1698 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1699 updateCbrsDataState(isChecked);
1700 }
1701 };
1702
Pengquan Meng7f602c72019-01-28 19:12:18 -08001703 private void showDsdsChangeDialog() {
1704 final AlertDialog confirmDialog = new Builder(RadioInfo.this)
1705 .setTitle(R.string.dsds_dialog_title)
1706 .setMessage(R.string.dsds_dialog_message)
1707 .setPositiveButton(R.string.dsds_dialog_confirm, mOnDsdsDialogConfirmedListener)
1708 .setNegativeButton(R.string.dsds_dialog_cancel, mOnDsdsDialogConfirmedListener)
1709 .create();
1710 confirmDialog.show();
1711 }
Naina Nallurid1b57f62019-01-08 15:19:58 -08001712
Pengquan Meng7f602c72019-01-28 19:12:18 -08001713 private static boolean isDsdsSupported() {
Michele3dafea22019-03-19 15:53:45 -07001714 return (TelephonyManager.getDefault().isMultiSimSupported()
1715 == TelephonyManager.MULTISIM_ALLOWED);
Pengquan Meng7f602c72019-01-28 19:12:18 -08001716 }
1717
1718 private static boolean isDsdsEnabled() {
1719 return TelephonyManager.getDefault().getPhoneCount() > 1;
1720 }
1721
1722 private void performDsdsSwitch() {
1723 mTelephonyManager.switchMultiSimConfig(dsdsSwitch.isChecked() ? 2 : 1);
1724 }
1725
1726 DialogInterface.OnClickListener mOnDsdsDialogConfirmedListener =
1727 new DialogInterface.OnClickListener() {
1728 @Override
1729 public void onClick(DialogInterface dialog, int which) {
1730 if (which == DialogInterface.BUTTON_POSITIVE) {
1731 dsdsSwitch.toggle();
1732 performDsdsSwitch();
1733 }
1734 }
1735 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001736}