blob: 557c39b164896ca120fdffdef098fea212f8771b [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings;
18
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;
Nathan Harolde272c202016-10-27 13:45:00 -070023import android.app.AlertDialog;
24import android.app.Dialog;
Pavel Zhamaitsiakcb267a62015-01-21 18:25:14 -080025import android.app.QueuedWork;
Youhan Wangfd781e92016-12-16 15:53:16 -080026import android.content.ComponentName;
Meng Wang586741c2017-04-26 15:02:51 -070027import android.content.Context;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080028import android.content.Intent;
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +080029import android.content.pm.PackageManager;
30import android.content.pm.ResolveInfo;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080031import android.content.res.Resources;
Nathan Haroldcea413a2015-11-23 15:48:10 -080032import android.graphics.Typeface;
Nathan Haroldf10ea322018-04-24 13:31:07 -070033import android.net.ConnectivityManager;
34import android.net.Network;
35import android.net.NetworkCapabilities;
36import android.net.NetworkRequest;
Jeff Sharkey93029862011-05-27 18:26:15 -070037import android.net.TrafficStats;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080038import android.net.Uri;
39import android.os.AsyncResult;
40import 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;
Wink Saville79bff2a2012-06-01 14:37:21 -070045import android.telephony.CellInfo;
Nathan Haroldcea413a2015-11-23 15:48:10 -080046import android.telephony.CellInfoCdma;
47import android.telephony.CellInfoGsm;
48import android.telephony.CellInfoLte;
49import android.telephony.CellInfoWcdma;
50import android.telephony.CellIdentityCdma;
51import android.telephony.CellIdentityGsm;
52import android.telephony.CellIdentityLte;
53import android.telephony.CellIdentityWcdma;
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;
Nathan Harold2b77d742016-03-19 13:22:10 -070059import android.telephony.PreciseCallState;
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;
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
Jason Monk39b46742015-09-10 15:52:51 -040084import com.android.ims.ImsConfig;
85import com.android.ims.ImsException;
86import com.android.ims.ImsManager;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080087import com.android.internal.telephony.Phone;
Wink Saville55434042012-06-14 12:33:43 -070088import com.android.internal.telephony.PhoneConstants;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080089import com.android.internal.telephony.PhoneFactory;
Nathan Haroldcea413a2015-11-23 15:48:10 -080090import com.android.internal.telephony.RILConstants;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080091import com.android.internal.telephony.TelephonyProperties;
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.net.UnknownHostException;
97import java.util.ArrayList;
98import java.util.List;
99
100public 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 = {
104 "WCDMA preferred",
105 "GSM only",
106 "WCDMA only",
107 "GSM auto (PRL)",
108 "CDMA auto (PRL)",
109 "CDMA only",
110 "EvDo only",
111 "Global auto (PRL)",
112 "LTE/CDMA auto (PRL)",
113 "LTE/UMTS auto (PRL)",
114 "LTE/CDMA/UMTS auto (PRL)",
115 "LTE only",
116 "LTE/WCDMA",
117 "TD-SCDMA only",
118 "TD-SCDMA/WCDMA",
119 "LTE/TD-SCDMA",
120 "TD-SCDMA/GSM",
121 "TD-SCDMA/UMTS",
122 "LTE/TD-SCDMA/WCDMA",
123 "LTE/TD-SCDMA/UMTS",
124 "TD-SCDMA/CDMA/UMTS",
125 "Global/TD-SCDMA",
126 "Unknown"
127 };
128
129
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
164 private void log(String s) {
165 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
175 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;
Nathan Harolde272c202016-10-27 13:45:00 -0700179 private static final int MENU_ITEM_GET_IMS_STATUS = 4;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800180 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;
Meng Wang9053f172017-06-23 16:02:14 -0700184 private TextView mSubscriberId;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800185 private TextView callState;
186 private TextView operatorName;
187 private TextView roamingState;
188 private TextView gsmState;
189 private TextView gprsState;
Nathan Harold2b77d742016-03-19 13:22:10 -0700190 private TextView voiceNetwork;
191 private TextView dataNetwork;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800192 private TextView dBm;
193 private TextView mMwi;
194 private TextView mCfi;
195 private TextView mLocation;
Wink Saville79bff2a2012-06-01 14:37:21 -0700196 private TextView mCellInfo;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800197 private TextView sent;
198 private TextView received;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800199 private TextView mPingHostnameV4;
200 private TextView mPingHostnameV6;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800201 private TextView mHttpClientTest;
Nathan Harold433ca442018-04-23 18:20:43 -0700202 private TextView mPhyChanConfig;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800203 private TextView dnsCheckState;
Nathan Haroldf10ea322018-04-24 13:31:07 -0700204 private TextView mDownlinkKbps;
205 private TextView mUplinkKbps;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800206 private EditText smsc;
Nathan Harold2b77d742016-03-19 13:22:10 -0700207 private Switch radioPowerOnSwitch;
208 private Button cellInfoRefreshRateButton;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800209 private Button dnsCheckToggleButton;
210 private Button pingTestButton;
211 private Button updateSmscButton;
212 private Button refreshSmscButton;
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800213 private Button oemInfoButton;
Youhan Wangfd781e92016-12-16 15:53:16 -0800214 private Button carrierProvisioningButton;
215 private Button triggercarrierProvisioningButton;
Nathan Harold12e1f552016-06-17 13:55:38 -0700216 private Switch imsVolteProvisionedSwitch;
217 private Switch imsVtProvisionedSwitch;
218 private Switch imsWfcProvisionedSwitch;
Meng Wang586741c2017-04-26 15:02:51 -0700219 private Switch eabProvisionedSwitch;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800220 private Spinner preferredNetworkType;
Nathan Harold2b77d742016-03-19 13:22:10 -0700221 private Spinner cellInfoRefreshRateSpinner;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800222
Nathan Haroldf10ea322018-04-24 13:31:07 -0700223 private ConnectivityManager mConnectivityManager;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800224 private TelephonyManager mTelephonyManager;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800225 private ImsManager mImsManager = null;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800226 private Phone phone = null;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800227
Nathan Haroldcea413a2015-11-23 15:48:10 -0800228 private String mPingHostnameResultV4;
229 private String mPingHostnameResultV6;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800230 private String mHttpClientTestResult;
231 private boolean mMwiValue = false;
232 private boolean mCfiValue = false;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800233
234 private List<CellInfo> mCellInfoResult = null;
235 private CellLocation mCellLocationResult = null;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800236
237 private int mPreferredNetworkTypeResult;
Nathan Harold2b77d742016-03-19 13:22:10 -0700238 private int mCellInfoRefreshRateIndex;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800239
Nathan Haroldf10ea322018-04-24 13:31:07 -0700240 private final NetworkRequest mDefaultNetworkRequest = new NetworkRequest.Builder()
241 .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
242 .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
243 .build();
244
245 private final NetworkCallback mNetworkCallback = new NetworkCallback() {
246 public void onCapabilitiesChanged(Network n, NetworkCapabilities nc) {
247 int dlbw = nc.getLinkDownstreamBandwidthKbps();
248 int ulbw = nc.getLinkUpstreamBandwidthKbps();
249 updateBandwidths(dlbw, ulbw);
250 }
251 };
252
Nathan Harold2b77d742016-03-19 13:22:10 -0700253 private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800254 @Override
255 public void onDataConnectionStateChanged(int state) {
256 updateDataState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800257 updateNetworkType();
258 }
259
260 @Override
261 public void onDataActivity(int direction) {
262 updateDataStats2();
263 }
264
265 @Override
Nathan Harold2b77d742016-03-19 13:22:10 -0700266 public void onCallStateChanged(int state, String incomingNumber) {
267 updateNetworkType();
268 updatePhoneState(state);
269 }
270
271 @Override
272 public void onPreciseCallStateChanged(PreciseCallState preciseState) {
273 updateNetworkType();
274 }
275
276 @Override
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800277 public void onCellLocationChanged(CellLocation location) {
278 updateLocation(location);
279 }
280
281 @Override
282 public void onMessageWaitingIndicatorChanged(boolean mwi) {
283 mMwiValue = mwi;
284 updateMessageWaiting();
285 }
286
287 @Override
288 public void onCallForwardingIndicatorChanged(boolean cfi) {
289 mCfiValue = cfi;
290 updateCallRedirect();
291 }
Wink Saville79bff2a2012-06-01 14:37:21 -0700292
293 @Override
294 public void onCellInfoChanged(List<CellInfo> arrayCi) {
Wink Savillebf471282013-04-05 15:04:05 -0700295 log("onCellInfoChanged: arrayCi=" + arrayCi);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800296 mCellInfoResult = arrayCi;
297 updateCellInfo(mCellInfoResult);
Wink Saville79bff2a2012-06-01 14:37:21 -0700298 }
Wink Saville4f0d8812014-04-15 22:05:24 -0700299
300 @Override
Nathan Harold2b77d742016-03-19 13:22:10 -0700301 public void onSignalStrengthsChanged(SignalStrength signalStrength) {
302 log("onSignalStrengthChanged: SignalStrength=" +signalStrength);
303 updateSignalStrength(signalStrength);
304 }
305
306 @Override
307 public void onServiceStateChanged(ServiceState serviceState) {
308 log("onServiceStateChanged: ServiceState=" + serviceState);
309 updateServiceState(serviceState);
310 updateRadioPowerState();
311 updateNetworkType();
Nathan Harold12e1f552016-06-17 13:55:38 -0700312 updateImsProvisionedState();
Nathan Harold2b77d742016-03-19 13:22:10 -0700313 }
Nathan Harold433ca442018-04-23 18:20:43 -0700314
315 @Override
316 public void onPhysicalChannelConfigurationChanged(
317 List<PhysicalChannelConfig> configs) {
318 updatePhysicalChannelConfiguration(configs);
319 }
320
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800321 };
322
Nathan Harold433ca442018-04-23 18:20:43 -0700323 private void updatePhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
324 StringBuilder sb = new StringBuilder();
325 String div = "";
326 sb.append("{");
327 if (configs != null) {
328 for(PhysicalChannelConfig c : configs) {
329 sb.append(div).append(c);
330 div = ",";
331 }
332 }
333 sb.append("}");
334 mPhyChanConfig.setText(sb.toString());
335 }
336
Nathan Haroldcea413a2015-11-23 15:48:10 -0800337 private void updatePreferredNetworkType(int type) {
338 if (type >= mPreferredNetworkLabels.length || type < 0) {
339 log("EVENT_QUERY_PREFERRED_TYPE_DONE: unknown " +
340 "type=" + type);
341 type = mPreferredNetworkLabels.length - 1; //set to Unknown
342 }
343 mPreferredNetworkTypeResult = type;
344
345 preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true);
346 }
347
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800348 private Handler mHandler = new Handler() {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800349 @Override
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800350 public void handleMessage(Message msg) {
351 AsyncResult ar;
352 switch (msg.what) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800353 case EVENT_QUERY_PREFERRED_TYPE_DONE:
354 ar= (AsyncResult) msg.obj;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800355 if (ar.exception == null && ar.result != null) {
356 updatePreferredNetworkType(((int[])ar.result)[0]);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800357 } else {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800358 //In case of an exception, we will set this to unknown
359 updatePreferredNetworkType(mPreferredNetworkLabels.length-1);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800360 }
361 break;
362 case EVENT_SET_PREFERRED_TYPE_DONE:
363 ar= (AsyncResult) msg.obj;
364 if (ar.exception != null) {
Nathan Harolded38afa2016-04-13 00:29:30 -0700365 log("Set preferred network type failed.");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800366 }
367 break;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800368 case EVENT_QUERY_SMSC_DONE:
369 ar= (AsyncResult) msg.obj;
370 if (ar.exception != null) {
371 smsc.setText("refresh error");
372 } else {
jsh21dd4072009-05-12 11:26:55 -0700373 smsc.setText((String)ar.result);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800374 }
375 break;
376 case EVENT_UPDATE_SMSC_DONE:
377 updateSmscButton.setEnabled(true);
378 ar= (AsyncResult) msg.obj;
379 if (ar.exception != null) {
380 smsc.setText("update error");
381 }
382 break;
383 default:
Nathan Haroldcea413a2015-11-23 15:48:10 -0800384 super.handleMessage(msg);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800385 break;
386
387 }
388 }
389 };
390
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800391 @Override
392 public void onCreate(Bundle icicle) {
393 super.onCreate(icicle);
fionaxub54cb2d2016-09-22 15:01:05 -0700394 if (!android.os.Process.myUserHandle().isSystem()) {
395 Log.e(TAG, "Not run from system user, don't do anything.");
396 finish();
397 return;
398 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800399
400 setContentView(R.layout.radio_info);
401
Nathan Haroldcea413a2015-11-23 15:48:10 -0800402 log("Started onCreate");
403
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800404 mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
Nathan Haroldf10ea322018-04-24 13:31:07 -0700405 mConnectivityManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800406 phone = PhoneFactory.getDefaultPhone();
407
Nathan Haroldcea413a2015-11-23 15:48:10 -0800408 //TODO: Need to update this if the default phoneId changes?
409 // Better to have an instance per phone?
410 mImsManager = ImsManager.getInstance(getApplicationContext(),
411 SubscriptionManager.getDefaultVoicePhoneId());
412
Meng Wang9053f172017-06-23 16:02:14 -0700413 mDeviceId = (TextView) findViewById(R.id.imei);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800414 number = (TextView) findViewById(R.id.number);
Meng Wang9053f172017-06-23 16:02:14 -0700415 mSubscriberId = (TextView) findViewById(R.id.imsi);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800416 callState = (TextView) findViewById(R.id.call);
417 operatorName = (TextView) findViewById(R.id.operator);
418 roamingState = (TextView) findViewById(R.id.roaming);
419 gsmState = (TextView) findViewById(R.id.gsm);
420 gprsState = (TextView) findViewById(R.id.gprs);
Nathan Harold2b77d742016-03-19 13:22:10 -0700421 voiceNetwork = (TextView) findViewById(R.id.voice_network);
422 dataNetwork = (TextView) findViewById(R.id.data_network);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800423 dBm = (TextView) findViewById(R.id.dbm);
424 mMwi = (TextView) findViewById(R.id.mwi);
425 mCfi = (TextView) findViewById(R.id.cfi);
426 mLocation = (TextView) findViewById(R.id.location);
Wink Saville79bff2a2012-06-01 14:37:21 -0700427 mCellInfo = (TextView) findViewById(R.id.cellinfo);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800428 mCellInfo.setTypeface(Typeface.MONOSPACE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800429
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800430 sent = (TextView) findViewById(R.id.sent);
431 received = (TextView) findViewById(R.id.received);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800432 smsc = (EditText) findViewById(R.id.smsc);
433 dnsCheckState = (TextView) findViewById(R.id.dnsCheckState);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800434 mPingHostnameV4 = (TextView) findViewById(R.id.pingHostnameV4);
435 mPingHostnameV6 = (TextView) findViewById(R.id.pingHostnameV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800436 mHttpClientTest = (TextView) findViewById(R.id.httpClientTest);
437
Nathan Harold433ca442018-04-23 18:20:43 -0700438 mPhyChanConfig = (TextView) findViewById(R.id.phy_chan_config);
439
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800440 preferredNetworkType = (Spinner) findViewById(R.id.preferredNetworkType);
441 ArrayAdapter<String> adapter = new ArrayAdapter<String> (this,
442 android.R.layout.simple_spinner_item, mPreferredNetworkLabels);
johnwang342101a2009-09-23 16:22:34 -0700443 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800444 preferredNetworkType.setAdapter(adapter);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800445
Nathan Harold2b77d742016-03-19 13:22:10 -0700446 cellInfoRefreshRateSpinner = (Spinner) findViewById(R.id.cell_info_rate_select);
447 ArrayAdapter<String> cellInfoAdapter = new ArrayAdapter<String>(this,
448 android.R.layout.simple_spinner_item, mCellInfoRefreshRateLabels);
449 cellInfoAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
450 cellInfoRefreshRateSpinner.setAdapter(cellInfoAdapter);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800451
Nathan Harold12e1f552016-06-17 13:55:38 -0700452 imsVolteProvisionedSwitch = (Switch) findViewById(R.id.volte_provisioned_switch);
453 imsVtProvisionedSwitch = (Switch) findViewById(R.id.vt_provisioned_switch);
454 imsWfcProvisionedSwitch = (Switch) findViewById(R.id.wfc_provisioned_switch);
Meng Wang69439b52017-05-01 08:31:14 -0700455 eabProvisionedSwitch = (Switch) findViewById(R.id.eab_provisioned_switch);
Wink Savillebf471282013-04-05 15:04:05 -0700456
Nathan Harold2b77d742016-03-19 13:22:10 -0700457 radioPowerOnSwitch = (Switch) findViewById(R.id.radio_power);
Wink Saville426fc662011-09-25 14:39:02 -0700458
Nathan Haroldf10ea322018-04-24 13:31:07 -0700459 mDownlinkKbps = (TextView) findViewById(R.id.dl_kbps);
460 mUplinkKbps = (TextView) findViewById(R.id.ul_kbps);
461 updateBandwidths(0, 0);
462
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800463 pingTestButton = (Button) findViewById(R.id.ping_test);
464 pingTestButton.setOnClickListener(mPingButtonHandler);
465 updateSmscButton = (Button) findViewById(R.id.update_smsc);
466 updateSmscButton.setOnClickListener(mUpdateSmscButtonHandler);
467 refreshSmscButton = (Button) findViewById(R.id.refresh_smsc);
468 refreshSmscButton.setOnClickListener(mRefreshSmscButtonHandler);
469 dnsCheckToggleButton = (Button) findViewById(R.id.dns_check_toggle);
470 dnsCheckToggleButton.setOnClickListener(mDnsCheckButtonHandler);
Youhan Wangfd781e92016-12-16 15:53:16 -0800471 carrierProvisioningButton = (Button) findViewById(R.id.carrier_provisioning);
472 carrierProvisioningButton.setOnClickListener(mCarrierProvisioningButtonHandler);
473 triggercarrierProvisioningButton = (Button) findViewById(R.id.trigger_carrier_provisioning);
474 triggercarrierProvisioningButton.setOnClickListener(
475 mTriggerCarrierProvisioningButtonHandler);
johnwang342101a2009-09-23 16:22:34 -0700476
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800477 oemInfoButton = (Button) findViewById(R.id.oem_info);
478 oemInfoButton.setOnClickListener(mOemInfoButtonHandler);
479 PackageManager pm = getPackageManager();
480 Intent oemInfoIntent = new Intent("com.android.settings.OEM_RADIO_INFO");
481 List<ResolveInfo> oemInfoIntentList = pm.queryIntentActivities(oemInfoIntent, 0);
482 if (oemInfoIntentList.size() == 0) {
483 oemInfoButton.setEnabled(false);
484 }
485
Nathan Harolded38afa2016-04-13 00:29:30 -0700486 mCellInfoRefreshRateIndex = 0; //disabled
Nathan Haroldcea413a2015-11-23 15:48:10 -0800487 mPreferredNetworkTypeResult = mPreferredNetworkLabels.length - 1; //Unknown
488
489 //FIXME: Replace with TelephonyManager call
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800490 phone.getPreferredNetworkType(
491 mHandler.obtainMessage(EVENT_QUERY_PREFERRED_TYPE_DONE));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800492
Nathan Haroldcea413a2015-11-23 15:48:10 -0800493 restoreFromBundle(icicle);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800494 }
495
496 @Override
497 protected void onResume() {
498 super.onResume();
499
Nathan Haroldcea413a2015-11-23 15:48:10 -0800500 log("Started onResume");
501
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800502 updateMessageWaiting();
503 updateCallRedirect();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800504 updateDataState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800505 updateDataStats2();
Nathan Harold2b77d742016-03-19 13:22:10 -0700506 updateRadioPowerState();
Nathan Harold12e1f552016-06-17 13:55:38 -0700507 updateImsProvisionedState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800508 updateProperties();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800509 updateDnsCheckState();
Nathan Harold2b77d742016-03-19 13:22:10 -0700510 updateNetworkType();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800511
Nathan Haroldcea413a2015-11-23 15:48:10 -0800512 updateLocation(mCellLocationResult);
513 updateCellInfo(mCellInfoResult);
514
515 mPingHostnameV4.setText(mPingHostnameResultV4);
516 mPingHostnameV6.setText(mPingHostnameResultV6);
517 mHttpClientTest.setText(mHttpClientTestResult);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800518
Nathan Harold2b77d742016-03-19 13:22:10 -0700519 cellInfoRefreshRateSpinner.setOnItemSelectedListener(mCellInfoRefreshRateHandler);
Nathan Harolded38afa2016-04-13 00:29:30 -0700520 //set selection after registering listener to force update
521 cellInfoRefreshRateSpinner.setSelection(mCellInfoRefreshRateIndex);
522
523 //set selection before registering to prevent update
524 preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true);
Nathan Harold2b77d742016-03-19 13:22:10 -0700525 preferredNetworkType.setOnItemSelectedListener(mPreferredNetworkHandler);
Nathan Harolded38afa2016-04-13 00:29:30 -0700526
Nathan Harold2b77d742016-03-19 13:22:10 -0700527 radioPowerOnSwitch.setOnCheckedChangeListener(mRadioPowerOnChangeListener);
Nathan Harold12e1f552016-06-17 13:55:38 -0700528 imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
529 imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
530 imsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
Meng Wang586741c2017-04-26 15:02:51 -0700531 eabProvisionedSwitch.setOnCheckedChangeListener(mEabCheckedChangeListener);
Nathan Harold2b77d742016-03-19 13:22:10 -0700532
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800533 mTelephonyManager.listen(mPhoneStateListener,
Nathan Harold2b77d742016-03-19 13:22:10 -0700534 PhoneStateListener.LISTEN_CALL_STATE
535 //b/27803938 - RadioInfo currently cannot read PRECISE_CALL_STATE
536 // | PhoneStateListener.LISTEN_PRECISE_CALL_STATE
537 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800538 | PhoneStateListener.LISTEN_DATA_ACTIVITY
539 | PhoneStateListener.LISTEN_CELL_LOCATION
540 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
Wink Saville79bff2a2012-06-01 14:37:21 -0700541 | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
Wink Saville4f0d8812014-04-15 22:05:24 -0700542 | PhoneStateListener.LISTEN_CELL_INFO
Nathan Harold2b77d742016-03-19 13:22:10 -0700543 | PhoneStateListener.LISTEN_SERVICE_STATE
544 | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
Nathan Harold433ca442018-04-23 18:20:43 -0700545 | PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION);
Nathan Harolded38afa2016-04-13 00:29:30 -0700546
Nathan Haroldf10ea322018-04-24 13:31:07 -0700547 mConnectivityManager.registerNetworkCallback(
548 mDefaultNetworkRequest, mNetworkCallback, mHandler);
549
Nathan Harolded38afa2016-04-13 00:29:30 -0700550 smsc.clearFocus();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800551 }
552
553 @Override
Nathan Haroldcea413a2015-11-23 15:48:10 -0800554 protected void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800555 super.onPause();
556
Wink Savillebf471282013-04-05 15:04:05 -0700557 log("onPause: unregister phone & data intents");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800558
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800559 mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
Sooraj Sasindran5cce06b2016-08-18 15:49:49 -0700560 mTelephonyManager.setCellInfoListRate(CELL_INFO_LIST_RATE_DISABLED);
Nathan Haroldf10ea322018-04-24 13:31:07 -0700561 mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
562
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800563 }
564
Nathan Haroldcea413a2015-11-23 15:48:10 -0800565 private void restoreFromBundle(Bundle b) {
Nathan Harolde272c202016-10-27 13:45:00 -0700566 if(b == null) {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800567 return;
568 }
569
570 mPingHostnameResultV4 = b.getString("mPingHostnameResultV4","");
571 mPingHostnameResultV6 = b.getString("mPingHostnameResultV6","");
572 mHttpClientTestResult = b.getString("mHttpClientTestResult","");
573
574 mPingHostnameV4.setText(mPingHostnameResultV4);
575 mPingHostnameV6.setText(mPingHostnameResultV6);
576 mHttpClientTest.setText(mHttpClientTestResult);
577
Nathan Harold2b77d742016-03-19 13:22:10 -0700578 mPreferredNetworkTypeResult = b.getInt("mPreferredNetworkTypeResult",
579 mPreferredNetworkLabels.length - 1);
580
581 mCellInfoRefreshRateIndex = b.getInt("mCellInfoRefreshRateIndex", 0);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800582 }
583
584 @Override
585 protected void onSaveInstanceState(Bundle outState) {
586 outState.putString("mPingHostnameResultV4", mPingHostnameResultV4);
587 outState.putString("mPingHostnameResultV6", mPingHostnameResultV6);
588 outState.putString("mHttpClientTestResult", mHttpClientTestResult);
Nathan Harold2b77d742016-03-19 13:22:10 -0700589
Nathan Haroldcea413a2015-11-23 15:48:10 -0800590 outState.putInt("mPreferredNetworkTypeResult", mPreferredNetworkTypeResult);
Nathan Harold2b77d742016-03-19 13:22:10 -0700591 outState.putInt("mCellInfoRefreshRateIndex", mCellInfoRefreshRateIndex);
592
Nathan Haroldcea413a2015-11-23 15:48:10 -0800593 }
594
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800595 @Override
596 public boolean onCreateOptionsMenu(Menu menu) {
Wink Savillec3886682009-04-02 11:00:56 -0700597 menu.add(0, MENU_ITEM_SELECT_BAND, 0, R.string.radio_info_band_mode_label)
598 .setOnMenuItemClickListener(mSelectBandCallback)
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800599 .setAlphabeticShortcut('b');
600 menu.add(1, MENU_ITEM_VIEW_ADN, 0,
601 R.string.radioInfo_menu_viewADN).setOnMenuItemClickListener(mViewADNCallback);
602 menu.add(1, MENU_ITEM_VIEW_FDN, 0,
603 R.string.radioInfo_menu_viewFDN).setOnMenuItemClickListener(mViewFDNCallback);
604 menu.add(1, MENU_ITEM_VIEW_SDN, 0,
605 R.string.radioInfo_menu_viewSDN).setOnMenuItemClickListener(mViewSDNCallback);
Nathan Harolde272c202016-10-27 13:45:00 -0700606 menu.add(1, MENU_ITEM_GET_IMS_STATUS,
607 0, R.string.radioInfo_menu_getIMS).setOnMenuItemClickListener(mGetImsStatus);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800608 menu.add(1, MENU_ITEM_TOGGLE_DATA,
Nathan Harold2b77d742016-03-19 13:22:10 -0700609 0, R.string.radio_info_data_connection_disable).setOnMenuItemClickListener(mToggleData);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800610 return true;
611 }
612
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800613 @Override
Wink Savillec3886682009-04-02 11:00:56 -0700614 public boolean onPrepareOptionsMenu(Menu menu) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800615 // Get the TOGGLE DATA menu item in the right state.
616 MenuItem item = menu.findItem(MENU_ITEM_TOGGLE_DATA);
617 int state = mTelephonyManager.getDataState();
618 boolean visible = true;
619
620 switch (state) {
621 case TelephonyManager.DATA_CONNECTED:
622 case TelephonyManager.DATA_SUSPENDED:
Nathan Harold2b77d742016-03-19 13:22:10 -0700623 item.setTitle(R.string.radio_info_data_connection_disable);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800624 break;
625 case TelephonyManager.DATA_DISCONNECTED:
Nathan Harold2b77d742016-03-19 13:22:10 -0700626 item.setTitle(R.string.radio_info_data_connection_enable);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800627 break;
628 default:
629 visible = false;
630 break;
631 }
632 item.setVisible(visible);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800633 return true;
634 }
635
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800636 private void updateDnsCheckState() {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800637 //FIXME: Replace with a TelephonyManager call
Mike Lockwood5304c7e2009-04-05 11:37:45 -0700638 dnsCheckState.setText(phone.isDnsCheckDisabled() ?
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800639 "0.0.0.0 allowed" :"0.0.0.0 not allowed");
640 }
Wink Savillee2a14e32009-05-29 14:06:30 -0700641
Nathan Haroldf10ea322018-04-24 13:31:07 -0700642 private void updateBandwidths(int dlbw, int ulbw) {
643 dlbw = (dlbw < 0 || dlbw == Integer.MAX_VALUE) ? -1 : dlbw;
644 ulbw = (ulbw < 0 || ulbw == Integer.MAX_VALUE) ? -1 : ulbw;
645 mDownlinkKbps.setText(String.format("%-5d", dlbw));
646 mUplinkKbps.setText(String.format("%-5d", ulbw));
647 }
648
649
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800650 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -0700651 updateSignalStrength(SignalStrength signalStrength) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800652 Resources r = getResources();
653
Nathan Harold2b77d742016-03-19 13:22:10 -0700654 int signalDbm = signalStrength.getDbm();
Wink Savillee2a14e32009-05-29 14:06:30 -0700655
Nathan Harold2b77d742016-03-19 13:22:10 -0700656 int signalAsu = signalStrength.getAsuLevel();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800657
658 if (-1 == signalAsu) signalAsu = 0;
659
660 dBm.setText(String.valueOf(signalDbm) + " "
661 + r.getString(R.string.radioInfo_display_dbm) + " "
662 + String.valueOf(signalAsu) + " "
663 + r.getString(R.string.radioInfo_display_asu));
664 }
665
666 private final void updateLocation(CellLocation location) {
jsh534f5ae2009-09-24 09:19:22 -0700667 Resources r = getResources();
Wink Savillec3886682009-04-02 11:00:56 -0700668 if (location instanceof GsmCellLocation) {
669 GsmCellLocation loc = (GsmCellLocation)location;
jsh534f5ae2009-09-24 09:19:22 -0700670 int lac = loc.getLac();
671 int cid = loc.getCid();
672 mLocation.setText(r.getString(R.string.radioInfo_lac) + " = "
673 + ((lac == -1) ? "unknown" : Integer.toHexString(lac))
674 + " "
675 + r.getString(R.string.radioInfo_cid) + " = "
676 + ((cid == -1) ? "unknown" : Integer.toHexString(cid)));
677 } else if (location instanceof CdmaCellLocation) {
678 CdmaCellLocation loc = (CdmaCellLocation)location;
679 int bid = loc.getBaseStationId();
680 int sid = loc.getSystemId();
681 int nid = loc.getNetworkId();
682 int lat = loc.getBaseStationLatitude();
683 int lon = loc.getBaseStationLongitude();
684 mLocation.setText("BID = "
685 + ((bid == -1) ? "unknown" : Integer.toHexString(bid))
686 + " "
687 + "SID = "
688 + ((sid == -1) ? "unknown" : Integer.toHexString(sid))
689 + " "
690 + "NID = "
691 + ((nid == -1) ? "unknown" : Integer.toHexString(nid))
692 + "\n"
693 + "LAT = "
694 + ((lat == -1) ? "unknown" : Integer.toHexString(lat))
695 + " "
696 + "LONG = "
697 + ((lon == -1) ? "unknown" : Integer.toHexString(lon)));
698 } else {
699 mLocation.setText("unknown");
Wink Savillec3886682009-04-02 11:00:56 -0700700 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800701
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800702
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800703 }
704
Nathan Haroldcea413a2015-11-23 15:48:10 -0800705 private final String getCellInfoDisplayString(int i) {
706 return (i != Integer.MAX_VALUE) ? Integer.toString(i) : "";
707 }
708
709 private final String getCellInfoDisplayString(long i) {
710 return (i != Long.MAX_VALUE) ? Long.toString(i) : "";
711 }
712
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700713 private final String getConnectionStatusString(CellInfo ci) {
714 String regStr = "";
715 String connStatStr = "";
716 String connector = "";
717
718 if (ci.isRegistered()) {
719 regStr = "R";
720 }
721 switch (ci.getCellConnectionStatus()) {
722 case CellInfo.CONNECTION_PRIMARY_SERVING: connStatStr = "P"; break;
723 case CellInfo.CONNECTION_SECONDARY_SERVING: connStatStr = "S"; break;
724 case CellInfo.CONNECTION_NONE: connStatStr = "N"; break;
725 case CellInfo.CONNECTION_UNKNOWN: /* Field is unsupported */ break;
726 default: break;
727 }
728 if (!TextUtils.isEmpty(regStr) && !TextUtils.isEmpty(connStatStr)) {
729 connector = "+";
730 }
731
732 return regStr + connector + connStatStr;
733 }
734
Nathan Haroldcea413a2015-11-23 15:48:10 -0800735 private final String buildCdmaInfoString(CellInfoCdma ci) {
736 CellIdentityCdma cidCdma = ci.getCellIdentity();
737 CellSignalStrengthCdma ssCdma = ci.getCellSignalStrength();
738
739 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 -0700740 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800741 getCellInfoDisplayString(cidCdma.getSystemId()),
742 getCellInfoDisplayString(cidCdma.getNetworkId()),
743 getCellInfoDisplayString(cidCdma.getBasestationId()),
744 getCellInfoDisplayString(ssCdma.getCdmaDbm()),
745 getCellInfoDisplayString(ssCdma.getCdmaEcio()),
746 getCellInfoDisplayString(ssCdma.getEvdoDbm()),
747 getCellInfoDisplayString(ssCdma.getEvdoEcio()),
748 getCellInfoDisplayString(ssCdma.getEvdoSnr()));
749 }
750
751 private final String buildGsmInfoString(CellInfoGsm ci) {
752 CellIdentityGsm cidGsm = ci.getCellIdentity();
753 CellSignalStrengthGsm ssGsm = ci.getCellSignalStrength();
754
Nathan Harold2b77d742016-03-19 13:22:10 -0700755 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 -0700756 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800757 getCellInfoDisplayString(cidGsm.getMcc()),
758 getCellInfoDisplayString(cidGsm.getMnc()),
759 getCellInfoDisplayString(cidGsm.getLac()),
760 getCellInfoDisplayString(cidGsm.getCid()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700761 getCellInfoDisplayString(cidGsm.getArfcn()),
762 getCellInfoDisplayString(cidGsm.getBsic()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800763 getCellInfoDisplayString(ssGsm.getDbm()));
764 }
765
766 private final String buildLteInfoString(CellInfoLte ci) {
767 CellIdentityLte cidLte = ci.getCellIdentity();
768 CellSignalStrengthLte ssLte = ci.getCellSignalStrength();
769
770 return String.format(
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700771 "%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s %-6.6s %-2.2s %-4.4s %-4.4s %-2.2s\n",
772 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800773 getCellInfoDisplayString(cidLte.getMcc()),
774 getCellInfoDisplayString(cidLte.getMnc()),
775 getCellInfoDisplayString(cidLte.getTac()),
776 getCellInfoDisplayString(cidLte.getCi()),
777 getCellInfoDisplayString(cidLte.getPci()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700778 getCellInfoDisplayString(cidLte.getEarfcn()),
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700779 getCellInfoDisplayString(cidLte.getBandwidth()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800780 getCellInfoDisplayString(ssLte.getDbm()),
781 getCellInfoDisplayString(ssLte.getRsrq()),
782 getCellInfoDisplayString(ssLte.getTimingAdvance()));
783 }
784
785 private final String buildWcdmaInfoString(CellInfoWcdma ci) {
786 CellIdentityWcdma cidWcdma = ci.getCellIdentity();
787 CellSignalStrengthWcdma ssWcdma = ci.getCellSignalStrength();
788
Nathan Harold2b77d742016-03-19 13:22:10 -0700789 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 -0700790 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800791 getCellInfoDisplayString(cidWcdma.getMcc()),
792 getCellInfoDisplayString(cidWcdma.getMnc()),
793 getCellInfoDisplayString(cidWcdma.getLac()),
794 getCellInfoDisplayString(cidWcdma.getCid()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700795 getCellInfoDisplayString(cidWcdma.getUarfcn()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800796 getCellInfoDisplayString(cidWcdma.getPsc()),
797 getCellInfoDisplayString(ssWcdma.getDbm()));
798 }
799
800 private final String buildCellInfoString(List<CellInfo> arrayCi) {
801 String value = new String();
802 StringBuilder cdmaCells = new StringBuilder(),
803 gsmCells = new StringBuilder(),
804 lteCells = new StringBuilder(),
805 wcdmaCells = new StringBuilder();
806
807 if (arrayCi != null) {
808 for (CellInfo ci : arrayCi) {
809
810 if (ci instanceof CellInfoLte) {
811 lteCells.append(buildLteInfoString((CellInfoLte) ci));
812 } else if (ci instanceof CellInfoWcdma) {
813 wcdmaCells.append(buildWcdmaInfoString((CellInfoWcdma) ci));
814 } else if (ci instanceof CellInfoGsm) {
815 gsmCells.append(buildGsmInfoString((CellInfoGsm) ci));
816 } else if (ci instanceof CellInfoCdma) {
817 cdmaCells.append(buildCdmaInfoString((CellInfoCdma) ci));
Wink Saville79bff2a2012-06-01 14:37:21 -0700818 }
819 }
Nathan Haroldcea413a2015-11-23 15:48:10 -0800820 if (lteCells.length() != 0) {
821 value += String.format(
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700822 "LTE\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s"
823 + " %-6.6s %-2.2s %-4.4s %-4.4s %-2.2s\n",
824 "SRV", "MCC", "MNC", "TAC", "CID", "PCI",
825 "EARFCN", "BW", "RSRP", "RSRQ", "TA");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800826 value += lteCells.toString();
827 }
828 if (wcdmaCells.length() != 0) {
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700829 value += String.format(
830 "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 -0700831 "SRV", "MCC", "MNC", "LAC", "CID", "UARFCN", "PSC", "RSCP");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800832 value += wcdmaCells.toString();
833 }
834 if (gsmCells.length() != 0) {
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700835 value += String.format(
836 "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 -0700837 "SRV", "MCC", "MNC", "LAC", "CID", "ARFCN", "BSIC", "RSSI");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800838 value += gsmCells.toString();
839 }
840 if (cdmaCells.length() != 0) {
841 value += String.format(
842 "CDMA/EVDO\n%-3.3s %-5.5s %-5.5s %-5.5s %-6.6s %-6.6s %-6.6s %-6.6s %-5.5s\n",
843 "SRV", "SID", "NID", "BSID", "C-RSSI", "C-ECIO", "E-RSSI", "E-ECIO", "E-SNR");
844 value += cdmaCells.toString();
845 }
846 } else {
847 value ="unknown";
Wink Saville79bff2a2012-06-01 14:37:21 -0700848 }
Nathan Haroldcea413a2015-11-23 15:48:10 -0800849
850 return value.toString();
851 }
852
853 private final void updateCellInfo(List<CellInfo> arrayCi) {
854 mCellInfo.setText(buildCellInfoString(arrayCi));
Wink Saville79bff2a2012-06-01 14:37:21 -0700855 }
856
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800857 private final void
858 updateMessageWaiting() {
859 mMwi.setText(String.valueOf(mMwiValue));
860 }
861
862 private final void
863 updateCallRedirect() {
864 mCfi.setText(String.valueOf(mCfiValue));
865 }
866
867
868 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -0700869 updateServiceState(ServiceState serviceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800870 int state = serviceState.getState();
871 Resources r = getResources();
872 String display = r.getString(R.string.radioInfo_unknown);
johnwang342101a2009-09-23 16:22:34 -0700873
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800874 switch (state) {
875 case ServiceState.STATE_IN_SERVICE:
876 display = r.getString(R.string.radioInfo_service_in);
877 break;
878 case ServiceState.STATE_OUT_OF_SERVICE:
879 case ServiceState.STATE_EMERGENCY_ONLY:
880 display = r.getString(R.string.radioInfo_service_emergency);
881 break;
882 case ServiceState.STATE_POWER_OFF:
883 display = r.getString(R.string.radioInfo_service_off);
884 break;
885 }
johnwang342101a2009-09-23 16:22:34 -0700886
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800887 gsmState.setText(display);
johnwang342101a2009-09-23 16:22:34 -0700888
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800889 if (serviceState.getRoaming()) {
890 roamingState.setText(R.string.radioInfo_roaming_in);
891 } else {
892 roamingState.setText(R.string.radioInfo_roaming_not);
893 }
894
895 operatorName.setText(serviceState.getOperatorAlphaLong());
896 }
897
898 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -0700899 updatePhoneState(int state) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800900 Resources r = getResources();
901 String display = r.getString(R.string.radioInfo_unknown);
902
903 switch (state) {
Nathan Harold2b77d742016-03-19 13:22:10 -0700904 case TelephonyManager.CALL_STATE_IDLE:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800905 display = r.getString(R.string.radioInfo_phone_idle);
906 break;
Nathan Harold2b77d742016-03-19 13:22:10 -0700907 case TelephonyManager.CALL_STATE_RINGING:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800908 display = r.getString(R.string.radioInfo_phone_ringing);
909 break;
Nathan Harold2b77d742016-03-19 13:22:10 -0700910 case TelephonyManager.CALL_STATE_OFFHOOK:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800911 display = r.getString(R.string.radioInfo_phone_offhook);
912 break;
913 }
914
915 callState.setText(display);
916 }
917
918 private final void
919 updateDataState() {
920 int state = mTelephonyManager.getDataState();
921 Resources r = getResources();
922 String display = r.getString(R.string.radioInfo_unknown);
923
924 switch (state) {
925 case TelephonyManager.DATA_CONNECTED:
926 display = r.getString(R.string.radioInfo_data_connected);
927 break;
928 case TelephonyManager.DATA_CONNECTING:
929 display = r.getString(R.string.radioInfo_data_connecting);
930 break;
931 case TelephonyManager.DATA_DISCONNECTED:
932 display = r.getString(R.string.radioInfo_data_disconnected);
933 break;
934 case TelephonyManager.DATA_SUSPENDED:
935 display = r.getString(R.string.radioInfo_data_suspended);
936 break;
937 }
johnwang342101a2009-09-23 16:22:34 -0700938
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800939 gprsState.setText(display);
940 }
941
942 private final void updateNetworkType() {
Nathan Harolde272c202016-10-27 13:45:00 -0700943 if(phone != null) {
Nathan Harold2b77d742016-03-19 13:22:10 -0700944 ServiceState ss = phone.getServiceState();
945 dataNetwork.setText(ServiceState.rilRadioTechnologyToString(
946 phone.getServiceState().getRilDataRadioTechnology()));
947 voiceNetwork.setText(ServiceState.rilRadioTechnologyToString(
948 phone.getServiceState().getRilVoiceRadioTechnology()));
949 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800950 }
951
952 private final void
953 updateProperties() {
954 String s;
955 Resources r = getResources();
956
957 s = phone.getDeviceId();
johnwang342101a2009-09-23 16:22:34 -0700958 if (s == null) s = r.getString(R.string.radioInfo_unknown);
Wink Savillec3886682009-04-02 11:00:56 -0700959 mDeviceId.setText(s);
johnwang342101a2009-09-23 16:22:34 -0700960
Meng Wang9053f172017-06-23 16:02:14 -0700961 s = phone.getSubscriberId();
962 if (s == null) s = r.getString(R.string.radioInfo_unknown);
963 mSubscriberId.setText(s);
964
Nathan Haroldcea413a2015-11-23 15:48:10 -0800965 //FIXME: Replace with a TelephonyManager call
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800966 s = phone.getLine1Number();
johnwang342101a2009-09-23 16:22:34 -0700967 if (s == null) s = r.getString(R.string.radioInfo_unknown);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800968 number.setText(s);
969 }
970
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800971 private final void updateDataStats2() {
972 Resources r = getResources();
973
Jeff Sharkey93029862011-05-27 18:26:15 -0700974 long txPackets = TrafficStats.getMobileTxPackets();
975 long rxPackets = TrafficStats.getMobileRxPackets();
976 long txBytes = TrafficStats.getMobileTxBytes();
977 long rxBytes = TrafficStats.getMobileRxBytes();
johnwang342101a2009-09-23 16:22:34 -0700978
Jeff Sharkey93029862011-05-27 18:26:15 -0700979 String packets = r.getString(R.string.radioInfo_display_packets);
980 String bytes = r.getString(R.string.radioInfo_display_bytes);
johnwang342101a2009-09-23 16:22:34 -0700981
Jeff Sharkey93029862011-05-27 18:26:15 -0700982 sent.setText(txPackets + " " + packets + ", " + txBytes + " " + bytes);
983 received.setText(rxPackets + " " + packets + ", " + rxBytes + " " + bytes);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800984 }
985
986 /**
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800987 * Ping a host name
988 */
989 private final void pingHostname() {
990 try {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800991 try {
992 Process p4 = Runtime.getRuntime().exec("ping -c 1 www.google.com");
993 int status4 = p4.waitFor();
994 if (status4 == 0) {
995 mPingHostnameResultV4 = "Pass";
996 } else {
997 mPingHostnameResultV4 = String.format("Fail(%d)", status4);
998 }
999 } catch (IOException e) {
1000 mPingHostnameResultV4 = "Fail: IOException";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001001 }
Nathan Haroldcea413a2015-11-23 15:48:10 -08001002 try {
1003 Process p6 = Runtime.getRuntime().exec("ping6 -c 1 www.google.com");
1004 int status6 = p6.waitFor();
1005 if (status6 == 0) {
1006 mPingHostnameResultV6 = "Pass";
1007 } else {
1008 mPingHostnameResultV6 = String.format("Fail(%d)", status6);
1009 }
1010 } catch (IOException e) {
1011 mPingHostnameResultV6 = "Fail: IOException";
1012 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001013 } catch (InterruptedException e) {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001014 mPingHostnameResultV4 = mPingHostnameResultV6 = "Fail: InterruptedException";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001015 }
1016 }
1017
1018 /**
1019 * This function checks for basic functionality of HTTP Client.
1020 */
1021 private void httpClientTest() {
Narayan Kamathf25627c2014-12-12 13:53:28 +00001022 HttpURLConnection urlConnection = null;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001023 try {
Narayan Kamathf25627c2014-12-12 13:53:28 +00001024 // TODO: Hardcoded for now, make it UI configurable
Alex Klyubinb0090232015-04-02 11:08:51 -07001025 URL url = new URL("https://www.google.com");
Narayan Kamathf25627c2014-12-12 13:53:28 +00001026 urlConnection = (HttpURLConnection) url.openConnection();
1027 if (urlConnection.getResponseCode() == 200) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001028 mHttpClientTestResult = "Pass";
1029 } else {
Narayan Kamathf25627c2014-12-12 13:53:28 +00001030 mHttpClientTestResult = "Fail: Code: " + urlConnection.getResponseMessage();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001031 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001032 } catch (IOException e) {
1033 mHttpClientTestResult = "Fail: IOException";
Narayan Kamathf25627c2014-12-12 13:53:28 +00001034 } finally {
1035 if (urlConnection != null) {
1036 urlConnection.disconnect();
1037 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001038 }
1039 }
1040
1041 private void refreshSmsc() {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001042 //FIXME: Replace with a TelephonyManager call
jsh21dd4072009-05-12 11:26:55 -07001043 phone.getSmscAddress(mHandler.obtainMessage(EVENT_QUERY_SMSC_DONE));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001044 }
1045
Nathan Haroldcea413a2015-11-23 15:48:10 -08001046 private final void updateAllCellInfo() {
1047
1048 mCellInfo.setText("");
Nathan Haroldcea413a2015-11-23 15:48:10 -08001049 mLocation.setText("");
1050
1051 final Runnable updateAllCellInfoResults = new Runnable() {
1052 public void run() {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001053 updateLocation(mCellLocationResult);
1054 updateCellInfo(mCellInfoResult);
1055 }
1056 };
1057
1058 Thread locThread = new Thread() {
1059 @Override
1060 public void run() {
1061 mCellInfoResult = mTelephonyManager.getAllCellInfo();
1062 mCellLocationResult = mTelephonyManager.getCellLocation();
Nathan Haroldcea413a2015-11-23 15:48:10 -08001063
1064 mHandler.post(updateAllCellInfoResults);
1065 }
1066 };
1067 locThread.start();
1068 }
1069
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001070 private final void updatePingState() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001071 // Set all to unknown since the threads will take a few secs to update.
Nathan Haroldcea413a2015-11-23 15:48:10 -08001072 mPingHostnameResultV4 = getResources().getString(R.string.radioInfo_unknown);
1073 mPingHostnameResultV6 = getResources().getString(R.string.radioInfo_unknown);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001074 mHttpClientTestResult = getResources().getString(R.string.radioInfo_unknown);
1075
Nathan Haroldcea413a2015-11-23 15:48:10 -08001076 mPingHostnameV4.setText(mPingHostnameResultV4);
1077 mPingHostnameV6.setText(mPingHostnameResultV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001078 mHttpClientTest.setText(mHttpClientTestResult);
1079
1080 final Runnable updatePingResults = new Runnable() {
1081 public void run() {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001082 mPingHostnameV4.setText(mPingHostnameResultV4);
1083 mPingHostnameV6.setText(mPingHostnameResultV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001084 mHttpClientTest.setText(mHttpClientTestResult);
1085 }
1086 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001087
1088 Thread hostname = new Thread() {
1089 @Override
1090 public void run() {
1091 pingHostname();
Nathan Haroldcea413a2015-11-23 15:48:10 -08001092 mHandler.post(updatePingResults);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001093 }
1094 };
1095 hostname.start();
1096
1097 Thread httpClient = new Thread() {
1098 @Override
1099 public void run() {
1100 httpClientTest();
Nathan Haroldcea413a2015-11-23 15:48:10 -08001101 mHandler.post(updatePingResults);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001102 }
1103 };
1104 httpClient.start();
1105 }
1106
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001107 private MenuItem.OnMenuItemClickListener mViewADNCallback = new MenuItem.OnMenuItemClickListener() {
1108 public boolean onMenuItemClick(MenuItem item) {
1109 Intent intent = new Intent(Intent.ACTION_VIEW);
1110 // XXX We need to specify the component here because if we don't
1111 // the activity manager will try to resolve the type by calling
1112 // the content provider, which causes it to be loaded in a process
1113 // other than the Dialer process, which causes a lot of stuff to
1114 // break.
1115 intent.setClassName("com.android.phone",
1116 "com.android.phone.SimContacts");
1117 startActivity(intent);
1118 return true;
1119 }
1120 };
1121
1122 private MenuItem.OnMenuItemClickListener mViewFDNCallback = new MenuItem.OnMenuItemClickListener() {
1123 public boolean onMenuItemClick(MenuItem item) {
1124 Intent intent = new Intent(Intent.ACTION_VIEW);
1125 // XXX We need to specify the component here because if we don't
1126 // the activity manager will try to resolve the type by calling
1127 // the content provider, which causes it to be loaded in a process
1128 // other than the Dialer process, which causes a lot of stuff to
1129 // break.
1130 intent.setClassName("com.android.phone",
Andrew Leeda90d682014-10-31 13:12:20 -07001131 "com.android.phone.settings.fdn.FdnList");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001132 startActivity(intent);
1133 return true;
1134 }
1135 };
1136
1137 private MenuItem.OnMenuItemClickListener mViewSDNCallback = new MenuItem.OnMenuItemClickListener() {
1138 public boolean onMenuItemClick(MenuItem item) {
1139 Intent intent = new Intent(
Wink Savillec3886682009-04-02 11:00:56 -07001140 Intent.ACTION_VIEW, Uri.parse("content://icc/sdn"));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001141 // XXX We need to specify the component here because if we don't
1142 // the activity manager will try to resolve the type by calling
1143 // the content provider, which causes it to be loaded in a process
1144 // other than the Dialer process, which causes a lot of stuff to
1145 // break.
1146 intent.setClassName("com.android.phone",
1147 "com.android.phone.ADNList");
1148 startActivity(intent);
1149 return true;
1150 }
1151 };
1152
Nathan Harolde272c202016-10-27 13:45:00 -07001153 private MenuItem.OnMenuItemClickListener mGetImsStatus = new MenuItem.OnMenuItemClickListener() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001154 public boolean onMenuItemClick(MenuItem item) {
Nathan Harolde272c202016-10-27 13:45:00 -07001155 boolean isImsRegistered = phone.isImsRegistered();
1156 boolean availableVolte = phone.isVolteEnabled();
1157 boolean availableWfc = phone.isWifiCallingEnabled();
1158 boolean availableVt = phone.isVideoEnabled();
1159 boolean availableUt = phone.isUtEnabled();
1160
1161 final String imsRegString = isImsRegistered ?
1162 getString(R.string.radio_info_ims_reg_status_registered) :
1163 getString(R.string.radio_info_ims_reg_status_not_registered);
1164
1165 final String available = getString(R.string.radio_info_ims_feature_status_available);
1166 final String unavailable = getString(
1167 R.string.radio_info_ims_feature_status_unavailable);
1168
1169 String imsStatus = getString(R.string.radio_info_ims_reg_status,
1170 imsRegString,
1171 availableVolte ? available : unavailable,
1172 availableWfc ? available : unavailable,
1173 availableVt ? available : unavailable,
1174 availableUt ? available : unavailable);
1175
1176 AlertDialog imsDialog = new AlertDialog.Builder(RadioInfo.this)
1177 .setMessage(imsStatus)
1178 .setTitle(getString(R.string.radio_info_ims_reg_status_title))
1179 .create();
1180
1181 imsDialog.show();
1182
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001183 return true;
1184 }
1185 };
1186
1187 private MenuItem.OnMenuItemClickListener mSelectBandCallback = new MenuItem.OnMenuItemClickListener() {
1188 public boolean onMenuItemClick(MenuItem item) {
1189 Intent intent = new Intent();
1190 intent.setClass(RadioInfo.this, BandMode.class);
1191 startActivity(intent);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001192 return true;
1193 }
1194 };
johnwang342101a2009-09-23 16:22:34 -07001195
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001196 private MenuItem.OnMenuItemClickListener mToggleData = new MenuItem.OnMenuItemClickListener() {
1197 public boolean onMenuItemClick(MenuItem item) {
1198 int state = mTelephonyManager.getDataState();
1199 switch (state) {
1200 case TelephonyManager.DATA_CONNECTED:
Nathan Haroldcea413a2015-11-23 15:48:10 -08001201 //FIXME: Replace with a TelephonyManager call
Malcolm Chenf612f592017-11-29 18:01:25 -08001202 phone.setUserDataEnabled(false);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001203 break;
1204 case TelephonyManager.DATA_DISCONNECTED:
Nathan Haroldcea413a2015-11-23 15:48:10 -08001205 //FIXME: Replace with a TelephonyManager call
Malcolm Chenf612f592017-11-29 18:01:25 -08001206 phone.setUserDataEnabled(true);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001207 break;
1208 default:
1209 // do nothing
1210 break;
1211 }
1212 return true;
1213 }
1214 };
1215
Nathan Harold2b77d742016-03-19 13:22:10 -07001216 private boolean isRadioOn() {
1217 //FIXME: Replace with a TelephonyManager call
1218 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1219 }
1220
1221 private void updateRadioPowerState() {
1222 //delightful hack to prevent on-checked-changed calls from
1223 //actually forcing the radio preference to its transient/current value.
1224 radioPowerOnSwitch.setOnCheckedChangeListener(null);
1225 radioPowerOnSwitch.setChecked(isRadioOn());
1226 radioPowerOnSwitch.setOnCheckedChangeListener(mRadioPowerOnChangeListener);
1227 }
1228
Nathan Harolde272c202016-10-27 13:45:00 -07001229 void setImsVolteProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001230 Log.d(TAG, "setImsVolteProvisioned state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001231 setImsConfigProvisionedState(IMS_VOLTE_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001232 }
1233
Nathan Harolde272c202016-10-27 13:45:00 -07001234 void setImsVtProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001235 Log.d(TAG, "setImsVtProvisioned() state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001236 setImsConfigProvisionedState(IMS_VT_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001237 }
1238
Nathan Harolde272c202016-10-27 13:45:00 -07001239 void setImsWfcProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001240 Log.d(TAG, "setImsWfcProvisioned() state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001241 setImsConfigProvisionedState(IMS_WFC_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001242 }
1243
Meng Wang586741c2017-04-26 15:02:51 -07001244 void setEabProvisionedState(boolean state) {
1245 Log.d(TAG, "setEabProvisioned() state: " + ((state)? "on":"off"));
1246 setImsConfigProvisionedState(EAB_PROVISIONED_CONFIG_ID, state);
1247 }
1248
Nathan Harolde272c202016-10-27 13:45:00 -07001249 void setImsConfigProvisionedState(int configItem, boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001250 if (phone != null && mImsManager != null) {
Philip P. Moltmann5c449ae2017-02-14 12:43:02 -08001251 QueuedWork.queue(new Runnable() {
Nathan Harold12e1f552016-06-17 13:55:38 -07001252 public void run() {
1253 try {
1254 mImsManager.getConfigInterface().setProvisionedValue(
1255 configItem,
1256 state? 1 : 0);
1257 } catch (ImsException e) {
1258 Log.e(TAG, "setImsConfigProvisioned() exception:", e);
1259 }
1260 }
Philip P. Moltmann5c449ae2017-02-14 12:43:02 -08001261 }, false);
Nathan Harold12e1f552016-06-17 13:55:38 -07001262 }
1263 }
1264
Nathan Harold2b77d742016-03-19 13:22:10 -07001265 OnCheckedChangeListener mRadioPowerOnChangeListener = new OnCheckedChangeListener() {
1266 @Override
1267 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1268 log("toggle radio power: currently " + (isRadioOn()?"on":"off"));
1269 phone.setRadioPower(isChecked);
1270 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001271 };
1272
Nathan Harold12e1f552016-06-17 13:55:38 -07001273 private boolean isImsVolteProvisioned() {
Nathan Harold2b77d742016-03-19 13:22:10 -07001274 if (phone != null && mImsManager != null) {
1275 return mImsManager.isVolteEnabledByPlatform(phone.getContext())
1276 && mImsManager.isVolteProvisionedOnDevice(phone.getContext());
Pavel Zhamaitsiakcb267a62015-01-21 18:25:14 -08001277 }
1278 return false;
1279 }
1280
Nathan Harold12e1f552016-06-17 13:55:38 -07001281 OnCheckedChangeListener mImsVolteCheckedChangeListener = new OnCheckedChangeListener() {
Wink Saville426fc662011-09-25 14:39:02 -07001282 @Override
Nathan Harold2b77d742016-03-19 13:22:10 -07001283 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001284 setImsVolteProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001285 }
Wink Saville426fc662011-09-25 14:39:02 -07001286 };
1287
Nathan Harold12e1f552016-06-17 13:55:38 -07001288 private boolean isImsVtProvisioned() {
1289 if (phone != null && mImsManager != null) {
1290 return mImsManager.isVtEnabledByPlatform(phone.getContext())
1291 && mImsManager.isVtProvisionedOnDevice(phone.getContext());
1292 }
1293 return false;
1294 }
1295
1296 OnCheckedChangeListener mImsVtCheckedChangeListener = new OnCheckedChangeListener() {
1297 @Override
1298 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1299 setImsVtProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001300 }
Nathan Harold12e1f552016-06-17 13:55:38 -07001301 };
1302
1303 private boolean isImsWfcProvisioned() {
1304 if (phone != null && mImsManager != null) {
1305 return mImsManager.isWfcEnabledByPlatform(phone.getContext())
1306 && mImsManager.isWfcProvisionedOnDevice(phone.getContext());
1307 }
1308 return false;
1309 }
1310
1311 OnCheckedChangeListener mImsWfcCheckedChangeListener = new OnCheckedChangeListener() {
1312 @Override
1313 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1314 setImsWfcProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001315 }
Nathan Harold12e1f552016-06-17 13:55:38 -07001316 };
1317
Meng Wang586741c2017-04-26 15:02:51 -07001318 private boolean isEabProvisioned() {
1319 return isFeatureProvisioned(EAB_PROVISIONED_CONFIG_ID, false);
1320 }
1321
1322 OnCheckedChangeListener mEabCheckedChangeListener = new OnCheckedChangeListener() {
1323 @Override
1324 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1325 setEabProvisionedState(isChecked);
1326 }
1327 };
1328
1329 private boolean isFeatureProvisioned(int featureId, boolean defaultValue) {
1330 boolean provisioned = defaultValue;
1331 if (mImsManager != null) {
1332 try {
1333 ImsConfig imsConfig = mImsManager.getConfigInterface();
1334 if (imsConfig != null) {
1335 provisioned =
1336 (imsConfig.getProvisionedValue(featureId)
1337 == ImsConfig.FeatureValueConstants.ON);
1338 }
1339 } catch (ImsException ex) {
1340 Log.e(TAG, "isFeatureProvisioned() exception:", ex);
1341 }
1342 }
1343
1344 log("isFeatureProvisioned() featureId=" + featureId + " provisioned=" + provisioned);
1345 return provisioned;
1346 }
1347
1348 private static boolean isEabEnabledByPlatform(Context context) {
1349 if (context != null) {
1350 CarrierConfigManager configManager = (CarrierConfigManager)
1351 context.getSystemService(Context.CARRIER_CONFIG_SERVICE);
1352 if (configManager != null && configManager.getConfig().getBoolean(
1353 CarrierConfigManager.KEY_USE_RCS_PRESENCE_BOOL)) {
1354 return true;
1355 }
1356 }
1357 return false;
1358 }
1359
Nathan Harold12e1f552016-06-17 13:55:38 -07001360 private void updateImsProvisionedState() {
1361 log("updateImsProvisionedState isImsVolteProvisioned()=" + isImsVolteProvisioned());
Nathan Harold2b77d742016-03-19 13:22:10 -07001362 //delightful hack to prevent on-checked-changed calls from
1363 //actually forcing the ims provisioning to its transient/current value.
Nathan Harold12e1f552016-06-17 13:55:38 -07001364 imsVolteProvisionedSwitch.setOnCheckedChangeListener(null);
1365 imsVolteProvisionedSwitch.setChecked(isImsVolteProvisioned());
1366 imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
Nathan Harold6dc15e92016-10-28 11:45:59 -07001367 imsVolteProvisionedSwitch.setEnabled(
1368 mImsManager.isVolteEnabledByPlatform(phone.getContext()));
Nathan Harold12e1f552016-06-17 13:55:38 -07001369
1370 imsVtProvisionedSwitch.setOnCheckedChangeListener(null);
1371 imsVtProvisionedSwitch.setChecked(isImsVtProvisioned());
1372 imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
Nathan Harold6dc15e92016-10-28 11:45:59 -07001373 imsVtProvisionedSwitch.setEnabled(
1374 mImsManager.isVtEnabledByPlatform(phone.getContext()));
Nathan Harold12e1f552016-06-17 13:55:38 -07001375
1376 imsWfcProvisionedSwitch.setOnCheckedChangeListener(null);
1377 imsWfcProvisionedSwitch.setChecked(isImsWfcProvisioned());
1378 imsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
Nathan Harold6dc15e92016-10-28 11:45:59 -07001379 imsWfcProvisionedSwitch.setEnabled(
1380 mImsManager.isWfcEnabledByPlatform(phone.getContext()));
Meng Wang586741c2017-04-26 15:02:51 -07001381
1382 eabProvisionedSwitch.setOnCheckedChangeListener(null);
1383 eabProvisionedSwitch.setChecked(isEabProvisioned());
1384 eabProvisionedSwitch.setOnCheckedChangeListener(mEabCheckedChangeListener);
1385 eabProvisionedSwitch.setEnabled(isEabEnabledByPlatform(phone.getContext()));
Wink Saville426fc662011-09-25 14:39:02 -07001386 }
1387
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001388 OnClickListener mDnsCheckButtonHandler = new OnClickListener() {
1389 public void onClick(View v) {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001390 //FIXME: Replace with a TelephonyManager call
Wink Savillec3886682009-04-02 11:00:56 -07001391 phone.disableDnsCheck(!phone.isDnsCheckDisabled());
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001392 updateDnsCheckState();
1393 }
1394 };
johnwang342101a2009-09-23 16:22:34 -07001395
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001396 OnClickListener mOemInfoButtonHandler = new OnClickListener() {
1397 public void onClick(View v) {
1398 Intent intent = new Intent("com.android.settings.OEM_RADIO_INFO");
1399 try {
1400 startActivity(intent);
1401 } catch (android.content.ActivityNotFoundException ex) {
Wink Savillebf471282013-04-05 15:04:05 -07001402 log("OEM-specific Info/Settings Activity Not Found : " + ex);
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001403 // If the activity does not exist, there are no OEM
1404 // settings, and so we can just do nothing...
1405 }
1406 }
1407 };
1408
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001409 OnClickListener mPingButtonHandler = new OnClickListener() {
1410 public void onClick(View v) {
1411 updatePingState();
1412 }
1413 };
1414
1415 OnClickListener mUpdateSmscButtonHandler = new OnClickListener() {
1416 public void onClick(View v) {
1417 updateSmscButton.setEnabled(false);
jsh21dd4072009-05-12 11:26:55 -07001418 phone.setSmscAddress(smsc.getText().toString(),
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001419 mHandler.obtainMessage(EVENT_UPDATE_SMSC_DONE));
1420 }
1421 };
1422
1423 OnClickListener mRefreshSmscButtonHandler = new OnClickListener() {
1424 public void onClick(View v) {
1425 refreshSmsc();
1426 }
1427 };
1428
Youhan Wangfd781e92016-12-16 15:53:16 -08001429 OnClickListener mCarrierProvisioningButtonHandler = new OnClickListener() {
1430 public void onClick(View v) {
Meng Wanga04449b2017-08-03 14:34:35 -07001431 final Intent intent = new Intent("com.android.settings.CARRIER_PROVISIONING");
1432 final ComponentName serviceComponent = ComponentName.unflattenFromString(
1433 "com.android.omadm.service/.DMIntentReceiver");
Youhan Wangfd781e92016-12-16 15:53:16 -08001434 intent.setComponent(serviceComponent);
Meng Wanga04449b2017-08-03 14:34:35 -07001435 sendBroadcast(intent);
Youhan Wangfd781e92016-12-16 15:53:16 -08001436 }
1437 };
1438
1439 OnClickListener mTriggerCarrierProvisioningButtonHandler = new OnClickListener() {
1440 public void onClick(View v) {
Meng Wanga04449b2017-08-03 14:34:35 -07001441 final Intent intent = new Intent("com.android.settings.TRIGGER_CARRIER_PROVISIONING");
1442 final ComponentName serviceComponent = ComponentName.unflattenFromString(
1443 "com.android.omadm.service/.DMIntentReceiver");
Youhan Wangfd781e92016-12-16 15:53:16 -08001444 intent.setComponent(serviceComponent);
Meng Wanga04449b2017-08-03 14:34:35 -07001445 sendBroadcast(intent);
Youhan Wangfd781e92016-12-16 15:53:16 -08001446 }
1447 };
1448
Nathan Haroldcea413a2015-11-23 15:48:10 -08001449 AdapterView.OnItemSelectedListener mPreferredNetworkHandler =
1450 new AdapterView.OnItemSelectedListener() {
1451
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001452 public void onItemSelected(AdapterView parent, View v, int pos, long id) {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001453 if (mPreferredNetworkTypeResult != pos && pos >= 0
1454 && pos <= mPreferredNetworkLabels.length - 2) {
1455 mPreferredNetworkTypeResult = pos;
Nathan Harolddaea8be2018-06-05 14:02:35 -07001456
1457 // TODO: Possibly migrate this to TelephonyManager.setPreferredNetworkType()
1458 // which today still has some issues (mostly that the "set" is conditional
1459 // on a successful modem call, which is not what we want). Instead we always
1460 // want this setting to be set, so that if the radio hiccups and this setting
1461 // is for some reason unsuccessful, future calls to the radio will reflect
1462 // the users's preference which is set here.
1463 final int subId = phone.getSubId();
1464 if (SubscriptionManager.isUsableSubIdValue(subId)) {
1465 Settings.Global.putInt(phone.getContext().getContentResolver(),
1466 PREFERRED_NETWORK_MODE + subId, mPreferredNetworkTypeResult);
1467 }
1468 log("Calling setPreferredNetworkType(" + mPreferredNetworkTypeResult + ")");
Nathan Haroldcea413a2015-11-23 15:48:10 -08001469 Message msg = mHandler.obtainMessage(EVENT_SET_PREFERRED_TYPE_DONE);
1470 phone.setPreferredNetworkType(mPreferredNetworkTypeResult, msg);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001471 }
1472 }
1473
1474 public void onNothingSelected(AdapterView parent) {
1475 }
1476 };
1477
Nathan Harold2b77d742016-03-19 13:22:10 -07001478 AdapterView.OnItemSelectedListener mCellInfoRefreshRateHandler =
1479 new AdapterView.OnItemSelectedListener() {
Wink Savillebf471282013-04-05 15:04:05 -07001480
Nathan Harold2b77d742016-03-19 13:22:10 -07001481 public void onItemSelected(AdapterView parent, View v, int pos, long id) {
1482 mCellInfoRefreshRateIndex = pos;
Sooraj Sasindran5cce06b2016-08-18 15:49:49 -07001483 mTelephonyManager.setCellInfoListRate(mCellInfoRefreshRates[pos]);
Nathan Harold2b77d742016-03-19 13:22:10 -07001484 updateAllCellInfo();
1485 }
1486
1487 public void onNothingSelected(AdapterView parent) {
1488 }
1489 };
1490
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001491}