blob: 8da507bdba4edede40dbd455f5fdfc4a4fb1404f [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;
Sreekanth Badidac888e192018-02-05 17:18:40 +010040import android.os.Build;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080041import android.os.Bundle;
42import android.os.Handler;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080043import android.os.Message;
Nathan Harolddaea8be2018-06-05 14:02:35 -070044import android.provider.Settings;
Meng Wang586741c2017-04-26 15:02:51 -070045import android.telephony.CarrierConfigManager;
Wink Saville79bff2a2012-06-01 14:37:21 -070046import android.telephony.CellInfo;
Nathan Haroldcea413a2015-11-23 15:48:10 -080047import android.telephony.CellInfoCdma;
48import android.telephony.CellInfoGsm;
49import android.telephony.CellInfoLte;
50import android.telephony.CellInfoWcdma;
51import android.telephony.CellIdentityCdma;
52import android.telephony.CellIdentityGsm;
53import android.telephony.CellIdentityLte;
54import android.telephony.CellIdentityWcdma;
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;
Nathan Harold2b77d742016-03-19 13:22:10 -070060import android.telephony.PreciseCallState;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080061import android.telephony.PhoneStateListener;
Nathan Harold433ca442018-04-23 18:20:43 -070062import android.telephony.PhysicalChannelConfig;
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
Jason Monk39b46742015-09-10 15:52:51 -040085import com.android.ims.ImsConfig;
86import com.android.ims.ImsException;
87import com.android.ims.ImsManager;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080088import com.android.internal.telephony.Phone;
Wink Saville55434042012-06-14 12:33:43 -070089import com.android.internal.telephony.PhoneConstants;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080090import com.android.internal.telephony.PhoneFactory;
Nathan Haroldcea413a2015-11-23 15:48:10 -080091import com.android.internal.telephony.RILConstants;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080092import com.android.internal.telephony.TelephonyProperties;
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.net.UnknownHostException;
98import java.util.ArrayList;
99import java.util.List;
100
101public class RadioInfo extends Activity {
Nathan Harold2b77d742016-03-19 13:22:10 -0700102 private static final String TAG = "RadioInfo";
johnwang342101a2009-09-23 16:22:34 -0700103
Nathan Harold2b77d742016-03-19 13:22:10 -0700104 private static final String[] mPreferredNetworkLabels = {
105 "WCDMA preferred",
106 "GSM only",
107 "WCDMA only",
108 "GSM auto (PRL)",
109 "CDMA auto (PRL)",
110 "CDMA only",
111 "EvDo only",
112 "Global auto (PRL)",
113 "LTE/CDMA auto (PRL)",
114 "LTE/UMTS auto (PRL)",
115 "LTE/CDMA/UMTS auto (PRL)",
116 "LTE only",
117 "LTE/WCDMA",
118 "TD-SCDMA only",
119 "TD-SCDMA/WCDMA",
120 "LTE/TD-SCDMA",
121 "TD-SCDMA/GSM",
122 "TD-SCDMA/UMTS",
123 "LTE/TD-SCDMA/WCDMA",
124 "LTE/TD-SCDMA/UMTS",
125 "TD-SCDMA/CDMA/UMTS",
126 "Global/TD-SCDMA",
127 "Unknown"
128 };
129
130
131 private static final int CELL_INFO_LIST_RATE_DISABLED = Integer.MAX_VALUE;
132 private static final int CELL_INFO_LIST_RATE_MAX = 0;
133
Nathan Harold12e1f552016-06-17 13:55:38 -0700134
135 private static final int IMS_VOLTE_PROVISIONED_CONFIG_ID =
136 ImsConfig.ConfigConstants.VLT_SETTING_ENABLED;
137
138 private static final int IMS_VT_PROVISIONED_CONFIG_ID =
139 ImsConfig.ConfigConstants.LVC_SETTING_ENABLED;
140
141 private static final int IMS_WFC_PROVISIONED_CONFIG_ID =
142 ImsConfig.ConfigConstants.VOICE_OVER_WIFI_SETTING_ENABLED;
143
Meng Wang586741c2017-04-26 15:02:51 -0700144 private static final int EAB_PROVISIONED_CONFIG_ID =
145 ImsConfig.ConfigConstants.EAB_SETTING_ENABLED;
146
Nathan Harold2b77d742016-03-19 13:22:10 -0700147 //Values in must match mCellInfoRefreshRates
148 private static final String[] mCellInfoRefreshRateLabels = {
149 "Disabled",
150 "Immediate",
151 "Min 5s",
152 "Min 10s",
153 "Min 60s"
154 };
155
156 //Values in seconds, must match mCellInfoRefreshRateLabels
157 private static final int mCellInfoRefreshRates[] = {
158 CELL_INFO_LIST_RATE_DISABLED,
159 CELL_INFO_LIST_RATE_MAX,
160 5000,
161 10000,
162 60000
163 };
164
165 private void log(String s) {
166 Log.d(TAG, s);
167 }
168
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800169 private static final int EVENT_CFI_CHANGED = 302;
170
171 private static final int EVENT_QUERY_PREFERRED_TYPE_DONE = 1000;
172 private static final int EVENT_SET_PREFERRED_TYPE_DONE = 1001;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800173 private static final int EVENT_QUERY_SMSC_DONE = 1005;
174 private static final int EVENT_UPDATE_SMSC_DONE = 1006;
175
176 private static final int MENU_ITEM_SELECT_BAND = 0;
177 private static final int MENU_ITEM_VIEW_ADN = 1;
178 private static final int MENU_ITEM_VIEW_FDN = 2;
179 private static final int MENU_ITEM_VIEW_SDN = 3;
Nathan Harolde272c202016-10-27 13:45:00 -0700180 private static final int MENU_ITEM_GET_IMS_STATUS = 4;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800181 private static final int MENU_ITEM_TOGGLE_DATA = 5;
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800182
Wink Savillec3886682009-04-02 11:00:56 -0700183 private TextView mDeviceId; //DeviceId is the IMEI in GSM and the MEID in CDMA
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800184 private TextView number;
Meng Wang9053f172017-06-23 16:02:14 -0700185 private TextView mSubscriberId;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800186 private TextView callState;
187 private TextView operatorName;
188 private TextView roamingState;
189 private TextView gsmState;
190 private TextView gprsState;
Nathan Harold2b77d742016-03-19 13:22:10 -0700191 private TextView voiceNetwork;
192 private TextView dataNetwork;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800193 private TextView dBm;
194 private TextView mMwi;
195 private TextView mCfi;
196 private TextView mLocation;
Wink Saville79bff2a2012-06-01 14:37:21 -0700197 private TextView mCellInfo;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800198 private TextView sent;
199 private TextView received;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800200 private TextView mPingHostnameV4;
201 private TextView mPingHostnameV6;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800202 private TextView mHttpClientTest;
Nathan Harold433ca442018-04-23 18:20:43 -0700203 private TextView mPhyChanConfig;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800204 private TextView dnsCheckState;
Nathan Haroldf10ea322018-04-24 13:31:07 -0700205 private TextView mDownlinkKbps;
206 private TextView mUplinkKbps;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800207 private EditText smsc;
Nathan Harold2b77d742016-03-19 13:22:10 -0700208 private Switch radioPowerOnSwitch;
209 private Button cellInfoRefreshRateButton;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800210 private Button dnsCheckToggleButton;
211 private Button pingTestButton;
212 private Button updateSmscButton;
213 private Button refreshSmscButton;
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800214 private Button oemInfoButton;
Youhan Wangfd781e92016-12-16 15:53:16 -0800215 private Button carrierProvisioningButton;
216 private Button triggercarrierProvisioningButton;
Nathan Harold12e1f552016-06-17 13:55:38 -0700217 private Switch imsVolteProvisionedSwitch;
218 private Switch imsVtProvisionedSwitch;
219 private Switch imsWfcProvisionedSwitch;
Meng Wang586741c2017-04-26 15:02:51 -0700220 private Switch eabProvisionedSwitch;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800221 private Spinner preferredNetworkType;
Nathan Harold2b77d742016-03-19 13:22:10 -0700222 private Spinner cellInfoRefreshRateSpinner;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800223
Nathan Haroldf10ea322018-04-24 13:31:07 -0700224 private ConnectivityManager mConnectivityManager;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800225 private TelephonyManager mTelephonyManager;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800226 private ImsManager mImsManager = null;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800227 private Phone phone = null;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800228
Nathan Haroldcea413a2015-11-23 15:48:10 -0800229 private String mPingHostnameResultV4;
230 private String mPingHostnameResultV6;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800231 private String mHttpClientTestResult;
232 private boolean mMwiValue = false;
233 private boolean mCfiValue = false;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800234
235 private List<CellInfo> mCellInfoResult = null;
236 private CellLocation mCellLocationResult = null;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800237
238 private int mPreferredNetworkTypeResult;
Nathan Harold2b77d742016-03-19 13:22:10 -0700239 private int mCellInfoRefreshRateIndex;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800240
Nathan Haroldf10ea322018-04-24 13:31:07 -0700241 private final NetworkRequest mDefaultNetworkRequest = new NetworkRequest.Builder()
242 .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
243 .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
244 .build();
245
246 private final NetworkCallback mNetworkCallback = new NetworkCallback() {
247 public void onCapabilitiesChanged(Network n, NetworkCapabilities nc) {
248 int dlbw = nc.getLinkDownstreamBandwidthKbps();
249 int ulbw = nc.getLinkUpstreamBandwidthKbps();
250 updateBandwidths(dlbw, ulbw);
251 }
252 };
253
Nathan Harold2b77d742016-03-19 13:22:10 -0700254 private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800255 @Override
256 public void onDataConnectionStateChanged(int state) {
257 updateDataState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800258 updateNetworkType();
259 }
260
261 @Override
262 public void onDataActivity(int direction) {
263 updateDataStats2();
264 }
265
266 @Override
Nathan Harold2b77d742016-03-19 13:22:10 -0700267 public void onCallStateChanged(int state, String incomingNumber) {
268 updateNetworkType();
269 updatePhoneState(state);
270 }
271
272 @Override
273 public void onPreciseCallStateChanged(PreciseCallState preciseState) {
274 updateNetworkType();
275 }
276
277 @Override
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800278 public void onCellLocationChanged(CellLocation location) {
279 updateLocation(location);
280 }
281
282 @Override
283 public void onMessageWaitingIndicatorChanged(boolean mwi) {
284 mMwiValue = mwi;
285 updateMessageWaiting();
286 }
287
288 @Override
289 public void onCallForwardingIndicatorChanged(boolean cfi) {
290 mCfiValue = cfi;
291 updateCallRedirect();
292 }
Wink Saville79bff2a2012-06-01 14:37:21 -0700293
294 @Override
295 public void onCellInfoChanged(List<CellInfo> arrayCi) {
Wink Savillebf471282013-04-05 15:04:05 -0700296 log("onCellInfoChanged: arrayCi=" + arrayCi);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800297 mCellInfoResult = arrayCi;
298 updateCellInfo(mCellInfoResult);
Wink Saville79bff2a2012-06-01 14:37:21 -0700299 }
Wink Saville4f0d8812014-04-15 22:05:24 -0700300
301 @Override
Nathan Harold2b77d742016-03-19 13:22:10 -0700302 public void onSignalStrengthsChanged(SignalStrength signalStrength) {
303 log("onSignalStrengthChanged: SignalStrength=" +signalStrength);
304 updateSignalStrength(signalStrength);
305 }
306
307 @Override
308 public void onServiceStateChanged(ServiceState serviceState) {
309 log("onServiceStateChanged: ServiceState=" + serviceState);
310 updateServiceState(serviceState);
311 updateRadioPowerState();
312 updateNetworkType();
Nathan Harold12e1f552016-06-17 13:55:38 -0700313 updateImsProvisionedState();
Nathan Harold2b77d742016-03-19 13:22:10 -0700314 }
Nathan Harold433ca442018-04-23 18:20:43 -0700315
316 @Override
317 public void onPhysicalChannelConfigurationChanged(
318 List<PhysicalChannelConfig> configs) {
319 updatePhysicalChannelConfiguration(configs);
320 }
321
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800322 };
323
Nathan Harold433ca442018-04-23 18:20:43 -0700324 private void updatePhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
325 StringBuilder sb = new StringBuilder();
326 String div = "";
327 sb.append("{");
328 if (configs != null) {
329 for(PhysicalChannelConfig c : configs) {
330 sb.append(div).append(c);
331 div = ",";
332 }
333 }
334 sb.append("}");
335 mPhyChanConfig.setText(sb.toString());
336 }
337
Nathan Haroldcea413a2015-11-23 15:48:10 -0800338 private void updatePreferredNetworkType(int type) {
339 if (type >= mPreferredNetworkLabels.length || type < 0) {
340 log("EVENT_QUERY_PREFERRED_TYPE_DONE: unknown " +
341 "type=" + type);
342 type = mPreferredNetworkLabels.length - 1; //set to Unknown
343 }
344 mPreferredNetworkTypeResult = type;
345
346 preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true);
347 }
348
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800349 private Handler mHandler = new Handler() {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800350 @Override
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800351 public void handleMessage(Message msg) {
352 AsyncResult ar;
353 switch (msg.what) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800354 case EVENT_QUERY_PREFERRED_TYPE_DONE:
355 ar= (AsyncResult) msg.obj;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800356 if (ar.exception == null && ar.result != null) {
357 updatePreferredNetworkType(((int[])ar.result)[0]);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800358 } else {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800359 //In case of an exception, we will set this to unknown
360 updatePreferredNetworkType(mPreferredNetworkLabels.length-1);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800361 }
362 break;
363 case EVENT_SET_PREFERRED_TYPE_DONE:
364 ar= (AsyncResult) msg.obj;
365 if (ar.exception != null) {
Nathan Harolded38afa2016-04-13 00:29:30 -0700366 log("Set preferred network type failed.");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800367 }
368 break;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800369 case EVENT_QUERY_SMSC_DONE:
370 ar= (AsyncResult) msg.obj;
371 if (ar.exception != null) {
372 smsc.setText("refresh error");
373 } else {
jsh21dd4072009-05-12 11:26:55 -0700374 smsc.setText((String)ar.result);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800375 }
376 break;
377 case EVENT_UPDATE_SMSC_DONE:
378 updateSmscButton.setEnabled(true);
379 ar= (AsyncResult) msg.obj;
380 if (ar.exception != null) {
381 smsc.setText("update error");
382 }
383 break;
384 default:
Nathan Haroldcea413a2015-11-23 15:48:10 -0800385 super.handleMessage(msg);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800386 break;
387
388 }
389 }
390 };
391
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800392 @Override
393 public void onCreate(Bundle icicle) {
394 super.onCreate(icicle);
fionaxub54cb2d2016-09-22 15:01:05 -0700395 if (!android.os.Process.myUserHandle().isSystem()) {
396 Log.e(TAG, "Not run from system user, don't do anything.");
397 finish();
398 return;
399 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800400
401 setContentView(R.layout.radio_info);
402
Nathan Haroldcea413a2015-11-23 15:48:10 -0800403 log("Started onCreate");
404
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800405 mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
Nathan Haroldf10ea322018-04-24 13:31:07 -0700406 mConnectivityManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800407 phone = PhoneFactory.getDefaultPhone();
408
Nathan Haroldcea413a2015-11-23 15:48:10 -0800409 //TODO: Need to update this if the default phoneId changes?
410 // Better to have an instance per phone?
411 mImsManager = ImsManager.getInstance(getApplicationContext(),
412 SubscriptionManager.getDefaultVoicePhoneId());
413
Meng Wang9053f172017-06-23 16:02:14 -0700414 mDeviceId = (TextView) findViewById(R.id.imei);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800415 number = (TextView) findViewById(R.id.number);
Meng Wang9053f172017-06-23 16:02:14 -0700416 mSubscriberId = (TextView) findViewById(R.id.imsi);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800417 callState = (TextView) findViewById(R.id.call);
418 operatorName = (TextView) findViewById(R.id.operator);
419 roamingState = (TextView) findViewById(R.id.roaming);
420 gsmState = (TextView) findViewById(R.id.gsm);
421 gprsState = (TextView) findViewById(R.id.gprs);
Nathan Harold2b77d742016-03-19 13:22:10 -0700422 voiceNetwork = (TextView) findViewById(R.id.voice_network);
423 dataNetwork = (TextView) findViewById(R.id.data_network);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800424 dBm = (TextView) findViewById(R.id.dbm);
425 mMwi = (TextView) findViewById(R.id.mwi);
426 mCfi = (TextView) findViewById(R.id.cfi);
427 mLocation = (TextView) findViewById(R.id.location);
Wink Saville79bff2a2012-06-01 14:37:21 -0700428 mCellInfo = (TextView) findViewById(R.id.cellinfo);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800429 mCellInfo.setTypeface(Typeface.MONOSPACE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800430
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800431 sent = (TextView) findViewById(R.id.sent);
432 received = (TextView) findViewById(R.id.received);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800433 smsc = (EditText) findViewById(R.id.smsc);
434 dnsCheckState = (TextView) findViewById(R.id.dnsCheckState);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800435 mPingHostnameV4 = (TextView) findViewById(R.id.pingHostnameV4);
436 mPingHostnameV6 = (TextView) findViewById(R.id.pingHostnameV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800437 mHttpClientTest = (TextView) findViewById(R.id.httpClientTest);
438
Nathan Harold433ca442018-04-23 18:20:43 -0700439 mPhyChanConfig = (TextView) findViewById(R.id.phy_chan_config);
440
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800441 preferredNetworkType = (Spinner) findViewById(R.id.preferredNetworkType);
442 ArrayAdapter<String> adapter = new ArrayAdapter<String> (this,
443 android.R.layout.simple_spinner_item, mPreferredNetworkLabels);
johnwang342101a2009-09-23 16:22:34 -0700444 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800445 preferredNetworkType.setAdapter(adapter);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800446
Nathan Harold2b77d742016-03-19 13:22:10 -0700447 cellInfoRefreshRateSpinner = (Spinner) findViewById(R.id.cell_info_rate_select);
448 ArrayAdapter<String> cellInfoAdapter = new ArrayAdapter<String>(this,
449 android.R.layout.simple_spinner_item, mCellInfoRefreshRateLabels);
450 cellInfoAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
451 cellInfoRefreshRateSpinner.setAdapter(cellInfoAdapter);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800452
Nathan Harold12e1f552016-06-17 13:55:38 -0700453 imsVolteProvisionedSwitch = (Switch) findViewById(R.id.volte_provisioned_switch);
454 imsVtProvisionedSwitch = (Switch) findViewById(R.id.vt_provisioned_switch);
455 imsWfcProvisionedSwitch = (Switch) findViewById(R.id.wfc_provisioned_switch);
Meng Wang69439b52017-05-01 08:31:14 -0700456 eabProvisionedSwitch = (Switch) findViewById(R.id.eab_provisioned_switch);
Wink Savillebf471282013-04-05 15:04:05 -0700457
Brad Ebinger8bff9c32019-03-11 17:33:53 -0700458 if (!ImsManager.isImsSupportedOnDevice(phone.getContext())) {
459 imsVolteProvisionedSwitch.setVisibility(View.GONE);
460 imsVtProvisionedSwitch.setVisibility(View.GONE);
461 imsWfcProvisionedSwitch.setVisibility(View.GONE);
462 eabProvisionedSwitch.setVisibility(View.GONE);
463 }
464
Nathan Harold2b77d742016-03-19 13:22:10 -0700465 radioPowerOnSwitch = (Switch) findViewById(R.id.radio_power);
Wink Saville426fc662011-09-25 14:39:02 -0700466
Nathan Haroldf10ea322018-04-24 13:31:07 -0700467 mDownlinkKbps = (TextView) findViewById(R.id.dl_kbps);
468 mUplinkKbps = (TextView) findViewById(R.id.ul_kbps);
469 updateBandwidths(0, 0);
470
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800471 pingTestButton = (Button) findViewById(R.id.ping_test);
472 pingTestButton.setOnClickListener(mPingButtonHandler);
473 updateSmscButton = (Button) findViewById(R.id.update_smsc);
474 updateSmscButton.setOnClickListener(mUpdateSmscButtonHandler);
475 refreshSmscButton = (Button) findViewById(R.id.refresh_smsc);
476 refreshSmscButton.setOnClickListener(mRefreshSmscButtonHandler);
477 dnsCheckToggleButton = (Button) findViewById(R.id.dns_check_toggle);
478 dnsCheckToggleButton.setOnClickListener(mDnsCheckButtonHandler);
Youhan Wangfd781e92016-12-16 15:53:16 -0800479 carrierProvisioningButton = (Button) findViewById(R.id.carrier_provisioning);
480 carrierProvisioningButton.setOnClickListener(mCarrierProvisioningButtonHandler);
481 triggercarrierProvisioningButton = (Button) findViewById(R.id.trigger_carrier_provisioning);
482 triggercarrierProvisioningButton.setOnClickListener(
483 mTriggerCarrierProvisioningButtonHandler);
johnwang342101a2009-09-23 16:22:34 -0700484
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800485 oemInfoButton = (Button) findViewById(R.id.oem_info);
486 oemInfoButton.setOnClickListener(mOemInfoButtonHandler);
487 PackageManager pm = getPackageManager();
488 Intent oemInfoIntent = new Intent("com.android.settings.OEM_RADIO_INFO");
489 List<ResolveInfo> oemInfoIntentList = pm.queryIntentActivities(oemInfoIntent, 0);
490 if (oemInfoIntentList.size() == 0) {
491 oemInfoButton.setEnabled(false);
492 }
493
Nathan Harolded38afa2016-04-13 00:29:30 -0700494 mCellInfoRefreshRateIndex = 0; //disabled
Nathan Haroldcea413a2015-11-23 15:48:10 -0800495 mPreferredNetworkTypeResult = mPreferredNetworkLabels.length - 1; //Unknown
496
497 //FIXME: Replace with TelephonyManager call
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800498 phone.getPreferredNetworkType(
499 mHandler.obtainMessage(EVENT_QUERY_PREFERRED_TYPE_DONE));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800500
Nathan Haroldcea413a2015-11-23 15:48:10 -0800501 restoreFromBundle(icicle);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800502 }
503
504 @Override
505 protected void onResume() {
506 super.onResume();
507
Nathan Haroldcea413a2015-11-23 15:48:10 -0800508 log("Started onResume");
509
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800510 updateMessageWaiting();
511 updateCallRedirect();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800512 updateDataState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800513 updateDataStats2();
Nathan Harold2b77d742016-03-19 13:22:10 -0700514 updateRadioPowerState();
Nathan Harold12e1f552016-06-17 13:55:38 -0700515 updateImsProvisionedState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800516 updateProperties();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800517 updateDnsCheckState();
Nathan Harold2b77d742016-03-19 13:22:10 -0700518 updateNetworkType();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800519
Nathan Haroldcea413a2015-11-23 15:48:10 -0800520 updateLocation(mCellLocationResult);
521 updateCellInfo(mCellInfoResult);
522
523 mPingHostnameV4.setText(mPingHostnameResultV4);
524 mPingHostnameV6.setText(mPingHostnameResultV6);
525 mHttpClientTest.setText(mHttpClientTestResult);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800526
Nathan Harold2b77d742016-03-19 13:22:10 -0700527 cellInfoRefreshRateSpinner.setOnItemSelectedListener(mCellInfoRefreshRateHandler);
Nathan Harolded38afa2016-04-13 00:29:30 -0700528 //set selection after registering listener to force update
529 cellInfoRefreshRateSpinner.setSelection(mCellInfoRefreshRateIndex);
530
531 //set selection before registering to prevent update
532 preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true);
Nathan Harold2b77d742016-03-19 13:22:10 -0700533 preferredNetworkType.setOnItemSelectedListener(mPreferredNetworkHandler);
Nathan Harolded38afa2016-04-13 00:29:30 -0700534
Nathan Harold2b77d742016-03-19 13:22:10 -0700535 radioPowerOnSwitch.setOnCheckedChangeListener(mRadioPowerOnChangeListener);
Nathan Harold12e1f552016-06-17 13:55:38 -0700536 imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
537 imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
538 imsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
Meng Wang586741c2017-04-26 15:02:51 -0700539 eabProvisionedSwitch.setOnCheckedChangeListener(mEabCheckedChangeListener);
Nathan Harold2b77d742016-03-19 13:22:10 -0700540
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800541 mTelephonyManager.listen(mPhoneStateListener,
Nathan Harold2b77d742016-03-19 13:22:10 -0700542 PhoneStateListener.LISTEN_CALL_STATE
543 //b/27803938 - RadioInfo currently cannot read PRECISE_CALL_STATE
544 // | PhoneStateListener.LISTEN_PRECISE_CALL_STATE
545 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800546 | PhoneStateListener.LISTEN_DATA_ACTIVITY
547 | PhoneStateListener.LISTEN_CELL_LOCATION
548 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
Wink Saville79bff2a2012-06-01 14:37:21 -0700549 | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
Wink Saville4f0d8812014-04-15 22:05:24 -0700550 | PhoneStateListener.LISTEN_CELL_INFO
Nathan Harold2b77d742016-03-19 13:22:10 -0700551 | PhoneStateListener.LISTEN_SERVICE_STATE
552 | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
Nathan Harold433ca442018-04-23 18:20:43 -0700553 | PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION);
Nathan Harolded38afa2016-04-13 00:29:30 -0700554
Nathan Haroldf10ea322018-04-24 13:31:07 -0700555 mConnectivityManager.registerNetworkCallback(
556 mDefaultNetworkRequest, mNetworkCallback, mHandler);
557
Nathan Harolded38afa2016-04-13 00:29:30 -0700558 smsc.clearFocus();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800559 }
560
561 @Override
Nathan Haroldcea413a2015-11-23 15:48:10 -0800562 protected void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800563 super.onPause();
564
Wink Savillebf471282013-04-05 15:04:05 -0700565 log("onPause: unregister phone & data intents");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800566
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800567 mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
Sooraj Sasindran5cce06b2016-08-18 15:49:49 -0700568 mTelephonyManager.setCellInfoListRate(CELL_INFO_LIST_RATE_DISABLED);
Nathan Haroldf10ea322018-04-24 13:31:07 -0700569 mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
570
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800571 }
572
Nathan Haroldcea413a2015-11-23 15:48:10 -0800573 private void restoreFromBundle(Bundle b) {
Nathan Harolde272c202016-10-27 13:45:00 -0700574 if(b == null) {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800575 return;
576 }
577
578 mPingHostnameResultV4 = b.getString("mPingHostnameResultV4","");
579 mPingHostnameResultV6 = b.getString("mPingHostnameResultV6","");
580 mHttpClientTestResult = b.getString("mHttpClientTestResult","");
581
582 mPingHostnameV4.setText(mPingHostnameResultV4);
583 mPingHostnameV6.setText(mPingHostnameResultV6);
584 mHttpClientTest.setText(mHttpClientTestResult);
585
Nathan Harold2b77d742016-03-19 13:22:10 -0700586 mPreferredNetworkTypeResult = b.getInt("mPreferredNetworkTypeResult",
587 mPreferredNetworkLabels.length - 1);
588
589 mCellInfoRefreshRateIndex = b.getInt("mCellInfoRefreshRateIndex", 0);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800590 }
591
592 @Override
593 protected void onSaveInstanceState(Bundle outState) {
594 outState.putString("mPingHostnameResultV4", mPingHostnameResultV4);
595 outState.putString("mPingHostnameResultV6", mPingHostnameResultV6);
596 outState.putString("mHttpClientTestResult", mHttpClientTestResult);
Nathan Harold2b77d742016-03-19 13:22:10 -0700597
Nathan Haroldcea413a2015-11-23 15:48:10 -0800598 outState.putInt("mPreferredNetworkTypeResult", mPreferredNetworkTypeResult);
Nathan Harold2b77d742016-03-19 13:22:10 -0700599 outState.putInt("mCellInfoRefreshRateIndex", mCellInfoRefreshRateIndex);
600
Nathan Haroldcea413a2015-11-23 15:48:10 -0800601 }
602
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800603 @Override
604 public boolean onCreateOptionsMenu(Menu menu) {
Wink Savillec3886682009-04-02 11:00:56 -0700605 menu.add(0, MENU_ITEM_SELECT_BAND, 0, R.string.radio_info_band_mode_label)
606 .setOnMenuItemClickListener(mSelectBandCallback)
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800607 .setAlphabeticShortcut('b');
608 menu.add(1, MENU_ITEM_VIEW_ADN, 0,
609 R.string.radioInfo_menu_viewADN).setOnMenuItemClickListener(mViewADNCallback);
610 menu.add(1, MENU_ITEM_VIEW_FDN, 0,
611 R.string.radioInfo_menu_viewFDN).setOnMenuItemClickListener(mViewFDNCallback);
612 menu.add(1, MENU_ITEM_VIEW_SDN, 0,
613 R.string.radioInfo_menu_viewSDN).setOnMenuItemClickListener(mViewSDNCallback);
Brad Ebinger8bff9c32019-03-11 17:33:53 -0700614 if (ImsManager.isImsSupportedOnDevice(phone.getContext())) {
615 menu.add(1, MENU_ITEM_GET_IMS_STATUS,
616 0, R.string.radioInfo_menu_getIMS).setOnMenuItemClickListener(mGetImsStatus);
617 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800618 menu.add(1, MENU_ITEM_TOGGLE_DATA,
Nathan Harold2b77d742016-03-19 13:22:10 -0700619 0, R.string.radio_info_data_connection_disable).setOnMenuItemClickListener(mToggleData);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800620 return true;
621 }
622
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800623 @Override
Wink Savillec3886682009-04-02 11:00:56 -0700624 public boolean onPrepareOptionsMenu(Menu menu) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800625 // Get the TOGGLE DATA menu item in the right state.
626 MenuItem item = menu.findItem(MENU_ITEM_TOGGLE_DATA);
627 int state = mTelephonyManager.getDataState();
628 boolean visible = true;
629
630 switch (state) {
631 case TelephonyManager.DATA_CONNECTED:
632 case TelephonyManager.DATA_SUSPENDED:
Nathan Harold2b77d742016-03-19 13:22:10 -0700633 item.setTitle(R.string.radio_info_data_connection_disable);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800634 break;
635 case TelephonyManager.DATA_DISCONNECTED:
Nathan Harold2b77d742016-03-19 13:22:10 -0700636 item.setTitle(R.string.radio_info_data_connection_enable);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800637 break;
638 default:
639 visible = false;
640 break;
641 }
642 item.setVisible(visible);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800643 return true;
644 }
645
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800646 private void updateDnsCheckState() {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800647 //FIXME: Replace with a TelephonyManager call
Mike Lockwood5304c7e2009-04-05 11:37:45 -0700648 dnsCheckState.setText(phone.isDnsCheckDisabled() ?
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800649 "0.0.0.0 allowed" :"0.0.0.0 not allowed");
650 }
Wink Savillee2a14e32009-05-29 14:06:30 -0700651
Nathan Haroldf10ea322018-04-24 13:31:07 -0700652 private void updateBandwidths(int dlbw, int ulbw) {
653 dlbw = (dlbw < 0 || dlbw == Integer.MAX_VALUE) ? -1 : dlbw;
654 ulbw = (ulbw < 0 || ulbw == Integer.MAX_VALUE) ? -1 : ulbw;
655 mDownlinkKbps.setText(String.format("%-5d", dlbw));
656 mUplinkKbps.setText(String.format("%-5d", ulbw));
657 }
658
659
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800660 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -0700661 updateSignalStrength(SignalStrength signalStrength) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800662 Resources r = getResources();
663
Nathan Harold2b77d742016-03-19 13:22:10 -0700664 int signalDbm = signalStrength.getDbm();
Wink Savillee2a14e32009-05-29 14:06:30 -0700665
Nathan Harold2b77d742016-03-19 13:22:10 -0700666 int signalAsu = signalStrength.getAsuLevel();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800667
668 if (-1 == signalAsu) signalAsu = 0;
669
670 dBm.setText(String.valueOf(signalDbm) + " "
671 + r.getString(R.string.radioInfo_display_dbm) + " "
672 + String.valueOf(signalAsu) + " "
673 + r.getString(R.string.radioInfo_display_asu));
674 }
675
676 private final void updateLocation(CellLocation location) {
jsh534f5ae2009-09-24 09:19:22 -0700677 Resources r = getResources();
Wink Savillec3886682009-04-02 11:00:56 -0700678 if (location instanceof GsmCellLocation) {
679 GsmCellLocation loc = (GsmCellLocation)location;
jsh534f5ae2009-09-24 09:19:22 -0700680 int lac = loc.getLac();
681 int cid = loc.getCid();
682 mLocation.setText(r.getString(R.string.radioInfo_lac) + " = "
683 + ((lac == -1) ? "unknown" : Integer.toHexString(lac))
684 + " "
685 + r.getString(R.string.radioInfo_cid) + " = "
686 + ((cid == -1) ? "unknown" : Integer.toHexString(cid)));
687 } else if (location instanceof CdmaCellLocation) {
688 CdmaCellLocation loc = (CdmaCellLocation)location;
689 int bid = loc.getBaseStationId();
690 int sid = loc.getSystemId();
691 int nid = loc.getNetworkId();
692 int lat = loc.getBaseStationLatitude();
693 int lon = loc.getBaseStationLongitude();
694 mLocation.setText("BID = "
695 + ((bid == -1) ? "unknown" : Integer.toHexString(bid))
696 + " "
697 + "SID = "
698 + ((sid == -1) ? "unknown" : Integer.toHexString(sid))
699 + " "
700 + "NID = "
701 + ((nid == -1) ? "unknown" : Integer.toHexString(nid))
702 + "\n"
703 + "LAT = "
704 + ((lat == -1) ? "unknown" : Integer.toHexString(lat))
705 + " "
706 + "LONG = "
707 + ((lon == -1) ? "unknown" : Integer.toHexString(lon)));
708 } else {
709 mLocation.setText("unknown");
Wink Savillec3886682009-04-02 11:00:56 -0700710 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800711
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800712
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800713 }
714
Nathan Haroldcea413a2015-11-23 15:48:10 -0800715 private final String getCellInfoDisplayString(int i) {
716 return (i != Integer.MAX_VALUE) ? Integer.toString(i) : "";
717 }
718
719 private final String getCellInfoDisplayString(long i) {
720 return (i != Long.MAX_VALUE) ? Long.toString(i) : "";
721 }
722
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700723 private final String getConnectionStatusString(CellInfo ci) {
724 String regStr = "";
725 String connStatStr = "";
726 String connector = "";
727
728 if (ci.isRegistered()) {
729 regStr = "R";
730 }
731 switch (ci.getCellConnectionStatus()) {
732 case CellInfo.CONNECTION_PRIMARY_SERVING: connStatStr = "P"; break;
733 case CellInfo.CONNECTION_SECONDARY_SERVING: connStatStr = "S"; break;
734 case CellInfo.CONNECTION_NONE: connStatStr = "N"; break;
735 case CellInfo.CONNECTION_UNKNOWN: /* Field is unsupported */ break;
736 default: break;
737 }
738 if (!TextUtils.isEmpty(regStr) && !TextUtils.isEmpty(connStatStr)) {
739 connector = "+";
740 }
741
742 return regStr + connector + connStatStr;
743 }
744
Nathan Haroldcea413a2015-11-23 15:48:10 -0800745 private final String buildCdmaInfoString(CellInfoCdma ci) {
746 CellIdentityCdma cidCdma = ci.getCellIdentity();
747 CellSignalStrengthCdma ssCdma = ci.getCellSignalStrength();
748
749 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 -0700750 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800751 getCellInfoDisplayString(cidCdma.getSystemId()),
752 getCellInfoDisplayString(cidCdma.getNetworkId()),
753 getCellInfoDisplayString(cidCdma.getBasestationId()),
754 getCellInfoDisplayString(ssCdma.getCdmaDbm()),
755 getCellInfoDisplayString(ssCdma.getCdmaEcio()),
756 getCellInfoDisplayString(ssCdma.getEvdoDbm()),
757 getCellInfoDisplayString(ssCdma.getEvdoEcio()),
758 getCellInfoDisplayString(ssCdma.getEvdoSnr()));
759 }
760
761 private final String buildGsmInfoString(CellInfoGsm ci) {
762 CellIdentityGsm cidGsm = ci.getCellIdentity();
763 CellSignalStrengthGsm ssGsm = ci.getCellSignalStrength();
764
Nathan Harold2b77d742016-03-19 13:22:10 -0700765 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 -0700766 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800767 getCellInfoDisplayString(cidGsm.getMcc()),
768 getCellInfoDisplayString(cidGsm.getMnc()),
769 getCellInfoDisplayString(cidGsm.getLac()),
770 getCellInfoDisplayString(cidGsm.getCid()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700771 getCellInfoDisplayString(cidGsm.getArfcn()),
772 getCellInfoDisplayString(cidGsm.getBsic()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800773 getCellInfoDisplayString(ssGsm.getDbm()));
774 }
775
776 private final String buildLteInfoString(CellInfoLte ci) {
777 CellIdentityLte cidLte = ci.getCellIdentity();
778 CellSignalStrengthLte ssLte = ci.getCellSignalStrength();
779
780 return String.format(
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700781 "%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s %-6.6s %-2.2s %-4.4s %-4.4s %-2.2s\n",
782 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800783 getCellInfoDisplayString(cidLte.getMcc()),
784 getCellInfoDisplayString(cidLte.getMnc()),
785 getCellInfoDisplayString(cidLte.getTac()),
786 getCellInfoDisplayString(cidLte.getCi()),
787 getCellInfoDisplayString(cidLte.getPci()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700788 getCellInfoDisplayString(cidLte.getEarfcn()),
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700789 getCellInfoDisplayString(cidLte.getBandwidth()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800790 getCellInfoDisplayString(ssLte.getDbm()),
791 getCellInfoDisplayString(ssLte.getRsrq()),
792 getCellInfoDisplayString(ssLte.getTimingAdvance()));
793 }
794
795 private final String buildWcdmaInfoString(CellInfoWcdma ci) {
796 CellIdentityWcdma cidWcdma = ci.getCellIdentity();
797 CellSignalStrengthWcdma ssWcdma = ci.getCellSignalStrength();
798
Nathan Harold2b77d742016-03-19 13:22:10 -0700799 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 -0700800 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800801 getCellInfoDisplayString(cidWcdma.getMcc()),
802 getCellInfoDisplayString(cidWcdma.getMnc()),
803 getCellInfoDisplayString(cidWcdma.getLac()),
804 getCellInfoDisplayString(cidWcdma.getCid()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700805 getCellInfoDisplayString(cidWcdma.getUarfcn()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800806 getCellInfoDisplayString(cidWcdma.getPsc()),
807 getCellInfoDisplayString(ssWcdma.getDbm()));
808 }
809
810 private final String buildCellInfoString(List<CellInfo> arrayCi) {
811 String value = new String();
812 StringBuilder cdmaCells = new StringBuilder(),
813 gsmCells = new StringBuilder(),
814 lteCells = new StringBuilder(),
815 wcdmaCells = new StringBuilder();
816
817 if (arrayCi != null) {
818 for (CellInfo ci : arrayCi) {
819
820 if (ci instanceof CellInfoLte) {
821 lteCells.append(buildLteInfoString((CellInfoLte) ci));
822 } else if (ci instanceof CellInfoWcdma) {
823 wcdmaCells.append(buildWcdmaInfoString((CellInfoWcdma) ci));
824 } else if (ci instanceof CellInfoGsm) {
825 gsmCells.append(buildGsmInfoString((CellInfoGsm) ci));
826 } else if (ci instanceof CellInfoCdma) {
827 cdmaCells.append(buildCdmaInfoString((CellInfoCdma) ci));
Wink Saville79bff2a2012-06-01 14:37:21 -0700828 }
829 }
Nathan Haroldcea413a2015-11-23 15:48:10 -0800830 if (lteCells.length() != 0) {
831 value += String.format(
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700832 "LTE\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s"
833 + " %-6.6s %-2.2s %-4.4s %-4.4s %-2.2s\n",
834 "SRV", "MCC", "MNC", "TAC", "CID", "PCI",
835 "EARFCN", "BW", "RSRP", "RSRQ", "TA");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800836 value += lteCells.toString();
837 }
838 if (wcdmaCells.length() != 0) {
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700839 value += String.format(
840 "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 -0700841 "SRV", "MCC", "MNC", "LAC", "CID", "UARFCN", "PSC", "RSCP");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800842 value += wcdmaCells.toString();
843 }
844 if (gsmCells.length() != 0) {
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700845 value += String.format(
846 "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 -0700847 "SRV", "MCC", "MNC", "LAC", "CID", "ARFCN", "BSIC", "RSSI");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800848 value += gsmCells.toString();
849 }
850 if (cdmaCells.length() != 0) {
851 value += String.format(
852 "CDMA/EVDO\n%-3.3s %-5.5s %-5.5s %-5.5s %-6.6s %-6.6s %-6.6s %-6.6s %-5.5s\n",
853 "SRV", "SID", "NID", "BSID", "C-RSSI", "C-ECIO", "E-RSSI", "E-ECIO", "E-SNR");
854 value += cdmaCells.toString();
855 }
856 } else {
857 value ="unknown";
Wink Saville79bff2a2012-06-01 14:37:21 -0700858 }
Nathan Haroldcea413a2015-11-23 15:48:10 -0800859
860 return value.toString();
861 }
862
863 private final void updateCellInfo(List<CellInfo> arrayCi) {
864 mCellInfo.setText(buildCellInfoString(arrayCi));
Wink Saville79bff2a2012-06-01 14:37:21 -0700865 }
866
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800867 private final void
868 updateMessageWaiting() {
869 mMwi.setText(String.valueOf(mMwiValue));
870 }
871
872 private final void
873 updateCallRedirect() {
874 mCfi.setText(String.valueOf(mCfiValue));
875 }
876
877
878 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -0700879 updateServiceState(ServiceState serviceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800880 int state = serviceState.getState();
881 Resources r = getResources();
882 String display = r.getString(R.string.radioInfo_unknown);
johnwang342101a2009-09-23 16:22:34 -0700883
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800884 switch (state) {
885 case ServiceState.STATE_IN_SERVICE:
886 display = r.getString(R.string.radioInfo_service_in);
887 break;
888 case ServiceState.STATE_OUT_OF_SERVICE:
889 case ServiceState.STATE_EMERGENCY_ONLY:
890 display = r.getString(R.string.radioInfo_service_emergency);
891 break;
892 case ServiceState.STATE_POWER_OFF:
893 display = r.getString(R.string.radioInfo_service_off);
894 break;
895 }
johnwang342101a2009-09-23 16:22:34 -0700896
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800897 gsmState.setText(display);
johnwang342101a2009-09-23 16:22:34 -0700898
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800899 if (serviceState.getRoaming()) {
900 roamingState.setText(R.string.radioInfo_roaming_in);
901 } else {
902 roamingState.setText(R.string.radioInfo_roaming_not);
903 }
904
905 operatorName.setText(serviceState.getOperatorAlphaLong());
906 }
907
908 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -0700909 updatePhoneState(int state) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800910 Resources r = getResources();
911 String display = r.getString(R.string.radioInfo_unknown);
912
913 switch (state) {
Nathan Harold2b77d742016-03-19 13:22:10 -0700914 case TelephonyManager.CALL_STATE_IDLE:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800915 display = r.getString(R.string.radioInfo_phone_idle);
916 break;
Nathan Harold2b77d742016-03-19 13:22:10 -0700917 case TelephonyManager.CALL_STATE_RINGING:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800918 display = r.getString(R.string.radioInfo_phone_ringing);
919 break;
Nathan Harold2b77d742016-03-19 13:22:10 -0700920 case TelephonyManager.CALL_STATE_OFFHOOK:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800921 display = r.getString(R.string.radioInfo_phone_offhook);
922 break;
923 }
924
925 callState.setText(display);
926 }
927
928 private final void
929 updateDataState() {
930 int state = mTelephonyManager.getDataState();
931 Resources r = getResources();
932 String display = r.getString(R.string.radioInfo_unknown);
933
934 switch (state) {
935 case TelephonyManager.DATA_CONNECTED:
936 display = r.getString(R.string.radioInfo_data_connected);
937 break;
938 case TelephonyManager.DATA_CONNECTING:
939 display = r.getString(R.string.radioInfo_data_connecting);
940 break;
941 case TelephonyManager.DATA_DISCONNECTED:
942 display = r.getString(R.string.radioInfo_data_disconnected);
943 break;
944 case TelephonyManager.DATA_SUSPENDED:
945 display = r.getString(R.string.radioInfo_data_suspended);
946 break;
947 }
johnwang342101a2009-09-23 16:22:34 -0700948
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800949 gprsState.setText(display);
950 }
951
952 private final void updateNetworkType() {
Nathan Harolde272c202016-10-27 13:45:00 -0700953 if(phone != null) {
Nathan Harold2b77d742016-03-19 13:22:10 -0700954 ServiceState ss = phone.getServiceState();
955 dataNetwork.setText(ServiceState.rilRadioTechnologyToString(
956 phone.getServiceState().getRilDataRadioTechnology()));
957 voiceNetwork.setText(ServiceState.rilRadioTechnologyToString(
958 phone.getServiceState().getRilVoiceRadioTechnology()));
959 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800960 }
961
962 private final void
963 updateProperties() {
964 String s;
965 Resources r = getResources();
966
967 s = phone.getDeviceId();
johnwang342101a2009-09-23 16:22:34 -0700968 if (s == null) s = r.getString(R.string.radioInfo_unknown);
Wink Savillec3886682009-04-02 11:00:56 -0700969 mDeviceId.setText(s);
johnwang342101a2009-09-23 16:22:34 -0700970
Meng Wang9053f172017-06-23 16:02:14 -0700971 s = phone.getSubscriberId();
972 if (s == null) s = r.getString(R.string.radioInfo_unknown);
973 mSubscriberId.setText(s);
974
Nathan Haroldcea413a2015-11-23 15:48:10 -0800975 //FIXME: Replace with a TelephonyManager call
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800976 s = phone.getLine1Number();
johnwang342101a2009-09-23 16:22:34 -0700977 if (s == null) s = r.getString(R.string.radioInfo_unknown);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800978 number.setText(s);
979 }
980
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800981 private final void updateDataStats2() {
982 Resources r = getResources();
983
Jeff Sharkey93029862011-05-27 18:26:15 -0700984 long txPackets = TrafficStats.getMobileTxPackets();
985 long rxPackets = TrafficStats.getMobileRxPackets();
986 long txBytes = TrafficStats.getMobileTxBytes();
987 long rxBytes = TrafficStats.getMobileRxBytes();
johnwang342101a2009-09-23 16:22:34 -0700988
Jeff Sharkey93029862011-05-27 18:26:15 -0700989 String packets = r.getString(R.string.radioInfo_display_packets);
990 String bytes = r.getString(R.string.radioInfo_display_bytes);
johnwang342101a2009-09-23 16:22:34 -0700991
Jeff Sharkey93029862011-05-27 18:26:15 -0700992 sent.setText(txPackets + " " + packets + ", " + txBytes + " " + bytes);
993 received.setText(rxPackets + " " + packets + ", " + rxBytes + " " + bytes);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800994 }
995
996 /**
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800997 * Ping a host name
998 */
999 private final void pingHostname() {
1000 try {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001001 try {
1002 Process p4 = Runtime.getRuntime().exec("ping -c 1 www.google.com");
1003 int status4 = p4.waitFor();
1004 if (status4 == 0) {
1005 mPingHostnameResultV4 = "Pass";
1006 } else {
1007 mPingHostnameResultV4 = String.format("Fail(%d)", status4);
1008 }
1009 } catch (IOException e) {
1010 mPingHostnameResultV4 = "Fail: IOException";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001011 }
Nathan Haroldcea413a2015-11-23 15:48:10 -08001012 try {
1013 Process p6 = Runtime.getRuntime().exec("ping6 -c 1 www.google.com");
1014 int status6 = p6.waitFor();
1015 if (status6 == 0) {
1016 mPingHostnameResultV6 = "Pass";
1017 } else {
1018 mPingHostnameResultV6 = String.format("Fail(%d)", status6);
1019 }
1020 } catch (IOException e) {
1021 mPingHostnameResultV6 = "Fail: IOException";
1022 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001023 } catch (InterruptedException e) {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001024 mPingHostnameResultV4 = mPingHostnameResultV6 = "Fail: InterruptedException";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001025 }
1026 }
1027
1028 /**
1029 * This function checks for basic functionality of HTTP Client.
1030 */
1031 private void httpClientTest() {
Narayan Kamathf25627c2014-12-12 13:53:28 +00001032 HttpURLConnection urlConnection = null;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001033 try {
Narayan Kamathf25627c2014-12-12 13:53:28 +00001034 // TODO: Hardcoded for now, make it UI configurable
Alex Klyubinb0090232015-04-02 11:08:51 -07001035 URL url = new URL("https://www.google.com");
Narayan Kamathf25627c2014-12-12 13:53:28 +00001036 urlConnection = (HttpURLConnection) url.openConnection();
1037 if (urlConnection.getResponseCode() == 200) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001038 mHttpClientTestResult = "Pass";
1039 } else {
Narayan Kamathf25627c2014-12-12 13:53:28 +00001040 mHttpClientTestResult = "Fail: Code: " + urlConnection.getResponseMessage();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001041 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001042 } catch (IOException e) {
1043 mHttpClientTestResult = "Fail: IOException";
Narayan Kamathf25627c2014-12-12 13:53:28 +00001044 } finally {
1045 if (urlConnection != null) {
1046 urlConnection.disconnect();
1047 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001048 }
1049 }
1050
1051 private void refreshSmsc() {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001052 //FIXME: Replace with a TelephonyManager call
jsh21dd4072009-05-12 11:26:55 -07001053 phone.getSmscAddress(mHandler.obtainMessage(EVENT_QUERY_SMSC_DONE));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001054 }
1055
Nathan Haroldcea413a2015-11-23 15:48:10 -08001056 private final void updateAllCellInfo() {
1057
1058 mCellInfo.setText("");
Nathan Haroldcea413a2015-11-23 15:48:10 -08001059 mLocation.setText("");
1060
1061 final Runnable updateAllCellInfoResults = new Runnable() {
1062 public void run() {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001063 updateLocation(mCellLocationResult);
1064 updateCellInfo(mCellInfoResult);
1065 }
1066 };
1067
1068 Thread locThread = new Thread() {
1069 @Override
1070 public void run() {
1071 mCellInfoResult = mTelephonyManager.getAllCellInfo();
1072 mCellLocationResult = mTelephonyManager.getCellLocation();
Nathan Haroldcea413a2015-11-23 15:48:10 -08001073
1074 mHandler.post(updateAllCellInfoResults);
1075 }
1076 };
1077 locThread.start();
1078 }
1079
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001080 private final void updatePingState() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001081 // Set all to unknown since the threads will take a few secs to update.
Nathan Haroldcea413a2015-11-23 15:48:10 -08001082 mPingHostnameResultV4 = getResources().getString(R.string.radioInfo_unknown);
1083 mPingHostnameResultV6 = getResources().getString(R.string.radioInfo_unknown);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001084 mHttpClientTestResult = getResources().getString(R.string.radioInfo_unknown);
1085
Nathan Haroldcea413a2015-11-23 15:48:10 -08001086 mPingHostnameV4.setText(mPingHostnameResultV4);
1087 mPingHostnameV6.setText(mPingHostnameResultV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001088 mHttpClientTest.setText(mHttpClientTestResult);
1089
1090 final Runnable updatePingResults = new Runnable() {
1091 public void run() {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001092 mPingHostnameV4.setText(mPingHostnameResultV4);
1093 mPingHostnameV6.setText(mPingHostnameResultV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001094 mHttpClientTest.setText(mHttpClientTestResult);
1095 }
1096 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001097
1098 Thread hostname = new Thread() {
1099 @Override
1100 public void run() {
1101 pingHostname();
Nathan Haroldcea413a2015-11-23 15:48:10 -08001102 mHandler.post(updatePingResults);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001103 }
1104 };
1105 hostname.start();
1106
1107 Thread httpClient = new Thread() {
1108 @Override
1109 public void run() {
1110 httpClientTest();
Nathan Haroldcea413a2015-11-23 15:48:10 -08001111 mHandler.post(updatePingResults);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001112 }
1113 };
1114 httpClient.start();
1115 }
1116
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001117 private MenuItem.OnMenuItemClickListener mViewADNCallback = new MenuItem.OnMenuItemClickListener() {
1118 public boolean onMenuItemClick(MenuItem item) {
1119 Intent intent = new Intent(Intent.ACTION_VIEW);
1120 // XXX We need to specify the component here because if we don't
1121 // the activity manager will try to resolve the type by calling
1122 // the content provider, which causes it to be loaded in a process
1123 // other than the Dialer process, which causes a lot of stuff to
1124 // break.
1125 intent.setClassName("com.android.phone",
1126 "com.android.phone.SimContacts");
1127 startActivity(intent);
1128 return true;
1129 }
1130 };
1131
1132 private MenuItem.OnMenuItemClickListener mViewFDNCallback = new MenuItem.OnMenuItemClickListener() {
1133 public boolean onMenuItemClick(MenuItem item) {
1134 Intent intent = new Intent(Intent.ACTION_VIEW);
1135 // XXX We need to specify the component here because if we don't
1136 // the activity manager will try to resolve the type by calling
1137 // the content provider, which causes it to be loaded in a process
1138 // other than the Dialer process, which causes a lot of stuff to
1139 // break.
1140 intent.setClassName("com.android.phone",
Andrew Leeda90d682014-10-31 13:12:20 -07001141 "com.android.phone.settings.fdn.FdnList");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001142 startActivity(intent);
1143 return true;
1144 }
1145 };
1146
1147 private MenuItem.OnMenuItemClickListener mViewSDNCallback = new MenuItem.OnMenuItemClickListener() {
1148 public boolean onMenuItemClick(MenuItem item) {
1149 Intent intent = new Intent(
Wink Savillec3886682009-04-02 11:00:56 -07001150 Intent.ACTION_VIEW, Uri.parse("content://icc/sdn"));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001151 // XXX We need to specify the component here because if we don't
1152 // the activity manager will try to resolve the type by calling
1153 // the content provider, which causes it to be loaded in a process
1154 // other than the Dialer process, which causes a lot of stuff to
1155 // break.
1156 intent.setClassName("com.android.phone",
1157 "com.android.phone.ADNList");
1158 startActivity(intent);
1159 return true;
1160 }
1161 };
1162
Nathan Harolde272c202016-10-27 13:45:00 -07001163 private MenuItem.OnMenuItemClickListener mGetImsStatus = new MenuItem.OnMenuItemClickListener() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001164 public boolean onMenuItemClick(MenuItem item) {
Nathan Harolde272c202016-10-27 13:45:00 -07001165 boolean isImsRegistered = phone.isImsRegistered();
1166 boolean availableVolte = phone.isVolteEnabled();
1167 boolean availableWfc = phone.isWifiCallingEnabled();
1168 boolean availableVt = phone.isVideoEnabled();
1169 boolean availableUt = phone.isUtEnabled();
1170
1171 final String imsRegString = isImsRegistered ?
1172 getString(R.string.radio_info_ims_reg_status_registered) :
1173 getString(R.string.radio_info_ims_reg_status_not_registered);
1174
1175 final String available = getString(R.string.radio_info_ims_feature_status_available);
1176 final String unavailable = getString(
1177 R.string.radio_info_ims_feature_status_unavailable);
1178
1179 String imsStatus = getString(R.string.radio_info_ims_reg_status,
1180 imsRegString,
1181 availableVolte ? available : unavailable,
1182 availableWfc ? available : unavailable,
1183 availableVt ? available : unavailable,
1184 availableUt ? available : unavailable);
1185
1186 AlertDialog imsDialog = new AlertDialog.Builder(RadioInfo.this)
1187 .setMessage(imsStatus)
1188 .setTitle(getString(R.string.radio_info_ims_reg_status_title))
1189 .create();
1190
1191 imsDialog.show();
1192
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001193 return true;
1194 }
1195 };
1196
1197 private MenuItem.OnMenuItemClickListener mSelectBandCallback = new MenuItem.OnMenuItemClickListener() {
1198 public boolean onMenuItemClick(MenuItem item) {
1199 Intent intent = new Intent();
1200 intent.setClass(RadioInfo.this, BandMode.class);
1201 startActivity(intent);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001202 return true;
1203 }
1204 };
johnwang342101a2009-09-23 16:22:34 -07001205
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001206 private MenuItem.OnMenuItemClickListener mToggleData = new MenuItem.OnMenuItemClickListener() {
1207 public boolean onMenuItemClick(MenuItem item) {
1208 int state = mTelephonyManager.getDataState();
1209 switch (state) {
1210 case TelephonyManager.DATA_CONNECTED:
Jack Yue5accf72018-12-13 11:51:20 -08001211 mTelephonyManager.setDataEnabled(false);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001212 break;
1213 case TelephonyManager.DATA_DISCONNECTED:
Jack Yue5accf72018-12-13 11:51:20 -08001214 mTelephonyManager.setDataEnabled(true);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001215 break;
1216 default:
1217 // do nothing
1218 break;
1219 }
1220 return true;
1221 }
1222 };
1223
Nathan Harold2b77d742016-03-19 13:22:10 -07001224 private boolean isRadioOn() {
1225 //FIXME: Replace with a TelephonyManager call
1226 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1227 }
1228
1229 private void updateRadioPowerState() {
1230 //delightful hack to prevent on-checked-changed calls from
1231 //actually forcing the radio preference to its transient/current value.
1232 radioPowerOnSwitch.setOnCheckedChangeListener(null);
1233 radioPowerOnSwitch.setChecked(isRadioOn());
1234 radioPowerOnSwitch.setOnCheckedChangeListener(mRadioPowerOnChangeListener);
1235 }
1236
Nathan Harolde272c202016-10-27 13:45:00 -07001237 void setImsVolteProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001238 Log.d(TAG, "setImsVolteProvisioned state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001239 setImsConfigProvisionedState(IMS_VOLTE_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001240 }
1241
Nathan Harolde272c202016-10-27 13:45:00 -07001242 void setImsVtProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001243 Log.d(TAG, "setImsVtProvisioned() state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001244 setImsConfigProvisionedState(IMS_VT_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001245 }
1246
Nathan Harolde272c202016-10-27 13:45:00 -07001247 void setImsWfcProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001248 Log.d(TAG, "setImsWfcProvisioned() state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001249 setImsConfigProvisionedState(IMS_WFC_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001250 }
1251
Meng Wang586741c2017-04-26 15:02:51 -07001252 void setEabProvisionedState(boolean state) {
1253 Log.d(TAG, "setEabProvisioned() state: " + ((state)? "on":"off"));
1254 setImsConfigProvisionedState(EAB_PROVISIONED_CONFIG_ID, state);
1255 }
1256
Nathan Harolde272c202016-10-27 13:45:00 -07001257 void setImsConfigProvisionedState(int configItem, boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001258 if (phone != null && mImsManager != null) {
Philip P. Moltmann5c449ae2017-02-14 12:43:02 -08001259 QueuedWork.queue(new Runnable() {
Nathan Harold12e1f552016-06-17 13:55:38 -07001260 public void run() {
1261 try {
1262 mImsManager.getConfigInterface().setProvisionedValue(
1263 configItem,
1264 state? 1 : 0);
1265 } catch (ImsException e) {
1266 Log.e(TAG, "setImsConfigProvisioned() exception:", e);
1267 }
1268 }
Philip P. Moltmann5c449ae2017-02-14 12:43:02 -08001269 }, false);
Nathan Harold12e1f552016-06-17 13:55:38 -07001270 }
1271 }
1272
Nathan Harold2b77d742016-03-19 13:22:10 -07001273 OnCheckedChangeListener mRadioPowerOnChangeListener = new OnCheckedChangeListener() {
1274 @Override
1275 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1276 log("toggle radio power: currently " + (isRadioOn()?"on":"off"));
1277 phone.setRadioPower(isChecked);
1278 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001279 };
1280
Nathan Harold12e1f552016-06-17 13:55:38 -07001281 private boolean isImsVolteProvisioned() {
Nathan Harold2b77d742016-03-19 13:22:10 -07001282 if (phone != null && mImsManager != null) {
1283 return mImsManager.isVolteEnabledByPlatform(phone.getContext())
1284 && mImsManager.isVolteProvisionedOnDevice(phone.getContext());
Pavel Zhamaitsiakcb267a62015-01-21 18:25:14 -08001285 }
1286 return false;
1287 }
1288
Nathan Harold12e1f552016-06-17 13:55:38 -07001289 OnCheckedChangeListener mImsVolteCheckedChangeListener = new OnCheckedChangeListener() {
Wink Saville426fc662011-09-25 14:39:02 -07001290 @Override
Nathan Harold2b77d742016-03-19 13:22:10 -07001291 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001292 setImsVolteProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001293 }
Wink Saville426fc662011-09-25 14:39:02 -07001294 };
1295
Nathan Harold12e1f552016-06-17 13:55:38 -07001296 private boolean isImsVtProvisioned() {
1297 if (phone != null && mImsManager != null) {
1298 return mImsManager.isVtEnabledByPlatform(phone.getContext())
1299 && mImsManager.isVtProvisionedOnDevice(phone.getContext());
1300 }
1301 return false;
1302 }
1303
1304 OnCheckedChangeListener mImsVtCheckedChangeListener = new OnCheckedChangeListener() {
1305 @Override
1306 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1307 setImsVtProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001308 }
Nathan Harold12e1f552016-06-17 13:55:38 -07001309 };
1310
1311 private boolean isImsWfcProvisioned() {
1312 if (phone != null && mImsManager != null) {
1313 return mImsManager.isWfcEnabledByPlatform(phone.getContext())
1314 && mImsManager.isWfcProvisionedOnDevice(phone.getContext());
1315 }
1316 return false;
1317 }
1318
1319 OnCheckedChangeListener mImsWfcCheckedChangeListener = new OnCheckedChangeListener() {
1320 @Override
1321 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1322 setImsWfcProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001323 }
Nathan Harold12e1f552016-06-17 13:55:38 -07001324 };
1325
Meng Wang586741c2017-04-26 15:02:51 -07001326 private boolean isEabProvisioned() {
1327 return isFeatureProvisioned(EAB_PROVISIONED_CONFIG_ID, false);
1328 }
1329
1330 OnCheckedChangeListener mEabCheckedChangeListener = new OnCheckedChangeListener() {
1331 @Override
1332 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1333 setEabProvisionedState(isChecked);
1334 }
1335 };
1336
1337 private boolean isFeatureProvisioned(int featureId, boolean defaultValue) {
1338 boolean provisioned = defaultValue;
1339 if (mImsManager != null) {
1340 try {
1341 ImsConfig imsConfig = mImsManager.getConfigInterface();
1342 if (imsConfig != null) {
1343 provisioned =
1344 (imsConfig.getProvisionedValue(featureId)
1345 == ImsConfig.FeatureValueConstants.ON);
1346 }
1347 } catch (ImsException ex) {
1348 Log.e(TAG, "isFeatureProvisioned() exception:", ex);
1349 }
1350 }
1351
1352 log("isFeatureProvisioned() featureId=" + featureId + " provisioned=" + provisioned);
1353 return provisioned;
1354 }
1355
1356 private static boolean isEabEnabledByPlatform(Context context) {
1357 if (context != null) {
1358 CarrierConfigManager configManager = (CarrierConfigManager)
1359 context.getSystemService(Context.CARRIER_CONFIG_SERVICE);
1360 if (configManager != null && configManager.getConfig().getBoolean(
1361 CarrierConfigManager.KEY_USE_RCS_PRESENCE_BOOL)) {
1362 return true;
1363 }
1364 }
1365 return false;
1366 }
1367
Nathan Harold12e1f552016-06-17 13:55:38 -07001368 private void updateImsProvisionedState() {
Brad Ebinger8bff9c32019-03-11 17:33:53 -07001369 if (!ImsManager.isImsSupportedOnDevice(phone.getContext())) {
1370 return;
1371 }
Nathan Harold12e1f552016-06-17 13:55:38 -07001372 log("updateImsProvisionedState isImsVolteProvisioned()=" + isImsVolteProvisioned());
Nathan Harold2b77d742016-03-19 13:22:10 -07001373 //delightful hack to prevent on-checked-changed calls from
1374 //actually forcing the ims provisioning to its transient/current value.
Nathan Harold12e1f552016-06-17 13:55:38 -07001375 imsVolteProvisionedSwitch.setOnCheckedChangeListener(null);
1376 imsVolteProvisionedSwitch.setChecked(isImsVolteProvisioned());
1377 imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
Sreekanth Badidac888e192018-02-05 17:18:40 +01001378 imsVolteProvisionedSwitch.setEnabled(!Build.IS_USER
1379 && mImsManager.isVolteEnabledByPlatform(phone.getContext()));
Nathan Harold12e1f552016-06-17 13:55:38 -07001380
1381 imsVtProvisionedSwitch.setOnCheckedChangeListener(null);
1382 imsVtProvisionedSwitch.setChecked(isImsVtProvisioned());
1383 imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
Sreekanth Badidac888e192018-02-05 17:18:40 +01001384 imsVtProvisionedSwitch.setEnabled(!Build.IS_USER
1385 && mImsManager.isVtEnabledByPlatform(phone.getContext()));
Nathan Harold12e1f552016-06-17 13:55:38 -07001386
1387 imsWfcProvisionedSwitch.setOnCheckedChangeListener(null);
1388 imsWfcProvisionedSwitch.setChecked(isImsWfcProvisioned());
1389 imsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
Sreekanth Badidac888e192018-02-05 17:18:40 +01001390 imsWfcProvisionedSwitch.setEnabled(!Build.IS_USER
1391 && mImsManager.isWfcEnabledByPlatform(phone.getContext()));
Meng Wang586741c2017-04-26 15:02:51 -07001392
1393 eabProvisionedSwitch.setOnCheckedChangeListener(null);
1394 eabProvisionedSwitch.setChecked(isEabProvisioned());
1395 eabProvisionedSwitch.setOnCheckedChangeListener(mEabCheckedChangeListener);
Sreekanth Badidac888e192018-02-05 17:18:40 +01001396 eabProvisionedSwitch.setEnabled(!Build.IS_USER
1397 && isEabEnabledByPlatform(phone.getContext()));
Wink Saville426fc662011-09-25 14:39:02 -07001398 }
1399
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001400 OnClickListener mDnsCheckButtonHandler = new OnClickListener() {
1401 public void onClick(View v) {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001402 //FIXME: Replace with a TelephonyManager call
Wink Savillec3886682009-04-02 11:00:56 -07001403 phone.disableDnsCheck(!phone.isDnsCheckDisabled());
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001404 updateDnsCheckState();
1405 }
1406 };
johnwang342101a2009-09-23 16:22:34 -07001407
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001408 OnClickListener mOemInfoButtonHandler = new OnClickListener() {
1409 public void onClick(View v) {
1410 Intent intent = new Intent("com.android.settings.OEM_RADIO_INFO");
1411 try {
1412 startActivity(intent);
1413 } catch (android.content.ActivityNotFoundException ex) {
Wink Savillebf471282013-04-05 15:04:05 -07001414 log("OEM-specific Info/Settings Activity Not Found : " + ex);
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001415 // If the activity does not exist, there are no OEM
1416 // settings, and so we can just do nothing...
1417 }
1418 }
1419 };
1420
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001421 OnClickListener mPingButtonHandler = new OnClickListener() {
1422 public void onClick(View v) {
1423 updatePingState();
1424 }
1425 };
1426
1427 OnClickListener mUpdateSmscButtonHandler = new OnClickListener() {
1428 public void onClick(View v) {
1429 updateSmscButton.setEnabled(false);
jsh21dd4072009-05-12 11:26:55 -07001430 phone.setSmscAddress(smsc.getText().toString(),
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001431 mHandler.obtainMessage(EVENT_UPDATE_SMSC_DONE));
1432 }
1433 };
1434
1435 OnClickListener mRefreshSmscButtonHandler = new OnClickListener() {
1436 public void onClick(View v) {
1437 refreshSmsc();
1438 }
1439 };
1440
Youhan Wangfd781e92016-12-16 15:53:16 -08001441 OnClickListener mCarrierProvisioningButtonHandler = new OnClickListener() {
1442 public void onClick(View v) {
Meng Wanga04449b2017-08-03 14:34:35 -07001443 final Intent intent = new Intent("com.android.settings.CARRIER_PROVISIONING");
1444 final ComponentName serviceComponent = ComponentName.unflattenFromString(
1445 "com.android.omadm.service/.DMIntentReceiver");
Youhan Wangfd781e92016-12-16 15:53:16 -08001446 intent.setComponent(serviceComponent);
Meng Wanga04449b2017-08-03 14:34:35 -07001447 sendBroadcast(intent);
Youhan Wangfd781e92016-12-16 15:53:16 -08001448 }
1449 };
1450
1451 OnClickListener mTriggerCarrierProvisioningButtonHandler = new OnClickListener() {
1452 public void onClick(View v) {
Meng Wanga04449b2017-08-03 14:34:35 -07001453 final Intent intent = new Intent("com.android.settings.TRIGGER_CARRIER_PROVISIONING");
1454 final ComponentName serviceComponent = ComponentName.unflattenFromString(
1455 "com.android.omadm.service/.DMIntentReceiver");
Youhan Wangfd781e92016-12-16 15:53:16 -08001456 intent.setComponent(serviceComponent);
Meng Wanga04449b2017-08-03 14:34:35 -07001457 sendBroadcast(intent);
Youhan Wangfd781e92016-12-16 15:53:16 -08001458 }
1459 };
1460
Nathan Haroldcea413a2015-11-23 15:48:10 -08001461 AdapterView.OnItemSelectedListener mPreferredNetworkHandler =
1462 new AdapterView.OnItemSelectedListener() {
1463
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001464 public void onItemSelected(AdapterView parent, View v, int pos, long id) {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001465 if (mPreferredNetworkTypeResult != pos && pos >= 0
1466 && pos <= mPreferredNetworkLabels.length - 2) {
1467 mPreferredNetworkTypeResult = pos;
Nathan Harolddaea8be2018-06-05 14:02:35 -07001468
1469 // TODO: Possibly migrate this to TelephonyManager.setPreferredNetworkType()
1470 // which today still has some issues (mostly that the "set" is conditional
1471 // on a successful modem call, which is not what we want). Instead we always
1472 // want this setting to be set, so that if the radio hiccups and this setting
1473 // is for some reason unsuccessful, future calls to the radio will reflect
1474 // the users's preference which is set here.
1475 final int subId = phone.getSubId();
1476 if (SubscriptionManager.isUsableSubIdValue(subId)) {
1477 Settings.Global.putInt(phone.getContext().getContentResolver(),
1478 PREFERRED_NETWORK_MODE + subId, mPreferredNetworkTypeResult);
1479 }
1480 log("Calling setPreferredNetworkType(" + mPreferredNetworkTypeResult + ")");
Nathan Haroldcea413a2015-11-23 15:48:10 -08001481 Message msg = mHandler.obtainMessage(EVENT_SET_PREFERRED_TYPE_DONE);
1482 phone.setPreferredNetworkType(mPreferredNetworkTypeResult, msg);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001483 }
1484 }
1485
1486 public void onNothingSelected(AdapterView parent) {
1487 }
1488 };
1489
Nathan Harold2b77d742016-03-19 13:22:10 -07001490 AdapterView.OnItemSelectedListener mCellInfoRefreshRateHandler =
1491 new AdapterView.OnItemSelectedListener() {
Wink Savillebf471282013-04-05 15:04:05 -07001492
Nathan Harold2b77d742016-03-19 13:22:10 -07001493 public void onItemSelected(AdapterView parent, View v, int pos, long id) {
1494 mCellInfoRefreshRateIndex = pos;
Sooraj Sasindran5cce06b2016-08-18 15:49:49 -07001495 mTelephonyManager.setCellInfoListRate(mCellInfoRefreshRates[pos]);
Nathan Harold2b77d742016-03-19 13:22:10 -07001496 updateAllCellInfo();
1497 }
1498
1499 public void onNothingSelected(AdapterView parent) {
1500 }
1501 };
1502
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001503}