blob: d0c68116a21cc8108018b2ba133a17920c8cdc8c [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;
Pengquan Menga40d2742019-04-30 19:32:58 -070043import android.os.SystemProperties;
Nathan Harolddaea8be2018-06-05 14:02:35 -070044import android.provider.Settings;
Meng Wang586741c2017-04-26 15:02:51 -070045import android.telephony.CarrierConfigManager;
Fan Zhangc7162cd2018-06-18 15:21:41 -070046import android.telephony.CellIdentityCdma;
47import android.telephony.CellIdentityGsm;
48import android.telephony.CellIdentityLte;
49import android.telephony.CellIdentityWcdma;
Wink Saville79bff2a2012-06-01 14:37:21 -070050import android.telephony.CellInfo;
Nathan Haroldcea413a2015-11-23 15:48:10 -080051import android.telephony.CellInfoCdma;
52import android.telephony.CellInfoGsm;
53import android.telephony.CellInfoLte;
54import android.telephony.CellInfoWcdma;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080055import android.telephony.CellLocation;
Nathan Haroldcea413a2015-11-23 15:48:10 -080056import android.telephony.CellSignalStrengthCdma;
57import android.telephony.CellSignalStrengthGsm;
58import android.telephony.CellSignalStrengthLte;
59import android.telephony.CellSignalStrengthWcdma;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080060import android.telephony.PhoneStateListener;
Nathan Harold433ca442018-04-23 18:20:43 -070061import android.telephony.PhysicalChannelConfig;
Fan Zhangc7162cd2018-06-18 15:21:41 -070062import android.telephony.PreciseCallState;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080063import android.telephony.ServiceState;
Nathan Harold2b77d742016-03-19 13:22:10 -070064import android.telephony.SignalStrength;
Nathan Haroldcea413a2015-11-23 15:48:10 -080065import android.telephony.SubscriptionManager;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080066import android.telephony.TelephonyManager;
jsh534f5ae2009-09-24 09:19:22 -070067import android.telephony.cdma.CdmaCellLocation;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080068import android.telephony.gsm.GsmCellLocation;
Nathan Harold6e16fdf2018-04-17 17:01:32 -070069import android.text.TextUtils;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080070import android.util.Log;
71import android.view.Menu;
72import android.view.MenuItem;
73import android.view.View;
74import android.view.View.OnClickListener;
75import android.widget.AdapterView;
76import android.widget.ArrayAdapter;
77import android.widget.Button;
Nathan Harold2b77d742016-03-19 13:22:10 -070078import android.widget.CompoundButton;
79import android.widget.CompoundButton.OnCheckedChangeListener;
Jason Monk39b46742015-09-10 15:52:51 -040080import android.widget.EditText;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080081import android.widget.Spinner;
Nathan Harold2b77d742016-03-19 13:22:10 -070082import android.widget.Switch;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080083import android.widget.TextView;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080084
Fan Zhang23f8d592018-08-28 15:11:40 -070085import androidx.appcompat.app.AlertDialog;
Pengquan Meng7f602c72019-01-28 19:12:18 -080086import androidx.appcompat.app.AlertDialog.Builder;
Fan Zhang23f8d592018-08-28 15:11:40 -070087
Jason Monk39b46742015-09-10 15:52:51 -040088import com.android.ims.ImsConfig;
89import com.android.ims.ImsException;
90import com.android.ims.ImsManager;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080091import com.android.internal.telephony.Phone;
92import com.android.internal.telephony.PhoneFactory;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080093
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080094import java.io.IOException;
Jason Monk39b46742015-09-10 15:52:51 -040095import java.net.HttpURLConnection;
96import java.net.URL;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080097import java.util.List;
98
Pengquan Meng7f602c72019-01-28 19:12:18 -080099// TODO(b/123598192) consider to move this activity to telephony package.
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800100public class RadioInfo extends Activity {
Nathan Harold2b77d742016-03-19 13:22:10 -0700101 private static final String TAG = "RadioInfo";
johnwang342101a2009-09-23 16:22:34 -0700102
Nathan Harold2b77d742016-03-19 13:22:10 -0700103 private static final String[] mPreferredNetworkLabels = {
SongFerngWangdc5149e2019-08-23 18:03:27 +0800104 "GSM/WCDMA preferred",
Nathan Harold2b77d742016-03-19 13:22:10 -0700105 "GSM only",
106 "WCDMA only",
SongFerngWangdc5149e2019-08-23 18:03:27 +0800107 "GSM/WCDMA auto (PRL)",
108 "CDMA/EvDo auto (PRL)",
Nathan Harold2b77d742016-03-19 13:22:10 -0700109 "CDMA only",
110 "EvDo only",
SongFerngWangdc5149e2019-08-23 18:03:27 +0800111 "CDMA/EvDo/GSM/WCDMA (PRL)",
112 "CDMA + LTE/EvDo (PRL)",
113 "GSM/WCDMA/LTE (PRL)",
114 "LTE/CDMA/EvDo/GSM/WCDMA (PRL)",
Nathan Harold2b77d742016-03-19 13:22:10 -0700115 "LTE only",
116 "LTE/WCDMA",
SongFerngWangdc5149e2019-08-23 18:03:27 +0800117 "TDSCDMA only",
118 "TDSCDMA/WCDMA",
119 "LTE/TDSCDMA",
120 "TDSCDMA/GSM",
121 "LTE/TDSCDMA/GSM",
122 "TDSCDMA/GSM/WCDMA",
123 "LTE/TDSCDMA/WCDMA",
124 "LTE/TDSCDMA/GSM/WCDMA",
125 "TDSCDMA/CDMA/EvDo/GSM/WCDMA ",
126 "LTE/TDSCDMA/CDMA/EvDo/GSM/WCDMA",
127 "NR only",
128 "NR/LTE",
129 "NR/LTE/CDME/EvDo",
130 "NR/LTE/GSM/WCDMA",
131 "NR/LTE/CDMA/EvDo/GSM/WCDMA",
132 "NR/LTE/WCDMA",
133 "NR/LTE/TDSCDMA",
134 "NR/LTE/TDSCDMA/GSM",
135 "NR/LTE/TDSCDMA/WCDMA",
136 "NR/LTE/TDSCDMA/GSM/WCDMA",
137 "NR/LTE/TDSCDMA/CDMA/EvDo/GSM/WCDMA",
Nathan Harold2b77d742016-03-19 13:22:10 -0700138 "Unknown"
139 };
140
Jordan Liub69e8f22019-04-02 12:13:31 -0700141 private static String[] mPhoneIndexLabels;
Nathan Harold2b77d742016-03-19 13:22:10 -0700142
143 private static final int CELL_INFO_LIST_RATE_DISABLED = Integer.MAX_VALUE;
144 private static final int CELL_INFO_LIST_RATE_MAX = 0;
145
Pengquan Menga40d2742019-04-30 19:32:58 -0700146 private static final String DSDS_MODE_PROPERTY = "ro.boot.hardware.dsds";
147
148 /**
149 * A value indicates the device is always on dsds mode.
150 * @see {@link #DSDS_MODE_PROPERTY}
151 */
152 private static final int ALWAYS_ON_DSDS_MODE = 1;
Nathan Harold12e1f552016-06-17 13:55:38 -0700153
154 private static final int IMS_VOLTE_PROVISIONED_CONFIG_ID =
155 ImsConfig.ConfigConstants.VLT_SETTING_ENABLED;
156
157 private static final int IMS_VT_PROVISIONED_CONFIG_ID =
158 ImsConfig.ConfigConstants.LVC_SETTING_ENABLED;
159
160 private static final int IMS_WFC_PROVISIONED_CONFIG_ID =
161 ImsConfig.ConfigConstants.VOICE_OVER_WIFI_SETTING_ENABLED;
162
Meng Wang586741c2017-04-26 15:02:51 -0700163 private static final int EAB_PROVISIONED_CONFIG_ID =
164 ImsConfig.ConfigConstants.EAB_SETTING_ENABLED;
165
Nathan Harold2b77d742016-03-19 13:22:10 -0700166 //Values in must match mCellInfoRefreshRates
167 private static final String[] mCellInfoRefreshRateLabels = {
168 "Disabled",
169 "Immediate",
170 "Min 5s",
171 "Min 10s",
172 "Min 60s"
173 };
174
175 //Values in seconds, must match mCellInfoRefreshRateLabels
176 private static final int mCellInfoRefreshRates[] = {
177 CELL_INFO_LIST_RATE_DISABLED,
178 CELL_INFO_LIST_RATE_MAX,
179 5000,
180 10000,
181 60000
182 };
183
Jordan Liub69e8f22019-04-02 12:13:31 -0700184 private static void log(String s) {
Nathan Harold2b77d742016-03-19 13:22:10 -0700185 Log.d(TAG, s);
186 }
187
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800188 private static final int EVENT_CFI_CHANGED = 302;
189
190 private static final int EVENT_QUERY_PREFERRED_TYPE_DONE = 1000;
191 private static final int EVENT_SET_PREFERRED_TYPE_DONE = 1001;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800192 private static final int EVENT_QUERY_SMSC_DONE = 1005;
193 private static final int EVENT_UPDATE_SMSC_DONE = 1006;
194
Jordan Liub69e8f22019-04-02 12:13:31 -0700195 private static final int MENU_ITEM_SELECT_BAND = 0;
196 private static final int MENU_ITEM_VIEW_ADN = 1;
197 private static final int MENU_ITEM_VIEW_FDN = 2;
198 private static final int MENU_ITEM_VIEW_SDN = 3;
199 private static final int MENU_ITEM_GET_IMS_STATUS = 4;
200 private static final int MENU_ITEM_TOGGLE_DATA = 5;
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800201
Wink Savillec3886682009-04-02 11:00:56 -0700202 private TextView mDeviceId; //DeviceId is the IMEI in GSM and the MEID in CDMA
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800203 private TextView number;
Jordan Liub69e8f22019-04-02 12:13:31 -0700204 private TextView mSubscriptionId;
205 private TextView mDds;
Meng Wang9053f172017-06-23 16:02:14 -0700206 private TextView mSubscriberId;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800207 private TextView callState;
208 private TextView operatorName;
209 private TextView roamingState;
210 private TextView gsmState;
211 private TextView gprsState;
Nathan Harold2b77d742016-03-19 13:22:10 -0700212 private TextView voiceNetwork;
213 private TextView dataNetwork;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800214 private TextView dBm;
215 private TextView mMwi;
216 private TextView mCfi;
217 private TextView mLocation;
Wink Saville79bff2a2012-06-01 14:37:21 -0700218 private TextView mCellInfo;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800219 private TextView sent;
220 private TextView received;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800221 private TextView mPingHostnameV4;
222 private TextView mPingHostnameV6;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800223 private TextView mHttpClientTest;
Nathan Harold433ca442018-04-23 18:20:43 -0700224 private TextView mPhyChanConfig;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800225 private TextView dnsCheckState;
Nathan Haroldf10ea322018-04-24 13:31:07 -0700226 private TextView mDownlinkKbps;
227 private TextView mUplinkKbps;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800228 private EditText smsc;
Nathan Harold2b77d742016-03-19 13:22:10 -0700229 private Switch radioPowerOnSwitch;
230 private Button cellInfoRefreshRateButton;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800231 private Button dnsCheckToggleButton;
232 private Button pingTestButton;
233 private Button updateSmscButton;
234 private Button refreshSmscButton;
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800235 private Button oemInfoButton;
Youhan Wangfd781e92016-12-16 15:53:16 -0800236 private Button carrierProvisioningButton;
237 private Button triggercarrierProvisioningButton;
Nathan Harold12e1f552016-06-17 13:55:38 -0700238 private Switch imsVolteProvisionedSwitch;
239 private Switch imsVtProvisionedSwitch;
240 private Switch imsWfcProvisionedSwitch;
Meng Wang586741c2017-04-26 15:02:51 -0700241 private Switch eabProvisionedSwitch;
Naina Nallurid1b57f62019-01-08 15:19:58 -0800242 private Switch cbrsDataSwitch;
Pengquan Meng7f602c72019-01-28 19:12:18 -0800243 private Switch dsdsSwitch;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800244 private Spinner preferredNetworkType;
Jordan Liub69e8f22019-04-02 12:13:31 -0700245 private Spinner mSelectPhoneIndex;
Nathan Harold2b77d742016-03-19 13:22:10 -0700246 private Spinner cellInfoRefreshRateSpinner;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800247
Nathan Haroldf10ea322018-04-24 13:31:07 -0700248 private ConnectivityManager mConnectivityManager;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800249 private TelephonyManager mTelephonyManager;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800250 private ImsManager mImsManager = null;
Jordan Liu84deb0a2019-04-05 14:39:41 -0700251 private Phone mPhone = null;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800252
Nathan Haroldcea413a2015-11-23 15:48:10 -0800253 private String mPingHostnameResultV4;
254 private String mPingHostnameResultV6;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800255 private String mHttpClientTestResult;
256 private boolean mMwiValue = false;
257 private boolean mCfiValue = false;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800258
259 private List<CellInfo> mCellInfoResult = null;
260 private CellLocation mCellLocationResult = null;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800261
262 private int mPreferredNetworkTypeResult;
Nathan Harold2b77d742016-03-19 13:22:10 -0700263 private int mCellInfoRefreshRateIndex;
Jordan Liub69e8f22019-04-02 12:13:31 -0700264 private int mSelectedPhoneIndex;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800265
Nathan Haroldf10ea322018-04-24 13:31:07 -0700266 private final NetworkRequest mDefaultNetworkRequest = new NetworkRequest.Builder()
267 .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
268 .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
269 .build();
270
271 private final NetworkCallback mNetworkCallback = new NetworkCallback() {
272 public void onCapabilitiesChanged(Network n, NetworkCapabilities nc) {
273 int dlbw = nc.getLinkDownstreamBandwidthKbps();
274 int ulbw = nc.getLinkUpstreamBandwidthKbps();
275 updateBandwidths(dlbw, ulbw);
276 }
277 };
278
Jordan Liu84deb0a2019-04-05 14:39:41 -0700279 // not final because we need to recreate this object to register on a new subId (b/117555407)
280 private PhoneStateListener mPhoneStateListener = new RadioInfoPhoneStateListener();
281 private class RadioInfoPhoneStateListener extends PhoneStateListener {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800282 @Override
283 public void onDataConnectionStateChanged(int state) {
284 updateDataState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800285 updateNetworkType();
286 }
287
288 @Override
289 public void onDataActivity(int direction) {
290 updateDataStats2();
291 }
292
293 @Override
Nathan Harold2b77d742016-03-19 13:22:10 -0700294 public void onCallStateChanged(int state, String incomingNumber) {
295 updateNetworkType();
296 updatePhoneState(state);
297 }
298
299 @Override
300 public void onPreciseCallStateChanged(PreciseCallState preciseState) {
301 updateNetworkType();
302 }
303
304 @Override
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800305 public void onCellLocationChanged(CellLocation location) {
306 updateLocation(location);
307 }
308
309 @Override
310 public void onMessageWaitingIndicatorChanged(boolean mwi) {
311 mMwiValue = mwi;
312 updateMessageWaiting();
313 }
314
315 @Override
316 public void onCallForwardingIndicatorChanged(boolean cfi) {
317 mCfiValue = cfi;
318 updateCallRedirect();
319 }
Wink Saville79bff2a2012-06-01 14:37:21 -0700320
321 @Override
322 public void onCellInfoChanged(List<CellInfo> arrayCi) {
Wink Savillebf471282013-04-05 15:04:05 -0700323 log("onCellInfoChanged: arrayCi=" + arrayCi);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800324 mCellInfoResult = arrayCi;
325 updateCellInfo(mCellInfoResult);
Wink Saville79bff2a2012-06-01 14:37:21 -0700326 }
Wink Saville4f0d8812014-04-15 22:05:24 -0700327
328 @Override
Nathan Harold2b77d742016-03-19 13:22:10 -0700329 public void onSignalStrengthsChanged(SignalStrength signalStrength) {
330 log("onSignalStrengthChanged: SignalStrength=" +signalStrength);
331 updateSignalStrength(signalStrength);
332 }
333
334 @Override
335 public void onServiceStateChanged(ServiceState serviceState) {
336 log("onServiceStateChanged: ServiceState=" + serviceState);
337 updateServiceState(serviceState);
338 updateRadioPowerState();
339 updateNetworkType();
Nathan Harold12e1f552016-06-17 13:55:38 -0700340 updateImsProvisionedState();
Nathan Harold2b77d742016-03-19 13:22:10 -0700341 }
Nathan Harold433ca442018-04-23 18:20:43 -0700342
343 @Override
344 public void onPhysicalChannelConfigurationChanged(
345 List<PhysicalChannelConfig> configs) {
346 updatePhysicalChannelConfiguration(configs);
347 }
348
Jordan Liu84deb0a2019-04-05 14:39:41 -0700349 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800350
Nathan Harold433ca442018-04-23 18:20:43 -0700351 private void updatePhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
352 StringBuilder sb = new StringBuilder();
353 String div = "";
354 sb.append("{");
355 if (configs != null) {
356 for(PhysicalChannelConfig c : configs) {
357 sb.append(div).append(c);
358 div = ",";
359 }
360 }
361 sb.append("}");
362 mPhyChanConfig.setText(sb.toString());
363 }
364
Nathan Haroldcea413a2015-11-23 15:48:10 -0800365 private void updatePreferredNetworkType(int type) {
366 if (type >= mPreferredNetworkLabels.length || type < 0) {
367 log("EVENT_QUERY_PREFERRED_TYPE_DONE: unknown " +
368 "type=" + type);
369 type = mPreferredNetworkLabels.length - 1; //set to Unknown
370 }
371 mPreferredNetworkTypeResult = type;
372
373 preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true);
374 }
375
Jordan Liub69e8f22019-04-02 12:13:31 -0700376 private void updatePhoneIndex(int phoneIndex, int subId) {
377 // unregister listeners on the old subId
Jordan Liu84deb0a2019-04-05 14:39:41 -0700378 unregisterPhoneStateListener();
Jordan Liub69e8f22019-04-02 12:13:31 -0700379 mTelephonyManager.setCellInfoListRate(CELL_INFO_LIST_RATE_DISABLED);
380
381 // update the subId
382 mTelephonyManager = mTelephonyManager.createForSubscriptionId(subId);
Jordan Liub69e8f22019-04-02 12:13:31 -0700383
384 // update the phoneId
Jordan Liu84deb0a2019-04-05 14:39:41 -0700385 mImsManager = ImsManager.getInstance(getApplicationContext(), phoneIndex);
386 mPhone = PhoneFactory.getPhone(phoneIndex);
Jordan Liub69e8f22019-04-02 12:13:31 -0700387
388 updateAllFields();
389 }
390
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800391 private Handler mHandler = new Handler() {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800392 @Override
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800393 public void handleMessage(Message msg) {
394 AsyncResult ar;
395 switch (msg.what) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800396 case EVENT_QUERY_PREFERRED_TYPE_DONE:
397 ar= (AsyncResult) msg.obj;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800398 if (ar.exception == null && ar.result != null) {
399 updatePreferredNetworkType(((int[])ar.result)[0]);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800400 } else {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800401 //In case of an exception, we will set this to unknown
402 updatePreferredNetworkType(mPreferredNetworkLabels.length-1);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800403 }
404 break;
405 case EVENT_SET_PREFERRED_TYPE_DONE:
406 ar= (AsyncResult) msg.obj;
407 if (ar.exception != null) {
Nathan Harolded38afa2016-04-13 00:29:30 -0700408 log("Set preferred network type failed.");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800409 }
410 break;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800411 case EVENT_QUERY_SMSC_DONE:
412 ar= (AsyncResult) msg.obj;
413 if (ar.exception != null) {
414 smsc.setText("refresh error");
415 } else {
jsh21dd4072009-05-12 11:26:55 -0700416 smsc.setText((String)ar.result);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800417 }
418 break;
419 case EVENT_UPDATE_SMSC_DONE:
420 updateSmscButton.setEnabled(true);
421 ar= (AsyncResult) msg.obj;
422 if (ar.exception != null) {
423 smsc.setText("update error");
424 }
425 break;
426 default:
Nathan Haroldcea413a2015-11-23 15:48:10 -0800427 super.handleMessage(msg);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800428 break;
429
430 }
431 }
432 };
433
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800434 @Override
435 public void onCreate(Bundle icicle) {
436 super.onCreate(icicle);
fionaxub54cb2d2016-09-22 15:01:05 -0700437 if (!android.os.Process.myUserHandle().isSystem()) {
438 Log.e(TAG, "Not run from system user, don't do anything.");
439 finish();
440 return;
441 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800442
443 setContentView(R.layout.radio_info);
444
Nathan Haroldcea413a2015-11-23 15:48:10 -0800445 log("Started onCreate");
446
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800447 mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
Nathan Haroldf10ea322018-04-24 13:31:07 -0700448 mConnectivityManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
Jordan Liu84deb0a2019-04-05 14:39:41 -0700449 mPhone = PhoneFactory.getDefaultPhone();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800450
Nathan Haroldcea413a2015-11-23 15:48:10 -0800451 mImsManager = ImsManager.getInstance(getApplicationContext(),
452 SubscriptionManager.getDefaultVoicePhoneId());
453
Jordan Liub69e8f22019-04-02 12:13:31 -0700454 mPhoneIndexLabels = getPhoneIndexLabels(mTelephonyManager);
455
Meng Wang9053f172017-06-23 16:02:14 -0700456 mDeviceId = (TextView) findViewById(R.id.imei);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800457 number = (TextView) findViewById(R.id.number);
Jordan Liub69e8f22019-04-02 12:13:31 -0700458 mSubscriptionId = (TextView) findViewById(R.id.subid);
459 mDds = (TextView) findViewById(R.id.dds);
Meng Wang9053f172017-06-23 16:02:14 -0700460 mSubscriberId = (TextView) findViewById(R.id.imsi);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800461 callState = (TextView) findViewById(R.id.call);
462 operatorName = (TextView) findViewById(R.id.operator);
463 roamingState = (TextView) findViewById(R.id.roaming);
464 gsmState = (TextView) findViewById(R.id.gsm);
465 gprsState = (TextView) findViewById(R.id.gprs);
Nathan Harold2b77d742016-03-19 13:22:10 -0700466 voiceNetwork = (TextView) findViewById(R.id.voice_network);
467 dataNetwork = (TextView) findViewById(R.id.data_network);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800468 dBm = (TextView) findViewById(R.id.dbm);
469 mMwi = (TextView) findViewById(R.id.mwi);
470 mCfi = (TextView) findViewById(R.id.cfi);
471 mLocation = (TextView) findViewById(R.id.location);
Wink Saville79bff2a2012-06-01 14:37:21 -0700472 mCellInfo = (TextView) findViewById(R.id.cellinfo);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800473 mCellInfo.setTypeface(Typeface.MONOSPACE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800474
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800475 sent = (TextView) findViewById(R.id.sent);
476 received = (TextView) findViewById(R.id.received);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800477 smsc = (EditText) findViewById(R.id.smsc);
478 dnsCheckState = (TextView) findViewById(R.id.dnsCheckState);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800479 mPingHostnameV4 = (TextView) findViewById(R.id.pingHostnameV4);
480 mPingHostnameV6 = (TextView) findViewById(R.id.pingHostnameV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800481 mHttpClientTest = (TextView) findViewById(R.id.httpClientTest);
482
Nathan Harold433ca442018-04-23 18:20:43 -0700483 mPhyChanConfig = (TextView) findViewById(R.id.phy_chan_config);
484
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800485 preferredNetworkType = (Spinner) findViewById(R.id.preferredNetworkType);
Jordan Liub69e8f22019-04-02 12:13:31 -0700486 ArrayAdapter<String> preferredNetworkTypeAdapter = new ArrayAdapter<String> (this,
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800487 android.R.layout.simple_spinner_item, mPreferredNetworkLabels);
Jordan Liub69e8f22019-04-02 12:13:31 -0700488 preferredNetworkTypeAdapter
489 .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
490 preferredNetworkType.setAdapter(preferredNetworkTypeAdapter);
491
492 mSelectPhoneIndex = (Spinner) findViewById(R.id.phoneIndex);
493 ArrayAdapter<String> phoneIndexAdapter = new ArrayAdapter<String> (this,
494 android.R.layout.simple_spinner_item, mPhoneIndexLabels);
495 phoneIndexAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
496 mSelectPhoneIndex.setAdapter(phoneIndexAdapter);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800497
Nathan Harold2b77d742016-03-19 13:22:10 -0700498 cellInfoRefreshRateSpinner = (Spinner) findViewById(R.id.cell_info_rate_select);
499 ArrayAdapter<String> cellInfoAdapter = new ArrayAdapter<String>(this,
500 android.R.layout.simple_spinner_item, mCellInfoRefreshRateLabels);
501 cellInfoAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
502 cellInfoRefreshRateSpinner.setAdapter(cellInfoAdapter);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800503
Nathan Harold12e1f552016-06-17 13:55:38 -0700504 imsVolteProvisionedSwitch = (Switch) findViewById(R.id.volte_provisioned_switch);
505 imsVtProvisionedSwitch = (Switch) findViewById(R.id.vt_provisioned_switch);
506 imsWfcProvisionedSwitch = (Switch) findViewById(R.id.wfc_provisioned_switch);
Meng Wang69439b52017-05-01 08:31:14 -0700507 eabProvisionedSwitch = (Switch) findViewById(R.id.eab_provisioned_switch);
Wink Savillebf471282013-04-05 15:04:05 -0700508
Jordan Liu84deb0a2019-04-05 14:39:41 -0700509 if (!ImsManager.isImsSupportedOnDevice(mPhone.getContext())) {
Brad Ebinger5dfe7f82019-03-11 17:33:53 -0700510 imsVolteProvisionedSwitch.setVisibility(View.GONE);
511 imsVtProvisionedSwitch.setVisibility(View.GONE);
512 imsWfcProvisionedSwitch.setVisibility(View.GONE);
513 eabProvisionedSwitch.setVisibility(View.GONE);
514 }
515
Naina Nallurid1b57f62019-01-08 15:19:58 -0800516 cbrsDataSwitch = (Switch) findViewById(R.id.cbrs_data_switch);
517 cbrsDataSwitch.setVisibility(isCbrsSupported() ? View.VISIBLE : View.GONE);
518
Pengquan Meng7f602c72019-01-28 19:12:18 -0800519 dsdsSwitch = findViewById(R.id.dsds_switch);
Pengquan Menga40d2742019-04-30 19:32:58 -0700520 if (isDsdsSupported() && !dsdsModeOnly()) {
Pengquan Meng7f602c72019-01-28 19:12:18 -0800521 dsdsSwitch.setVisibility(View.VISIBLE);
522 dsdsSwitch.setOnClickListener(v -> {
chen xu4f379d22019-04-03 10:31:19 -0700523 if (mTelephonyManager.doesSwitchMultiSimConfigTriggerReboot()) {
Pengquan Meng7f602c72019-01-28 19:12:18 -0800524 // Undo the click action until user clicks the confirm dialog.
525 dsdsSwitch.toggle();
526 showDsdsChangeDialog();
527 } else {
528 performDsdsSwitch();
529 }
530 });
531 dsdsSwitch.setChecked(isDsdsEnabled());
532 } else {
533 dsdsSwitch.setVisibility(View.GONE);
534 }
535
Nathan Harold2b77d742016-03-19 13:22:10 -0700536 radioPowerOnSwitch = (Switch) findViewById(R.id.radio_power);
Wink Saville426fc662011-09-25 14:39:02 -0700537
Nathan Haroldf10ea322018-04-24 13:31:07 -0700538 mDownlinkKbps = (TextView) findViewById(R.id.dl_kbps);
539 mUplinkKbps = (TextView) findViewById(R.id.ul_kbps);
540 updateBandwidths(0, 0);
541
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800542 pingTestButton = (Button) findViewById(R.id.ping_test);
543 pingTestButton.setOnClickListener(mPingButtonHandler);
544 updateSmscButton = (Button) findViewById(R.id.update_smsc);
545 updateSmscButton.setOnClickListener(mUpdateSmscButtonHandler);
546 refreshSmscButton = (Button) findViewById(R.id.refresh_smsc);
547 refreshSmscButton.setOnClickListener(mRefreshSmscButtonHandler);
548 dnsCheckToggleButton = (Button) findViewById(R.id.dns_check_toggle);
549 dnsCheckToggleButton.setOnClickListener(mDnsCheckButtonHandler);
Youhan Wangfd781e92016-12-16 15:53:16 -0800550 carrierProvisioningButton = (Button) findViewById(R.id.carrier_provisioning);
551 carrierProvisioningButton.setOnClickListener(mCarrierProvisioningButtonHandler);
552 triggercarrierProvisioningButton = (Button) findViewById(R.id.trigger_carrier_provisioning);
553 triggercarrierProvisioningButton.setOnClickListener(
554 mTriggerCarrierProvisioningButtonHandler);
johnwang342101a2009-09-23 16:22:34 -0700555
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800556 oemInfoButton = (Button) findViewById(R.id.oem_info);
557 oemInfoButton.setOnClickListener(mOemInfoButtonHandler);
558 PackageManager pm = getPackageManager();
559 Intent oemInfoIntent = new Intent("com.android.settings.OEM_RADIO_INFO");
560 List<ResolveInfo> oemInfoIntentList = pm.queryIntentActivities(oemInfoIntent, 0);
561 if (oemInfoIntentList.size() == 0) {
562 oemInfoButton.setEnabled(false);
563 }
564
Nathan Harolded38afa2016-04-13 00:29:30 -0700565 mCellInfoRefreshRateIndex = 0; //disabled
Nathan Haroldcea413a2015-11-23 15:48:10 -0800566 mPreferredNetworkTypeResult = mPreferredNetworkLabels.length - 1; //Unknown
Jordan Liub69e8f22019-04-02 12:13:31 -0700567 mSelectedPhoneIndex = 0; //phone 0
Nathan Haroldcea413a2015-11-23 15:48:10 -0800568
569 //FIXME: Replace with TelephonyManager call
Jordan Liu84deb0a2019-04-05 14:39:41 -0700570 mPhone.getPreferredNetworkType(
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800571 mHandler.obtainMessage(EVENT_QUERY_PREFERRED_TYPE_DONE));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800572
Nathan Haroldcea413a2015-11-23 15:48:10 -0800573 restoreFromBundle(icicle);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800574 }
575
576 @Override
577 protected void onResume() {
578 super.onResume();
579
Nathan Haroldcea413a2015-11-23 15:48:10 -0800580 log("Started onResume");
581
Jordan Liub69e8f22019-04-02 12:13:31 -0700582 updateAllFields();
583 }
584
585 private void updateAllFields() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800586 updateMessageWaiting();
587 updateCallRedirect();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800588 updateDataState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800589 updateDataStats2();
Nathan Harold2b77d742016-03-19 13:22:10 -0700590 updateRadioPowerState();
Nathan Harold12e1f552016-06-17 13:55:38 -0700591 updateImsProvisionedState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800592 updateProperties();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800593 updateDnsCheckState();
Nathan Harold2b77d742016-03-19 13:22:10 -0700594 updateNetworkType();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800595
Nathan Haroldcea413a2015-11-23 15:48:10 -0800596 updateLocation(mCellLocationResult);
597 updateCellInfo(mCellInfoResult);
Jordan Liub69e8f22019-04-02 12:13:31 -0700598 updateSubscriptionIds();
Nathan Haroldcea413a2015-11-23 15:48:10 -0800599
600 mPingHostnameV4.setText(mPingHostnameResultV4);
601 mPingHostnameV6.setText(mPingHostnameResultV6);
602 mHttpClientTest.setText(mHttpClientTestResult);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800603
Nathan Harold2b77d742016-03-19 13:22:10 -0700604 cellInfoRefreshRateSpinner.setOnItemSelectedListener(mCellInfoRefreshRateHandler);
Nathan Harolded38afa2016-04-13 00:29:30 -0700605 //set selection after registering listener to force update
606 cellInfoRefreshRateSpinner.setSelection(mCellInfoRefreshRateIndex);
607
608 //set selection before registering to prevent update
609 preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true);
Nathan Harold2b77d742016-03-19 13:22:10 -0700610 preferredNetworkType.setOnItemSelectedListener(mPreferredNetworkHandler);
Nathan Harolded38afa2016-04-13 00:29:30 -0700611
Jordan Liub69e8f22019-04-02 12:13:31 -0700612 // set phone index
613 mSelectPhoneIndex.setSelection(mSelectedPhoneIndex, true);
614 mSelectPhoneIndex.setOnItemSelectedListener(mSelectPhoneIndexHandler);
615
Nathan Harold2b77d742016-03-19 13:22:10 -0700616 radioPowerOnSwitch.setOnCheckedChangeListener(mRadioPowerOnChangeListener);
Nathan Harold12e1f552016-06-17 13:55:38 -0700617 imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
618 imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
619 imsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
Meng Wang586741c2017-04-26 15:02:51 -0700620 eabProvisionedSwitch.setOnCheckedChangeListener(mEabCheckedChangeListener);
Nathan Harold2b77d742016-03-19 13:22:10 -0700621
Naina Nallurid1b57f62019-01-08 15:19:58 -0800622 if (isCbrsSupported()) {
623 cbrsDataSwitch.setChecked(getCbrsDataState());
624 cbrsDataSwitch.setOnCheckedChangeListener(mCbrsDataSwitchChangeListener);
625 }
626
Jordan Liu84deb0a2019-04-05 14:39:41 -0700627 unregisterPhoneStateListener();
Jordan Liub69e8f22019-04-02 12:13:31 -0700628 registerPhoneStateListener();
Nathan Harolded38afa2016-04-13 00:29:30 -0700629
Nathan Haroldf10ea322018-04-24 13:31:07 -0700630 mConnectivityManager.registerNetworkCallback(
631 mDefaultNetworkRequest, mNetworkCallback, mHandler);
632
Nathan Harolded38afa2016-04-13 00:29:30 -0700633 smsc.clearFocus();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800634 }
635
636 @Override
Nathan Haroldcea413a2015-11-23 15:48:10 -0800637 protected void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800638 super.onPause();
639
Wink Savillebf471282013-04-05 15:04:05 -0700640 log("onPause: unregister phone & data intents");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800641
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800642 mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
Sooraj Sasindran5cce06b2016-08-18 15:49:49 -0700643 mTelephonyManager.setCellInfoListRate(CELL_INFO_LIST_RATE_DISABLED);
Nathan Haroldf10ea322018-04-24 13:31:07 -0700644 mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
645
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800646 }
647
Nathan Haroldcea413a2015-11-23 15:48:10 -0800648 private void restoreFromBundle(Bundle b) {
Nathan Harolde272c202016-10-27 13:45:00 -0700649 if(b == null) {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800650 return;
651 }
652
653 mPingHostnameResultV4 = b.getString("mPingHostnameResultV4","");
654 mPingHostnameResultV6 = b.getString("mPingHostnameResultV6","");
655 mHttpClientTestResult = b.getString("mHttpClientTestResult","");
656
657 mPingHostnameV4.setText(mPingHostnameResultV4);
658 mPingHostnameV6.setText(mPingHostnameResultV6);
659 mHttpClientTest.setText(mHttpClientTestResult);
660
Nathan Harold2b77d742016-03-19 13:22:10 -0700661 mPreferredNetworkTypeResult = b.getInt("mPreferredNetworkTypeResult",
662 mPreferredNetworkLabels.length - 1);
663
Jordan Liub69e8f22019-04-02 12:13:31 -0700664 mSelectedPhoneIndex = b.getInt("mSelectedPhoneIndex", 0);
665
Nathan Harold2b77d742016-03-19 13:22:10 -0700666 mCellInfoRefreshRateIndex = b.getInt("mCellInfoRefreshRateIndex", 0);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800667 }
668
669 @Override
670 protected void onSaveInstanceState(Bundle outState) {
671 outState.putString("mPingHostnameResultV4", mPingHostnameResultV4);
672 outState.putString("mPingHostnameResultV6", mPingHostnameResultV6);
673 outState.putString("mHttpClientTestResult", mHttpClientTestResult);
Nathan Harold2b77d742016-03-19 13:22:10 -0700674
Nathan Haroldcea413a2015-11-23 15:48:10 -0800675 outState.putInt("mPreferredNetworkTypeResult", mPreferredNetworkTypeResult);
Jordan Liub69e8f22019-04-02 12:13:31 -0700676 outState.putInt("mSelectedPhoneIndex", mSelectedPhoneIndex);
Nathan Harold2b77d742016-03-19 13:22:10 -0700677 outState.putInt("mCellInfoRefreshRateIndex", mCellInfoRefreshRateIndex);
678
Nathan Haroldcea413a2015-11-23 15:48:10 -0800679 }
680
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800681 @Override
682 public boolean onCreateOptionsMenu(Menu menu) {
Wink Savillec3886682009-04-02 11:00:56 -0700683 menu.add(0, MENU_ITEM_SELECT_BAND, 0, R.string.radio_info_band_mode_label)
684 .setOnMenuItemClickListener(mSelectBandCallback)
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800685 .setAlphabeticShortcut('b');
686 menu.add(1, MENU_ITEM_VIEW_ADN, 0,
687 R.string.radioInfo_menu_viewADN).setOnMenuItemClickListener(mViewADNCallback);
688 menu.add(1, MENU_ITEM_VIEW_FDN, 0,
689 R.string.radioInfo_menu_viewFDN).setOnMenuItemClickListener(mViewFDNCallback);
690 menu.add(1, MENU_ITEM_VIEW_SDN, 0,
691 R.string.radioInfo_menu_viewSDN).setOnMenuItemClickListener(mViewSDNCallback);
Jordan Liu84deb0a2019-04-05 14:39:41 -0700692 if (ImsManager.isImsSupportedOnDevice(mPhone.getContext())) {
Brad Ebinger5dfe7f82019-03-11 17:33:53 -0700693 menu.add(1, MENU_ITEM_GET_IMS_STATUS,
694 0, R.string.radioInfo_menu_getIMS).setOnMenuItemClickListener(mGetImsStatus);
695 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800696 menu.add(1, MENU_ITEM_TOGGLE_DATA,
Nathan Harold2b77d742016-03-19 13:22:10 -0700697 0, R.string.radio_info_data_connection_disable).setOnMenuItemClickListener(mToggleData);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800698 return true;
699 }
700
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800701 @Override
Wink Savillec3886682009-04-02 11:00:56 -0700702 public boolean onPrepareOptionsMenu(Menu menu) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800703 // Get the TOGGLE DATA menu item in the right state.
704 MenuItem item = menu.findItem(MENU_ITEM_TOGGLE_DATA);
705 int state = mTelephonyManager.getDataState();
706 boolean visible = true;
707
708 switch (state) {
709 case TelephonyManager.DATA_CONNECTED:
710 case TelephonyManager.DATA_SUSPENDED:
Nathan Harold2b77d742016-03-19 13:22:10 -0700711 item.setTitle(R.string.radio_info_data_connection_disable);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800712 break;
713 case TelephonyManager.DATA_DISCONNECTED:
Nathan Harold2b77d742016-03-19 13:22:10 -0700714 item.setTitle(R.string.radio_info_data_connection_enable);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800715 break;
716 default:
717 visible = false;
718 break;
719 }
720 item.setVisible(visible);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800721 return true;
722 }
723
Jordan Liub69e8f22019-04-02 12:13:31 -0700724 // returns array of string labels for each phone index. The array index is equal to the phone
725 // index.
726 private static String[] getPhoneIndexLabels(TelephonyManager tm) {
727 int phones = tm.getPhoneCount();
728 String[] labels = new String[phones];
729 for (int i = 0; i < phones; i++) {
730 labels[i] = "Phone " + i;
731 }
732 return labels;
733 }
734
Jordan Liu84deb0a2019-04-05 14:39:41 -0700735 private void unregisterPhoneStateListener() {
736 mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
737
738 // clear all fields so they are blank until the next listener event occurs
739 operatorName.setText("");
740 gprsState.setText("");
741 dataNetwork.setText("");
742 voiceNetwork.setText("");
743 sent.setText("");
744 received.setText("");
745 callState.setText("");
746 mLocation.setText("");
747 mMwiValue = false;
748 mMwi.setText("");
749 mCfiValue = false;
750 mCfi.setText("");
751 mCellInfo.setText("");
752 dBm.setText("");
753 gsmState.setText("");
754 roamingState.setText("");
755 mPhyChanConfig.setText("");
756 }
757
Jordan Liub69e8f22019-04-02 12:13:31 -0700758 // register mPhoneStateListener for relevant fields using the current TelephonyManager
759 private void registerPhoneStateListener() {
Jordan Liu84deb0a2019-04-05 14:39:41 -0700760 mPhoneStateListener = new RadioInfoPhoneStateListener();
Jordan Liub69e8f22019-04-02 12:13:31 -0700761 mTelephonyManager.listen(mPhoneStateListener,
762 PhoneStateListener.LISTEN_CALL_STATE
763 //b/27803938 - RadioInfo currently cannot read PRECISE_CALL_STATE
764 // | PhoneStateListener.LISTEN_PRECISE_CALL_STATE
765 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
766 | PhoneStateListener.LISTEN_DATA_ACTIVITY
767 | PhoneStateListener.LISTEN_CELL_LOCATION
768 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
769 | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
770 | PhoneStateListener.LISTEN_CELL_INFO
771 | PhoneStateListener.LISTEN_SERVICE_STATE
772 | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
773 | PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION);
774 }
775
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800776 private void updateDnsCheckState() {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800777 //FIXME: Replace with a TelephonyManager call
Jordan Liu84deb0a2019-04-05 14:39:41 -0700778 dnsCheckState.setText(mPhone.isDnsCheckDisabled() ?
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800779 "0.0.0.0 allowed" :"0.0.0.0 not allowed");
780 }
Wink Savillee2a14e32009-05-29 14:06:30 -0700781
Nathan Haroldf10ea322018-04-24 13:31:07 -0700782 private void updateBandwidths(int dlbw, int ulbw) {
783 dlbw = (dlbw < 0 || dlbw == Integer.MAX_VALUE) ? -1 : dlbw;
784 ulbw = (ulbw < 0 || ulbw == Integer.MAX_VALUE) ? -1 : ulbw;
785 mDownlinkKbps.setText(String.format("%-5d", dlbw));
786 mUplinkKbps.setText(String.format("%-5d", ulbw));
787 }
788
789
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800790 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -0700791 updateSignalStrength(SignalStrength signalStrength) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800792 Resources r = getResources();
793
Nathan Harold2b77d742016-03-19 13:22:10 -0700794 int signalDbm = signalStrength.getDbm();
Wink Savillee2a14e32009-05-29 14:06:30 -0700795
Nathan Harold2b77d742016-03-19 13:22:10 -0700796 int signalAsu = signalStrength.getAsuLevel();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800797
798 if (-1 == signalAsu) signalAsu = 0;
799
800 dBm.setText(String.valueOf(signalDbm) + " "
801 + r.getString(R.string.radioInfo_display_dbm) + " "
802 + String.valueOf(signalAsu) + " "
803 + r.getString(R.string.radioInfo_display_asu));
804 }
805
806 private final void updateLocation(CellLocation location) {
jsh534f5ae2009-09-24 09:19:22 -0700807 Resources r = getResources();
Wink Savillec3886682009-04-02 11:00:56 -0700808 if (location instanceof GsmCellLocation) {
809 GsmCellLocation loc = (GsmCellLocation)location;
jsh534f5ae2009-09-24 09:19:22 -0700810 int lac = loc.getLac();
811 int cid = loc.getCid();
812 mLocation.setText(r.getString(R.string.radioInfo_lac) + " = "
813 + ((lac == -1) ? "unknown" : Integer.toHexString(lac))
814 + " "
815 + r.getString(R.string.radioInfo_cid) + " = "
816 + ((cid == -1) ? "unknown" : Integer.toHexString(cid)));
817 } else if (location instanceof CdmaCellLocation) {
818 CdmaCellLocation loc = (CdmaCellLocation)location;
819 int bid = loc.getBaseStationId();
820 int sid = loc.getSystemId();
821 int nid = loc.getNetworkId();
822 int lat = loc.getBaseStationLatitude();
823 int lon = loc.getBaseStationLongitude();
824 mLocation.setText("BID = "
825 + ((bid == -1) ? "unknown" : Integer.toHexString(bid))
826 + " "
827 + "SID = "
828 + ((sid == -1) ? "unknown" : Integer.toHexString(sid))
829 + " "
830 + "NID = "
831 + ((nid == -1) ? "unknown" : Integer.toHexString(nid))
832 + "\n"
833 + "LAT = "
834 + ((lat == -1) ? "unknown" : Integer.toHexString(lat))
835 + " "
836 + "LONG = "
837 + ((lon == -1) ? "unknown" : Integer.toHexString(lon)));
838 } else {
839 mLocation.setText("unknown");
Wink Savillec3886682009-04-02 11:00:56 -0700840 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800841
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800842
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800843 }
844
Nathan Haroldcea413a2015-11-23 15:48:10 -0800845 private final String getCellInfoDisplayString(int i) {
846 return (i != Integer.MAX_VALUE) ? Integer.toString(i) : "";
847 }
848
849 private final String getCellInfoDisplayString(long i) {
850 return (i != Long.MAX_VALUE) ? Long.toString(i) : "";
851 }
852
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700853 private final String getConnectionStatusString(CellInfo ci) {
854 String regStr = "";
855 String connStatStr = "";
856 String connector = "";
857
858 if (ci.isRegistered()) {
859 regStr = "R";
860 }
861 switch (ci.getCellConnectionStatus()) {
862 case CellInfo.CONNECTION_PRIMARY_SERVING: connStatStr = "P"; break;
863 case CellInfo.CONNECTION_SECONDARY_SERVING: connStatStr = "S"; break;
864 case CellInfo.CONNECTION_NONE: connStatStr = "N"; break;
865 case CellInfo.CONNECTION_UNKNOWN: /* Field is unsupported */ break;
866 default: break;
867 }
868 if (!TextUtils.isEmpty(regStr) && !TextUtils.isEmpty(connStatStr)) {
869 connector = "+";
870 }
871
872 return regStr + connector + connStatStr;
873 }
874
Nathan Haroldcea413a2015-11-23 15:48:10 -0800875 private final String buildCdmaInfoString(CellInfoCdma ci) {
876 CellIdentityCdma cidCdma = ci.getCellIdentity();
877 CellSignalStrengthCdma ssCdma = ci.getCellSignalStrength();
878
879 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 -0700880 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800881 getCellInfoDisplayString(cidCdma.getSystemId()),
882 getCellInfoDisplayString(cidCdma.getNetworkId()),
883 getCellInfoDisplayString(cidCdma.getBasestationId()),
884 getCellInfoDisplayString(ssCdma.getCdmaDbm()),
885 getCellInfoDisplayString(ssCdma.getCdmaEcio()),
886 getCellInfoDisplayString(ssCdma.getEvdoDbm()),
887 getCellInfoDisplayString(ssCdma.getEvdoEcio()),
888 getCellInfoDisplayString(ssCdma.getEvdoSnr()));
889 }
890
891 private final String buildGsmInfoString(CellInfoGsm ci) {
892 CellIdentityGsm cidGsm = ci.getCellIdentity();
893 CellSignalStrengthGsm ssGsm = ci.getCellSignalStrength();
894
Nathan Harold2b77d742016-03-19 13:22:10 -0700895 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 -0700896 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800897 getCellInfoDisplayString(cidGsm.getMcc()),
898 getCellInfoDisplayString(cidGsm.getMnc()),
899 getCellInfoDisplayString(cidGsm.getLac()),
900 getCellInfoDisplayString(cidGsm.getCid()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700901 getCellInfoDisplayString(cidGsm.getArfcn()),
902 getCellInfoDisplayString(cidGsm.getBsic()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800903 getCellInfoDisplayString(ssGsm.getDbm()));
904 }
905
906 private final String buildLteInfoString(CellInfoLte ci) {
907 CellIdentityLte cidLte = ci.getCellIdentity();
908 CellSignalStrengthLte ssLte = ci.getCellSignalStrength();
909
910 return String.format(
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700911 "%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s %-6.6s %-2.2s %-4.4s %-4.4s %-2.2s\n",
912 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800913 getCellInfoDisplayString(cidLte.getMcc()),
914 getCellInfoDisplayString(cidLte.getMnc()),
915 getCellInfoDisplayString(cidLte.getTac()),
916 getCellInfoDisplayString(cidLte.getCi()),
917 getCellInfoDisplayString(cidLte.getPci()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700918 getCellInfoDisplayString(cidLte.getEarfcn()),
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700919 getCellInfoDisplayString(cidLte.getBandwidth()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800920 getCellInfoDisplayString(ssLte.getDbm()),
921 getCellInfoDisplayString(ssLte.getRsrq()),
922 getCellInfoDisplayString(ssLte.getTimingAdvance()));
923 }
924
925 private final String buildWcdmaInfoString(CellInfoWcdma ci) {
926 CellIdentityWcdma cidWcdma = ci.getCellIdentity();
927 CellSignalStrengthWcdma ssWcdma = ci.getCellSignalStrength();
928
Nathan Harold2b77d742016-03-19 13:22:10 -0700929 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 -0700930 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800931 getCellInfoDisplayString(cidWcdma.getMcc()),
932 getCellInfoDisplayString(cidWcdma.getMnc()),
933 getCellInfoDisplayString(cidWcdma.getLac()),
934 getCellInfoDisplayString(cidWcdma.getCid()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700935 getCellInfoDisplayString(cidWcdma.getUarfcn()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800936 getCellInfoDisplayString(cidWcdma.getPsc()),
937 getCellInfoDisplayString(ssWcdma.getDbm()));
938 }
939
940 private final String buildCellInfoString(List<CellInfo> arrayCi) {
941 String value = new String();
942 StringBuilder cdmaCells = new StringBuilder(),
943 gsmCells = new StringBuilder(),
944 lteCells = new StringBuilder(),
945 wcdmaCells = new StringBuilder();
946
947 if (arrayCi != null) {
948 for (CellInfo ci : arrayCi) {
949
950 if (ci instanceof CellInfoLte) {
951 lteCells.append(buildLteInfoString((CellInfoLte) ci));
952 } else if (ci instanceof CellInfoWcdma) {
953 wcdmaCells.append(buildWcdmaInfoString((CellInfoWcdma) ci));
954 } else if (ci instanceof CellInfoGsm) {
955 gsmCells.append(buildGsmInfoString((CellInfoGsm) ci));
956 } else if (ci instanceof CellInfoCdma) {
957 cdmaCells.append(buildCdmaInfoString((CellInfoCdma) ci));
Wink Saville79bff2a2012-06-01 14:37:21 -0700958 }
959 }
Nathan Haroldcea413a2015-11-23 15:48:10 -0800960 if (lteCells.length() != 0) {
961 value += String.format(
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700962 "LTE\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s"
963 + " %-6.6s %-2.2s %-4.4s %-4.4s %-2.2s\n",
964 "SRV", "MCC", "MNC", "TAC", "CID", "PCI",
965 "EARFCN", "BW", "RSRP", "RSRQ", "TA");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800966 value += lteCells.toString();
967 }
968 if (wcdmaCells.length() != 0) {
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700969 value += String.format(
970 "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 -0700971 "SRV", "MCC", "MNC", "LAC", "CID", "UARFCN", "PSC", "RSCP");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800972 value += wcdmaCells.toString();
973 }
974 if (gsmCells.length() != 0) {
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700975 value += String.format(
976 "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 -0700977 "SRV", "MCC", "MNC", "LAC", "CID", "ARFCN", "BSIC", "RSSI");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800978 value += gsmCells.toString();
979 }
980 if (cdmaCells.length() != 0) {
981 value += String.format(
982 "CDMA/EVDO\n%-3.3s %-5.5s %-5.5s %-5.5s %-6.6s %-6.6s %-6.6s %-6.6s %-5.5s\n",
983 "SRV", "SID", "NID", "BSID", "C-RSSI", "C-ECIO", "E-RSSI", "E-ECIO", "E-SNR");
984 value += cdmaCells.toString();
985 }
986 } else {
987 value ="unknown";
Wink Saville79bff2a2012-06-01 14:37:21 -0700988 }
Nathan Haroldcea413a2015-11-23 15:48:10 -0800989
990 return value.toString();
991 }
992
993 private final void updateCellInfo(List<CellInfo> arrayCi) {
994 mCellInfo.setText(buildCellInfoString(arrayCi));
Wink Saville79bff2a2012-06-01 14:37:21 -0700995 }
996
Jordan Liub69e8f22019-04-02 12:13:31 -0700997 private final void updateSubscriptionIds() {
Jordan Liu84deb0a2019-04-05 14:39:41 -0700998 mSubscriptionId.setText(Integer.toString(mPhone.getSubId()));
Jordan Liub69e8f22019-04-02 12:13:31 -0700999 mDds.setText(Integer.toString(SubscriptionManager.getDefaultDataSubscriptionId()));
1000 }
1001
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001002 private final void
1003 updateMessageWaiting() {
1004 mMwi.setText(String.valueOf(mMwiValue));
1005 }
1006
1007 private final void
1008 updateCallRedirect() {
1009 mCfi.setText(String.valueOf(mCfiValue));
1010 }
1011
1012
1013 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -07001014 updateServiceState(ServiceState serviceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001015 int state = serviceState.getState();
1016 Resources r = getResources();
1017 String display = r.getString(R.string.radioInfo_unknown);
johnwang342101a2009-09-23 16:22:34 -07001018
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001019 switch (state) {
1020 case ServiceState.STATE_IN_SERVICE:
1021 display = r.getString(R.string.radioInfo_service_in);
1022 break;
1023 case ServiceState.STATE_OUT_OF_SERVICE:
1024 case ServiceState.STATE_EMERGENCY_ONLY:
1025 display = r.getString(R.string.radioInfo_service_emergency);
1026 break;
1027 case ServiceState.STATE_POWER_OFF:
1028 display = r.getString(R.string.radioInfo_service_off);
1029 break;
1030 }
johnwang342101a2009-09-23 16:22:34 -07001031
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001032 gsmState.setText(display);
johnwang342101a2009-09-23 16:22:34 -07001033
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001034 if (serviceState.getRoaming()) {
1035 roamingState.setText(R.string.radioInfo_roaming_in);
1036 } else {
1037 roamingState.setText(R.string.radioInfo_roaming_not);
1038 }
1039
1040 operatorName.setText(serviceState.getOperatorAlphaLong());
1041 }
1042
1043 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -07001044 updatePhoneState(int state) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001045 Resources r = getResources();
1046 String display = r.getString(R.string.radioInfo_unknown);
1047
1048 switch (state) {
Nathan Harold2b77d742016-03-19 13:22:10 -07001049 case TelephonyManager.CALL_STATE_IDLE:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001050 display = r.getString(R.string.radioInfo_phone_idle);
1051 break;
Nathan Harold2b77d742016-03-19 13:22:10 -07001052 case TelephonyManager.CALL_STATE_RINGING:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001053 display = r.getString(R.string.radioInfo_phone_ringing);
1054 break;
Nathan Harold2b77d742016-03-19 13:22:10 -07001055 case TelephonyManager.CALL_STATE_OFFHOOK:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001056 display = r.getString(R.string.radioInfo_phone_offhook);
1057 break;
1058 }
1059
1060 callState.setText(display);
1061 }
1062
1063 private final void
1064 updateDataState() {
1065 int state = mTelephonyManager.getDataState();
1066 Resources r = getResources();
1067 String display = r.getString(R.string.radioInfo_unknown);
1068
1069 switch (state) {
1070 case TelephonyManager.DATA_CONNECTED:
1071 display = r.getString(R.string.radioInfo_data_connected);
1072 break;
1073 case TelephonyManager.DATA_CONNECTING:
1074 display = r.getString(R.string.radioInfo_data_connecting);
1075 break;
1076 case TelephonyManager.DATA_DISCONNECTED:
1077 display = r.getString(R.string.radioInfo_data_disconnected);
1078 break;
1079 case TelephonyManager.DATA_SUSPENDED:
1080 display = r.getString(R.string.radioInfo_data_suspended);
1081 break;
1082 }
johnwang342101a2009-09-23 16:22:34 -07001083
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001084 gprsState.setText(display);
1085 }
1086
1087 private final void updateNetworkType() {
Jordan Liu84deb0a2019-04-05 14:39:41 -07001088 if(mPhone != null) {
1089 ServiceState ss = mPhone.getServiceState();
Nathan Harold2b77d742016-03-19 13:22:10 -07001090 dataNetwork.setText(ServiceState.rilRadioTechnologyToString(
Jordan Liu84deb0a2019-04-05 14:39:41 -07001091 mPhone.getServiceState().getRilDataRadioTechnology()));
Nathan Harold2b77d742016-03-19 13:22:10 -07001092 voiceNetwork.setText(ServiceState.rilRadioTechnologyToString(
Jordan Liu84deb0a2019-04-05 14:39:41 -07001093 mPhone.getServiceState().getRilVoiceRadioTechnology()));
Nathan Harold2b77d742016-03-19 13:22:10 -07001094 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001095 }
1096
1097 private final void
1098 updateProperties() {
1099 String s;
1100 Resources r = getResources();
1101
Jordan Liu84deb0a2019-04-05 14:39:41 -07001102 s = mPhone.getDeviceId();
johnwang342101a2009-09-23 16:22:34 -07001103 if (s == null) s = r.getString(R.string.radioInfo_unknown);
Wink Savillec3886682009-04-02 11:00:56 -07001104 mDeviceId.setText(s);
johnwang342101a2009-09-23 16:22:34 -07001105
Jordan Liu84deb0a2019-04-05 14:39:41 -07001106 s = mPhone.getSubscriberId();
Meng Wang9053f172017-06-23 16:02:14 -07001107 if (s == null) s = r.getString(R.string.radioInfo_unknown);
1108 mSubscriberId.setText(s);
1109
Nathan Haroldcea413a2015-11-23 15:48:10 -08001110 //FIXME: Replace with a TelephonyManager call
Jordan Liu84deb0a2019-04-05 14:39:41 -07001111 s = mPhone.getLine1Number();
johnwang342101a2009-09-23 16:22:34 -07001112 if (s == null) s = r.getString(R.string.radioInfo_unknown);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001113 number.setText(s);
1114 }
1115
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001116 private final void updateDataStats2() {
1117 Resources r = getResources();
1118
Jeff Sharkey93029862011-05-27 18:26:15 -07001119 long txPackets = TrafficStats.getMobileTxPackets();
1120 long rxPackets = TrafficStats.getMobileRxPackets();
1121 long txBytes = TrafficStats.getMobileTxBytes();
1122 long rxBytes = TrafficStats.getMobileRxBytes();
johnwang342101a2009-09-23 16:22:34 -07001123
Jeff Sharkey93029862011-05-27 18:26:15 -07001124 String packets = r.getString(R.string.radioInfo_display_packets);
1125 String bytes = r.getString(R.string.radioInfo_display_bytes);
johnwang342101a2009-09-23 16:22:34 -07001126
Jeff Sharkey93029862011-05-27 18:26:15 -07001127 sent.setText(txPackets + " " + packets + ", " + txBytes + " " + bytes);
1128 received.setText(rxPackets + " " + packets + ", " + rxBytes + " " + bytes);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001129 }
1130
1131 /**
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001132 * Ping a host name
1133 */
1134 private final void pingHostname() {
1135 try {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001136 try {
1137 Process p4 = Runtime.getRuntime().exec("ping -c 1 www.google.com");
1138 int status4 = p4.waitFor();
1139 if (status4 == 0) {
1140 mPingHostnameResultV4 = "Pass";
1141 } else {
1142 mPingHostnameResultV4 = String.format("Fail(%d)", status4);
1143 }
1144 } catch (IOException e) {
1145 mPingHostnameResultV4 = "Fail: IOException";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001146 }
Nathan Haroldcea413a2015-11-23 15:48:10 -08001147 try {
1148 Process p6 = Runtime.getRuntime().exec("ping6 -c 1 www.google.com");
1149 int status6 = p6.waitFor();
1150 if (status6 == 0) {
1151 mPingHostnameResultV6 = "Pass";
1152 } else {
1153 mPingHostnameResultV6 = String.format("Fail(%d)", status6);
1154 }
1155 } catch (IOException e) {
1156 mPingHostnameResultV6 = "Fail: IOException";
1157 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001158 } catch (InterruptedException e) {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001159 mPingHostnameResultV4 = mPingHostnameResultV6 = "Fail: InterruptedException";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001160 }
1161 }
1162
1163 /**
1164 * This function checks for basic functionality of HTTP Client.
1165 */
1166 private void httpClientTest() {
Narayan Kamathf25627c2014-12-12 13:53:28 +00001167 HttpURLConnection urlConnection = null;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001168 try {
Narayan Kamathf25627c2014-12-12 13:53:28 +00001169 // TODO: Hardcoded for now, make it UI configurable
Alex Klyubinb0090232015-04-02 11:08:51 -07001170 URL url = new URL("https://www.google.com");
Narayan Kamathf25627c2014-12-12 13:53:28 +00001171 urlConnection = (HttpURLConnection) url.openConnection();
1172 if (urlConnection.getResponseCode() == 200) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001173 mHttpClientTestResult = "Pass";
1174 } else {
Narayan Kamathf25627c2014-12-12 13:53:28 +00001175 mHttpClientTestResult = "Fail: Code: " + urlConnection.getResponseMessage();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001176 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001177 } catch (IOException e) {
1178 mHttpClientTestResult = "Fail: IOException";
Narayan Kamathf25627c2014-12-12 13:53:28 +00001179 } finally {
1180 if (urlConnection != null) {
1181 urlConnection.disconnect();
1182 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001183 }
1184 }
1185
1186 private void refreshSmsc() {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001187 //FIXME: Replace with a TelephonyManager call
Jordan Liu84deb0a2019-04-05 14:39:41 -07001188 mPhone.getSmscAddress(mHandler.obtainMessage(EVENT_QUERY_SMSC_DONE));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001189 }
1190
Nathan Haroldcea413a2015-11-23 15:48:10 -08001191 private final void updateAllCellInfo() {
1192
1193 mCellInfo.setText("");
Nathan Haroldcea413a2015-11-23 15:48:10 -08001194 mLocation.setText("");
1195
1196 final Runnable updateAllCellInfoResults = new Runnable() {
1197 public void run() {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001198 updateLocation(mCellLocationResult);
1199 updateCellInfo(mCellInfoResult);
1200 }
1201 };
1202
1203 Thread locThread = new Thread() {
1204 @Override
1205 public void run() {
1206 mCellInfoResult = mTelephonyManager.getAllCellInfo();
1207 mCellLocationResult = mTelephonyManager.getCellLocation();
Nathan Haroldcea413a2015-11-23 15:48:10 -08001208
1209 mHandler.post(updateAllCellInfoResults);
1210 }
1211 };
1212 locThread.start();
1213 }
1214
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001215 private final void updatePingState() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001216 // Set all to unknown since the threads will take a few secs to update.
Nathan Haroldcea413a2015-11-23 15:48:10 -08001217 mPingHostnameResultV4 = getResources().getString(R.string.radioInfo_unknown);
1218 mPingHostnameResultV6 = getResources().getString(R.string.radioInfo_unknown);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001219 mHttpClientTestResult = getResources().getString(R.string.radioInfo_unknown);
1220
Nathan Haroldcea413a2015-11-23 15:48:10 -08001221 mPingHostnameV4.setText(mPingHostnameResultV4);
1222 mPingHostnameV6.setText(mPingHostnameResultV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001223 mHttpClientTest.setText(mHttpClientTestResult);
1224
1225 final Runnable updatePingResults = new Runnable() {
1226 public void run() {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001227 mPingHostnameV4.setText(mPingHostnameResultV4);
1228 mPingHostnameV6.setText(mPingHostnameResultV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001229 mHttpClientTest.setText(mHttpClientTestResult);
1230 }
1231 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001232
1233 Thread hostname = new Thread() {
1234 @Override
1235 public void run() {
1236 pingHostname();
Nathan Haroldcea413a2015-11-23 15:48:10 -08001237 mHandler.post(updatePingResults);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001238 }
1239 };
1240 hostname.start();
1241
1242 Thread httpClient = new Thread() {
1243 @Override
1244 public void run() {
1245 httpClientTest();
Nathan Haroldcea413a2015-11-23 15:48:10 -08001246 mHandler.post(updatePingResults);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001247 }
1248 };
1249 httpClient.start();
1250 }
1251
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001252 private MenuItem.OnMenuItemClickListener mViewADNCallback = new MenuItem.OnMenuItemClickListener() {
1253 public boolean onMenuItemClick(MenuItem item) {
1254 Intent intent = new Intent(Intent.ACTION_VIEW);
1255 // XXX We need to specify the component here because if we don't
1256 // the activity manager will try to resolve the type by calling
1257 // the content provider, which causes it to be loaded in a process
1258 // other than the Dialer process, which causes a lot of stuff to
1259 // break.
Jordan Liu84deb0a2019-04-05 14:39:41 -07001260 intent.setClassName("com.android.phone", "com.android.phone.SimContacts");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001261 startActivity(intent);
1262 return true;
1263 }
1264 };
1265
1266 private MenuItem.OnMenuItemClickListener mViewFDNCallback = new MenuItem.OnMenuItemClickListener() {
1267 public boolean onMenuItemClick(MenuItem item) {
1268 Intent intent = new Intent(Intent.ACTION_VIEW);
1269 // XXX We need to specify the component here because if we don't
1270 // the activity manager will try to resolve the type by calling
1271 // the content provider, which causes it to be loaded in a process
1272 // other than the Dialer process, which causes a lot of stuff to
1273 // break.
Jordan Liu84deb0a2019-04-05 14:39:41 -07001274 intent.setClassName("com.android.phone", "com.android.phone.settings.fdn.FdnList");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001275 startActivity(intent);
1276 return true;
1277 }
1278 };
1279
1280 private MenuItem.OnMenuItemClickListener mViewSDNCallback = new MenuItem.OnMenuItemClickListener() {
1281 public boolean onMenuItemClick(MenuItem item) {
1282 Intent intent = new Intent(
Wink Savillec3886682009-04-02 11:00:56 -07001283 Intent.ACTION_VIEW, Uri.parse("content://icc/sdn"));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001284 // XXX We need to specify the component here because if we don't
1285 // the activity manager will try to resolve the type by calling
1286 // the content provider, which causes it to be loaded in a process
1287 // other than the Dialer process, which causes a lot of stuff to
1288 // break.
Jordan Liu84deb0a2019-04-05 14:39:41 -07001289 intent.setClassName("com.android.phone", "com.android.phone.ADNList");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001290 startActivity(intent);
1291 return true;
1292 }
1293 };
1294
Nathan Harolde272c202016-10-27 13:45:00 -07001295 private MenuItem.OnMenuItemClickListener mGetImsStatus = new MenuItem.OnMenuItemClickListener() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001296 public boolean onMenuItemClick(MenuItem item) {
Jordan Liu84deb0a2019-04-05 14:39:41 -07001297 boolean isImsRegistered = mPhone.isImsRegistered();
1298 boolean availableVolte = mPhone.isVolteEnabled();
1299 boolean availableWfc = mPhone.isWifiCallingEnabled();
1300 boolean availableVt = mPhone.isVideoEnabled();
1301 boolean availableUt = mPhone.isUtEnabled();
Nathan Harolde272c202016-10-27 13:45:00 -07001302
1303 final String imsRegString = isImsRegistered ?
1304 getString(R.string.radio_info_ims_reg_status_registered) :
1305 getString(R.string.radio_info_ims_reg_status_not_registered);
1306
1307 final String available = getString(R.string.radio_info_ims_feature_status_available);
1308 final String unavailable = getString(
1309 R.string.radio_info_ims_feature_status_unavailable);
1310
1311 String imsStatus = getString(R.string.radio_info_ims_reg_status,
1312 imsRegString,
1313 availableVolte ? available : unavailable,
1314 availableWfc ? available : unavailable,
1315 availableVt ? available : unavailable,
1316 availableUt ? available : unavailable);
1317
1318 AlertDialog imsDialog = new AlertDialog.Builder(RadioInfo.this)
1319 .setMessage(imsStatus)
1320 .setTitle(getString(R.string.radio_info_ims_reg_status_title))
1321 .create();
1322
1323 imsDialog.show();
1324
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001325 return true;
1326 }
1327 };
1328
1329 private MenuItem.OnMenuItemClickListener mSelectBandCallback = new MenuItem.OnMenuItemClickListener() {
1330 public boolean onMenuItemClick(MenuItem item) {
1331 Intent intent = new Intent();
1332 intent.setClass(RadioInfo.this, BandMode.class);
1333 startActivity(intent);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001334 return true;
1335 }
1336 };
johnwang342101a2009-09-23 16:22:34 -07001337
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001338 private MenuItem.OnMenuItemClickListener mToggleData = new MenuItem.OnMenuItemClickListener() {
1339 public boolean onMenuItemClick(MenuItem item) {
1340 int state = mTelephonyManager.getDataState();
1341 switch (state) {
1342 case TelephonyManager.DATA_CONNECTED:
Jack Yu50972ed2018-12-13 11:51:20 -08001343 mTelephonyManager.setDataEnabled(false);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001344 break;
1345 case TelephonyManager.DATA_DISCONNECTED:
Jack Yu50972ed2018-12-13 11:51:20 -08001346 mTelephonyManager.setDataEnabled(true);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001347 break;
1348 default:
1349 // do nothing
1350 break;
1351 }
1352 return true;
1353 }
1354 };
1355
Nathan Harold2b77d742016-03-19 13:22:10 -07001356 private boolean isRadioOn() {
1357 //FIXME: Replace with a TelephonyManager call
Jordan Liu84deb0a2019-04-05 14:39:41 -07001358 return mPhone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
Nathan Harold2b77d742016-03-19 13:22:10 -07001359 }
1360
1361 private void updateRadioPowerState() {
1362 //delightful hack to prevent on-checked-changed calls from
1363 //actually forcing the radio preference to its transient/current value.
1364 radioPowerOnSwitch.setOnCheckedChangeListener(null);
1365 radioPowerOnSwitch.setChecked(isRadioOn());
1366 radioPowerOnSwitch.setOnCheckedChangeListener(mRadioPowerOnChangeListener);
1367 }
1368
Nathan Harolde272c202016-10-27 13:45:00 -07001369 void setImsVolteProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001370 Log.d(TAG, "setImsVolteProvisioned state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001371 setImsConfigProvisionedState(IMS_VOLTE_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001372 }
1373
Nathan Harolde272c202016-10-27 13:45:00 -07001374 void setImsVtProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001375 Log.d(TAG, "setImsVtProvisioned() state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001376 setImsConfigProvisionedState(IMS_VT_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001377 }
1378
Nathan Harolde272c202016-10-27 13:45:00 -07001379 void setImsWfcProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001380 Log.d(TAG, "setImsWfcProvisioned() state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001381 setImsConfigProvisionedState(IMS_WFC_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001382 }
1383
Meng Wang586741c2017-04-26 15:02:51 -07001384 void setEabProvisionedState(boolean state) {
1385 Log.d(TAG, "setEabProvisioned() state: " + ((state)? "on":"off"));
1386 setImsConfigProvisionedState(EAB_PROVISIONED_CONFIG_ID, state);
1387 }
1388
Nathan Harolde272c202016-10-27 13:45:00 -07001389 void setImsConfigProvisionedState(int configItem, boolean state) {
Jordan Liu84deb0a2019-04-05 14:39:41 -07001390 if (mPhone != null && mImsManager != null) {
Philip P. Moltmann5c449ae2017-02-14 12:43:02 -08001391 QueuedWork.queue(new Runnable() {
Nathan Harold12e1f552016-06-17 13:55:38 -07001392 public void run() {
1393 try {
1394 mImsManager.getConfigInterface().setProvisionedValue(
1395 configItem,
1396 state? 1 : 0);
1397 } catch (ImsException e) {
1398 Log.e(TAG, "setImsConfigProvisioned() exception:", e);
1399 }
1400 }
Philip P. Moltmann5c449ae2017-02-14 12:43:02 -08001401 }, false);
Nathan Harold12e1f552016-06-17 13:55:38 -07001402 }
1403 }
1404
Nathan Harold2b77d742016-03-19 13:22:10 -07001405 OnCheckedChangeListener mRadioPowerOnChangeListener = new OnCheckedChangeListener() {
1406 @Override
1407 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1408 log("toggle radio power: currently " + (isRadioOn()?"on":"off"));
Jordan Liu84deb0a2019-04-05 14:39:41 -07001409 mPhone.setRadioPower(isChecked);
Nathan Harold2b77d742016-03-19 13:22:10 -07001410 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001411 };
1412
Nathan Harold12e1f552016-06-17 13:55:38 -07001413 private boolean isImsVolteProvisioned() {
Jordan Liu84deb0a2019-04-05 14:39:41 -07001414 if (mPhone != null && mImsManager != null) {
1415 return mImsManager.isVolteEnabledByPlatform(mPhone.getContext())
1416 && mImsManager.isVolteProvisionedOnDevice(mPhone.getContext());
Pavel Zhamaitsiakcb267a62015-01-21 18:25:14 -08001417 }
1418 return false;
1419 }
1420
Nathan Harold12e1f552016-06-17 13:55:38 -07001421 OnCheckedChangeListener mImsVolteCheckedChangeListener = new OnCheckedChangeListener() {
Wink Saville426fc662011-09-25 14:39:02 -07001422 @Override
Nathan Harold2b77d742016-03-19 13:22:10 -07001423 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001424 setImsVolteProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001425 }
Wink Saville426fc662011-09-25 14:39:02 -07001426 };
1427
Nathan Harold12e1f552016-06-17 13:55:38 -07001428 private boolean isImsVtProvisioned() {
Jordan Liu84deb0a2019-04-05 14:39:41 -07001429 if (mPhone != null && mImsManager != null) {
1430 return mImsManager.isVtEnabledByPlatform(mPhone.getContext())
1431 && mImsManager.isVtProvisionedOnDevice(mPhone.getContext());
Nathan Harold12e1f552016-06-17 13:55:38 -07001432 }
1433 return false;
1434 }
1435
1436 OnCheckedChangeListener mImsVtCheckedChangeListener = new OnCheckedChangeListener() {
1437 @Override
1438 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1439 setImsVtProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001440 }
Nathan Harold12e1f552016-06-17 13:55:38 -07001441 };
1442
1443 private boolean isImsWfcProvisioned() {
Jordan Liu84deb0a2019-04-05 14:39:41 -07001444 if (mPhone != null && mImsManager != null) {
1445 return mImsManager.isWfcEnabledByPlatform(mPhone.getContext())
1446 && mImsManager.isWfcProvisionedOnDevice(mPhone.getContext());
Nathan Harold12e1f552016-06-17 13:55:38 -07001447 }
1448 return false;
1449 }
1450
1451 OnCheckedChangeListener mImsWfcCheckedChangeListener = new OnCheckedChangeListener() {
1452 @Override
1453 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1454 setImsWfcProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001455 }
Nathan Harold12e1f552016-06-17 13:55:38 -07001456 };
1457
Meng Wang586741c2017-04-26 15:02:51 -07001458 private boolean isEabProvisioned() {
1459 return isFeatureProvisioned(EAB_PROVISIONED_CONFIG_ID, false);
1460 }
1461
1462 OnCheckedChangeListener mEabCheckedChangeListener = new OnCheckedChangeListener() {
1463 @Override
1464 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1465 setEabProvisionedState(isChecked);
1466 }
1467 };
1468
1469 private boolean isFeatureProvisioned(int featureId, boolean defaultValue) {
1470 boolean provisioned = defaultValue;
1471 if (mImsManager != null) {
1472 try {
1473 ImsConfig imsConfig = mImsManager.getConfigInterface();
1474 if (imsConfig != null) {
1475 provisioned =
1476 (imsConfig.getProvisionedValue(featureId)
1477 == ImsConfig.FeatureValueConstants.ON);
1478 }
1479 } catch (ImsException ex) {
1480 Log.e(TAG, "isFeatureProvisioned() exception:", ex);
1481 }
1482 }
1483
1484 log("isFeatureProvisioned() featureId=" + featureId + " provisioned=" + provisioned);
1485 return provisioned;
1486 }
1487
1488 private static boolean isEabEnabledByPlatform(Context context) {
1489 if (context != null) {
1490 CarrierConfigManager configManager = (CarrierConfigManager)
1491 context.getSystemService(Context.CARRIER_CONFIG_SERVICE);
1492 if (configManager != null && configManager.getConfig().getBoolean(
1493 CarrierConfigManager.KEY_USE_RCS_PRESENCE_BOOL)) {
1494 return true;
1495 }
1496 }
1497 return false;
1498 }
1499
Nathan Harold12e1f552016-06-17 13:55:38 -07001500 private void updateImsProvisionedState() {
Jordan Liu84deb0a2019-04-05 14:39:41 -07001501 if (!ImsManager.isImsSupportedOnDevice(mPhone.getContext())) {
Brad Ebinger5dfe7f82019-03-11 17:33:53 -07001502 return;
1503 }
Nathan Harold12e1f552016-06-17 13:55:38 -07001504 log("updateImsProvisionedState isImsVolteProvisioned()=" + isImsVolteProvisioned());
Nathan Harold2b77d742016-03-19 13:22:10 -07001505 //delightful hack to prevent on-checked-changed calls from
1506 //actually forcing the ims provisioning to its transient/current value.
Nathan Harold12e1f552016-06-17 13:55:38 -07001507 imsVolteProvisionedSwitch.setOnCheckedChangeListener(null);
1508 imsVolteProvisionedSwitch.setChecked(isImsVolteProvisioned());
1509 imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
Sreekanth Badidac888e192018-02-05 17:18:40 +01001510 imsVolteProvisionedSwitch.setEnabled(!Build.IS_USER
Jordan Liu84deb0a2019-04-05 14:39:41 -07001511 && mImsManager.isVolteEnabledByPlatform(mPhone.getContext()));
Nathan Harold12e1f552016-06-17 13:55:38 -07001512
1513 imsVtProvisionedSwitch.setOnCheckedChangeListener(null);
1514 imsVtProvisionedSwitch.setChecked(isImsVtProvisioned());
1515 imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
Sreekanth Badidac888e192018-02-05 17:18:40 +01001516 imsVtProvisionedSwitch.setEnabled(!Build.IS_USER
Jordan Liu84deb0a2019-04-05 14:39:41 -07001517 && mImsManager.isVtEnabledByPlatform(mPhone.getContext()));
Nathan Harold12e1f552016-06-17 13:55:38 -07001518
1519 imsWfcProvisionedSwitch.setOnCheckedChangeListener(null);
1520 imsWfcProvisionedSwitch.setChecked(isImsWfcProvisioned());
1521 imsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
Sreekanth Badidac888e192018-02-05 17:18:40 +01001522 imsWfcProvisionedSwitch.setEnabled(!Build.IS_USER
Jordan Liu84deb0a2019-04-05 14:39:41 -07001523 && mImsManager.isWfcEnabledByPlatform(mPhone.getContext()));
Meng Wang586741c2017-04-26 15:02:51 -07001524
1525 eabProvisionedSwitch.setOnCheckedChangeListener(null);
1526 eabProvisionedSwitch.setChecked(isEabProvisioned());
1527 eabProvisionedSwitch.setOnCheckedChangeListener(mEabCheckedChangeListener);
Sreekanth Badidac888e192018-02-05 17:18:40 +01001528 eabProvisionedSwitch.setEnabled(!Build.IS_USER
Jordan Liu84deb0a2019-04-05 14:39:41 -07001529 && isEabEnabledByPlatform(mPhone.getContext()));
Wink Saville426fc662011-09-25 14:39:02 -07001530 }
1531
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001532 OnClickListener mDnsCheckButtonHandler = new OnClickListener() {
1533 public void onClick(View v) {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001534 //FIXME: Replace with a TelephonyManager call
Jordan Liu84deb0a2019-04-05 14:39:41 -07001535 mPhone.disableDnsCheck(!mPhone.isDnsCheckDisabled());
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001536 updateDnsCheckState();
1537 }
1538 };
johnwang342101a2009-09-23 16:22:34 -07001539
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001540 OnClickListener mOemInfoButtonHandler = new OnClickListener() {
1541 public void onClick(View v) {
1542 Intent intent = new Intent("com.android.settings.OEM_RADIO_INFO");
1543 try {
1544 startActivity(intent);
1545 } catch (android.content.ActivityNotFoundException ex) {
Wink Savillebf471282013-04-05 15:04:05 -07001546 log("OEM-specific Info/Settings Activity Not Found : " + ex);
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001547 // If the activity does not exist, there are no OEM
1548 // settings, and so we can just do nothing...
1549 }
1550 }
1551 };
1552
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001553 OnClickListener mPingButtonHandler = new OnClickListener() {
1554 public void onClick(View v) {
1555 updatePingState();
1556 }
1557 };
1558
1559 OnClickListener mUpdateSmscButtonHandler = new OnClickListener() {
1560 public void onClick(View v) {
1561 updateSmscButton.setEnabled(false);
Jordan Liu84deb0a2019-04-05 14:39:41 -07001562 mPhone.setSmscAddress(smsc.getText().toString(),
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001563 mHandler.obtainMessage(EVENT_UPDATE_SMSC_DONE));
1564 }
1565 };
1566
1567 OnClickListener mRefreshSmscButtonHandler = new OnClickListener() {
1568 public void onClick(View v) {
1569 refreshSmsc();
1570 }
1571 };
1572
Youhan Wangfd781e92016-12-16 15:53:16 -08001573 OnClickListener mCarrierProvisioningButtonHandler = new OnClickListener() {
1574 public void onClick(View v) {
Meng Wanga04449b2017-08-03 14:34:35 -07001575 final Intent intent = new Intent("com.android.settings.CARRIER_PROVISIONING");
1576 final ComponentName serviceComponent = ComponentName.unflattenFromString(
1577 "com.android.omadm.service/.DMIntentReceiver");
Youhan Wangfd781e92016-12-16 15:53:16 -08001578 intent.setComponent(serviceComponent);
Meng Wanga04449b2017-08-03 14:34:35 -07001579 sendBroadcast(intent);
Youhan Wangfd781e92016-12-16 15:53:16 -08001580 }
1581 };
1582
1583 OnClickListener mTriggerCarrierProvisioningButtonHandler = new OnClickListener() {
1584 public void onClick(View v) {
Meng Wanga04449b2017-08-03 14:34:35 -07001585 final Intent intent = new Intent("com.android.settings.TRIGGER_CARRIER_PROVISIONING");
1586 final ComponentName serviceComponent = ComponentName.unflattenFromString(
1587 "com.android.omadm.service/.DMIntentReceiver");
Youhan Wangfd781e92016-12-16 15:53:16 -08001588 intent.setComponent(serviceComponent);
Meng Wanga04449b2017-08-03 14:34:35 -07001589 sendBroadcast(intent);
Youhan Wangfd781e92016-12-16 15:53:16 -08001590 }
1591 };
1592
Nathan Haroldcea413a2015-11-23 15:48:10 -08001593 AdapterView.OnItemSelectedListener mPreferredNetworkHandler =
1594 new AdapterView.OnItemSelectedListener() {
1595
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001596 public void onItemSelected(AdapterView parent, View v, int pos, long id) {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001597 if (mPreferredNetworkTypeResult != pos && pos >= 0
1598 && pos <= mPreferredNetworkLabels.length - 2) {
1599 mPreferredNetworkTypeResult = pos;
Nathan Harolddaea8be2018-06-05 14:02:35 -07001600
1601 // TODO: Possibly migrate this to TelephonyManager.setPreferredNetworkType()
1602 // which today still has some issues (mostly that the "set" is conditional
1603 // on a successful modem call, which is not what we want). Instead we always
1604 // want this setting to be set, so that if the radio hiccups and this setting
1605 // is for some reason unsuccessful, future calls to the radio will reflect
1606 // the users's preference which is set here.
Jordan Liu84deb0a2019-04-05 14:39:41 -07001607 final int subId = mPhone.getSubId();
Nathan Harolddaea8be2018-06-05 14:02:35 -07001608 if (SubscriptionManager.isUsableSubIdValue(subId)) {
Jordan Liu84deb0a2019-04-05 14:39:41 -07001609 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Nathan Harolddaea8be2018-06-05 14:02:35 -07001610 PREFERRED_NETWORK_MODE + subId, mPreferredNetworkTypeResult);
1611 }
1612 log("Calling setPreferredNetworkType(" + mPreferredNetworkTypeResult + ")");
Nathan Haroldcea413a2015-11-23 15:48:10 -08001613 Message msg = mHandler.obtainMessage(EVENT_SET_PREFERRED_TYPE_DONE);
Jordan Liu84deb0a2019-04-05 14:39:41 -07001614 mPhone.setPreferredNetworkType(mPreferredNetworkTypeResult, msg);
1615 }
1616 }
1617
1618 public void onNothingSelected(AdapterView parent) {
1619 }
1620 };
1621
1622 AdapterView.OnItemSelectedListener mSelectPhoneIndexHandler =
1623 new AdapterView.OnItemSelectedListener() {
1624
1625 public void onItemSelected(AdapterView parent, View v, int pos, long id) {
1626 if (pos >= 0 && pos <= mPhoneIndexLabels.length - 1) {
1627 // the array position is equal to the phone index
1628 int phoneIndex = pos;
1629 Phone[] phones = PhoneFactory.getPhones();
1630 if (phones == null || phones.length <= phoneIndex) {
Jordan Liub69e8f22019-04-02 12:13:31 -07001631 log("phoneIndex " + phoneIndex + " is invalid");
1632 return;
1633 }
1634 log("switching to phone " + phoneIndex);
1635 // getSubId says it takes a slotIndex, but it actually takes a phone index
Jordan Liu655c1be2019-08-07 16:51:36 -07001636 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Jordan Liub69e8f22019-04-02 12:13:31 -07001637 int[] subIds = SubscriptionManager.getSubId(phoneIndex);
Jordan Liu655c1be2019-08-07 16:51:36 -07001638 if (subIds != null && subIds.length > 0) {
1639 subId = subIds[0];
Jordan Liub69e8f22019-04-02 12:13:31 -07001640 }
1641 mSelectedPhoneIndex = phoneIndex;
1642
Jordan Liu655c1be2019-08-07 16:51:36 -07001643 updatePhoneIndex(phoneIndex, subId);
Jordan Liub69e8f22019-04-02 12:13:31 -07001644 }
1645 }
1646
1647 public void onNothingSelected(AdapterView parent) {
1648 }
1649 };
1650
Nathan Harold2b77d742016-03-19 13:22:10 -07001651 AdapterView.OnItemSelectedListener mCellInfoRefreshRateHandler =
1652 new AdapterView.OnItemSelectedListener() {
Wink Savillebf471282013-04-05 15:04:05 -07001653
Nathan Harold2b77d742016-03-19 13:22:10 -07001654 public void onItemSelected(AdapterView parent, View v, int pos, long id) {
1655 mCellInfoRefreshRateIndex = pos;
Sooraj Sasindran5cce06b2016-08-18 15:49:49 -07001656 mTelephonyManager.setCellInfoListRate(mCellInfoRefreshRates[pos]);
Nathan Harold2b77d742016-03-19 13:22:10 -07001657 updateAllCellInfo();
1658 }
1659
1660 public void onNothingSelected(AdapterView parent) {
1661 }
1662 };
1663
Naina Nallurid1b57f62019-01-08 15:19:58 -08001664 boolean isCbrsSupported() {
1665 return getResources().getBoolean(
1666 com.android.internal.R.bool.config_cbrs_supported);
1667 }
1668
1669 void updateCbrsDataState(boolean state) {
1670 Log.d(TAG, "setCbrsDataSwitchState() state:" + ((state)? "on":"off"));
1671 if (mTelephonyManager != null) {
1672 QueuedWork.queue(new Runnable() {
1673 public void run() {
1674 mTelephonyManager.setOpportunisticNetworkState(state);
1675 cbrsDataSwitch.setChecked(getCbrsDataState());
1676 }
1677 }, false);
1678 }
1679 }
1680
1681 boolean getCbrsDataState() {
1682 boolean state = false;
1683 if (mTelephonyManager != null) {
1684 state = mTelephonyManager.isOpportunisticNetworkEnabled();
1685 }
1686 Log.d(TAG, "getCbrsDataState() state:" +((state)? "on":"off"));
1687 return state;
1688 }
1689
1690 OnCheckedChangeListener mCbrsDataSwitchChangeListener = new OnCheckedChangeListener() {
1691 @Override
1692 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1693 updateCbrsDataState(isChecked);
1694 }
1695 };
1696
Pengquan Meng7f602c72019-01-28 19:12:18 -08001697 private void showDsdsChangeDialog() {
1698 final AlertDialog confirmDialog = new Builder(RadioInfo.this)
1699 .setTitle(R.string.dsds_dialog_title)
1700 .setMessage(R.string.dsds_dialog_message)
1701 .setPositiveButton(R.string.dsds_dialog_confirm, mOnDsdsDialogConfirmedListener)
1702 .setNegativeButton(R.string.dsds_dialog_cancel, mOnDsdsDialogConfirmedListener)
1703 .create();
1704 confirmDialog.show();
1705 }
Naina Nallurid1b57f62019-01-08 15:19:58 -08001706
Pengquan Meng7f602c72019-01-28 19:12:18 -08001707 private static boolean isDsdsSupported() {
Michele3dafea22019-03-19 15:53:45 -07001708 return (TelephonyManager.getDefault().isMultiSimSupported()
1709 == TelephonyManager.MULTISIM_ALLOWED);
Pengquan Meng7f602c72019-01-28 19:12:18 -08001710 }
1711
1712 private static boolean isDsdsEnabled() {
1713 return TelephonyManager.getDefault().getPhoneCount() > 1;
1714 }
1715
1716 private void performDsdsSwitch() {
1717 mTelephonyManager.switchMultiSimConfig(dsdsSwitch.isChecked() ? 2 : 1);
1718 }
1719
Pengquan Menga40d2742019-04-30 19:32:58 -07001720 /**
1721 * @return {@code True} if the device is only supported dsds mode.
1722 */
1723 private boolean dsdsModeOnly() {
1724 String dsdsMode = SystemProperties.get(DSDS_MODE_PROPERTY);
1725 return !TextUtils.isEmpty(dsdsMode) && Integer.parseInt(dsdsMode) == ALWAYS_ON_DSDS_MODE;
1726 }
1727
Pengquan Meng7f602c72019-01-28 19:12:18 -08001728 DialogInterface.OnClickListener mOnDsdsDialogConfirmedListener =
1729 new DialogInterface.OnClickListener() {
1730 @Override
1731 public void onClick(DialogInterface dialog, int which) {
1732 if (which == DialogInterface.BUTTON_POSITIVE) {
1733 dsdsSwitch.toggle();
1734 performDsdsSwitch();
1735 }
1736 }
1737 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001738}