1 /* 2 * Copyright (C) 2016 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * 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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17 package com.googlecode.android_scripting.jsonrpc; 18 19 import java.io.IOException; 20 import java.net.HttpURLConnection; 21 import java.net.InetAddress; 22 import java.net.InetSocketAddress; 23 import java.net.URL; 24 import java.security.PrivateKey; 25 import java.security.cert.CertificateEncodingException; 26 import java.security.cert.X509Certificate; 27 import java.util.ArrayList; 28 import java.util.Collection; 29 import java.util.List; 30 import java.util.Map; 31 import java.util.Map.Entry; 32 import java.util.Set; 33 34 import org.apache.commons.codec.binary.Base64Codec; 35 import org.json.JSONArray; 36 import org.json.JSONException; 37 import org.json.JSONObject; 38 39 import com.android.internal.net.LegacyVpnInfo; 40 import com.googlecode.android_scripting.ConvertUtils; 41 import com.googlecode.android_scripting.Log; 42 import com.googlecode.android_scripting.event.Event; 43 //FIXME: Refactor classes, constants and conversions out of here 44 import com.googlecode.android_scripting.facade.telephony.InCallServiceImpl; 45 import com.googlecode.android_scripting.facade.telephony.TelephonyConstants; 46 import com.googlecode.android_scripting.facade.telephony.TelephonyUtils; 47 48 import android.bluetooth.BluetoothDevice; 49 import android.bluetooth.BluetoothGattCharacteristic; 50 import android.bluetooth.BluetoothGattDescriptor; 51 import android.bluetooth.BluetoothGattService; 52 import android.bluetooth.le.AdvertiseSettings; 53 import android.content.ComponentName; 54 import android.content.Intent; 55 import android.graphics.Point; 56 import android.location.Address; 57 import android.location.Location; 58 import android.net.DhcpInfo; 59 import android.net.Network; 60 import android.net.NetworkInfo; 61 import android.net.Uri; 62 import android.net.wifi.RttManager.RttCapabilities; 63 import android.net.wifi.ScanResult; 64 import android.net.wifi.WifiActivityEnergyInfo; 65 import android.net.wifi.WifiChannel; 66 import android.net.wifi.WifiConfiguration; 67 import android.net.wifi.WifiEnterpriseConfig; 68 import android.net.wifi.WifiInfo; 69 import android.net.wifi.WifiScanner.ScanData; 70 import android.net.wifi.p2p.WifiP2pDevice; 71 import android.net.wifi.p2p.WifiP2pGroup; 72 import android.net.wifi.p2p.WifiP2pInfo; 73 import android.os.Bundle; 74 import android.os.ParcelUuid; 75 import android.telecom.Call; 76 import android.telecom.CallAudioState; 77 import android.telecom.PhoneAccount; 78 import android.telecom.PhoneAccountHandle; 79 import android.telecom.VideoProfile; 80 import android.telecom.VideoProfile.CameraCapabilities; 81 import android.telephony.CellIdentityCdma; 82 import android.telephony.CellIdentityGsm; 83 import android.telephony.CellIdentityLte; 84 import android.telephony.CellIdentityWcdma; 85 import android.telephony.CellInfoCdma; 86 import android.telephony.CellInfoGsm; 87 import android.telephony.CellInfoLte; 88 import android.telephony.CellInfoWcdma; 89 import android.telephony.CellLocation; 90 import android.telephony.CellSignalStrengthCdma; 91 import android.telephony.CellSignalStrengthGsm; 92 import android.telephony.CellSignalStrengthLte; 93 import android.telephony.CellSignalStrengthWcdma; 94 import android.telephony.ModemActivityInfo; 95 import android.telephony.NeighboringCellInfo; 96 import android.telephony.SignalStrength; 97 import android.telephony.SmsMessage; 98 import android.telephony.SubscriptionInfo; 99 import android.telephony.VoLteServiceState; 100 import android.telephony.gsm.GsmCellLocation; 101 import android.util.Base64; 102 import android.util.DisplayMetrics; 103 import android.util.SparseArray; 104 105 public class JsonBuilder { 106 107 @SuppressWarnings("unchecked") 108 public static Object build(Object data) throws JSONException { 109 if (data == null) { 110 return JSONObject.NULL; 111 } 112 if (data instanceof Integer) { 113 return data; 114 } 115 if (data instanceof Float) { 116 return data; 117 } 118 if (data instanceof Double) { 119 return data; 120 } 121 if (data instanceof Long) { 122 return data; 123 } 124 if (data instanceof String) { 125 return data; 126 } 127 if (data instanceof Boolean) { 128 return data; 129 } 130 if (data instanceof JsonSerializable) { 131 return ((JsonSerializable) data).toJSON(); 132 } 133 if (data instanceof JSONObject) { 134 return data; 135 } 136 if (data instanceof JSONArray) { 137 return data; 138 } 139 if (data instanceof Set<?>) { 140 List<Object> items = new ArrayList<Object>((Set<?>) data); 141 return buildJsonList(items); 142 } 143 if (data instanceof Collection<?>) { 144 List<Object> items = new ArrayList<Object>((Collection<?>) data); 145 return buildJsonList(items); 146 } 147 if (data instanceof List<?>) { 148 return buildJsonList((List<?>) data); 149 } 150 if (data instanceof Address) { 151 return buildJsonAddress((Address) data); 152 } 153 if (data instanceof CallAudioState) { 154 return buildJsonAudioState((CallAudioState) data); 155 } 156 if (data instanceof Location) { 157 return buildJsonLocation((Location) data); 158 } 159 if (data instanceof Bundle) { 160 return buildJsonBundle((Bundle) data); 161 } 162 if (data instanceof Intent) { 163 return buildJsonIntent((Intent) data); 164 } 165 if (data instanceof Event) { 166 return buildJsonEvent((Event) data); 167 } 168 if (data instanceof Map<?, ?>) { 169 // TODO(damonkohler): I would like to make this a checked cast if 170 // possible. 171 return buildJsonMap((Map<String, ?>) data); 172 } 173 if (data instanceof ParcelUuid) { 174 return data.toString(); 175 } 176 if (data instanceof ScanResult) { 177 return buildJsonScanResult((ScanResult) data); 178 } 179 if (data instanceof ScanData) { 180 return buildJsonScanData((ScanData) data); 181 } 182 if (data instanceof android.bluetooth.le.ScanResult) { 183 return buildJsonBleScanResult((android.bluetooth.le.ScanResult) data); 184 } 185 if (data instanceof AdvertiseSettings) { 186 return buildJsonBleAdvertiseSettings((AdvertiseSettings) data); 187 } 188 if (data instanceof BluetoothGattService) { 189 return buildJsonBluetoothGattService((BluetoothGattService) data); 190 } 191 if (data instanceof BluetoothGattCharacteristic) { 192 return buildJsonBluetoothGattCharacteristic((BluetoothGattCharacteristic) data); 193 } 194 if (data instanceof BluetoothGattDescriptor) { 195 return buildJsonBluetoothGattDescriptor((BluetoothGattDescriptor) data); 196 } 197 if (data instanceof BluetoothDevice) { 198 return buildJsonBluetoothDevice((BluetoothDevice) data); 199 } 200 if (data instanceof CellLocation) { 201 return buildJsonCellLocation((CellLocation) data); 202 } 203 if (data instanceof WifiInfo) { 204 return buildJsonWifiInfo((WifiInfo) data); 205 } 206 if (data instanceof NeighboringCellInfo) { 207 return buildNeighboringCellInfo((NeighboringCellInfo) data); 208 } 209 if (data instanceof Network) { 210 return buildNetwork((Network) data); 211 } 212 if (data instanceof NetworkInfo) { 213 return buildNetworkInfo((NetworkInfo) data); 214 } 215 if (data instanceof HttpURLConnection) { 216 return buildHttpURLConnection((HttpURLConnection) data); 217 } 218 if (data instanceof InetSocketAddress) { 219 return buildInetSocketAddress((InetSocketAddress) data); 220 } 221 if (data instanceof InetAddress) { 222 return buildInetAddress((InetAddress) data); 223 } 224 if (data instanceof URL) { 225 return buildURL((URL) data); 226 } 227 if (data instanceof Point) { 228 return buildPoint((Point) data); 229 } 230 if (data instanceof SmsMessage) { 231 return buildSmsMessage((SmsMessage) data); 232 } 233 if (data instanceof PhoneAccount) { 234 return buildPhoneAccount((PhoneAccount) data); 235 } 236 if (data instanceof PhoneAccountHandle) { 237 return buildPhoneAccountHandle((PhoneAccountHandle) data); 238 } 239 if (data instanceof SubscriptionInfo) { 240 return buildSubscriptionInfoRecord((SubscriptionInfo) data); 241 } 242 if (data instanceof DhcpInfo) { 243 return buildDhcpInfo((DhcpInfo) data); 244 } 245 if (data instanceof DisplayMetrics) { 246 return buildDisplayMetrics((DisplayMetrics) data); 247 } 248 if (data instanceof RttCapabilities) { 249 return buildRttCapabilities((RttCapabilities) data); 250 } 251 if (data instanceof WifiActivityEnergyInfo) { 252 return buildWifiActivityEnergyInfo((WifiActivityEnergyInfo) data); 253 } 254 if (data instanceof WifiChannel) { 255 return buildWifiChannel((WifiChannel) data); 256 } 257 if (data instanceof WifiConfiguration) { 258 return buildWifiConfiguration((WifiConfiguration) data); 259 } 260 if (data instanceof WifiP2pDevice) { 261 return buildWifiP2pDevice((WifiP2pDevice) data); 262 } 263 if (data instanceof WifiP2pInfo) { 264 return buildWifiP2pInfo((WifiP2pInfo) data); 265 } 266 if (data instanceof WifiP2pGroup) { 267 return buildWifiP2pGroup((WifiP2pGroup) data); 268 } 269 if (data instanceof byte[]) { 270 JSONArray result = new JSONArray(); 271 for (byte b : (byte[]) data) { 272 result.put(b & 0xFF); 273 } 274 return result; 275 } 276 if (data instanceof Object[]) { 277 return buildJSONArray((Object[]) data); 278 } 279 if (data instanceof CellInfoLte) { 280 return buildCellInfoLte((CellInfoLte) data); 281 } 282 if (data instanceof CellInfoWcdma) { 283 return buildCellInfoWcdma((CellInfoWcdma) data); 284 } 285 if (data instanceof CellInfoGsm) { 286 return buildCellInfoGsm((CellInfoGsm) data); 287 } 288 if (data instanceof CellInfoCdma) { 289 return buildCellInfoCdma((CellInfoCdma) data); 290 } 291 if (data instanceof Call) { 292 return buildCall((Call) data); 293 } 294 if (data instanceof Call.Details) { 295 return buildCallDetails((Call.Details) data); 296 } 297 if (data instanceof InCallServiceImpl.CallEvent<?>) { 298 return buildCallEvent((InCallServiceImpl.CallEvent<?>) data); 299 } 300 if (data instanceof VideoProfile) { 301 return buildVideoProfile((VideoProfile) data); 302 } 303 if (data instanceof CameraCapabilities) { 304 return buildCameraCapabilities((CameraCapabilities) data); 305 } 306 if (data instanceof VoLteServiceState) { 307 return buildVoLteServiceStateEvent((VoLteServiceState) data); 308 } 309 if (data instanceof LegacyVpnInfo) { 310 return buildLegacyVpnInfo((LegacyVpnInfo) data); 311 } 312 if (data instanceof ModemActivityInfo) { 313 return buildModemActivityInfo((ModemActivityInfo) data); 314 } 315 if (data instanceof SignalStrength) { 316 return buildSignalStrength((SignalStrength) data); 317 } 318 319 return data.toString(); 320 // throw new JSONException("Failed to build JSON result. " + 321 // data.getClass().getName()); 322 } 323 324 private static JSONObject buildJsonAudioState(CallAudioState data) 325 throws JSONException { 326 JSONObject state = new JSONObject(); 327 state.put("isMuted", data.isMuted()); 328 state.put("AudioRoute", InCallServiceImpl.getAudioRouteString(data.getRoute())); 329 return state; 330 } 331 332 private static Object buildDisplayMetrics(DisplayMetrics data) 333 throws JSONException { 334 JSONObject dm = new JSONObject(); 335 dm.put("widthPixels", data.widthPixels); 336 dm.put("heightPixels", data.heightPixels); 337 dm.put("noncompatHeightPixels", data.noncompatHeightPixels); 338 dm.put("noncompatWidthPixels", data.noncompatWidthPixels); 339 return dm; 340 } 341 342 private static Object buildInetAddress(InetAddress data) { 343 JSONArray address = new JSONArray(); 344 address.put(data.getHostName()); 345 address.put(data.getHostAddress()); 346 return address; 347 } 348 349 private static Object buildInetSocketAddress(InetSocketAddress data) { 350 JSONArray address = new JSONArray(); 351 address.put(data.getHostName()); 352 address.put(data.getPort()); 353 return address; 354 } 355 356 private static JSONObject buildJsonAddress(Address address) 357 throws JSONException { 358 JSONObject result = new JSONObject(); 359 result.put("admin_area", address.getAdminArea()); 360 result.put("country_code", address.getCountryCode()); 361 result.put("country_name", address.getCountryName()); 362 result.put("feature_name", address.getFeatureName()); 363 result.put("phone", address.getPhone()); 364 result.put("locality", address.getLocality()); 365 result.put("postal_code", address.getPostalCode()); 366 result.put("sub_admin_area", address.getSubAdminArea()); 367 result.put("thoroughfare", address.getThoroughfare()); 368 result.put("url", address.getUrl()); 369 return result; 370 } 371 372 private static JSONArray buildJSONArray(Object[] data) throws JSONException { 373 JSONArray result = new JSONArray(); 374 for (Object o : data) { 375 result.put(build(o)); 376 } 377 return result; 378 } 379 380 private static JSONObject buildJsonBleAdvertiseSettings( 381 AdvertiseSettings advertiseSettings) throws JSONException { 382 JSONObject result = new JSONObject(); 383 result.put("mode", advertiseSettings.getMode()); 384 result.put("txPowerLevel", advertiseSettings.getTxPowerLevel()); 385 result.put("isConnectable", advertiseSettings.isConnectable()); 386 return result; 387 } 388 389 private static JSONObject buildJsonBleScanResult( 390 android.bluetooth.le.ScanResult scanResult) throws JSONException { 391 JSONObject result = new JSONObject(); 392 result.put("rssi", scanResult.getRssi()); 393 result.put("timestampNanos", scanResult.getTimestampNanos()); 394 result.put("deviceName", scanResult.getScanRecord().getDeviceName()); 395 result.put("txPowerLevel", scanResult.getScanRecord().getTxPowerLevel()); 396 result.put("advertiseFlags", scanResult.getScanRecord() 397 .getAdvertiseFlags()); 398 ArrayList<String> manufacturerDataList = new ArrayList<String>(); 399 ArrayList<Integer> idList = new ArrayList<Integer>(); 400 if (scanResult.getScanRecord().getManufacturerSpecificData() != null) { 401 SparseArray<byte[]> manufacturerSpecificData = scanResult 402 .getScanRecord().getManufacturerSpecificData(); 403 for (int i = 0; i < manufacturerSpecificData.size(); i++) { 404 manufacturerDataList.add(ConvertUtils 405 .convertByteArrayToString(manufacturerSpecificData 406 .valueAt(i))); 407 idList.add(manufacturerSpecificData.keyAt(i)); 408 } 409 } 410 result.put("manufacturerSpecificDataList", manufacturerDataList); 411 result.put("manufacturerIdList", idList); 412 ArrayList<String> serviceUuidList = new ArrayList<String>(); 413 ArrayList<String> serviceDataList = new ArrayList<String>(); 414 if (scanResult.getScanRecord().getServiceData() != null) { 415 Map<ParcelUuid, byte[]> serviceDataMap = scanResult.getScanRecord() 416 .getServiceData(); 417 for (ParcelUuid serviceUuid : serviceDataMap.keySet()) { 418 serviceUuidList.add(serviceUuid.toString()); 419 serviceDataList.add(ConvertUtils 420 .convertByteArrayToString(serviceDataMap 421 .get(serviceUuid))); 422 } 423 } 424 result.put("serviceUuidList", serviceUuidList); 425 result.put("serviceDataList", serviceDataList); 426 List<ParcelUuid> serviceUuids = scanResult.getScanRecord() 427 .getServiceUuids(); 428 String serviceUuidsString = ""; 429 if (serviceUuids != null && serviceUuids.size() > 0) { 430 for (ParcelUuid uuid : serviceUuids) { 431 serviceUuidsString = serviceUuidsString + "," + uuid; 432 } 433 } 434 result.put("serviceUuids", serviceUuidsString); 435 result.put("scanRecord", 436 build(ConvertUtils.convertByteArrayToString(scanResult 437 .getScanRecord().getBytes()))); 438 result.put("deviceInfo", build(scanResult.getDevice())); 439 return result; 440 } 441 442 private static JSONObject buildJsonBluetoothDevice(BluetoothDevice data) 443 throws JSONException { 444 JSONObject deviceInfo = new JSONObject(); 445 deviceInfo.put("address", data.getAddress()); 446 deviceInfo.put("state", data.getBondState()); 447 deviceInfo.put("name", data.getName()); 448 deviceInfo.put("type", data.getType()); 449 return deviceInfo; 450 } 451 452 private static Object buildJsonBluetoothGattCharacteristic( 453 BluetoothGattCharacteristic data) throws JSONException { 454 JSONObject result = new JSONObject(); 455 result.put("instanceId", data.getInstanceId()); 456 result.put("permissions", data.getPermissions()); 457 result.put("properties", data.getProperties()); 458 result.put("writeType", data.getWriteType()); 459 result.put("descriptorsList", build(data.getDescriptors())); 460 result.put("uuid", data.getUuid().toString()); 461 result.put("value", build(data.getValue())); 462 463 return result; 464 } 465 466 private static Object buildJsonBluetoothGattDescriptor( 467 BluetoothGattDescriptor data) throws JSONException { 468 JSONObject result = new JSONObject(); 469 result.put("instanceId", data.getInstanceId()); 470 result.put("permissions", data.getPermissions()); 471 result.put("characteristic", data.getCharacteristic()); 472 result.put("uuid", data.getUuid().toString()); 473 result.put("value", build(data.getValue())); 474 return result; 475 } 476 477 private static Object buildJsonBluetoothGattService( 478 BluetoothGattService data) throws JSONException { 479 JSONObject result = new JSONObject(); 480 result.put("instanceId", data.getInstanceId()); 481 result.put("type", data.getType()); 482 result.put("gattCharacteristicList", build(data.getCharacteristics())); 483 result.put("includedServices", build(data.getIncludedServices())); 484 result.put("uuid", data.getUuid().toString()); 485 return result; 486 } 487 488 private static JSONObject buildJsonBundle(Bundle bundle) 489 throws JSONException { 490 JSONObject result = new JSONObject(); 491 for (String key : bundle.keySet()) { 492 result.put(key, build(bundle.get(key))); 493 } 494 return result; 495 } 496 497 private static JSONObject buildJsonCellLocation(CellLocation cellLocation) 498 throws JSONException { 499 JSONObject result = new JSONObject(); 500 if (cellLocation instanceof GsmCellLocation) { 501 GsmCellLocation location = (GsmCellLocation) cellLocation; 502 result.put("lac", location.getLac()); 503 result.put("cid", location.getCid()); 504 } 505 // TODO(damonkohler): Add support for CdmaCellLocation. Not supported 506 // until API level 5. 507 return result; 508 } 509 510 private static JSONObject buildDhcpInfo(DhcpInfo data) throws JSONException { 511 JSONObject result = new JSONObject(); 512 result.put("ipAddress", data.ipAddress); 513 result.put("dns1", data.dns1); 514 result.put("dns2", data.dns2); 515 result.put("gateway", data.gateway); 516 result.put("serverAddress", data.serverAddress); 517 result.put("leaseDuration", data.leaseDuration); 518 return result; 519 } 520 521 private static JSONObject buildJsonEvent(Event event) throws JSONException { 522 JSONObject result = new JSONObject(); 523 result.put("name", event.getName()); 524 result.put("data", build(event.getData())); 525 result.put("time", event.getCreationTime()); 526 return result; 527 } 528 529 private static JSONObject buildJsonIntent(Intent data) throws JSONException { 530 JSONObject result = new JSONObject(); 531 result.put("data", data.getDataString()); 532 result.put("type", data.getType()); 533 result.put("extras", build(data.getExtras())); 534 result.put("categories", build(data.getCategories())); 535 result.put("action", data.getAction()); 536 ComponentName component = data.getComponent(); 537 if (component != null) { 538 result.put("packagename", component.getPackageName()); 539 result.put("classname", component.getClassName()); 540 } 541 result.put("flags", data.getFlags()); 542 return result; 543 } 544 545 private static <T> JSONArray buildJsonList(final List<T> list) 546 throws JSONException { 547 JSONArray result = new JSONArray(); 548 for (T item : list) { 549 result.put(build(item)); 550 } 551 return result; 552 } 553 554 private static JSONObject buildJsonLocation(Location location) 555 throws JSONException { 556 JSONObject result = new JSONObject(); 557 result.put("altitude", location.getAltitude()); 558 result.put("latitude", location.getLatitude()); 559 result.put("longitude", location.getLongitude()); 560 result.put("time", location.getTime()); 561 result.put("accuracy", location.getAccuracy()); 562 result.put("speed", location.getSpeed()); 563 result.put("provider", location.getProvider()); 564 result.put("bearing", location.getBearing()); 565 return result; 566 } 567 568 private static JSONObject buildJsonMap(Map<String, ?> map) 569 throws JSONException { 570 JSONObject result = new JSONObject(); 571 for (Entry<String, ?> entry : map.entrySet()) { 572 String key = entry.getKey(); 573 if (key == null) { 574 key = ""; 575 } 576 result.put(key, build(entry.getValue())); 577 } 578 return result; 579 } 580 581 private static JSONObject buildJsonScanResult(ScanResult scanResult) 582 throws JSONException { 583 JSONObject result = new JSONObject(); 584 result.put("BSSID", scanResult.BSSID); 585 result.put("SSID", scanResult.SSID); 586 result.put("frequency", scanResult.frequency); 587 result.put("level", scanResult.level); 588 result.put("capabilities", scanResult.capabilities); 589 result.put("timestamp", scanResult.timestamp); 590 result.put("blackListTimestamp", scanResult.blackListTimestamp); 591 result.put("centerFreq0", scanResult.centerFreq0); 592 result.put("centerFreq1", scanResult.centerFreq1); 593 result.put("channelWidth", scanResult.channelWidth); 594 result.put("distanceCm", scanResult.distanceCm); 595 result.put("distanceSdCm", scanResult.distanceSdCm); 596 result.put("is80211McRTTResponder", scanResult.is80211mcResponder()); 597 result.put("isAutoJoinCandidate", scanResult.isAutoJoinCandidate); 598 result.put("numConnection", scanResult.numConnection); 599 result.put("passpointNetwork", scanResult.isPasspointNetwork()); 600 result.put("numIpConfigFailures", scanResult.numIpConfigFailures); 601 result.put("numUsage", scanResult.numUsage); 602 result.put("seen", scanResult.seen); 603 result.put("untrusted", scanResult.untrusted); 604 result.put("operatorFriendlyName", scanResult.operatorFriendlyName); 605 result.put("venueName", scanResult.venueName); 606 if (scanResult.informationElements != null) { 607 JSONArray infoEles = new JSONArray(); 608 for (ScanResult.InformationElement ie : scanResult.informationElements) { 609 JSONObject infoEle = new JSONObject(); 610 infoEle.put("id", ie.id); 611 infoEle.put("bytes", Base64Codec.encodeBase64(ie.bytes).toString()); 612 infoEles.put(infoEle); 613 } 614 result.put("InfomationElements", infoEles); 615 } else { 616 result.put("InfomationElements", null); 617 } 618 return result; 619 } 620 621 private static JSONObject buildJsonScanData(ScanData scanData) 622 throws JSONException { 623 JSONObject result = new JSONObject(); 624 result.put("Id", scanData.getId()); 625 result.put("Flags", scanData.getFlags()); 626 JSONArray scanResults = new JSONArray(); 627 for (ScanResult sr : scanData.getResults()) { 628 scanResults.put(buildJsonScanResult(sr)); 629 } 630 result.put("ScanResults", scanResults); 631 return result; 632 } 633 634 private static JSONObject buildJsonWifiInfo(WifiInfo data) 635 throws JSONException { 636 JSONObject result = new JSONObject(); 637 result.put("hidden_ssid", data.getHiddenSSID()); 638 result.put("ip_address", data.getIpAddress()); 639 result.put("link_speed", data.getLinkSpeed()); 640 result.put("network_id", data.getNetworkId()); 641 result.put("rssi", data.getRssi()); 642 result.put("BSSID", data.getBSSID()); 643 result.put("mac_address", data.getMacAddress()); 644 // Trim the double quotes if exist 645 String ssid = data.getSSID(); 646 if (ssid.charAt(0) == '"' 647 && ssid.charAt(ssid.length() - 1) == '"') { 648 result.put("SSID", ssid.substring(1, ssid.length() - 1)); 649 } else { 650 result.put("SSID", ssid); 651 } 652 String supplicantState = ""; 653 switch (data.getSupplicantState()) { 654 case ASSOCIATED: 655 supplicantState = "associated"; 656 break; 657 case ASSOCIATING: 658 supplicantState = "associating"; 659 break; 660 case COMPLETED: 661 supplicantState = "completed"; 662 break; 663 case DISCONNECTED: 664 supplicantState = "disconnected"; 665 break; 666 case DORMANT: 667 supplicantState = "dormant"; 668 break; 669 case FOUR_WAY_HANDSHAKE: 670 supplicantState = "four_way_handshake"; 671 break; 672 case GROUP_HANDSHAKE: 673 supplicantState = "group_handshake"; 674 break; 675 case INACTIVE: 676 supplicantState = "inactive"; 677 break; 678 case INVALID: 679 supplicantState = "invalid"; 680 break; 681 case SCANNING: 682 supplicantState = "scanning"; 683 break; 684 case UNINITIALIZED: 685 supplicantState = "uninitialized"; 686 break; 687 default: 688 supplicantState = null; 689 } 690 result.put("supplicant_state", build(supplicantState)); 691 result.put("is_5ghz", data.is5GHz()); 692 result.put("is_24ghz", data.is24GHz()); 693 return result; 694 } 695 696 private static JSONObject buildNeighboringCellInfo(NeighboringCellInfo data) 697 throws JSONException { 698 JSONObject result = new JSONObject(); 699 result.put("cid", data.getCid()); 700 result.put("rssi", data.getRssi()); 701 result.put("lac", data.getLac()); 702 result.put("psc", data.getPsc()); 703 String networkType = TelephonyUtils.getNetworkTypeString(data.getNetworkType()); 704 result.put("network_type", build(networkType)); 705 return result; 706 } 707 708 private static JSONObject buildCellInfoLte(CellInfoLte data) 709 throws JSONException { 710 JSONObject result = new JSONObject(); 711 result.put("rat", "lte"); 712 result.put("registered", data.isRegistered()); 713 CellIdentityLte cellidentity = ((CellInfoLte) data).getCellIdentity(); 714 CellSignalStrengthLte signalstrength = ((CellInfoLte) data).getCellSignalStrength(); 715 result.put("mcc", cellidentity.getMcc()); 716 result.put("mnc", cellidentity.getMnc()); 717 result.put("cid", cellidentity.getCi()); 718 result.put("pcid", cellidentity.getPci()); 719 result.put("tac", cellidentity.getTac()); 720 result.put("rsrp", signalstrength.getDbm()); 721 result.put("asulevel", signalstrength.getAsuLevel()); 722 result.put("timing_advance", signalstrength.getTimingAdvance()); 723 return result; 724 } 725 726 private static JSONObject buildCellInfoGsm(CellInfoGsm data) 727 throws JSONException { 728 JSONObject result = new JSONObject(); 729 result.put("rat", "gsm"); 730 result.put("registered", data.isRegistered()); 731 CellIdentityGsm cellidentity = ((CellInfoGsm) data).getCellIdentity(); 732 CellSignalStrengthGsm signalstrength = ((CellInfoGsm) data).getCellSignalStrength(); 733 result.put("mcc", cellidentity.getMcc()); 734 result.put("mnc", cellidentity.getMnc()); 735 result.put("cid", cellidentity.getCid()); 736 result.put("lac", cellidentity.getLac()); 737 result.put("signal_strength", signalstrength.getDbm()); 738 result.put("asulevel", signalstrength.getAsuLevel()); 739 return result; 740 } 741 742 private static JSONObject buildCellInfoWcdma(CellInfoWcdma data) 743 throws JSONException { 744 JSONObject result = new JSONObject(); 745 result.put("rat", "wcdma"); 746 result.put("registered", data.isRegistered()); 747 CellIdentityWcdma cellidentity = ((CellInfoWcdma) data).getCellIdentity(); 748 CellSignalStrengthWcdma signalstrength = ((CellInfoWcdma) data).getCellSignalStrength(); 749 result.put("mcc", cellidentity.getMcc()); 750 result.put("mnc", cellidentity.getMnc()); 751 result.put("cid", cellidentity.getCid()); 752 result.put("lac", cellidentity.getLac()); 753 result.put("psc", cellidentity.getPsc()); 754 result.put("signal_strength", signalstrength.getDbm()); 755 result.put("asulevel", signalstrength.getAsuLevel()); 756 return result; 757 } 758 759 private static JSONObject buildCellInfoCdma(CellInfoCdma data) 760 throws JSONException { 761 JSONObject result = new JSONObject(); 762 result.put("rat", "cdma"); 763 result.put("registered", data.isRegistered()); 764 CellIdentityCdma cellidentity = ((CellInfoCdma) data).getCellIdentity(); 765 CellSignalStrengthCdma signalstrength = ((CellInfoCdma) data).getCellSignalStrength(); 766 result.put("network_id", cellidentity.getNetworkId()); 767 result.put("system_id", cellidentity.getSystemId()); 768 result.put("basestation_id", cellidentity.getBasestationId()); 769 result.put("longitude", cellidentity.getLongitude()); 770 result.put("latitude", cellidentity.getLatitude()); 771 result.put("cdma_dbm", signalstrength.getCdmaDbm()); 772 result.put("cdma_ecio", signalstrength.getCdmaEcio()); 773 result.put("evdo_dbm", signalstrength.getEvdoDbm()); 774 result.put("evdo_ecio", signalstrength.getEvdoEcio()); 775 result.put("evdo_snr", signalstrength.getEvdoSnr()); 776 return result; 777 } 778 779 private static Object buildHttpURLConnection(HttpURLConnection data) 780 throws JSONException { 781 JSONObject con = new JSONObject(); 782 try { 783 con.put("ResponseCode", data.getResponseCode()); 784 con.put("ResponseMessage", data.getResponseMessage()); 785 } catch (IOException e) { 786 e.printStackTrace(); 787 return con; 788 } 789 con.put("ContentLength", data.getContentLength()); 790 con.put("ContentEncoding", data.getContentEncoding()); 791 con.put("ContentType", data.getContentType()); 792 con.put("Date", data.getDate()); 793 con.put("ReadTimeout", data.getReadTimeout()); 794 con.put("HeaderFields", buildJsonMap(data.getHeaderFields())); 795 con.put("URL", buildURL(data.getURL())); 796 return con; 797 } 798 799 private static Object buildNetwork(Network data) throws JSONException { 800 JSONObject nw = new JSONObject(); 801 nw.put("netId", data.netId); 802 return nw; 803 } 804 805 private static Object buildNetworkInfo(NetworkInfo data) 806 throws JSONException { 807 JSONObject info = new JSONObject(); 808 info.put("isAvailable", data.isAvailable()); 809 info.put("isConnected", data.isConnected()); 810 info.put("isFailover", data.isFailover()); 811 info.put("isRoaming", data.isRoaming()); 812 info.put("ExtraInfo", data.getExtraInfo()); 813 info.put("FailedReason", data.getReason()); 814 info.put("TypeName", data.getTypeName()); 815 info.put("SubtypeName", data.getSubtypeName()); 816 info.put("State", data.getState().name().toString()); 817 return info; 818 } 819 820 private static Object buildURL(URL data) throws JSONException { 821 JSONObject url = new JSONObject(); 822 url.put("Authority", data.getAuthority()); 823 url.put("Host", data.getHost()); 824 url.put("Path", data.getPath()); 825 url.put("Port", data.getPort()); 826 url.put("Protocol", data.getProtocol()); 827 return url; 828 } 829 830 private static JSONObject buildPhoneAccount(PhoneAccount data) 831 throws JSONException { 832 JSONObject acct = new JSONObject(); 833 acct.put("Address", data.getAddress().toSafeString()); 834 acct.put("SubscriptionAddress", data.getSubscriptionAddress() 835 .toSafeString()); 836 acct.put("Label", ((data.getLabel() != null) ? data.getLabel().toString() : "")); 837 acct.put("ShortDescription", ((data.getShortDescription() != null) ? data 838 .getShortDescription().toString() : "")); 839 return acct; 840 } 841 842 private static Object buildPhoneAccountHandle(PhoneAccountHandle data) 843 throws JSONException { 844 JSONObject msg = new JSONObject(); 845 msg.put("id", data.getId()); 846 msg.put("ComponentName", data.getComponentName().flattenToString()); 847 return msg; 848 } 849 850 private static Object buildSubscriptionInfoRecord(SubscriptionInfo data) 851 throws JSONException { 852 JSONObject msg = new JSONObject(); 853 msg.put("subscriptionId", data.getSubscriptionId()); 854 msg.put("iccId", data.getIccId()); 855 msg.put("simSlotIndex", data.getSimSlotIndex()); 856 msg.put("displayName", data.getDisplayName()); 857 msg.put("nameSource", data.getNameSource()); 858 msg.put("iconTint", data.getIconTint()); 859 msg.put("number", data.getNumber()); 860 msg.put("dataRoaming", data.getDataRoaming()); 861 msg.put("mcc", data.getMcc()); 862 msg.put("mnc", data.getMnc()); 863 return msg; 864 } 865 866 private static Object buildPoint(Point data) throws JSONException { 867 JSONObject point = new JSONObject(); 868 point.put("x", data.x); 869 point.put("y", data.y); 870 return point; 871 } 872 873 private static Object buildRttCapabilities(RttCapabilities data) 874 throws JSONException { 875 JSONObject cap = new JSONObject(); 876 cap.put("bwSupported", data.bwSupported); 877 cap.put("lciSupported", data.lciSupported); 878 cap.put("lcrSupported", data.lcrSupported); 879 cap.put("oneSidedRttSupported", data.oneSidedRttSupported); 880 cap.put("preambleSupported", data.preambleSupported); 881 cap.put("twoSided11McRttSupported", data.twoSided11McRttSupported); 882 return cap; 883 } 884 885 private static Object buildSmsMessage(SmsMessage data) throws JSONException { 886 JSONObject msg = new JSONObject(); 887 msg.put("originatingAddress", data.getOriginatingAddress()); 888 msg.put("messageBody", data.getMessageBody()); 889 return msg; 890 } 891 892 private static JSONObject buildWifiActivityEnergyInfo( 893 WifiActivityEnergyInfo data) throws JSONException { 894 JSONObject result = new JSONObject(); 895 result.put("ControllerEnergyUsed", data.getControllerEnergyUsed()); 896 result.put("ControllerIdleTimeMillis", 897 data.getControllerIdleTimeMillis()); 898 result.put("ControllerRxTimeMillis", data.getControllerRxTimeMillis()); 899 result.put("ControllerTxTimeMillis", data.getControllerTxTimeMillis()); 900 result.put("StackState", data.getStackState()); 901 result.put("TimeStamp", data.getTimeStamp()); 902 return result; 903 } 904 905 private static Object buildWifiChannel(WifiChannel data) throws JSONException { 906 JSONObject channel = new JSONObject(); 907 channel.put("channelNum", data.channelNum); 908 channel.put("freqMHz", data.freqMHz); 909 channel.put("isDFS", data.isDFS); 910 channel.put("isValid", data.isValid()); 911 return channel; 912 } 913 914 private static Object buildWifiConfiguration(WifiConfiguration data) 915 throws JSONException { 916 JSONObject config = new JSONObject(); 917 config.put("networkId", data.networkId); 918 // Trim the double quotes if exist 919 if (data.SSID.charAt(0) == '"' 920 && data.SSID.charAt(data.SSID.length() - 1) == '"') { 921 config.put("SSID", data.SSID.substring(1, data.SSID.length() - 1)); 922 } else { 923 config.put("SSID", data.SSID); 924 } 925 config.put("BSSID", data.BSSID); 926 config.put("priority", data.priority); 927 config.put("hiddenSSID", data.hiddenSSID); 928 config.put("FQDN", data.FQDN); 929 config.put("providerFriendlyName", data.providerFriendlyName); 930 config.put("isPasspoint", data.isPasspoint()); 931 config.put("hiddenSSID", data.hiddenSSID); 932 if (data.status == WifiConfiguration.Status.CURRENT) { 933 config.put("status", "CURRENT"); 934 } else if (data.status == WifiConfiguration.Status.DISABLED) { 935 config.put("status", "DISABLED"); 936 } else if (data.status == WifiConfiguration.Status.ENABLED) { 937 config.put("status", "ENABLED"); 938 } else { 939 config.put("status", "UNKNOWN"); 940 } 941 // config.put("enterpriseConfig", buildWifiEnterpriseConfig(data.enterpriseConfig)); 942 return config; 943 } 944 945 private static Object buildWifiEnterpriseConfig(WifiEnterpriseConfig data) 946 throws JSONException, CertificateEncodingException { 947 JSONObject config = new JSONObject(); 948 config.put(WifiEnterpriseConfig.PLMN_KEY, data.getPlmn()); 949 config.put(WifiEnterpriseConfig.REALM_KEY, data.getRealm()); 950 config.put(WifiEnterpriseConfig.EAP_KEY, data.getEapMethod()); 951 config.put(WifiEnterpriseConfig.PHASE2_KEY, data.getPhase2Method()); 952 config.put(WifiEnterpriseConfig.ALTSUBJECT_MATCH_KEY, data.getAltSubjectMatch()); 953 X509Certificate caCert = data.getCaCertificate(); 954 String caCertString = Base64.encodeToString(caCert.getEncoded(), Base64.DEFAULT); 955 config.put(WifiEnterpriseConfig.CA_CERT_KEY, caCertString); 956 X509Certificate clientCert = data.getClientCertificate(); 957 String clientCertString = Base64.encodeToString(clientCert.getEncoded(), Base64.DEFAULT); 958 config.put(WifiEnterpriseConfig.CLIENT_CERT_KEY, clientCertString); 959 PrivateKey pk = data.getClientPrivateKey(); 960 String privateKeyString = Base64.encodeToString(pk.getEncoded(), Base64.DEFAULT); 961 config.put(WifiEnterpriseConfig.PRIVATE_KEY_ID_KEY, privateKeyString); 962 config.put(WifiEnterpriseConfig.PASSWORD_KEY, data.getPassword()); 963 return config; 964 } 965 966 private static JSONObject buildWifiP2pDevice(WifiP2pDevice data) 967 throws JSONException { 968 JSONObject deviceInfo = new JSONObject(); 969 deviceInfo.put("Name", data.deviceName); 970 deviceInfo.put("Address", data.deviceAddress); 971 return deviceInfo; 972 } 973 974 private static JSONObject buildWifiP2pGroup(WifiP2pGroup data) 975 throws JSONException { 976 JSONObject group = new JSONObject(); 977 Log.d("build p2p group."); 978 group.put("ClientList", build(data.getClientList())); 979 group.put("Interface", data.getInterface()); 980 group.put("Networkname", data.getNetworkName()); 981 group.put("Owner", data.getOwner()); 982 group.put("Passphrase", data.getPassphrase()); 983 group.put("NetworkId", data.getNetworkId()); 984 return group; 985 } 986 987 private static JSONObject buildWifiP2pInfo(WifiP2pInfo data) 988 throws JSONException { 989 JSONObject info = new JSONObject(); 990 Log.d("build p2p info."); 991 info.put("groupFormed", data.groupFormed); 992 info.put("isGroupOwner", data.isGroupOwner); 993 info.put("groupOwnerAddress", data.groupOwnerAddress); 994 return info; 995 } 996 997 private static <T> JSONObject buildCallEvent(InCallServiceImpl.CallEvent<T> callEvent) 998 throws JSONException { 999 JSONObject jsonEvent = new JSONObject(); 1000 jsonEvent.put("CallId", callEvent.getCallId()); 1001 jsonEvent.put("Event", build(callEvent.getEvent())); 1002 return jsonEvent; 1003 } 1004 1005 private static JSONObject buildUri(Uri uri) throws JSONException { 1006 return new JSONObject().put("Uri", build((uri != null) ? uri.toString() : "")); 1007 } 1008 1009 private static JSONObject buildCallDetails(Call.Details details) throws JSONException { 1010 1011 JSONObject callDetails = new JSONObject(); 1012 1013 callDetails.put("Handle", buildUri(details.getHandle())); 1014 callDetails.put("HandlePresentation", 1015 build(InCallServiceImpl.getCallPresentationInfoString( 1016 details.getHandlePresentation()))); 1017 callDetails.put("CallerDisplayName", build(details.getCallerDisplayName())); 1018 1019 // TODO AccountHandle 1020 // callDetails.put("AccountHandle", build("")); 1021 1022 callDetails.put("Capabilities", 1023 build(InCallServiceImpl.getCallCapabilitiesString(details.getCallCapabilities()))); 1024 1025 callDetails.put("Properties", 1026 build(InCallServiceImpl.getCallPropertiesString(details.getCallProperties()))); 1027 1028 // TODO Parse fields in Disconnect Cause 1029 callDetails.put("DisconnectCause", build((details.getDisconnectCause() != null) ? details 1030 .getDisconnectCause().toString() : "")); 1031 callDetails.put("ConnectTimeMillis", build(details.getConnectTimeMillis())); 1032 1033 // TODO: GatewayInfo 1034 // callDetails.put("GatewayInfo", build("")); 1035 1036 callDetails.put("VideoState", 1037 build(InCallServiceImpl.getVideoCallStateString(details.getVideoState()))); 1038 1039 // TODO: StatusHints 1040 // callDetails.put("StatusHints", build("")); 1041 1042 callDetails.put("Extras", build(details.getExtras())); 1043 1044 return callDetails; 1045 } 1046 1047 private static JSONObject buildCall(Call call) throws JSONException { 1048 1049 JSONObject callInfo = new JSONObject(); 1050 1051 callInfo.put("Parent", build(InCallServiceImpl.getCallId(call))); 1052 1053 // TODO:Make a function out of this for consistency 1054 ArrayList<String> children = new ArrayList<String>(); 1055 for (Call child : call.getChildren()) { 1056 children.add(InCallServiceImpl.getCallId(child)); 1057 } 1058 callInfo.put("Children", build(children)); 1059 1060 // TODO:Make a function out of this for consistency 1061 ArrayList<String> conferenceables = new ArrayList<String>(); 1062 for (Call conferenceable : call.getChildren()) { 1063 children.add(InCallServiceImpl.getCallId(conferenceable)); 1064 } 1065 callInfo.put("ConferenceableCalls", build(conferenceables)); 1066 1067 callInfo.put("State", build(InCallServiceImpl.getCallStateString(call.getState()))); 1068 callInfo.put("CannedTextResponses", build(call.getCannedTextResponses())); 1069 callInfo.put("VideoCall", InCallServiceImpl.getVideoCallId(call.getVideoCall())); 1070 callInfo.put("Details", build(call.getDetails())); 1071 1072 return callInfo; 1073 } 1074 1075 private static JSONObject buildVideoProfile(VideoProfile videoProfile) throws JSONException { 1076 JSONObject profile = new JSONObject(); 1077 1078 profile.put("VideoState", 1079 InCallServiceImpl.getVideoCallStateString(videoProfile.getVideoState())); 1080 profile.put("VideoQuality", 1081 InCallServiceImpl.getVideoCallQualityString(videoProfile.getQuality())); 1082 1083 return profile; 1084 } 1085 1086 private static JSONObject buildCameraCapabilities(CameraCapabilities cameraCapabilities) 1087 throws JSONException { 1088 JSONObject capabilities = new JSONObject(); 1089 1090 capabilities.put("Height", build(cameraCapabilities.getHeight())); 1091 capabilities.put("Width", build(cameraCapabilities.getWidth())); 1092 capabilities.put("ZoomSupported", build(cameraCapabilities.isZoomSupported())); 1093 capabilities.put("MaxZoom", build(cameraCapabilities.getMaxZoom())); 1094 1095 return capabilities; 1096 } 1097 1098 private static JSONObject buildVoLteServiceStateEvent( 1099 VoLteServiceState volteInfo) 1100 throws JSONException { 1101 JSONObject info = new JSONObject(); 1102 info.put(TelephonyConstants.VoLteServiceStateContainer.SRVCC_STATE, 1103 TelephonyUtils.getSrvccStateString(volteInfo.getSrvccState())); 1104 return info; 1105 } 1106 1107 private static JSONObject buildLegacyVpnInfo(LegacyVpnInfo data) throws JSONException { 1108 JSONObject info = new JSONObject(); 1109 if (data == null) { 1110 return info; 1111 } 1112 info.put("state", data.state); 1113 info.put("key", data.key); 1114 String intentStr = ""; 1115 if (data.intent != null) { 1116 intentStr = data.intent.toString(); 1117 } 1118 info.put("intent", intentStr); 1119 return info; 1120 } 1121 1122 private static JSONObject buildModemActivityInfo(ModemActivityInfo modemInfo) 1123 throws JSONException { 1124 JSONObject info = new JSONObject(); 1125 1126 info.put("Timestamp", modemInfo.getTimestamp()); 1127 info.put("SleepTimeMs", modemInfo.getSleepTimeMillis()); 1128 info.put("IdleTimeMs", modemInfo.getIdleTimeMillis()); 1129 // convert from int[] to List<Integer> for proper JSON translation 1130 int[] txTimes = modemInfo.getTxTimeMillis(); 1131 List<Integer> tmp = new ArrayList<Integer>(txTimes.length); 1132 for (int val : txTimes) { 1133 tmp.add(val); 1134 } 1135 info.put("TxTimeMs", build(tmp)); 1136 info.put("RxTimeMs", modemInfo.getRxTimeMillis()); 1137 info.put("EnergyUsedMw", modemInfo.getEnergyUsed()); 1138 return info; 1139 } 1140 1141 private static JSONObject buildSignalStrength(SignalStrength signalStrength) 1142 throws JSONException { 1143 JSONObject info = new JSONObject(); 1144 info.put(TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_GSM, 1145 signalStrength.getGsmSignalStrength()); 1146 info.put( 1147 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_GSM_DBM, 1148 signalStrength.getGsmDbm()); 1149 info.put( 1150 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_GSM_LEVEL, 1151 signalStrength.getGsmLevel()); 1152 info.put( 1153 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_GSM_ASU_LEVEL, 1154 signalStrength.getGsmAsuLevel()); 1155 info.put( 1156 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_GSM_BIT_ERROR_RATE, 1157 signalStrength.getGsmBitErrorRate()); 1158 info.put( 1159 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_CDMA_DBM, 1160 signalStrength.getCdmaDbm()); 1161 info.put( 1162 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_CDMA_LEVEL, 1163 signalStrength.getCdmaLevel()); 1164 info.put( 1165 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_CDMA_ASU_LEVEL, 1166 signalStrength.getCdmaAsuLevel()); 1167 info.put( 1168 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_CDMA_ECIO, 1169 signalStrength.getCdmaEcio()); 1170 info.put( 1171 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_EVDO_DBM, 1172 signalStrength.getEvdoDbm()); 1173 info.put( 1174 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_EVDO_ECIO, 1175 signalStrength.getEvdoEcio()); 1176 info.put(TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_LTE, 1177 signalStrength.getLteSignalStrength()); 1178 info.put( 1179 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_LTE_DBM, 1180 signalStrength.getLteDbm()); 1181 info.put( 1182 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_LTE_LEVEL, 1183 signalStrength.getLteLevel()); 1184 info.put( 1185 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_LTE_ASU_LEVEL, 1186 signalStrength.getLteAsuLevel()); 1187 info.put( 1188 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_LEVEL, 1189 signalStrength.getLevel()); 1190 info.put( 1191 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_ASU_LEVEL, 1192 signalStrength.getAsuLevel()); 1193 info.put(TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_DBM, 1194 signalStrength.getDbm()); 1195 return info; 1196 } 1197 1198 private JsonBuilder() { 1199 // This is a utility class. 1200 } 1201 } 1202