blob: 5d3afa5ff58956eb5800a7dfcb02cbddf9e0b3f3 [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;
Wink Saville4f0d8812014-04-15 22:05:24 -070059import android.telephony.DataConnectionRealTimeInfo;
Jason Monk39b46742015-09-10 15:52:51 -040060import android.telephony.NeighboringCellInfo;
Nathan Harold2b77d742016-03-19 13:22:10 -070061import android.telephony.PreciseCallState;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080062import android.telephony.PhoneStateListener;
Nathan Harold433ca442018-04-23 18:20:43 -070063import android.telephony.PhysicalChannelConfig;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080064import android.telephony.ServiceState;
Nathan Harold2b77d742016-03-19 13:22:10 -070065import android.telephony.SignalStrength;
Nathan Haroldcea413a2015-11-23 15:48:10 -080066import android.telephony.SubscriptionManager;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080067import android.telephony.TelephonyManager;
jsh534f5ae2009-09-24 09:19:22 -070068import android.telephony.cdma.CdmaCellLocation;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080069import android.telephony.gsm.GsmCellLocation;
Nathan Harold6e16fdf2018-04-17 17:01:32 -070070import android.text.TextUtils;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080071import android.util.Log;
72import android.view.Menu;
73import android.view.MenuItem;
74import android.view.View;
75import android.view.View.OnClickListener;
76import android.widget.AdapterView;
77import android.widget.ArrayAdapter;
78import android.widget.Button;
Nathan Harold2b77d742016-03-19 13:22:10 -070079import android.widget.CompoundButton;
80import android.widget.CompoundButton.OnCheckedChangeListener;
Jason Monk39b46742015-09-10 15:52:51 -040081import android.widget.EditText;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080082import android.widget.Spinner;
Nathan Harold2b77d742016-03-19 13:22:10 -070083import android.widget.Switch;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080084import android.widget.TextView;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080085
Jason Monk39b46742015-09-10 15:52:51 -040086import com.android.ims.ImsConfig;
87import com.android.ims.ImsException;
88import com.android.ims.ImsManager;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080089import com.android.internal.telephony.Phone;
Wink Saville55434042012-06-14 12:33:43 -070090import com.android.internal.telephony.PhoneConstants;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080091import com.android.internal.telephony.PhoneFactory;
Nathan Haroldcea413a2015-11-23 15:48:10 -080092import com.android.internal.telephony.RILConstants;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080093import com.android.internal.telephony.TelephonyProperties;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080094
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080095import java.io.IOException;
Jason Monk39b46742015-09-10 15:52:51 -040096import java.net.HttpURLConnection;
97import java.net.URL;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080098import java.net.UnknownHostException;
99import java.util.ArrayList;
100import java.util.List;
101
102public class RadioInfo extends Activity {
Nathan Harold2b77d742016-03-19 13:22:10 -0700103 private static final String TAG = "RadioInfo";
johnwang342101a2009-09-23 16:22:34 -0700104
Nathan Harold2b77d742016-03-19 13:22:10 -0700105 private static final String[] mPreferredNetworkLabels = {
106 "WCDMA preferred",
107 "GSM only",
108 "WCDMA only",
109 "GSM auto (PRL)",
110 "CDMA auto (PRL)",
111 "CDMA only",
112 "EvDo only",
113 "Global auto (PRL)",
114 "LTE/CDMA auto (PRL)",
115 "LTE/UMTS auto (PRL)",
116 "LTE/CDMA/UMTS auto (PRL)",
117 "LTE only",
118 "LTE/WCDMA",
119 "TD-SCDMA only",
120 "TD-SCDMA/WCDMA",
121 "LTE/TD-SCDMA",
122 "TD-SCDMA/GSM",
123 "TD-SCDMA/UMTS",
124 "LTE/TD-SCDMA/WCDMA",
125 "LTE/TD-SCDMA/UMTS",
126 "TD-SCDMA/CDMA/UMTS",
127 "Global/TD-SCDMA",
128 "Unknown"
129 };
130
131
132 private static final int CELL_INFO_LIST_RATE_DISABLED = Integer.MAX_VALUE;
133 private static final int CELL_INFO_LIST_RATE_MAX = 0;
134
Nathan Harold12e1f552016-06-17 13:55:38 -0700135
136 private static final int IMS_VOLTE_PROVISIONED_CONFIG_ID =
137 ImsConfig.ConfigConstants.VLT_SETTING_ENABLED;
138
139 private static final int IMS_VT_PROVISIONED_CONFIG_ID =
140 ImsConfig.ConfigConstants.LVC_SETTING_ENABLED;
141
142 private static final int IMS_WFC_PROVISIONED_CONFIG_ID =
143 ImsConfig.ConfigConstants.VOICE_OVER_WIFI_SETTING_ENABLED;
144
Meng Wang586741c2017-04-26 15:02:51 -0700145 private static final int EAB_PROVISIONED_CONFIG_ID =
146 ImsConfig.ConfigConstants.EAB_SETTING_ENABLED;
147
Nathan Harold2b77d742016-03-19 13:22:10 -0700148 //Values in must match mCellInfoRefreshRates
149 private static final String[] mCellInfoRefreshRateLabels = {
150 "Disabled",
151 "Immediate",
152 "Min 5s",
153 "Min 10s",
154 "Min 60s"
155 };
156
157 //Values in seconds, must match mCellInfoRefreshRateLabels
158 private static final int mCellInfoRefreshRates[] = {
159 CELL_INFO_LIST_RATE_DISABLED,
160 CELL_INFO_LIST_RATE_MAX,
161 5000,
162 10000,
163 60000
164 };
165
166 private void log(String s) {
167 Log.d(TAG, s);
168 }
169
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800170 private static final int EVENT_CFI_CHANGED = 302;
171
172 private static final int EVENT_QUERY_PREFERRED_TYPE_DONE = 1000;
173 private static final int EVENT_SET_PREFERRED_TYPE_DONE = 1001;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800174 private static final int EVENT_QUERY_SMSC_DONE = 1005;
175 private static final int EVENT_UPDATE_SMSC_DONE = 1006;
176
177 private static final int MENU_ITEM_SELECT_BAND = 0;
178 private static final int MENU_ITEM_VIEW_ADN = 1;
179 private static final int MENU_ITEM_VIEW_FDN = 2;
180 private static final int MENU_ITEM_VIEW_SDN = 3;
Nathan Harolde272c202016-10-27 13:45:00 -0700181 private static final int MENU_ITEM_GET_IMS_STATUS = 4;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800182 private static final int MENU_ITEM_TOGGLE_DATA = 5;
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800183
Wink Savillec3886682009-04-02 11:00:56 -0700184 private TextView mDeviceId; //DeviceId is the IMEI in GSM and the MEID in CDMA
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800185 private TextView number;
Meng Wang9053f172017-06-23 16:02:14 -0700186 private TextView mSubscriberId;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800187 private TextView callState;
188 private TextView operatorName;
189 private TextView roamingState;
190 private TextView gsmState;
191 private TextView gprsState;
Nathan Harold2b77d742016-03-19 13:22:10 -0700192 private TextView voiceNetwork;
193 private TextView dataNetwork;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800194 private TextView dBm;
195 private TextView mMwi;
196 private TextView mCfi;
197 private TextView mLocation;
198 private TextView mNeighboringCids;
Wink Saville79bff2a2012-06-01 14:37:21 -0700199 private TextView mCellInfo;
Wink Saville4f0d8812014-04-15 22:05:24 -0700200 private TextView mDcRtInfoTv;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800201 private TextView sent;
202 private TextView received;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800203 private TextView mPingHostnameV4;
204 private TextView mPingHostnameV6;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800205 private TextView mHttpClientTest;
Nathan Harold433ca442018-04-23 18:20:43 -0700206 private TextView mPhyChanConfig;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800207 private TextView dnsCheckState;
Nathan Haroldf10ea322018-04-24 13:31:07 -0700208 private TextView mDownlinkKbps;
209 private TextView mUplinkKbps;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800210 private EditText smsc;
Nathan Harold2b77d742016-03-19 13:22:10 -0700211 private Switch radioPowerOnSwitch;
212 private Button cellInfoRefreshRateButton;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800213 private Button dnsCheckToggleButton;
214 private Button pingTestButton;
215 private Button updateSmscButton;
216 private Button refreshSmscButton;
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800217 private Button oemInfoButton;
Youhan Wangfd781e92016-12-16 15:53:16 -0800218 private Button carrierProvisioningButton;
219 private Button triggercarrierProvisioningButton;
Nathan Harold12e1f552016-06-17 13:55:38 -0700220 private Switch imsVolteProvisionedSwitch;
221 private Switch imsVtProvisionedSwitch;
222 private Switch imsWfcProvisionedSwitch;
Meng Wang586741c2017-04-26 15:02:51 -0700223 private Switch eabProvisionedSwitch;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800224 private Spinner preferredNetworkType;
Nathan Harold2b77d742016-03-19 13:22:10 -0700225 private Spinner cellInfoRefreshRateSpinner;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800226
Nathan Haroldf10ea322018-04-24 13:31:07 -0700227 private ConnectivityManager mConnectivityManager;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800228 private TelephonyManager mTelephonyManager;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800229 private ImsManager mImsManager = null;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800230 private Phone phone = null;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800231
Nathan Haroldcea413a2015-11-23 15:48:10 -0800232 private String mPingHostnameResultV4;
233 private String mPingHostnameResultV6;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800234 private String mHttpClientTestResult;
235 private boolean mMwiValue = false;
236 private boolean mCfiValue = false;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800237
238 private List<CellInfo> mCellInfoResult = null;
239 private CellLocation mCellLocationResult = null;
240 private List<NeighboringCellInfo> mNeighboringCellResult = null;
241
242 private int mPreferredNetworkTypeResult;
Nathan Harold2b77d742016-03-19 13:22:10 -0700243 private int mCellInfoRefreshRateIndex;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800244
Nathan Haroldf10ea322018-04-24 13:31:07 -0700245 private final NetworkRequest mDefaultNetworkRequest = new NetworkRequest.Builder()
246 .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
247 .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
248 .build();
249
250 private final NetworkCallback mNetworkCallback = new NetworkCallback() {
251 public void onCapabilitiesChanged(Network n, NetworkCapabilities nc) {
252 int dlbw = nc.getLinkDownstreamBandwidthKbps();
253 int ulbw = nc.getLinkUpstreamBandwidthKbps();
254 updateBandwidths(dlbw, ulbw);
255 }
256 };
257
Nathan Harold2b77d742016-03-19 13:22:10 -0700258 private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800259 @Override
260 public void onDataConnectionStateChanged(int state) {
261 updateDataState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800262 updateNetworkType();
263 }
264
265 @Override
266 public void onDataActivity(int direction) {
267 updateDataStats2();
268 }
269
270 @Override
Nathan Harold2b77d742016-03-19 13:22:10 -0700271 public void onCallStateChanged(int state, String incomingNumber) {
272 updateNetworkType();
273 updatePhoneState(state);
274 }
275
276 @Override
277 public void onPreciseCallStateChanged(PreciseCallState preciseState) {
278 updateNetworkType();
279 }
280
281 @Override
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800282 public void onCellLocationChanged(CellLocation location) {
283 updateLocation(location);
284 }
285
286 @Override
287 public void onMessageWaitingIndicatorChanged(boolean mwi) {
288 mMwiValue = mwi;
289 updateMessageWaiting();
290 }
291
292 @Override
293 public void onCallForwardingIndicatorChanged(boolean cfi) {
294 mCfiValue = cfi;
295 updateCallRedirect();
296 }
Wink Saville79bff2a2012-06-01 14:37:21 -0700297
298 @Override
299 public void onCellInfoChanged(List<CellInfo> arrayCi) {
Wink Savillebf471282013-04-05 15:04:05 -0700300 log("onCellInfoChanged: arrayCi=" + arrayCi);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800301 mCellInfoResult = arrayCi;
302 updateCellInfo(mCellInfoResult);
Wink Saville79bff2a2012-06-01 14:37:21 -0700303 }
Wink Saville4f0d8812014-04-15 22:05:24 -0700304
305 @Override
306 public void onDataConnectionRealTimeInfoChanged(DataConnectionRealTimeInfo dcRtInfo) {
307 log("onDataConnectionRealTimeInfoChanged: dcRtInfo=" + dcRtInfo);
308 updateDcRtInfoTv(dcRtInfo);
309 }
Nathan Harold2b77d742016-03-19 13:22:10 -0700310
311 @Override
312 public void onSignalStrengthsChanged(SignalStrength signalStrength) {
313 log("onSignalStrengthChanged: SignalStrength=" +signalStrength);
314 updateSignalStrength(signalStrength);
315 }
316
317 @Override
318 public void onServiceStateChanged(ServiceState serviceState) {
319 log("onServiceStateChanged: ServiceState=" + serviceState);
320 updateServiceState(serviceState);
321 updateRadioPowerState();
322 updateNetworkType();
Nathan Harold12e1f552016-06-17 13:55:38 -0700323 updateImsProvisionedState();
Nathan Harold2b77d742016-03-19 13:22:10 -0700324 }
Nathan Harold433ca442018-04-23 18:20:43 -0700325
326 @Override
327 public void onPhysicalChannelConfigurationChanged(
328 List<PhysicalChannelConfig> configs) {
329 updatePhysicalChannelConfiguration(configs);
330 }
331
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800332 };
333
Nathan Harold433ca442018-04-23 18:20:43 -0700334 private void updatePhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
335 StringBuilder sb = new StringBuilder();
336 String div = "";
337 sb.append("{");
338 if (configs != null) {
339 for(PhysicalChannelConfig c : configs) {
340 sb.append(div).append(c);
341 div = ",";
342 }
343 }
344 sb.append("}");
345 mPhyChanConfig.setText(sb.toString());
346 }
347
Nathan Haroldcea413a2015-11-23 15:48:10 -0800348 private void updatePreferredNetworkType(int type) {
349 if (type >= mPreferredNetworkLabels.length || type < 0) {
350 log("EVENT_QUERY_PREFERRED_TYPE_DONE: unknown " +
351 "type=" + type);
352 type = mPreferredNetworkLabels.length - 1; //set to Unknown
353 }
354 mPreferredNetworkTypeResult = type;
355
356 preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true);
357 }
358
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800359 private Handler mHandler = new Handler() {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800360 @Override
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800361 public void handleMessage(Message msg) {
362 AsyncResult ar;
363 switch (msg.what) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800364 case EVENT_QUERY_PREFERRED_TYPE_DONE:
365 ar= (AsyncResult) msg.obj;
Nathan Haroldcea413a2015-11-23 15:48:10 -0800366 if (ar.exception == null && ar.result != null) {
367 updatePreferredNetworkType(((int[])ar.result)[0]);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800368 } else {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800369 //In case of an exception, we will set this to unknown
370 updatePreferredNetworkType(mPreferredNetworkLabels.length-1);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800371 }
372 break;
373 case EVENT_SET_PREFERRED_TYPE_DONE:
374 ar= (AsyncResult) msg.obj;
375 if (ar.exception != null) {
Nathan Harolded38afa2016-04-13 00:29:30 -0700376 log("Set preferred network type failed.");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800377 }
378 break;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800379 case EVENT_QUERY_SMSC_DONE:
380 ar= (AsyncResult) msg.obj;
381 if (ar.exception != null) {
382 smsc.setText("refresh error");
383 } else {
jsh21dd4072009-05-12 11:26:55 -0700384 smsc.setText((String)ar.result);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800385 }
386 break;
387 case EVENT_UPDATE_SMSC_DONE:
388 updateSmscButton.setEnabled(true);
389 ar= (AsyncResult) msg.obj;
390 if (ar.exception != null) {
391 smsc.setText("update error");
392 }
393 break;
394 default:
Nathan Haroldcea413a2015-11-23 15:48:10 -0800395 super.handleMessage(msg);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800396 break;
397
398 }
399 }
400 };
401
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800402 @Override
403 public void onCreate(Bundle icicle) {
404 super.onCreate(icicle);
fionaxub54cb2d2016-09-22 15:01:05 -0700405 if (!android.os.Process.myUserHandle().isSystem()) {
406 Log.e(TAG, "Not run from system user, don't do anything.");
407 finish();
408 return;
409 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800410
411 setContentView(R.layout.radio_info);
412
Nathan Haroldcea413a2015-11-23 15:48:10 -0800413 log("Started onCreate");
414
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800415 mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
Nathan Haroldf10ea322018-04-24 13:31:07 -0700416 mConnectivityManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800417 phone = PhoneFactory.getDefaultPhone();
418
Nathan Haroldcea413a2015-11-23 15:48:10 -0800419 //TODO: Need to update this if the default phoneId changes?
420 // Better to have an instance per phone?
421 mImsManager = ImsManager.getInstance(getApplicationContext(),
422 SubscriptionManager.getDefaultVoicePhoneId());
423
Meng Wang9053f172017-06-23 16:02:14 -0700424 mDeviceId = (TextView) findViewById(R.id.imei);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800425 number = (TextView) findViewById(R.id.number);
Meng Wang9053f172017-06-23 16:02:14 -0700426 mSubscriberId = (TextView) findViewById(R.id.imsi);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800427 callState = (TextView) findViewById(R.id.call);
428 operatorName = (TextView) findViewById(R.id.operator);
429 roamingState = (TextView) findViewById(R.id.roaming);
430 gsmState = (TextView) findViewById(R.id.gsm);
431 gprsState = (TextView) findViewById(R.id.gprs);
Nathan Harold2b77d742016-03-19 13:22:10 -0700432 voiceNetwork = (TextView) findViewById(R.id.voice_network);
433 dataNetwork = (TextView) findViewById(R.id.data_network);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800434 dBm = (TextView) findViewById(R.id.dbm);
435 mMwi = (TextView) findViewById(R.id.mwi);
436 mCfi = (TextView) findViewById(R.id.cfi);
437 mLocation = (TextView) findViewById(R.id.location);
438 mNeighboringCids = (TextView) findViewById(R.id.neighboring);
Wink Saville79bff2a2012-06-01 14:37:21 -0700439 mCellInfo = (TextView) findViewById(R.id.cellinfo);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800440 mCellInfo.setTypeface(Typeface.MONOSPACE);
Wink Saville4f0d8812014-04-15 22:05:24 -0700441 mDcRtInfoTv = (TextView) findViewById(R.id.dcrtinfo);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800442
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800443 sent = (TextView) findViewById(R.id.sent);
444 received = (TextView) findViewById(R.id.received);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800445 smsc = (EditText) findViewById(R.id.smsc);
446 dnsCheckState = (TextView) findViewById(R.id.dnsCheckState);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800447 mPingHostnameV4 = (TextView) findViewById(R.id.pingHostnameV4);
448 mPingHostnameV6 = (TextView) findViewById(R.id.pingHostnameV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800449 mHttpClientTest = (TextView) findViewById(R.id.httpClientTest);
450
Nathan Harold433ca442018-04-23 18:20:43 -0700451 mPhyChanConfig = (TextView) findViewById(R.id.phy_chan_config);
452
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800453 preferredNetworkType = (Spinner) findViewById(R.id.preferredNetworkType);
454 ArrayAdapter<String> adapter = new ArrayAdapter<String> (this,
455 android.R.layout.simple_spinner_item, mPreferredNetworkLabels);
johnwang342101a2009-09-23 16:22:34 -0700456 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800457 preferredNetworkType.setAdapter(adapter);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800458
Nathan Harold2b77d742016-03-19 13:22:10 -0700459 cellInfoRefreshRateSpinner = (Spinner) findViewById(R.id.cell_info_rate_select);
460 ArrayAdapter<String> cellInfoAdapter = new ArrayAdapter<String>(this,
461 android.R.layout.simple_spinner_item, mCellInfoRefreshRateLabels);
462 cellInfoAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
463 cellInfoRefreshRateSpinner.setAdapter(cellInfoAdapter);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800464
Nathan Harold12e1f552016-06-17 13:55:38 -0700465 imsVolteProvisionedSwitch = (Switch) findViewById(R.id.volte_provisioned_switch);
466 imsVtProvisionedSwitch = (Switch) findViewById(R.id.vt_provisioned_switch);
467 imsWfcProvisionedSwitch = (Switch) findViewById(R.id.wfc_provisioned_switch);
Meng Wang69439b52017-05-01 08:31:14 -0700468 eabProvisionedSwitch = (Switch) findViewById(R.id.eab_provisioned_switch);
Wink Savillebf471282013-04-05 15:04:05 -0700469
Nathan Harold2b77d742016-03-19 13:22:10 -0700470 radioPowerOnSwitch = (Switch) findViewById(R.id.radio_power);
Wink Saville426fc662011-09-25 14:39:02 -0700471
Nathan Haroldf10ea322018-04-24 13:31:07 -0700472 mDownlinkKbps = (TextView) findViewById(R.id.dl_kbps);
473 mUplinkKbps = (TextView) findViewById(R.id.ul_kbps);
474 updateBandwidths(0, 0);
475
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800476 pingTestButton = (Button) findViewById(R.id.ping_test);
477 pingTestButton.setOnClickListener(mPingButtonHandler);
478 updateSmscButton = (Button) findViewById(R.id.update_smsc);
479 updateSmscButton.setOnClickListener(mUpdateSmscButtonHandler);
480 refreshSmscButton = (Button) findViewById(R.id.refresh_smsc);
481 refreshSmscButton.setOnClickListener(mRefreshSmscButtonHandler);
482 dnsCheckToggleButton = (Button) findViewById(R.id.dns_check_toggle);
483 dnsCheckToggleButton.setOnClickListener(mDnsCheckButtonHandler);
Youhan Wangfd781e92016-12-16 15:53:16 -0800484 carrierProvisioningButton = (Button) findViewById(R.id.carrier_provisioning);
485 carrierProvisioningButton.setOnClickListener(mCarrierProvisioningButtonHandler);
486 triggercarrierProvisioningButton = (Button) findViewById(R.id.trigger_carrier_provisioning);
487 triggercarrierProvisioningButton.setOnClickListener(
488 mTriggerCarrierProvisioningButtonHandler);
johnwang342101a2009-09-23 16:22:34 -0700489
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +0800490 oemInfoButton = (Button) findViewById(R.id.oem_info);
491 oemInfoButton.setOnClickListener(mOemInfoButtonHandler);
492 PackageManager pm = getPackageManager();
493 Intent oemInfoIntent = new Intent("com.android.settings.OEM_RADIO_INFO");
494 List<ResolveInfo> oemInfoIntentList = pm.queryIntentActivities(oemInfoIntent, 0);
495 if (oemInfoIntentList.size() == 0) {
496 oemInfoButton.setEnabled(false);
497 }
498
Nathan Harolded38afa2016-04-13 00:29:30 -0700499 mCellInfoRefreshRateIndex = 0; //disabled
Nathan Haroldcea413a2015-11-23 15:48:10 -0800500 mPreferredNetworkTypeResult = mPreferredNetworkLabels.length - 1; //Unknown
501
502 //FIXME: Replace with TelephonyManager call
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800503 phone.getPreferredNetworkType(
504 mHandler.obtainMessage(EVENT_QUERY_PREFERRED_TYPE_DONE));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800505
Nathan Haroldcea413a2015-11-23 15:48:10 -0800506 restoreFromBundle(icicle);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800507 }
508
509 @Override
510 protected void onResume() {
511 super.onResume();
512
Nathan Haroldcea413a2015-11-23 15:48:10 -0800513 log("Started onResume");
514
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800515 updateMessageWaiting();
516 updateCallRedirect();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800517 updateDataState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800518 updateDataStats2();
Nathan Harold2b77d742016-03-19 13:22:10 -0700519 updateRadioPowerState();
Nathan Harold12e1f552016-06-17 13:55:38 -0700520 updateImsProvisionedState();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800521 updateProperties();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800522 updateDnsCheckState();
Nathan Harold2b77d742016-03-19 13:22:10 -0700523 updateNetworkType();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800524
Nathan Haroldcea413a2015-11-23 15:48:10 -0800525 updateNeighboringCids(mNeighboringCellResult);
526 updateLocation(mCellLocationResult);
527 updateCellInfo(mCellInfoResult);
528
529 mPingHostnameV4.setText(mPingHostnameResultV4);
530 mPingHostnameV6.setText(mPingHostnameResultV6);
531 mHttpClientTest.setText(mHttpClientTestResult);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800532
Nathan Harold2b77d742016-03-19 13:22:10 -0700533 cellInfoRefreshRateSpinner.setOnItemSelectedListener(mCellInfoRefreshRateHandler);
Nathan Harolded38afa2016-04-13 00:29:30 -0700534 //set selection after registering listener to force update
535 cellInfoRefreshRateSpinner.setSelection(mCellInfoRefreshRateIndex);
536
537 //set selection before registering to prevent update
538 preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true);
Nathan Harold2b77d742016-03-19 13:22:10 -0700539 preferredNetworkType.setOnItemSelectedListener(mPreferredNetworkHandler);
Nathan Harolded38afa2016-04-13 00:29:30 -0700540
Nathan Harold2b77d742016-03-19 13:22:10 -0700541 radioPowerOnSwitch.setOnCheckedChangeListener(mRadioPowerOnChangeListener);
Nathan Harold12e1f552016-06-17 13:55:38 -0700542 imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
543 imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
544 imsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
Meng Wang586741c2017-04-26 15:02:51 -0700545 eabProvisionedSwitch.setOnCheckedChangeListener(mEabCheckedChangeListener);
Nathan Harold2b77d742016-03-19 13:22:10 -0700546
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800547 mTelephonyManager.listen(mPhoneStateListener,
Nathan Harold2b77d742016-03-19 13:22:10 -0700548 PhoneStateListener.LISTEN_CALL_STATE
549 //b/27803938 - RadioInfo currently cannot read PRECISE_CALL_STATE
550 // | PhoneStateListener.LISTEN_PRECISE_CALL_STATE
551 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800552 | PhoneStateListener.LISTEN_DATA_ACTIVITY
553 | PhoneStateListener.LISTEN_CELL_LOCATION
554 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
Wink Saville79bff2a2012-06-01 14:37:21 -0700555 | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
Wink Saville4f0d8812014-04-15 22:05:24 -0700556 | PhoneStateListener.LISTEN_CELL_INFO
Nathan Harold2b77d742016-03-19 13:22:10 -0700557 | PhoneStateListener.LISTEN_SERVICE_STATE
558 | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
Nathan Harold433ca442018-04-23 18:20:43 -0700559 | PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION);
Nathan Harolded38afa2016-04-13 00:29:30 -0700560
Nathan Haroldf10ea322018-04-24 13:31:07 -0700561 mConnectivityManager.registerNetworkCallback(
562 mDefaultNetworkRequest, mNetworkCallback, mHandler);
563
Nathan Harolded38afa2016-04-13 00:29:30 -0700564 smsc.clearFocus();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800565 }
566
567 @Override
Nathan Haroldcea413a2015-11-23 15:48:10 -0800568 protected void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800569 super.onPause();
570
Wink Savillebf471282013-04-05 15:04:05 -0700571 log("onPause: unregister phone & data intents");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800572
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800573 mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
Sooraj Sasindran5cce06b2016-08-18 15:49:49 -0700574 mTelephonyManager.setCellInfoListRate(CELL_INFO_LIST_RATE_DISABLED);
Nathan Haroldf10ea322018-04-24 13:31:07 -0700575 mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
576
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800577 }
578
Nathan Haroldcea413a2015-11-23 15:48:10 -0800579 private void restoreFromBundle(Bundle b) {
Nathan Harolde272c202016-10-27 13:45:00 -0700580 if(b == null) {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800581 return;
582 }
583
584 mPingHostnameResultV4 = b.getString("mPingHostnameResultV4","");
585 mPingHostnameResultV6 = b.getString("mPingHostnameResultV6","");
586 mHttpClientTestResult = b.getString("mHttpClientTestResult","");
587
588 mPingHostnameV4.setText(mPingHostnameResultV4);
589 mPingHostnameV6.setText(mPingHostnameResultV6);
590 mHttpClientTest.setText(mHttpClientTestResult);
591
Nathan Harold2b77d742016-03-19 13:22:10 -0700592 mPreferredNetworkTypeResult = b.getInt("mPreferredNetworkTypeResult",
593 mPreferredNetworkLabels.length - 1);
594
595 mCellInfoRefreshRateIndex = b.getInt("mCellInfoRefreshRateIndex", 0);
Nathan Haroldcea413a2015-11-23 15:48:10 -0800596 }
597
598 @Override
599 protected void onSaveInstanceState(Bundle outState) {
600 outState.putString("mPingHostnameResultV4", mPingHostnameResultV4);
601 outState.putString("mPingHostnameResultV6", mPingHostnameResultV6);
602 outState.putString("mHttpClientTestResult", mHttpClientTestResult);
Nathan Harold2b77d742016-03-19 13:22:10 -0700603
Nathan Haroldcea413a2015-11-23 15:48:10 -0800604 outState.putInt("mPreferredNetworkTypeResult", mPreferredNetworkTypeResult);
Nathan Harold2b77d742016-03-19 13:22:10 -0700605 outState.putInt("mCellInfoRefreshRateIndex", mCellInfoRefreshRateIndex);
606
Nathan Haroldcea413a2015-11-23 15:48:10 -0800607 }
608
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800609 @Override
610 public boolean onCreateOptionsMenu(Menu menu) {
Wink Savillec3886682009-04-02 11:00:56 -0700611 menu.add(0, MENU_ITEM_SELECT_BAND, 0, R.string.radio_info_band_mode_label)
612 .setOnMenuItemClickListener(mSelectBandCallback)
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800613 .setAlphabeticShortcut('b');
614 menu.add(1, MENU_ITEM_VIEW_ADN, 0,
615 R.string.radioInfo_menu_viewADN).setOnMenuItemClickListener(mViewADNCallback);
616 menu.add(1, MENU_ITEM_VIEW_FDN, 0,
617 R.string.radioInfo_menu_viewFDN).setOnMenuItemClickListener(mViewFDNCallback);
618 menu.add(1, MENU_ITEM_VIEW_SDN, 0,
619 R.string.radioInfo_menu_viewSDN).setOnMenuItemClickListener(mViewSDNCallback);
Nathan Harolde272c202016-10-27 13:45:00 -0700620 menu.add(1, MENU_ITEM_GET_IMS_STATUS,
621 0, R.string.radioInfo_menu_getIMS).setOnMenuItemClickListener(mGetImsStatus);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800622 menu.add(1, MENU_ITEM_TOGGLE_DATA,
Nathan Harold2b77d742016-03-19 13:22:10 -0700623 0, R.string.radio_info_data_connection_disable).setOnMenuItemClickListener(mToggleData);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800624 return true;
625 }
626
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800627 @Override
Wink Savillec3886682009-04-02 11:00:56 -0700628 public boolean onPrepareOptionsMenu(Menu menu) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800629 // Get the TOGGLE DATA menu item in the right state.
630 MenuItem item = menu.findItem(MENU_ITEM_TOGGLE_DATA);
631 int state = mTelephonyManager.getDataState();
632 boolean visible = true;
633
634 switch (state) {
635 case TelephonyManager.DATA_CONNECTED:
636 case TelephonyManager.DATA_SUSPENDED:
Nathan Harold2b77d742016-03-19 13:22:10 -0700637 item.setTitle(R.string.radio_info_data_connection_disable);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800638 break;
639 case TelephonyManager.DATA_DISCONNECTED:
Nathan Harold2b77d742016-03-19 13:22:10 -0700640 item.setTitle(R.string.radio_info_data_connection_enable);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800641 break;
642 default:
643 visible = false;
644 break;
645 }
646 item.setVisible(visible);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800647 return true;
648 }
649
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800650 private void updateDnsCheckState() {
Nathan Haroldcea413a2015-11-23 15:48:10 -0800651 //FIXME: Replace with a TelephonyManager call
Mike Lockwood5304c7e2009-04-05 11:37:45 -0700652 dnsCheckState.setText(phone.isDnsCheckDisabled() ?
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800653 "0.0.0.0 allowed" :"0.0.0.0 not allowed");
654 }
Wink Savillee2a14e32009-05-29 14:06:30 -0700655
Nathan Haroldf10ea322018-04-24 13:31:07 -0700656 private void updateBandwidths(int dlbw, int ulbw) {
657 dlbw = (dlbw < 0 || dlbw == Integer.MAX_VALUE) ? -1 : dlbw;
658 ulbw = (ulbw < 0 || ulbw == Integer.MAX_VALUE) ? -1 : ulbw;
659 mDownlinkKbps.setText(String.format("%-5d", dlbw));
660 mUplinkKbps.setText(String.format("%-5d", ulbw));
661 }
662
663
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800664 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -0700665 updateSignalStrength(SignalStrength signalStrength) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800666 Resources r = getResources();
667
Nathan Harold2b77d742016-03-19 13:22:10 -0700668 int signalDbm = signalStrength.getDbm();
Wink Savillee2a14e32009-05-29 14:06:30 -0700669
Nathan Harold2b77d742016-03-19 13:22:10 -0700670 int signalAsu = signalStrength.getAsuLevel();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800671
672 if (-1 == signalAsu) signalAsu = 0;
673
674 dBm.setText(String.valueOf(signalDbm) + " "
675 + r.getString(R.string.radioInfo_display_dbm) + " "
676 + String.valueOf(signalAsu) + " "
677 + r.getString(R.string.radioInfo_display_asu));
678 }
679
680 private final void updateLocation(CellLocation location) {
jsh534f5ae2009-09-24 09:19:22 -0700681 Resources r = getResources();
Wink Savillec3886682009-04-02 11:00:56 -0700682 if (location instanceof GsmCellLocation) {
683 GsmCellLocation loc = (GsmCellLocation)location;
jsh534f5ae2009-09-24 09:19:22 -0700684 int lac = loc.getLac();
685 int cid = loc.getCid();
686 mLocation.setText(r.getString(R.string.radioInfo_lac) + " = "
687 + ((lac == -1) ? "unknown" : Integer.toHexString(lac))
688 + " "
689 + r.getString(R.string.radioInfo_cid) + " = "
690 + ((cid == -1) ? "unknown" : Integer.toHexString(cid)));
691 } else if (location instanceof CdmaCellLocation) {
692 CdmaCellLocation loc = (CdmaCellLocation)location;
693 int bid = loc.getBaseStationId();
694 int sid = loc.getSystemId();
695 int nid = loc.getNetworkId();
696 int lat = loc.getBaseStationLatitude();
697 int lon = loc.getBaseStationLongitude();
698 mLocation.setText("BID = "
699 + ((bid == -1) ? "unknown" : Integer.toHexString(bid))
700 + " "
701 + "SID = "
702 + ((sid == -1) ? "unknown" : Integer.toHexString(sid))
703 + " "
704 + "NID = "
705 + ((nid == -1) ? "unknown" : Integer.toHexString(nid))
706 + "\n"
707 + "LAT = "
708 + ((lat == -1) ? "unknown" : Integer.toHexString(lat))
709 + " "
710 + "LONG = "
711 + ((lon == -1) ? "unknown" : Integer.toHexString(lon)));
712 } else {
713 mLocation.setText("unknown");
Wink Savillec3886682009-04-02 11:00:56 -0700714 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800715
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800716
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800717 }
718
Nathan Haroldcea413a2015-11-23 15:48:10 -0800719 private final void updateNeighboringCids(List<NeighboringCellInfo> cids) {
johnwangf02c65f2009-09-25 17:26:54 -0700720 StringBuilder sb = new StringBuilder();
721
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800722 if (cids != null) {
Nathan Harolde272c202016-10-27 13:45:00 -0700723 if (cids.isEmpty()) {
johnwangf02c65f2009-09-25 17:26:54 -0700724 sb.append("no neighboring cells");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800725 } else {
726 for (NeighboringCellInfo cell : cids) {
johnwangf02c65f2009-09-25 17:26:54 -0700727 sb.append(cell.toString()).append(" ");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800728 }
729 }
730 } else {
johnwangf02c65f2009-09-25 17:26:54 -0700731 sb.append("unknown");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800732 }
johnwangf02c65f2009-09-25 17:26:54 -0700733 mNeighboringCids.setText(sb.toString());
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800734 }
735
Nathan Haroldcea413a2015-11-23 15:48:10 -0800736 private final String getCellInfoDisplayString(int i) {
737 return (i != Integer.MAX_VALUE) ? Integer.toString(i) : "";
738 }
739
740 private final String getCellInfoDisplayString(long i) {
741 return (i != Long.MAX_VALUE) ? Long.toString(i) : "";
742 }
743
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700744 private final String getConnectionStatusString(CellInfo ci) {
745 String regStr = "";
746 String connStatStr = "";
747 String connector = "";
748
749 if (ci.isRegistered()) {
750 regStr = "R";
751 }
752 switch (ci.getCellConnectionStatus()) {
753 case CellInfo.CONNECTION_PRIMARY_SERVING: connStatStr = "P"; break;
754 case CellInfo.CONNECTION_SECONDARY_SERVING: connStatStr = "S"; break;
755 case CellInfo.CONNECTION_NONE: connStatStr = "N"; break;
756 case CellInfo.CONNECTION_UNKNOWN: /* Field is unsupported */ break;
757 default: break;
758 }
759 if (!TextUtils.isEmpty(regStr) && !TextUtils.isEmpty(connStatStr)) {
760 connector = "+";
761 }
762
763 return regStr + connector + connStatStr;
764 }
765
Nathan Haroldcea413a2015-11-23 15:48:10 -0800766 private final String buildCdmaInfoString(CellInfoCdma ci) {
767 CellIdentityCdma cidCdma = ci.getCellIdentity();
768 CellSignalStrengthCdma ssCdma = ci.getCellSignalStrength();
769
770 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 -0700771 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800772 getCellInfoDisplayString(cidCdma.getSystemId()),
773 getCellInfoDisplayString(cidCdma.getNetworkId()),
774 getCellInfoDisplayString(cidCdma.getBasestationId()),
775 getCellInfoDisplayString(ssCdma.getCdmaDbm()),
776 getCellInfoDisplayString(ssCdma.getCdmaEcio()),
777 getCellInfoDisplayString(ssCdma.getEvdoDbm()),
778 getCellInfoDisplayString(ssCdma.getEvdoEcio()),
779 getCellInfoDisplayString(ssCdma.getEvdoSnr()));
780 }
781
782 private final String buildGsmInfoString(CellInfoGsm ci) {
783 CellIdentityGsm cidGsm = ci.getCellIdentity();
784 CellSignalStrengthGsm ssGsm = ci.getCellSignalStrength();
785
Nathan Harold2b77d742016-03-19 13:22:10 -0700786 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 -0700787 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800788 getCellInfoDisplayString(cidGsm.getMcc()),
789 getCellInfoDisplayString(cidGsm.getMnc()),
790 getCellInfoDisplayString(cidGsm.getLac()),
791 getCellInfoDisplayString(cidGsm.getCid()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700792 getCellInfoDisplayString(cidGsm.getArfcn()),
793 getCellInfoDisplayString(cidGsm.getBsic()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800794 getCellInfoDisplayString(ssGsm.getDbm()));
795 }
796
797 private final String buildLteInfoString(CellInfoLte ci) {
798 CellIdentityLte cidLte = ci.getCellIdentity();
799 CellSignalStrengthLte ssLte = ci.getCellSignalStrength();
800
801 return String.format(
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700802 "%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s %-6.6s %-2.2s %-4.4s %-4.4s %-2.2s\n",
803 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800804 getCellInfoDisplayString(cidLte.getMcc()),
805 getCellInfoDisplayString(cidLte.getMnc()),
806 getCellInfoDisplayString(cidLte.getTac()),
807 getCellInfoDisplayString(cidLte.getCi()),
808 getCellInfoDisplayString(cidLte.getPci()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700809 getCellInfoDisplayString(cidLte.getEarfcn()),
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700810 getCellInfoDisplayString(cidLte.getBandwidth()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800811 getCellInfoDisplayString(ssLte.getDbm()),
812 getCellInfoDisplayString(ssLte.getRsrq()),
813 getCellInfoDisplayString(ssLte.getTimingAdvance()));
814 }
815
816 private final String buildWcdmaInfoString(CellInfoWcdma ci) {
817 CellIdentityWcdma cidWcdma = ci.getCellIdentity();
818 CellSignalStrengthWcdma ssWcdma = ci.getCellSignalStrength();
819
Nathan Harold2b77d742016-03-19 13:22:10 -0700820 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 -0700821 getConnectionStatusString(ci),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800822 getCellInfoDisplayString(cidWcdma.getMcc()),
823 getCellInfoDisplayString(cidWcdma.getMnc()),
824 getCellInfoDisplayString(cidWcdma.getLac()),
825 getCellInfoDisplayString(cidWcdma.getCid()),
Nathan Harold2b77d742016-03-19 13:22:10 -0700826 getCellInfoDisplayString(cidWcdma.getUarfcn()),
Nathan Haroldcea413a2015-11-23 15:48:10 -0800827 getCellInfoDisplayString(cidWcdma.getPsc()),
828 getCellInfoDisplayString(ssWcdma.getDbm()));
829 }
830
831 private final String buildCellInfoString(List<CellInfo> arrayCi) {
832 String value = new String();
833 StringBuilder cdmaCells = new StringBuilder(),
834 gsmCells = new StringBuilder(),
835 lteCells = new StringBuilder(),
836 wcdmaCells = new StringBuilder();
837
838 if (arrayCi != null) {
839 for (CellInfo ci : arrayCi) {
840
841 if (ci instanceof CellInfoLte) {
842 lteCells.append(buildLteInfoString((CellInfoLte) ci));
843 } else if (ci instanceof CellInfoWcdma) {
844 wcdmaCells.append(buildWcdmaInfoString((CellInfoWcdma) ci));
845 } else if (ci instanceof CellInfoGsm) {
846 gsmCells.append(buildGsmInfoString((CellInfoGsm) ci));
847 } else if (ci instanceof CellInfoCdma) {
848 cdmaCells.append(buildCdmaInfoString((CellInfoCdma) ci));
Wink Saville79bff2a2012-06-01 14:37:21 -0700849 }
850 }
Nathan Haroldcea413a2015-11-23 15:48:10 -0800851 if (lteCells.length() != 0) {
852 value += String.format(
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700853 "LTE\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s"
854 + " %-6.6s %-2.2s %-4.4s %-4.4s %-2.2s\n",
855 "SRV", "MCC", "MNC", "TAC", "CID", "PCI",
856 "EARFCN", "BW", "RSRP", "RSRQ", "TA");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800857 value += lteCells.toString();
858 }
859 if (wcdmaCells.length() != 0) {
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700860 value += String.format(
861 "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 -0700862 "SRV", "MCC", "MNC", "LAC", "CID", "UARFCN", "PSC", "RSCP");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800863 value += wcdmaCells.toString();
864 }
865 if (gsmCells.length() != 0) {
Nathan Harold6e16fdf2018-04-17 17:01:32 -0700866 value += String.format(
867 "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 -0700868 "SRV", "MCC", "MNC", "LAC", "CID", "ARFCN", "BSIC", "RSSI");
Nathan Haroldcea413a2015-11-23 15:48:10 -0800869 value += gsmCells.toString();
870 }
871 if (cdmaCells.length() != 0) {
872 value += String.format(
873 "CDMA/EVDO\n%-3.3s %-5.5s %-5.5s %-5.5s %-6.6s %-6.6s %-6.6s %-6.6s %-5.5s\n",
874 "SRV", "SID", "NID", "BSID", "C-RSSI", "C-ECIO", "E-RSSI", "E-ECIO", "E-SNR");
875 value += cdmaCells.toString();
876 }
877 } else {
878 value ="unknown";
Wink Saville79bff2a2012-06-01 14:37:21 -0700879 }
Nathan Haroldcea413a2015-11-23 15:48:10 -0800880
881 return value.toString();
882 }
883
884 private final void updateCellInfo(List<CellInfo> arrayCi) {
885 mCellInfo.setText(buildCellInfoString(arrayCi));
Wink Saville79bff2a2012-06-01 14:37:21 -0700886 }
887
Wink Saville4f0d8812014-04-15 22:05:24 -0700888 private final void updateDcRtInfoTv(DataConnectionRealTimeInfo dcRtInfo) {
889 mDcRtInfoTv.setText(dcRtInfo.toString());
890 }
891
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800892 private final void
893 updateMessageWaiting() {
894 mMwi.setText(String.valueOf(mMwiValue));
895 }
896
897 private final void
898 updateCallRedirect() {
899 mCfi.setText(String.valueOf(mCfiValue));
900 }
901
902
903 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -0700904 updateServiceState(ServiceState serviceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800905 int state = serviceState.getState();
906 Resources r = getResources();
907 String display = r.getString(R.string.radioInfo_unknown);
johnwang342101a2009-09-23 16:22:34 -0700908
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800909 switch (state) {
910 case ServiceState.STATE_IN_SERVICE:
911 display = r.getString(R.string.radioInfo_service_in);
912 break;
913 case ServiceState.STATE_OUT_OF_SERVICE:
914 case ServiceState.STATE_EMERGENCY_ONLY:
915 display = r.getString(R.string.radioInfo_service_emergency);
916 break;
917 case ServiceState.STATE_POWER_OFF:
918 display = r.getString(R.string.radioInfo_service_off);
919 break;
920 }
johnwang342101a2009-09-23 16:22:34 -0700921
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800922 gsmState.setText(display);
johnwang342101a2009-09-23 16:22:34 -0700923
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800924 if (serviceState.getRoaming()) {
925 roamingState.setText(R.string.radioInfo_roaming_in);
926 } else {
927 roamingState.setText(R.string.radioInfo_roaming_not);
928 }
929
930 operatorName.setText(serviceState.getOperatorAlphaLong());
931 }
932
933 private final void
Nathan Harold2b77d742016-03-19 13:22:10 -0700934 updatePhoneState(int state) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800935 Resources r = getResources();
936 String display = r.getString(R.string.radioInfo_unknown);
937
938 switch (state) {
Nathan Harold2b77d742016-03-19 13:22:10 -0700939 case TelephonyManager.CALL_STATE_IDLE:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800940 display = r.getString(R.string.radioInfo_phone_idle);
941 break;
Nathan Harold2b77d742016-03-19 13:22:10 -0700942 case TelephonyManager.CALL_STATE_RINGING:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800943 display = r.getString(R.string.radioInfo_phone_ringing);
944 break;
Nathan Harold2b77d742016-03-19 13:22:10 -0700945 case TelephonyManager.CALL_STATE_OFFHOOK:
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800946 display = r.getString(R.string.radioInfo_phone_offhook);
947 break;
948 }
949
950 callState.setText(display);
951 }
952
953 private final void
954 updateDataState() {
955 int state = mTelephonyManager.getDataState();
956 Resources r = getResources();
957 String display = r.getString(R.string.radioInfo_unknown);
958
959 switch (state) {
960 case TelephonyManager.DATA_CONNECTED:
961 display = r.getString(R.string.radioInfo_data_connected);
962 break;
963 case TelephonyManager.DATA_CONNECTING:
964 display = r.getString(R.string.radioInfo_data_connecting);
965 break;
966 case TelephonyManager.DATA_DISCONNECTED:
967 display = r.getString(R.string.radioInfo_data_disconnected);
968 break;
969 case TelephonyManager.DATA_SUSPENDED:
970 display = r.getString(R.string.radioInfo_data_suspended);
971 break;
972 }
johnwang342101a2009-09-23 16:22:34 -0700973
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800974 gprsState.setText(display);
975 }
976
977 private final void updateNetworkType() {
Nathan Harolde272c202016-10-27 13:45:00 -0700978 if(phone != null) {
Nathan Harold2b77d742016-03-19 13:22:10 -0700979 ServiceState ss = phone.getServiceState();
980 dataNetwork.setText(ServiceState.rilRadioTechnologyToString(
981 phone.getServiceState().getRilDataRadioTechnology()));
982 voiceNetwork.setText(ServiceState.rilRadioTechnologyToString(
983 phone.getServiceState().getRilVoiceRadioTechnology()));
984 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800985 }
986
987 private final void
988 updateProperties() {
989 String s;
990 Resources r = getResources();
991
992 s = phone.getDeviceId();
johnwang342101a2009-09-23 16:22:34 -0700993 if (s == null) s = r.getString(R.string.radioInfo_unknown);
Wink Savillec3886682009-04-02 11:00:56 -0700994 mDeviceId.setText(s);
johnwang342101a2009-09-23 16:22:34 -0700995
Meng Wang9053f172017-06-23 16:02:14 -0700996 s = phone.getSubscriberId();
997 if (s == null) s = r.getString(R.string.radioInfo_unknown);
998 mSubscriberId.setText(s);
999
Nathan Haroldcea413a2015-11-23 15:48:10 -08001000 //FIXME: Replace with a TelephonyManager call
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001001 s = phone.getLine1Number();
johnwang342101a2009-09-23 16:22:34 -07001002 if (s == null) s = r.getString(R.string.radioInfo_unknown);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001003 number.setText(s);
1004 }
1005
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001006 private final void updateDataStats2() {
1007 Resources r = getResources();
1008
Jeff Sharkey93029862011-05-27 18:26:15 -07001009 long txPackets = TrafficStats.getMobileTxPackets();
1010 long rxPackets = TrafficStats.getMobileRxPackets();
1011 long txBytes = TrafficStats.getMobileTxBytes();
1012 long rxBytes = TrafficStats.getMobileRxBytes();
johnwang342101a2009-09-23 16:22:34 -07001013
Jeff Sharkey93029862011-05-27 18:26:15 -07001014 String packets = r.getString(R.string.radioInfo_display_packets);
1015 String bytes = r.getString(R.string.radioInfo_display_bytes);
johnwang342101a2009-09-23 16:22:34 -07001016
Jeff Sharkey93029862011-05-27 18:26:15 -07001017 sent.setText(txPackets + " " + packets + ", " + txBytes + " " + bytes);
1018 received.setText(rxPackets + " " + packets + ", " + rxBytes + " " + bytes);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001019 }
1020
1021 /**
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001022 * Ping a host name
1023 */
1024 private final void pingHostname() {
1025 try {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001026 try {
1027 Process p4 = Runtime.getRuntime().exec("ping -c 1 www.google.com");
1028 int status4 = p4.waitFor();
1029 if (status4 == 0) {
1030 mPingHostnameResultV4 = "Pass";
1031 } else {
1032 mPingHostnameResultV4 = String.format("Fail(%d)", status4);
1033 }
1034 } catch (IOException e) {
1035 mPingHostnameResultV4 = "Fail: IOException";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001036 }
Nathan Haroldcea413a2015-11-23 15:48:10 -08001037 try {
1038 Process p6 = Runtime.getRuntime().exec("ping6 -c 1 www.google.com");
1039 int status6 = p6.waitFor();
1040 if (status6 == 0) {
1041 mPingHostnameResultV6 = "Pass";
1042 } else {
1043 mPingHostnameResultV6 = String.format("Fail(%d)", status6);
1044 }
1045 } catch (IOException e) {
1046 mPingHostnameResultV6 = "Fail: IOException";
1047 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001048 } catch (InterruptedException e) {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001049 mPingHostnameResultV4 = mPingHostnameResultV6 = "Fail: InterruptedException";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001050 }
1051 }
1052
1053 /**
1054 * This function checks for basic functionality of HTTP Client.
1055 */
1056 private void httpClientTest() {
Narayan Kamathf25627c2014-12-12 13:53:28 +00001057 HttpURLConnection urlConnection = null;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001058 try {
Narayan Kamathf25627c2014-12-12 13:53:28 +00001059 // TODO: Hardcoded for now, make it UI configurable
Alex Klyubinb0090232015-04-02 11:08:51 -07001060 URL url = new URL("https://www.google.com");
Narayan Kamathf25627c2014-12-12 13:53:28 +00001061 urlConnection = (HttpURLConnection) url.openConnection();
1062 if (urlConnection.getResponseCode() == 200) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001063 mHttpClientTestResult = "Pass";
1064 } else {
Narayan Kamathf25627c2014-12-12 13:53:28 +00001065 mHttpClientTestResult = "Fail: Code: " + urlConnection.getResponseMessage();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001066 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001067 } catch (IOException e) {
1068 mHttpClientTestResult = "Fail: IOException";
Narayan Kamathf25627c2014-12-12 13:53:28 +00001069 } finally {
1070 if (urlConnection != null) {
1071 urlConnection.disconnect();
1072 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001073 }
1074 }
1075
1076 private void refreshSmsc() {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001077 //FIXME: Replace with a TelephonyManager call
jsh21dd4072009-05-12 11:26:55 -07001078 phone.getSmscAddress(mHandler.obtainMessage(EVENT_QUERY_SMSC_DONE));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001079 }
1080
Nathan Haroldcea413a2015-11-23 15:48:10 -08001081 private final void updateAllCellInfo() {
1082
1083 mCellInfo.setText("");
1084 mNeighboringCids.setText("");
1085 mLocation.setText("");
1086
1087 final Runnable updateAllCellInfoResults = new Runnable() {
1088 public void run() {
1089 updateNeighboringCids(mNeighboringCellResult);
1090 updateLocation(mCellLocationResult);
1091 updateCellInfo(mCellInfoResult);
1092 }
1093 };
1094
1095 Thread locThread = new Thread() {
1096 @Override
1097 public void run() {
1098 mCellInfoResult = mTelephonyManager.getAllCellInfo();
1099 mCellLocationResult = mTelephonyManager.getCellLocation();
1100 mNeighboringCellResult = mTelephonyManager.getNeighboringCellInfo();
1101
1102 mHandler.post(updateAllCellInfoResults);
1103 }
1104 };
1105 locThread.start();
1106 }
1107
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001108 private final void updatePingState() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001109 // Set all to unknown since the threads will take a few secs to update.
Nathan Haroldcea413a2015-11-23 15:48:10 -08001110 mPingHostnameResultV4 = getResources().getString(R.string.radioInfo_unknown);
1111 mPingHostnameResultV6 = getResources().getString(R.string.radioInfo_unknown);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001112 mHttpClientTestResult = getResources().getString(R.string.radioInfo_unknown);
1113
Nathan Haroldcea413a2015-11-23 15:48:10 -08001114 mPingHostnameV4.setText(mPingHostnameResultV4);
1115 mPingHostnameV6.setText(mPingHostnameResultV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001116 mHttpClientTest.setText(mHttpClientTestResult);
1117
1118 final Runnable updatePingResults = new Runnable() {
1119 public void run() {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001120 mPingHostnameV4.setText(mPingHostnameResultV4);
1121 mPingHostnameV6.setText(mPingHostnameResultV6);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001122 mHttpClientTest.setText(mHttpClientTestResult);
1123 }
1124 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001125
1126 Thread hostname = new Thread() {
1127 @Override
1128 public void run() {
1129 pingHostname();
Nathan Haroldcea413a2015-11-23 15:48:10 -08001130 mHandler.post(updatePingResults);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001131 }
1132 };
1133 hostname.start();
1134
1135 Thread httpClient = new Thread() {
1136 @Override
1137 public void run() {
1138 httpClientTest();
Nathan Haroldcea413a2015-11-23 15:48:10 -08001139 mHandler.post(updatePingResults);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001140 }
1141 };
1142 httpClient.start();
1143 }
1144
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001145 private MenuItem.OnMenuItemClickListener mViewADNCallback = new MenuItem.OnMenuItemClickListener() {
1146 public boolean onMenuItemClick(MenuItem item) {
1147 Intent intent = new Intent(Intent.ACTION_VIEW);
1148 // XXX We need to specify the component here because if we don't
1149 // the activity manager will try to resolve the type by calling
1150 // the content provider, which causes it to be loaded in a process
1151 // other than the Dialer process, which causes a lot of stuff to
1152 // break.
1153 intent.setClassName("com.android.phone",
1154 "com.android.phone.SimContacts");
1155 startActivity(intent);
1156 return true;
1157 }
1158 };
1159
1160 private MenuItem.OnMenuItemClickListener mViewFDNCallback = new MenuItem.OnMenuItemClickListener() {
1161 public boolean onMenuItemClick(MenuItem item) {
1162 Intent intent = new Intent(Intent.ACTION_VIEW);
1163 // XXX We need to specify the component here because if we don't
1164 // the activity manager will try to resolve the type by calling
1165 // the content provider, which causes it to be loaded in a process
1166 // other than the Dialer process, which causes a lot of stuff to
1167 // break.
1168 intent.setClassName("com.android.phone",
Andrew Leeda90d682014-10-31 13:12:20 -07001169 "com.android.phone.settings.fdn.FdnList");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001170 startActivity(intent);
1171 return true;
1172 }
1173 };
1174
1175 private MenuItem.OnMenuItemClickListener mViewSDNCallback = new MenuItem.OnMenuItemClickListener() {
1176 public boolean onMenuItemClick(MenuItem item) {
1177 Intent intent = new Intent(
Wink Savillec3886682009-04-02 11:00:56 -07001178 Intent.ACTION_VIEW, Uri.parse("content://icc/sdn"));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001179 // XXX We need to specify the component here because if we don't
1180 // the activity manager will try to resolve the type by calling
1181 // the content provider, which causes it to be loaded in a process
1182 // other than the Dialer process, which causes a lot of stuff to
1183 // break.
1184 intent.setClassName("com.android.phone",
1185 "com.android.phone.ADNList");
1186 startActivity(intent);
1187 return true;
1188 }
1189 };
1190
Nathan Harolde272c202016-10-27 13:45:00 -07001191 private MenuItem.OnMenuItemClickListener mGetImsStatus = new MenuItem.OnMenuItemClickListener() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001192 public boolean onMenuItemClick(MenuItem item) {
Nathan Harolde272c202016-10-27 13:45:00 -07001193 boolean isImsRegistered = phone.isImsRegistered();
1194 boolean availableVolte = phone.isVolteEnabled();
1195 boolean availableWfc = phone.isWifiCallingEnabled();
1196 boolean availableVt = phone.isVideoEnabled();
1197 boolean availableUt = phone.isUtEnabled();
1198
1199 final String imsRegString = isImsRegistered ?
1200 getString(R.string.radio_info_ims_reg_status_registered) :
1201 getString(R.string.radio_info_ims_reg_status_not_registered);
1202
1203 final String available = getString(R.string.radio_info_ims_feature_status_available);
1204 final String unavailable = getString(
1205 R.string.radio_info_ims_feature_status_unavailable);
1206
1207 String imsStatus = getString(R.string.radio_info_ims_reg_status,
1208 imsRegString,
1209 availableVolte ? available : unavailable,
1210 availableWfc ? available : unavailable,
1211 availableVt ? available : unavailable,
1212 availableUt ? available : unavailable);
1213
1214 AlertDialog imsDialog = new AlertDialog.Builder(RadioInfo.this)
1215 .setMessage(imsStatus)
1216 .setTitle(getString(R.string.radio_info_ims_reg_status_title))
1217 .create();
1218
1219 imsDialog.show();
1220
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001221 return true;
1222 }
1223 };
1224
1225 private MenuItem.OnMenuItemClickListener mSelectBandCallback = new MenuItem.OnMenuItemClickListener() {
1226 public boolean onMenuItemClick(MenuItem item) {
1227 Intent intent = new Intent();
1228 intent.setClass(RadioInfo.this, BandMode.class);
1229 startActivity(intent);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001230 return true;
1231 }
1232 };
johnwang342101a2009-09-23 16:22:34 -07001233
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001234 private MenuItem.OnMenuItemClickListener mToggleData = new MenuItem.OnMenuItemClickListener() {
1235 public boolean onMenuItemClick(MenuItem item) {
1236 int state = mTelephonyManager.getDataState();
1237 switch (state) {
1238 case TelephonyManager.DATA_CONNECTED:
Nathan Haroldcea413a2015-11-23 15:48:10 -08001239 //FIXME: Replace with a TelephonyManager call
Malcolm Chenf612f592017-11-29 18:01:25 -08001240 phone.setUserDataEnabled(false);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001241 break;
1242 case TelephonyManager.DATA_DISCONNECTED:
Nathan Haroldcea413a2015-11-23 15:48:10 -08001243 //FIXME: Replace with a TelephonyManager call
Malcolm Chenf612f592017-11-29 18:01:25 -08001244 phone.setUserDataEnabled(true);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001245 break;
1246 default:
1247 // do nothing
1248 break;
1249 }
1250 return true;
1251 }
1252 };
1253
Nathan Harold2b77d742016-03-19 13:22:10 -07001254 private boolean isRadioOn() {
1255 //FIXME: Replace with a TelephonyManager call
1256 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1257 }
1258
1259 private void updateRadioPowerState() {
1260 //delightful hack to prevent on-checked-changed calls from
1261 //actually forcing the radio preference to its transient/current value.
1262 radioPowerOnSwitch.setOnCheckedChangeListener(null);
1263 radioPowerOnSwitch.setChecked(isRadioOn());
1264 radioPowerOnSwitch.setOnCheckedChangeListener(mRadioPowerOnChangeListener);
1265 }
1266
Nathan Harolde272c202016-10-27 13:45:00 -07001267 void setImsVolteProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001268 Log.d(TAG, "setImsVolteProvisioned state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001269 setImsConfigProvisionedState(IMS_VOLTE_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001270 }
1271
Nathan Harolde272c202016-10-27 13:45:00 -07001272 void setImsVtProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001273 Log.d(TAG, "setImsVtProvisioned() state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001274 setImsConfigProvisionedState(IMS_VT_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001275 }
1276
Nathan Harolde272c202016-10-27 13:45:00 -07001277 void setImsWfcProvisionedState(boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001278 Log.d(TAG, "setImsWfcProvisioned() state: " + ((state)? "on":"off"));
Nathan Harolde272c202016-10-27 13:45:00 -07001279 setImsConfigProvisionedState(IMS_WFC_PROVISIONED_CONFIG_ID, state);
Nathan Harold12e1f552016-06-17 13:55:38 -07001280 }
1281
Meng Wang586741c2017-04-26 15:02:51 -07001282 void setEabProvisionedState(boolean state) {
1283 Log.d(TAG, "setEabProvisioned() state: " + ((state)? "on":"off"));
1284 setImsConfigProvisionedState(EAB_PROVISIONED_CONFIG_ID, state);
1285 }
1286
Nathan Harolde272c202016-10-27 13:45:00 -07001287 void setImsConfigProvisionedState(int configItem, boolean state) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001288 if (phone != null && mImsManager != null) {
Philip P. Moltmann5c449ae2017-02-14 12:43:02 -08001289 QueuedWork.queue(new Runnable() {
Nathan Harold12e1f552016-06-17 13:55:38 -07001290 public void run() {
1291 try {
1292 mImsManager.getConfigInterface().setProvisionedValue(
1293 configItem,
1294 state? 1 : 0);
1295 } catch (ImsException e) {
1296 Log.e(TAG, "setImsConfigProvisioned() exception:", e);
1297 }
1298 }
Philip P. Moltmann5c449ae2017-02-14 12:43:02 -08001299 }, false);
Nathan Harold12e1f552016-06-17 13:55:38 -07001300 }
1301 }
1302
Nathan Harold2b77d742016-03-19 13:22:10 -07001303 OnCheckedChangeListener mRadioPowerOnChangeListener = new OnCheckedChangeListener() {
1304 @Override
1305 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1306 log("toggle radio power: currently " + (isRadioOn()?"on":"off"));
1307 phone.setRadioPower(isChecked);
1308 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001309 };
1310
Nathan Harold12e1f552016-06-17 13:55:38 -07001311 private boolean isImsVolteProvisioned() {
Nathan Harold2b77d742016-03-19 13:22:10 -07001312 if (phone != null && mImsManager != null) {
1313 return mImsManager.isVolteEnabledByPlatform(phone.getContext())
1314 && mImsManager.isVolteProvisionedOnDevice(phone.getContext());
Pavel Zhamaitsiakcb267a62015-01-21 18:25:14 -08001315 }
1316 return false;
1317 }
1318
Nathan Harold12e1f552016-06-17 13:55:38 -07001319 OnCheckedChangeListener mImsVolteCheckedChangeListener = new OnCheckedChangeListener() {
Wink Saville426fc662011-09-25 14:39:02 -07001320 @Override
Nathan Harold2b77d742016-03-19 13:22:10 -07001321 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Nathan Harold12e1f552016-06-17 13:55:38 -07001322 setImsVolteProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001323 }
Wink Saville426fc662011-09-25 14:39:02 -07001324 };
1325
Nathan Harold12e1f552016-06-17 13:55:38 -07001326 private boolean isImsVtProvisioned() {
1327 if (phone != null && mImsManager != null) {
1328 return mImsManager.isVtEnabledByPlatform(phone.getContext())
1329 && mImsManager.isVtProvisionedOnDevice(phone.getContext());
1330 }
1331 return false;
1332 }
1333
1334 OnCheckedChangeListener mImsVtCheckedChangeListener = new OnCheckedChangeListener() {
1335 @Override
1336 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1337 setImsVtProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001338 }
Nathan Harold12e1f552016-06-17 13:55:38 -07001339 };
1340
1341 private boolean isImsWfcProvisioned() {
1342 if (phone != null && mImsManager != null) {
1343 return mImsManager.isWfcEnabledByPlatform(phone.getContext())
1344 && mImsManager.isWfcProvisionedOnDevice(phone.getContext());
1345 }
1346 return false;
1347 }
1348
1349 OnCheckedChangeListener mImsWfcCheckedChangeListener = new OnCheckedChangeListener() {
1350 @Override
1351 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1352 setImsWfcProvisionedState(isChecked);
Nathan Harolde272c202016-10-27 13:45:00 -07001353 }
Nathan Harold12e1f552016-06-17 13:55:38 -07001354 };
1355
Meng Wang586741c2017-04-26 15:02:51 -07001356 private boolean isEabProvisioned() {
1357 return isFeatureProvisioned(EAB_PROVISIONED_CONFIG_ID, false);
1358 }
1359
1360 OnCheckedChangeListener mEabCheckedChangeListener = new OnCheckedChangeListener() {
1361 @Override
1362 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
1363 setEabProvisionedState(isChecked);
1364 }
1365 };
1366
1367 private boolean isFeatureProvisioned(int featureId, boolean defaultValue) {
1368 boolean provisioned = defaultValue;
1369 if (mImsManager != null) {
1370 try {
1371 ImsConfig imsConfig = mImsManager.getConfigInterface();
1372 if (imsConfig != null) {
1373 provisioned =
1374 (imsConfig.getProvisionedValue(featureId)
1375 == ImsConfig.FeatureValueConstants.ON);
1376 }
1377 } catch (ImsException ex) {
1378 Log.e(TAG, "isFeatureProvisioned() exception:", ex);
1379 }
1380 }
1381
1382 log("isFeatureProvisioned() featureId=" + featureId + " provisioned=" + provisioned);
1383 return provisioned;
1384 }
1385
1386 private static boolean isEabEnabledByPlatform(Context context) {
1387 if (context != null) {
1388 CarrierConfigManager configManager = (CarrierConfigManager)
1389 context.getSystemService(Context.CARRIER_CONFIG_SERVICE);
1390 if (configManager != null && configManager.getConfig().getBoolean(
1391 CarrierConfigManager.KEY_USE_RCS_PRESENCE_BOOL)) {
1392 return true;
1393 }
1394 }
1395 return false;
1396 }
1397
Nathan Harold12e1f552016-06-17 13:55:38 -07001398 private void updateImsProvisionedState() {
1399 log("updateImsProvisionedState isImsVolteProvisioned()=" + isImsVolteProvisioned());
Nathan Harold2b77d742016-03-19 13:22:10 -07001400 //delightful hack to prevent on-checked-changed calls from
1401 //actually forcing the ims provisioning to its transient/current value.
Nathan Harold12e1f552016-06-17 13:55:38 -07001402 imsVolteProvisionedSwitch.setOnCheckedChangeListener(null);
1403 imsVolteProvisionedSwitch.setChecked(isImsVolteProvisioned());
1404 imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
Nathan Harold6dc15e92016-10-28 11:45:59 -07001405 imsVolteProvisionedSwitch.setEnabled(
1406 mImsManager.isVolteEnabledByPlatform(phone.getContext()));
Nathan Harold12e1f552016-06-17 13:55:38 -07001407
1408 imsVtProvisionedSwitch.setOnCheckedChangeListener(null);
1409 imsVtProvisionedSwitch.setChecked(isImsVtProvisioned());
1410 imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
Nathan Harold6dc15e92016-10-28 11:45:59 -07001411 imsVtProvisionedSwitch.setEnabled(
1412 mImsManager.isVtEnabledByPlatform(phone.getContext()));
Nathan Harold12e1f552016-06-17 13:55:38 -07001413
1414 imsWfcProvisionedSwitch.setOnCheckedChangeListener(null);
1415 imsWfcProvisionedSwitch.setChecked(isImsWfcProvisioned());
1416 imsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
Nathan Harold6dc15e92016-10-28 11:45:59 -07001417 imsWfcProvisionedSwitch.setEnabled(
1418 mImsManager.isWfcEnabledByPlatform(phone.getContext()));
Meng Wang586741c2017-04-26 15:02:51 -07001419
1420 eabProvisionedSwitch.setOnCheckedChangeListener(null);
1421 eabProvisionedSwitch.setChecked(isEabProvisioned());
1422 eabProvisionedSwitch.setOnCheckedChangeListener(mEabCheckedChangeListener);
1423 eabProvisionedSwitch.setEnabled(isEabEnabledByPlatform(phone.getContext()));
Wink Saville426fc662011-09-25 14:39:02 -07001424 }
1425
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001426 OnClickListener mDnsCheckButtonHandler = new OnClickListener() {
1427 public void onClick(View v) {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001428 //FIXME: Replace with a TelephonyManager call
Wink Savillec3886682009-04-02 11:00:56 -07001429 phone.disableDnsCheck(!phone.isDnsCheckDisabled());
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001430 updateDnsCheckState();
1431 }
1432 };
johnwang342101a2009-09-23 16:22:34 -07001433
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001434 OnClickListener mOemInfoButtonHandler = new OnClickListener() {
1435 public void onClick(View v) {
1436 Intent intent = new Intent("com.android.settings.OEM_RADIO_INFO");
1437 try {
1438 startActivity(intent);
1439 } catch (android.content.ActivityNotFoundException ex) {
Wink Savillebf471282013-04-05 15:04:05 -07001440 log("OEM-specific Info/Settings Activity Not Found : " + ex);
Tammo Spalinka5f4c8f2009-10-15 20:08:58 +08001441 // If the activity does not exist, there are no OEM
1442 // settings, and so we can just do nothing...
1443 }
1444 }
1445 };
1446
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001447 OnClickListener mPingButtonHandler = new OnClickListener() {
1448 public void onClick(View v) {
1449 updatePingState();
1450 }
1451 };
1452
1453 OnClickListener mUpdateSmscButtonHandler = new OnClickListener() {
1454 public void onClick(View v) {
1455 updateSmscButton.setEnabled(false);
jsh21dd4072009-05-12 11:26:55 -07001456 phone.setSmscAddress(smsc.getText().toString(),
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001457 mHandler.obtainMessage(EVENT_UPDATE_SMSC_DONE));
1458 }
1459 };
1460
1461 OnClickListener mRefreshSmscButtonHandler = new OnClickListener() {
1462 public void onClick(View v) {
1463 refreshSmsc();
1464 }
1465 };
1466
Youhan Wangfd781e92016-12-16 15:53:16 -08001467 OnClickListener mCarrierProvisioningButtonHandler = new OnClickListener() {
1468 public void onClick(View v) {
Meng Wanga04449b2017-08-03 14:34:35 -07001469 final Intent intent = new Intent("com.android.settings.CARRIER_PROVISIONING");
1470 final ComponentName serviceComponent = ComponentName.unflattenFromString(
1471 "com.android.omadm.service/.DMIntentReceiver");
Youhan Wangfd781e92016-12-16 15:53:16 -08001472 intent.setComponent(serviceComponent);
Meng Wanga04449b2017-08-03 14:34:35 -07001473 sendBroadcast(intent);
Youhan Wangfd781e92016-12-16 15:53:16 -08001474 }
1475 };
1476
1477 OnClickListener mTriggerCarrierProvisioningButtonHandler = new OnClickListener() {
1478 public void onClick(View v) {
Meng Wanga04449b2017-08-03 14:34:35 -07001479 final Intent intent = new Intent("com.android.settings.TRIGGER_CARRIER_PROVISIONING");
1480 final ComponentName serviceComponent = ComponentName.unflattenFromString(
1481 "com.android.omadm.service/.DMIntentReceiver");
Youhan Wangfd781e92016-12-16 15:53:16 -08001482 intent.setComponent(serviceComponent);
Meng Wanga04449b2017-08-03 14:34:35 -07001483 sendBroadcast(intent);
Youhan Wangfd781e92016-12-16 15:53:16 -08001484 }
1485 };
1486
Nathan Haroldcea413a2015-11-23 15:48:10 -08001487 AdapterView.OnItemSelectedListener mPreferredNetworkHandler =
1488 new AdapterView.OnItemSelectedListener() {
1489
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001490 public void onItemSelected(AdapterView parent, View v, int pos, long id) {
Nathan Haroldcea413a2015-11-23 15:48:10 -08001491 if (mPreferredNetworkTypeResult != pos && pos >= 0
1492 && pos <= mPreferredNetworkLabels.length - 2) {
1493 mPreferredNetworkTypeResult = pos;
Nathan Harolddaea8be2018-06-05 14:02:35 -07001494
1495 // TODO: Possibly migrate this to TelephonyManager.setPreferredNetworkType()
1496 // which today still has some issues (mostly that the "set" is conditional
1497 // on a successful modem call, which is not what we want). Instead we always
1498 // want this setting to be set, so that if the radio hiccups and this setting
1499 // is for some reason unsuccessful, future calls to the radio will reflect
1500 // the users's preference which is set here.
1501 final int subId = phone.getSubId();
1502 if (SubscriptionManager.isUsableSubIdValue(subId)) {
1503 Settings.Global.putInt(phone.getContext().getContentResolver(),
1504 PREFERRED_NETWORK_MODE + subId, mPreferredNetworkTypeResult);
1505 }
1506 log("Calling setPreferredNetworkType(" + mPreferredNetworkTypeResult + ")");
Nathan Haroldcea413a2015-11-23 15:48:10 -08001507 Message msg = mHandler.obtainMessage(EVENT_SET_PREFERRED_TYPE_DONE);
1508 phone.setPreferredNetworkType(mPreferredNetworkTypeResult, msg);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001509 }
1510 }
1511
1512 public void onNothingSelected(AdapterView parent) {
1513 }
1514 };
1515
Nathan Harold2b77d742016-03-19 13:22:10 -07001516 AdapterView.OnItemSelectedListener mCellInfoRefreshRateHandler =
1517 new AdapterView.OnItemSelectedListener() {
Wink Savillebf471282013-04-05 15:04:05 -07001518
Nathan Harold2b77d742016-03-19 13:22:10 -07001519 public void onItemSelected(AdapterView parent, View v, int pos, long id) {
1520 mCellInfoRefreshRateIndex = pos;
Sooraj Sasindran5cce06b2016-08-18 15:49:49 -07001521 mTelephonyManager.setCellInfoListRate(mCellInfoRefreshRates[pos]);
Nathan Harold2b77d742016-03-19 13:22:10 -07001522 updateAllCellInfo();
1523 }
1524
1525 public void onNothingSelected(AdapterView parent) {
1526 }
1527 };
1528
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001529}