Home | History | Annotate | Download | only in jsonrpc
      1 /*
      2  * Copyright (C) 2017 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 
     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("numConnection", scanResult.numConnection);
    598         result.put("passpointNetwork", scanResult.isPasspointNetwork());
    599         result.put("numIpConfigFailures", scanResult.numIpConfigFailures);
    600         result.put("numUsage", scanResult.numUsage);
    601         result.put("seen", scanResult.seen);
    602         result.put("untrusted", scanResult.untrusted);
    603         result.put("operatorFriendlyName", scanResult.operatorFriendlyName);
    604         result.put("venueName", scanResult.venueName);
    605         if (scanResult.informationElements != null) {
    606             JSONArray infoEles = new JSONArray();
    607             for (ScanResult.InformationElement ie : scanResult.informationElements) {
    608                 JSONObject infoEle = new JSONObject();
    609                 infoEle.put("id", ie.id);
    610                 infoEle.put("bytes", Base64Codec.encodeBase64(ie.bytes).toString());
    611                 infoEles.put(infoEle);
    612             }
    613             result.put("InfomationElements", infoEles);
    614         } else {
    615             result.put("InfomationElements", null);
    616         }
    617         return result;
    618     }
    619 
    620     private static JSONObject buildJsonScanData(ScanData scanData)
    621             throws JSONException {
    622         JSONObject result = new JSONObject();
    623         result.put("Id", scanData.getId());
    624         result.put("Flags", scanData.getFlags());
    625         JSONArray scanResults = new JSONArray();
    626         for (ScanResult sr : scanData.getResults()) {
    627             scanResults.put(buildJsonScanResult(sr));
    628         }
    629         result.put("ScanResults", scanResults);
    630         return result;
    631     }
    632 
    633     private static JSONObject buildJsonWifiInfo(WifiInfo data)
    634             throws JSONException {
    635         JSONObject result = new JSONObject();
    636         result.put("hidden_ssid", data.getHiddenSSID());
    637         result.put("ip_address", data.getIpAddress());
    638         result.put("link_speed", data.getLinkSpeed());
    639         result.put("network_id", data.getNetworkId());
    640         result.put("rssi", data.getRssi());
    641         result.put("BSSID", data.getBSSID());
    642         result.put("mac_address", data.getMacAddress());
    643         // Trim the double quotes if exist
    644         String ssid = data.getSSID();
    645         if (ssid.charAt(0) == '"'
    646                 && ssid.charAt(ssid.length() - 1) == '"') {
    647             result.put("SSID", ssid.substring(1, ssid.length() - 1));
    648         } else {
    649             result.put("SSID", ssid);
    650         }
    651         String supplicantState = "";
    652         switch (data.getSupplicantState()) {
    653             case ASSOCIATED:
    654                 supplicantState = "associated";
    655                 break;
    656             case ASSOCIATING:
    657                 supplicantState = "associating";
    658                 break;
    659             case COMPLETED:
    660                 supplicantState = "completed";
    661                 break;
    662             case DISCONNECTED:
    663                 supplicantState = "disconnected";
    664                 break;
    665             case DORMANT:
    666                 supplicantState = "dormant";
    667                 break;
    668             case FOUR_WAY_HANDSHAKE:
    669                 supplicantState = "four_way_handshake";
    670                 break;
    671             case GROUP_HANDSHAKE:
    672                 supplicantState = "group_handshake";
    673                 break;
    674             case INACTIVE:
    675                 supplicantState = "inactive";
    676                 break;
    677             case INVALID:
    678                 supplicantState = "invalid";
    679                 break;
    680             case SCANNING:
    681                 supplicantState = "scanning";
    682                 break;
    683             case UNINITIALIZED:
    684                 supplicantState = "uninitialized";
    685                 break;
    686             default:
    687                 supplicantState = null;
    688         }
    689         result.put("supplicant_state", build(supplicantState));
    690         result.put("is_5ghz", data.is5GHz());
    691         result.put("is_24ghz", data.is24GHz());
    692         return result;
    693     }
    694 
    695     private static JSONObject buildNeighboringCellInfo(NeighboringCellInfo data)
    696             throws JSONException {
    697         JSONObject result = new JSONObject();
    698         result.put("cid", data.getCid());
    699         result.put("rssi", data.getRssi());
    700         result.put("lac", data.getLac());
    701         result.put("psc", data.getPsc());
    702         String networkType = TelephonyUtils.getNetworkTypeString(data.getNetworkType());
    703         result.put("network_type", build(networkType));
    704         return result;
    705     }
    706 
    707     private static JSONObject buildCellInfoLte(CellInfoLte data)
    708             throws JSONException {
    709         JSONObject result = new JSONObject();
    710         result.put("rat", "lte");
    711         result.put("registered", data.isRegistered());
    712         CellIdentityLte cellidentity = ((CellInfoLte) data).getCellIdentity();
    713         CellSignalStrengthLte signalstrength = ((CellInfoLte) data).getCellSignalStrength();
    714         result.put("mcc", cellidentity.getMcc());
    715         result.put("mnc", cellidentity.getMnc());
    716         result.put("cid", cellidentity.getCi());
    717         result.put("pcid", cellidentity.getPci());
    718         result.put("tac", cellidentity.getTac());
    719         result.put("rsrp", signalstrength.getDbm());
    720         result.put("asulevel", signalstrength.getAsuLevel());
    721         result.put("timing_advance", signalstrength.getTimingAdvance());
    722         return result;
    723     }
    724 
    725     private static JSONObject buildCellInfoGsm(CellInfoGsm data)
    726             throws JSONException {
    727         JSONObject result = new JSONObject();
    728         result.put("rat", "gsm");
    729         result.put("registered", data.isRegistered());
    730         CellIdentityGsm cellidentity = ((CellInfoGsm) data).getCellIdentity();
    731         CellSignalStrengthGsm signalstrength = ((CellInfoGsm) data).getCellSignalStrength();
    732         result.put("mcc", cellidentity.getMcc());
    733         result.put("mnc", cellidentity.getMnc());
    734         result.put("cid", cellidentity.getCid());
    735         result.put("lac", cellidentity.getLac());
    736         result.put("signal_strength", signalstrength.getDbm());
    737         result.put("asulevel", signalstrength.getAsuLevel());
    738         return result;
    739     }
    740 
    741     private static JSONObject buildCellInfoWcdma(CellInfoWcdma data)
    742             throws JSONException {
    743         JSONObject result = new JSONObject();
    744         result.put("rat", "wcdma");
    745         result.put("registered", data.isRegistered());
    746         CellIdentityWcdma cellidentity = ((CellInfoWcdma) data).getCellIdentity();
    747         CellSignalStrengthWcdma signalstrength = ((CellInfoWcdma) data).getCellSignalStrength();
    748         result.put("mcc", cellidentity.getMcc());
    749         result.put("mnc", cellidentity.getMnc());
    750         result.put("cid", cellidentity.getCid());
    751         result.put("lac", cellidentity.getLac());
    752         result.put("psc", cellidentity.getPsc());
    753         result.put("signal_strength", signalstrength.getDbm());
    754         result.put("asulevel", signalstrength.getAsuLevel());
    755         return result;
    756     }
    757 
    758     private static JSONObject buildCellInfoCdma(CellInfoCdma data)
    759             throws JSONException {
    760         JSONObject result = new JSONObject();
    761         result.put("rat", "cdma");
    762         result.put("registered", data.isRegistered());
    763         CellIdentityCdma cellidentity = ((CellInfoCdma) data).getCellIdentity();
    764         CellSignalStrengthCdma signalstrength = ((CellInfoCdma) data).getCellSignalStrength();
    765         result.put("network_id", cellidentity.getNetworkId());
    766         result.put("system_id", cellidentity.getSystemId());
    767         result.put("basestation_id", cellidentity.getBasestationId());
    768         result.put("longitude", cellidentity.getLongitude());
    769         result.put("latitude", cellidentity.getLatitude());
    770         result.put("cdma_dbm", signalstrength.getCdmaDbm());
    771         result.put("cdma_ecio", signalstrength.getCdmaEcio());
    772         result.put("evdo_dbm", signalstrength.getEvdoDbm());
    773         result.put("evdo_ecio", signalstrength.getEvdoEcio());
    774         result.put("evdo_snr", signalstrength.getEvdoSnr());
    775         return result;
    776     }
    777 
    778     private static Object buildHttpURLConnection(HttpURLConnection data)
    779             throws JSONException {
    780         JSONObject con = new JSONObject();
    781         try {
    782             con.put("ResponseCode", data.getResponseCode());
    783             con.put("ResponseMessage", data.getResponseMessage());
    784         } catch (IOException e) {
    785             e.printStackTrace();
    786             return con;
    787         }
    788         con.put("ContentLength", data.getContentLength());
    789         con.put("ContentEncoding", data.getContentEncoding());
    790         con.put("ContentType", data.getContentType());
    791         con.put("Date", data.getDate());
    792         con.put("ReadTimeout", data.getReadTimeout());
    793         con.put("HeaderFields", buildJsonMap(data.getHeaderFields()));
    794         con.put("URL", buildURL(data.getURL()));
    795         return con;
    796     }
    797 
    798     private static Object buildNetwork(Network data) throws JSONException {
    799         JSONObject nw = new JSONObject();
    800         nw.put("netId", data.netId);
    801         return nw;
    802     }
    803 
    804     private static Object buildNetworkInfo(NetworkInfo data)
    805             throws JSONException {
    806         JSONObject info = new JSONObject();
    807         info.put("isAvailable", data.isAvailable());
    808         info.put("isConnected", data.isConnected());
    809         info.put("isFailover", data.isFailover());
    810         info.put("isRoaming", data.isRoaming());
    811         info.put("ExtraInfo", data.getExtraInfo());
    812         info.put("FailedReason", data.getReason());
    813         info.put("TypeName", data.getTypeName());
    814         info.put("SubtypeName", data.getSubtypeName());
    815         info.put("State", data.getState().name().toString());
    816         return info;
    817     }
    818 
    819     private static Object buildURL(URL data) throws JSONException {
    820         JSONObject url = new JSONObject();
    821         url.put("Authority", data.getAuthority());
    822         url.put("Host", data.getHost());
    823         url.put("Path", data.getPath());
    824         url.put("Port", data.getPort());
    825         url.put("Protocol", data.getProtocol());
    826         return url;
    827     }
    828 
    829     private static JSONObject buildPhoneAccount(PhoneAccount data)
    830             throws JSONException {
    831         JSONObject acct = new JSONObject();
    832         acct.put("Address", data.getAddress().toSafeString());
    833         acct.put("SubscriptionAddress", data.getSubscriptionAddress()
    834                 .toSafeString());
    835         acct.put("Label", ((data.getLabel() != null) ? data.getLabel().toString() : ""));
    836         acct.put("ShortDescription", ((data.getShortDescription() != null) ? data
    837                 .getShortDescription().toString() : ""));
    838         return acct;
    839     }
    840 
    841     private static Object buildPhoneAccountHandle(PhoneAccountHandle data)
    842             throws JSONException {
    843         JSONObject msg = new JSONObject();
    844         msg.put("id", data.getId());
    845         msg.put("ComponentName", data.getComponentName().flattenToString());
    846         return msg;
    847     }
    848 
    849     private static Object buildSubscriptionInfoRecord(SubscriptionInfo data)
    850             throws JSONException {
    851         JSONObject msg = new JSONObject();
    852         msg.put("subscriptionId", data.getSubscriptionId());
    853         msg.put("iccId", data.getIccId());
    854         msg.put("simSlotIndex", data.getSimSlotIndex());
    855         msg.put("displayName", data.getDisplayName());
    856         msg.put("nameSource", data.getNameSource());
    857         msg.put("iconTint", data.getIconTint());
    858         msg.put("number", data.getNumber());
    859         msg.put("dataRoaming", data.getDataRoaming());
    860         msg.put("mcc", data.getMcc());
    861         msg.put("mnc", data.getMnc());
    862         return msg;
    863     }
    864 
    865     private static Object buildPoint(Point data) throws JSONException {
    866         JSONObject point = new JSONObject();
    867         point.put("x", data.x);
    868         point.put("y", data.y);
    869         return point;
    870     }
    871 
    872     private static Object buildRttCapabilities(RttCapabilities data)
    873             throws JSONException {
    874         JSONObject cap = new JSONObject();
    875         cap.put("bwSupported", data.bwSupported);
    876         cap.put("lciSupported", data.lciSupported);
    877         cap.put("lcrSupported", data.lcrSupported);
    878         cap.put("oneSidedRttSupported", data.oneSidedRttSupported);
    879         cap.put("preambleSupported", data.preambleSupported);
    880         cap.put("twoSided11McRttSupported", data.twoSided11McRttSupported);
    881         return cap;
    882     }
    883 
    884     private static Object buildSmsMessage(SmsMessage data) throws JSONException {
    885         JSONObject msg = new JSONObject();
    886         msg.put("originatingAddress", data.getOriginatingAddress());
    887         msg.put("messageBody", data.getMessageBody());
    888         return msg;
    889     }
    890 
    891     private static JSONObject buildWifiActivityEnergyInfo(
    892             WifiActivityEnergyInfo data) throws JSONException {
    893         JSONObject result = new JSONObject();
    894         result.put("ControllerEnergyUsed", data.getControllerEnergyUsed());
    895         result.put("ControllerIdleTimeMillis",
    896                 data.getControllerIdleTimeMillis());
    897         result.put("ControllerRxTimeMillis", data.getControllerRxTimeMillis());
    898         result.put("ControllerTxTimeMillis", data.getControllerTxTimeMillis());
    899         result.put("StackState", data.getStackState());
    900         result.put("TimeStamp", data.getTimeStamp());
    901         return result;
    902     }
    903 
    904     private static Object buildWifiChannel(WifiChannel data) throws JSONException {
    905         JSONObject channel = new JSONObject();
    906         channel.put("channelNum", data.channelNum);
    907         channel.put("freqMHz", data.freqMHz);
    908         channel.put("isDFS", data.isDFS);
    909         channel.put("isValid", data.isValid());
    910         return channel;
    911     }
    912 
    913     private static Object buildWifiConfiguration(WifiConfiguration data)
    914             throws JSONException {
    915         JSONObject config = new JSONObject();
    916         config.put("networkId", data.networkId);
    917         // Trim the double quotes if exist
    918         if (data.SSID.charAt(0) == '"'
    919                 && data.SSID.charAt(data.SSID.length() - 1) == '"') {
    920             config.put("SSID", data.SSID.substring(1, data.SSID.length() - 1));
    921         } else {
    922             config.put("SSID", data.SSID);
    923         }
    924         config.put("BSSID", data.BSSID);
    925         config.put("priority", data.priority);
    926         config.put("hiddenSSID", data.hiddenSSID);
    927         config.put("FQDN", data.FQDN);
    928         config.put("providerFriendlyName", data.providerFriendlyName);
    929         config.put("isPasspoint", data.isPasspoint());
    930         config.put("hiddenSSID", data.hiddenSSID);
    931         if (data.status == WifiConfiguration.Status.CURRENT) {
    932             config.put("status", "CURRENT");
    933         } else if (data.status == WifiConfiguration.Status.DISABLED) {
    934             config.put("status", "DISABLED");
    935         } else if (data.status == WifiConfiguration.Status.ENABLED) {
    936             config.put("status", "ENABLED");
    937         } else {
    938             config.put("status", "UNKNOWN");
    939         }
    940         // config.put("enterpriseConfig", buildWifiEnterpriseConfig(data.enterpriseConfig));
    941         return config;
    942     }
    943 
    944     private static Object buildWifiEnterpriseConfig(WifiEnterpriseConfig data)
    945             throws JSONException, CertificateEncodingException {
    946         JSONObject config = new JSONObject();
    947         config.put(WifiEnterpriseConfig.PLMN_KEY, data.getPlmn());
    948         config.put(WifiEnterpriseConfig.REALM_KEY, data.getRealm());
    949         config.put(WifiEnterpriseConfig.EAP_KEY, data.getEapMethod());
    950         config.put(WifiEnterpriseConfig.PHASE2_KEY, data.getPhase2Method());
    951         config.put(WifiEnterpriseConfig.ALTSUBJECT_MATCH_KEY, data.getAltSubjectMatch());
    952         X509Certificate caCert = data.getCaCertificate();
    953         String caCertString = Base64.encodeToString(caCert.getEncoded(), Base64.DEFAULT);
    954         config.put(WifiEnterpriseConfig.CA_CERT_KEY, caCertString);
    955         X509Certificate clientCert = data.getClientCertificate();
    956         String clientCertString = Base64.encodeToString(clientCert.getEncoded(), Base64.DEFAULT);
    957         config.put(WifiEnterpriseConfig.CLIENT_CERT_KEY, clientCertString);
    958         PrivateKey pk = data.getClientPrivateKey();
    959         String privateKeyString = Base64.encodeToString(pk.getEncoded(), Base64.DEFAULT);
    960         config.put(WifiEnterpriseConfig.PRIVATE_KEY_ID_KEY, privateKeyString);
    961         config.put(WifiEnterpriseConfig.PASSWORD_KEY, data.getPassword());
    962         return config;
    963     }
    964 
    965     private static JSONObject buildWifiP2pDevice(WifiP2pDevice data)
    966             throws JSONException {
    967         JSONObject deviceInfo = new JSONObject();
    968         deviceInfo.put("Name", data.deviceName);
    969         deviceInfo.put("Address", data.deviceAddress);
    970         return deviceInfo;
    971     }
    972 
    973     private static JSONObject buildWifiP2pGroup(WifiP2pGroup data)
    974             throws JSONException {
    975         JSONObject group = new JSONObject();
    976         Log.d("build p2p group.");
    977         group.put("ClientList", build(data.getClientList()));
    978         group.put("Interface", data.getInterface());
    979         group.put("Networkname", data.getNetworkName());
    980         group.put("Owner", data.getOwner());
    981         group.put("Passphrase", data.getPassphrase());
    982         group.put("NetworkId", data.getNetworkId());
    983         return group;
    984     }
    985 
    986     private static JSONObject buildWifiP2pInfo(WifiP2pInfo data)
    987             throws JSONException {
    988         JSONObject info = new JSONObject();
    989         Log.d("build p2p info.");
    990         info.put("groupFormed", data.groupFormed);
    991         info.put("isGroupOwner", data.isGroupOwner);
    992         info.put("groupOwnerAddress", data.groupOwnerAddress);
    993         return info;
    994     }
    995 
    996     private static <T> JSONObject buildCallEvent(InCallServiceImpl.CallEvent<T> callEvent)
    997             throws JSONException {
    998         JSONObject jsonEvent = new JSONObject();
    999         jsonEvent.put("CallId", callEvent.getCallId());
   1000         jsonEvent.put("Event", build(callEvent.getEvent()));
   1001         return jsonEvent;
   1002     }
   1003 
   1004     private static JSONObject buildUri(Uri uri) throws JSONException {
   1005         return new JSONObject().put("Uri", build((uri != null) ? uri.toString() : ""));
   1006     }
   1007 
   1008     private static JSONObject buildCallDetails(Call.Details details) throws JSONException {
   1009 
   1010         JSONObject callDetails = new JSONObject();
   1011 
   1012         callDetails.put("Handle", buildUri(details.getHandle()));
   1013         callDetails.put("HandlePresentation",
   1014                 build(InCallServiceImpl.getCallPresentationInfoString(
   1015                         details.getHandlePresentation())));
   1016         callDetails.put("CallerDisplayName", build(details.getCallerDisplayName()));
   1017 
   1018         // TODO AccountHandle
   1019         // callDetails.put("AccountHandle", build(""));
   1020 
   1021         callDetails.put("Capabilities",
   1022                 build(InCallServiceImpl.getCallCapabilitiesString(details.getCallCapabilities())));
   1023 
   1024         callDetails.put("Properties",
   1025                 build(InCallServiceImpl.getCallPropertiesString(details.getCallProperties())));
   1026 
   1027         // TODO Parse fields in Disconnect Cause
   1028         callDetails.put("DisconnectCause", build((details.getDisconnectCause() != null) ? details
   1029                 .getDisconnectCause().toString() : ""));
   1030         callDetails.put("ConnectTimeMillis", build(details.getConnectTimeMillis()));
   1031 
   1032         // TODO: GatewayInfo
   1033         // callDetails.put("GatewayInfo", build(""));
   1034 
   1035         callDetails.put("VideoState",
   1036                 build(InCallServiceImpl.getVideoCallStateString(details.getVideoState())));
   1037 
   1038         // TODO: StatusHints
   1039         // callDetails.put("StatusHints", build(""));
   1040 
   1041         callDetails.put("Extras", build(details.getExtras()));
   1042 
   1043         return callDetails;
   1044     }
   1045 
   1046     private static JSONObject buildCall(Call call) throws JSONException {
   1047 
   1048         JSONObject callInfo = new JSONObject();
   1049 
   1050         callInfo.put("Parent", build(InCallServiceImpl.getCallId(call)));
   1051 
   1052         // TODO:Make a function out of this for consistency
   1053         ArrayList<String> children = new ArrayList<String>();
   1054         for (Call child : call.getChildren()) {
   1055             children.add(InCallServiceImpl.getCallId(child));
   1056         }
   1057         callInfo.put("Children", build(children));
   1058 
   1059         // TODO:Make a function out of this for consistency
   1060         ArrayList<String> conferenceables = new ArrayList<String>();
   1061         for (Call conferenceable : call.getChildren()) {
   1062             children.add(InCallServiceImpl.getCallId(conferenceable));
   1063         }
   1064         callInfo.put("ConferenceableCalls", build(conferenceables));
   1065 
   1066         callInfo.put("State", build(InCallServiceImpl.getCallStateString(call.getState())));
   1067         callInfo.put("CannedTextResponses", build(call.getCannedTextResponses()));
   1068         callInfo.put("VideoCall", InCallServiceImpl.getVideoCallId(call.getVideoCall()));
   1069         callInfo.put("Details", build(call.getDetails()));
   1070 
   1071         return callInfo;
   1072     }
   1073 
   1074     private static JSONObject buildVideoProfile(VideoProfile videoProfile) throws JSONException {
   1075         JSONObject profile = new JSONObject();
   1076 
   1077         profile.put("VideoState",
   1078                 InCallServiceImpl.getVideoCallStateString(videoProfile.getVideoState()));
   1079         profile.put("VideoQuality",
   1080                 InCallServiceImpl.getVideoCallQualityString(videoProfile.getQuality()));
   1081 
   1082         return profile;
   1083     }
   1084 
   1085     private static JSONObject buildCameraCapabilities(CameraCapabilities cameraCapabilities)
   1086             throws JSONException {
   1087         JSONObject capabilities = new JSONObject();
   1088 
   1089         capabilities.put("Height", build(cameraCapabilities.getHeight()));
   1090         capabilities.put("Width", build(cameraCapabilities.getWidth()));
   1091         capabilities.put("ZoomSupported", build(cameraCapabilities.isZoomSupported()));
   1092         capabilities.put("MaxZoom", build(cameraCapabilities.getMaxZoom()));
   1093 
   1094         return capabilities;
   1095     }
   1096 
   1097     private static JSONObject buildVoLteServiceStateEvent(
   1098             VoLteServiceState volteInfo)
   1099             throws JSONException {
   1100         JSONObject info = new JSONObject();
   1101         info.put(TelephonyConstants.VoLteServiceStateContainer.SRVCC_STATE,
   1102                 TelephonyUtils.getSrvccStateString(volteInfo.getSrvccState()));
   1103         return info;
   1104     }
   1105 
   1106     private static JSONObject buildLegacyVpnInfo(LegacyVpnInfo data) throws JSONException {
   1107         JSONObject info = new JSONObject();
   1108         if (data == null) {
   1109             return info;
   1110         }
   1111         info.put("state", data.state);
   1112         info.put("key", data.key);
   1113         String intentStr = "";
   1114         if (data.intent != null) {
   1115             intentStr = data.intent.toString();
   1116         }
   1117         info.put("intent", intentStr);
   1118         return info;
   1119     }
   1120 
   1121     private static JSONObject buildModemActivityInfo(ModemActivityInfo modemInfo)
   1122             throws JSONException {
   1123         JSONObject info = new JSONObject();
   1124 
   1125         info.put("Timestamp", modemInfo.getTimestamp());
   1126         info.put("SleepTimeMs", modemInfo.getSleepTimeMillis());
   1127         info.put("IdleTimeMs", modemInfo.getIdleTimeMillis());
   1128         // convert from int[] to List<Integer> for proper JSON translation
   1129         int[] txTimes = modemInfo.getTxTimeMillis();
   1130         List<Integer> tmp = new ArrayList<Integer>(txTimes.length);
   1131         for (int val : txTimes) {
   1132             tmp.add(val);
   1133         }
   1134         info.put("TxTimeMs", build(tmp));
   1135         info.put("RxTimeMs", modemInfo.getRxTimeMillis());
   1136         info.put("EnergyUsedMw", modemInfo.getEnergyUsed());
   1137         return info;
   1138     }
   1139 
   1140     private static JSONObject buildSignalStrength(SignalStrength signalStrength)
   1141             throws JSONException {
   1142         JSONObject info = new JSONObject();
   1143         info.put(TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_GSM,
   1144                 signalStrength.getGsmSignalStrength());
   1145         info.put(
   1146                 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_GSM_DBM,
   1147                 signalStrength.getGsmDbm());
   1148         info.put(
   1149                 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_GSM_LEVEL,
   1150                 signalStrength.getGsmLevel());
   1151         info.put(
   1152                 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_GSM_ASU_LEVEL,
   1153                 signalStrength.getGsmAsuLevel());
   1154         info.put(
   1155                 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_GSM_BIT_ERROR_RATE,
   1156                 signalStrength.getGsmBitErrorRate());
   1157         info.put(
   1158                 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_CDMA_DBM,
   1159                 signalStrength.getCdmaDbm());
   1160         info.put(
   1161                 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_CDMA_LEVEL,
   1162                 signalStrength.getCdmaLevel());
   1163         info.put(
   1164                 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_CDMA_ASU_LEVEL,
   1165                 signalStrength.getCdmaAsuLevel());
   1166         info.put(
   1167                 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_CDMA_ECIO,
   1168                 signalStrength.getCdmaEcio());
   1169         info.put(
   1170                 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_EVDO_DBM,
   1171                 signalStrength.getEvdoDbm());
   1172         info.put(
   1173                 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_EVDO_ECIO,
   1174                 signalStrength.getEvdoEcio());
   1175         info.put(TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_LTE,
   1176                 signalStrength.getLteSignalStrength());
   1177         info.put(
   1178                 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_LTE_DBM,
   1179                 signalStrength.getLteDbm());
   1180         info.put(
   1181                 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_LTE_LEVEL,
   1182                 signalStrength.getLteLevel());
   1183         info.put(
   1184                 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_LTE_ASU_LEVEL,
   1185                 signalStrength.getLteAsuLevel());
   1186         info.put(
   1187                 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_LEVEL,
   1188                 signalStrength.getLevel());
   1189         info.put(
   1190                 TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_ASU_LEVEL,
   1191                 signalStrength.getAsuLevel());
   1192         info.put(TelephonyConstants.SignalStrengthContainer.SIGNAL_STRENGTH_DBM,
   1193                 signalStrength.getDbm());
   1194         return info;
   1195     }
   1196 
   1197     private JsonBuilder() {
   1198         // This is a utility class.
   1199     }
   1200 }
   1201