Update WifiRttManager facade in sl4a for the new APIs.
Change-Id: I6789fd2eba6adae834926b0640508a33aad2c2ad
diff --git a/Common/src/com/googlecode/android_scripting/facade/wifi/WifiManagerFacade.java b/Common/src/com/googlecode/android_scripting/facade/wifi/WifiManagerFacade.java
index abf9ab7..752fa81 100755
--- a/Common/src/com/googlecode/android_scripting/facade/wifi/WifiManagerFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/wifi/WifiManagerFacade.java
@@ -50,7 +50,6 @@
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -276,7 +275,7 @@
}
private WifiConfiguration genEnterpriseConfig(String configStr) throws JSONException,
- GeneralSecurityException {
+ GeneralSecurityException {
if (configStr == null) {
return null;
}
@@ -402,7 +401,7 @@
}
private PrivateKey strToPrivateKey(String key) throws NoSuchAlgorithmException,
- InvalidKeySpecException {
+ InvalidKeySpecException {
byte[] keyBytes = base64StrToBytes(key);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory fact = KeyFactory.getInstance("RSA");
@@ -411,7 +410,7 @@
}
private PublicKey strToPublicKey(String key) throws NoSuchAlgorithmException,
- InvalidKeySpecException {
+ InvalidKeySpecException {
byte[] keyBytes = base64StrToBytes(key);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
KeyFactory fact = KeyFactory.getInstance("RSA");
@@ -474,7 +473,7 @@
public Boolean wifiConnect(
@RpcParameter(name = "SSID") String SSID,
@RpcParameter(name = "Password") @RpcOptional String Password)
- throws ConnectException {
+ throws ConnectException {
WifiConfiguration wifiConfig = genWifiConfig(SSID, Password);
mWifi.addNetwork(wifiConfig);
Boolean status = false;
@@ -645,8 +644,8 @@
@Rpc(description = "Start Wi-fi Protected Setup.")
public void wifiStartWps(
@RpcParameter(name = "config",
- description = "A json string with fields \"setup\", \"BSSID\", and \"pin\"") String config)
- throws JSONException {
+ description = "A json string with fields \"setup\", \"BSSID\", and \"pin\"") String config)
+ throws JSONException {
WpsInfo info = parseWpsInfo(config);
WifiWpsCallback listener = new WifiWpsCallback();
Log.d("Starting wps with: " + info);
@@ -682,7 +681,7 @@
returns = "True if Wifi scan is always available.")
public Boolean wifiToggleScanAlwaysAvailable(
@RpcParameter(name = "enabled") @RpcOptional Boolean enabled)
- throws SettingNotFoundException {
+ throws SettingNotFoundException {
ContentResolver cr = mService.getContentResolver();
int isSet = 0;
if (enabled == null) {
diff --git a/Common/src/com/googlecode/android_scripting/facade/wifi/WifiRttManagerFacade.java b/Common/src/com/googlecode/android_scripting/facade/wifi/WifiRttManagerFacade.java
index 52c1526..58c3fb6 100644
--- a/Common/src/com/googlecode/android_scripting/facade/wifi/WifiRttManagerFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/wifi/WifiRttManagerFacade.java
@@ -1,9 +1,11 @@
+
package com.googlecode.android_scripting.facade.wifi;
import android.app.Service;
import android.content.Context;
import android.net.wifi.RttManager;
import android.net.wifi.RttManager.Capabilities;
+import android.net.wifi.RttManager.RttCapabilities;
import android.net.wifi.RttManager.RttListener;
import android.net.wifi.RttManager.RttParams;
import android.net.wifi.RttManager.RttResult;
@@ -19,6 +21,7 @@
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Map;
+
import org.json.JSONException;
import org.json.JSONObject;
@@ -26,130 +29,175 @@
* WifiRttManager functions.
*/
public class WifiRttManagerFacade extends RpcReceiver {
- private final Service mService;
- private final RttManager mRtt;
- private final EventFacade mEventFacade;
- private final Map<Integer, RttListener> mRangingListeners;
-
- public WifiRttManagerFacade(FacadeManager manager) {
- super(manager);
- mService = manager.getService();
- mRtt = (RttManager) mService.getSystemService(Context.WIFI_RTT_SERVICE);
- mEventFacade = manager.getReceiver(EventFacade.class);
- mRangingListeners = new Hashtable<Integer, RttListener>();
- }
-
- public static class RangingListener implements RttListener {
- private static final String TAG = "WifiRttRanging";
- private static int sCount = 0;
+ private final Service mService;
+ private final RttManager mRtt;
private final EventFacade mEventFacade;
- public final int mId;
+ private final Map<Integer, RttListener> mRangingListeners;
- public RangingListener(EventFacade eventFacade) {
- sCount += 1;
- mId = sCount;
- mEventFacade = eventFacade;
+ public WifiRttManagerFacade(FacadeManager manager) {
+ super(manager);
+ mService = manager.getService();
+ mRtt = (RttManager) mService.getSystemService(Context.WIFI_RTT_SERVICE);
+ mEventFacade = manager.getReceiver(EventFacade.class);
+ mRangingListeners = new Hashtable<Integer, RttListener>();
}
- private Bundle packRttResult(RttResult result) {
- Bundle rttResult = new Bundle();
- rttResult.putString("bssid", result.bssid);
- rttResult.putLong("distance", result.distance);
- rttResult.putLong("distanceStandardDeviation", result.distance);
- rttResult.putLong("distanceSpread", result.distanceSpread);
- rttResult.putLong("rtt", result.rtt);
- rttResult.putLong("rttStandardDeviation", result.rttStandardDeviation);
- rttResult.putLong("rttSpread", result.rttSpread);
- rttResult.putLong("ts", result.ts);
- rttResult.putInt("rssi", result.rssi);
- rttResult.putInt("status", result.status);
- rttResult.putInt("txRate", result.tx_rate);
- return rttResult;
- }
+ public static class RangingListener implements RttListener {
+ private static final String TAG = "WifiRttRanging";
+ private static int sCount = 0;
+ private final EventFacade mEventFacade;
+ public final int mId;
- @Override
- public void onSuccess(RttResult[] results) {
- Bundle msg = new Bundle();
- Parcelable[] resultBundles = new Parcelable[results.length];
- for (int i = 0; i < results.length; i++) {
- resultBundles[i] = packRttResult(results[i]);
+ public RangingListener(EventFacade eventFacade) {
+ sCount += 1;
+ mId = sCount;
+ mEventFacade = eventFacade;
}
- msg.putParcelableArray("Results", resultBundles);
- mEventFacade.postEvent(RangingListener.TAG + mId + "onSuccess", msg);
+
+ private Bundle packRttResult(RttResult result) {
+ Bundle rttResult = new Bundle();
+ rttResult.putString("BSSID", result.bssid);
+ rttResult.putInt("txRate", result.txRate);
+ rttResult.putInt("rxRate", result.rxRate);
+ rttResult.putInt("distance", result.distance);
+ rttResult.putInt("distanceStandardDeviation",
+ result.distanceStandardDeviation);
+ rttResult.putInt("distanceSpread", result.distanceSpread);
+ rttResult.putInt("burstDuration", result.burstDuration);
+ rttResult.putLong("rtt", result.rtt);
+ rttResult.putLong("rttStandardDeviation",
+ result.rttStandardDeviation);
+ rttResult.putLong("rttSpread", result.rttSpread);
+ rttResult.putLong("ts", result.ts);
+ rttResult.putInt("rssi", result.rssi);
+ rttResult.putInt("rssiSpread", result.rssiSpread);
+ rttResult.putInt("retryAfterDuration", result.retryAfterDuration);
+ rttResult.putInt("measurementType", result.measurementType);
+ rttResult.putInt("status", result.status);
+ rttResult.putInt("frameNumberPerBurstPeer",
+ result.frameNumberPerBurstPeer);
+ rttResult.putInt("successMeasurementFrameNumber",
+ result.successMeasurementFrameNumber);
+ rttResult.putInt("measurementFrameNumber",
+ result.measurementFrameNumber);
+ rttResult.putInt("burstNumber", result.burstNumber);
+ rttResult.putInt("status", result.status);
+ return rttResult;
+ }
+
+ @Override
+ public void onSuccess(RttResult[] results) {
+ Bundle msg = new Bundle();
+ Parcelable[] resultBundles = new Parcelable[results.length];
+ for (int i = 0; i < results.length; i++) {
+ resultBundles[i] = packRttResult(results[i]);
+ }
+ msg.putParcelableArray("Results", resultBundles);
+ mEventFacade
+ .postEvent(RangingListener.TAG + mId + "onSuccess", msg);
+ }
+
+ @Override
+ public void onFailure(int reason, String description) {
+ Bundle msg = new Bundle();
+ msg.putInt("Reason", reason);
+ msg.putString("Description", description);
+ mEventFacade
+ .postEvent(RangingListener.TAG + mId + "onFailure", msg);
+ }
+
+ @Override
+ public void onAborted() {
+ mEventFacade.postEvent(RangingListener.TAG + mId + "onAborted",
+ new Bundle());
+ }
+ }
+
+ @Rpc(description = "Get wifi Rtt capabilities.")
+ public RttCapabilities wifiRttGetCapabilities() {
+ return mRtt.getRttCapabilities();
+ }
+
+ private RttParams parseRttParam(String rttParam) throws JSONException {
+ JSONObject j = new JSONObject(rttParam);
+ RttParams result = new RttParams();
+ if (j.has("deviceType")) {
+ result.deviceType = j.getInt("deviceType");
+ }
+ if (j.has("requestType")) {
+ result.requestType = j.getInt("requestType");
+ }
+ if (j.has("bssid")) {
+ result.bssid = j.getString("bssid");
+ }
+ if (j.has("frequency")) {
+ result.frequency = j.getInt("frequency");
+ }
+ if (j.has("channelWidth")) {
+ result.channelWidth = j.getInt("channelWidth");
+ }
+ if (j.has("centerFreq0")) {
+ result.centerFreq0 = j.getInt("centerFreq0");
+ }
+ if (j.has("centerFreq1")) {
+ result.centerFreq1 = j.getInt("centerFreq1");
+ }
+ if (j.has("numberBurst")) {
+ result.numberBurst = j.getInt("numberBurst");
+ }
+ if (j.has("interval")) {
+ result.interval = j.getInt("interval");
+ }
+ if (j.has("numSamplesPerBurst")) {
+ result.numSamplesPerBurst = j.getInt("numSamplesPerBurst");
+ }
+ if (j.has("numRetriesPerMeasurementFrame")) {
+ result.numRetriesPerMeasurementFrame = j
+ .getInt("numRetriesPerMeasurementFrame");
+ }
+ if (j.has("numRetriesPerFTMR")) {
+ result.numRetriesPerFTMR = j.getInt("numRetriesPerFTMR");
+ }
+ if (j.has("LCIRequest")) {
+ result.LCIRequest = j.getBoolean("LCIRequest");
+ }
+ if (j.has("LCRRequest")) {
+ result.LCRRequest = j.getBoolean("LCRRequest");
+ }
+ if (j.has("preamble")) {
+ result.preamble = j.getInt("preamble");
+ }
+ if (j.has("bandwidth")) {
+ result.bandwidth = j.getInt("bandwidth");
+ }
+ return result;
+ }
+
+ @Rpc(description = "Start ranging.", returns = "Id of the listener associated with the started ranging.")
+ public Integer wifiRttStartRanging(
+ @RpcParameter(name = "params") String[] params)
+ throws JSONException {
+ RttParams[] rParams = new RttParams[params.length];
+ for (int i = 0; i < params.length; i++) {
+ rParams[i] = parseRttParam(params[i]);
+ }
+ RangingListener listener = new RangingListener(mEventFacade);
+ mRangingListeners.put(listener.mId, listener);
+ mRtt.startRanging(rParams, listener);
+ return listener.mId;
+ }
+
+ @Rpc(description = "Stop ranging.")
+ public void wifiRttStopRanging(@RpcParameter(name = "index") Integer index) {
+ mRtt.stopRanging(mRangingListeners.remove(index));
}
@Override
- public void onFailure(int reason, String description) {
- Bundle msg = new Bundle();
- msg.putInt("Reason", reason);
- msg.putString("Description", description);
- mEventFacade.postEvent(RangingListener.TAG + mId + "onFailure", msg);
+ public void shutdown() {
+ ArrayList<Integer> keys = new ArrayList<Integer>(
+ mRangingListeners.keySet());
+ for (int k : keys) {
+ wifiRttStopRanging(k);
+ }
}
-
- @Override
- public void onAborted() {
- mEventFacade.postEvent(RangingListener.TAG + mId + "onAborted", new Bundle());
- }
- }
-
- @Rpc(description = "Get wifi Rtt capabilities.")
- public Capabilities wifiRttGetCapabilities() {
- return mRtt.getCapabilities();
- }
-
- private RttParams parseRttParam(String rttParam) throws JSONException {
- JSONObject j = new JSONObject(rttParam);
- RttParams result = new RttParams();
- if (j.has("deviceType")) {
- result.deviceType = j.getInt("deviceType");
- }
- if (j.has("requestType")) {
- result.requestType = j.getInt("requestType");
- }
- if (j.has("bssid")) {
- result.bssid = j.getString("bssid");
- }
-
- /*if (j.has("frequency")) {
- result.frequency = j.getInt("frequency");
- }
- if (j.has("channelWidth")) {
- result.channelWidth = j.getInt("channelWidth");
- }*/
-
- if (j.has("numSamplesPerBurst")) {
- result.numSamplesPerBurst = j.getInt("numSamplesPerBurst");
- }
- if (j.has("numRetriesPerMeasurementFrame")) {
- result.numRetriesPerMeasurementFrame = j.getInt("numRetriesPerMeasurementFrame");
- }
- return result;
- }
-
- @Rpc(description = "Start ranging.",
- returns = "Id of the listener associated with the started ranging.")
- public Integer wifiRttStartRanging(@RpcParameter(name = "params")
- String[] params) throws JSONException {
- RttParams[] rParams = new RttParams[params.length];
- for (int i = 0; i < params.length; i++) {
- rParams[i] = parseRttParam(params[i]);
- }
- RangingListener listener = new RangingListener(mEventFacade);
- mRangingListeners.put(listener.mId, listener);
- mRtt.startRanging(rParams, listener);
- return listener.mId;
- }
-
- @Rpc(description = "Stop ranging.")
- public void wifiRttStopRanging(@RpcParameter(name = "index") Integer index) {
- mRtt.stopRanging(mRangingListeners.remove(index));
- }
-
- @Override
- public void shutdown() {
- ArrayList<Integer> keys = new ArrayList<Integer>(mRangingListeners.keySet());
- for (int k : keys) {
- wifiRttStopRanging(k);
- }
- }
}
diff --git a/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java b/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
index ddb2e54..1b82dd9 100644
--- a/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
+++ b/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
@@ -19,7 +19,6 @@
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -42,7 +41,7 @@
import android.location.Address;
import android.location.Location;
import android.net.NetworkInfo;
-import android.net.wifi.RttManager.Capabilities;
+import android.net.wifi.RttManager.RttCapabilities;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiActivityEnergyInfo;
import android.net.wifi.WifiConfiguration;
@@ -59,7 +58,6 @@
import android.telephony.CellLocation;
import android.telephony.NeighboringCellInfo;
import android.telephony.SmsMessage;
-import android.telephony.SubscriptionManager;
import android.telephony.gsm.GsmCellLocation;
import android.telephony.SubscriptionInfo;
import android.util.DisplayMetrics;
@@ -130,7 +128,8 @@
return buildJsonEvent((Event) data);
}
if (data instanceof Map<?, ?>) {
- // TODO(damonkohler): I would like to make this a checked cast if possible.
+ // TODO(damonkohler): I would like to make this a checked cast if
+ // possible.
return buildJsonMap((Map<String, ?>) data);
}
if (data instanceof ParcelUuid) {
@@ -140,7 +139,7 @@
return buildJsonScanResult((ScanResult) data);
}
if (data instanceof ScanData) {
- return buildJsonScanData((ScanData) data);
+ return buildJsonScanData((ScanData) data);
}
if (data instanceof android.bluetooth.le.ScanResult) {
return buildJsonBleScanResult((android.bluetooth.le.ScanResult) data);
@@ -197,8 +196,8 @@
if (data instanceof DisplayMetrics) {
return buildDisplayMetrics((DisplayMetrics) data);
}
- if (data instanceof Capabilities) {
- return buildRttCapabilities((Capabilities) data);
+ if (data instanceof RttCapabilities) {
+ return buildRttCapabilities((RttCapabilities) data);
}
if (data instanceof WifiActivityEnergyInfo) {
return buildWifiActivityEnergyInfo((WifiActivityEnergyInfo) data);
@@ -223,17 +222,20 @@
}
return data.toString();
- // throw new JSONException("Failed to build JSON result. " + data.getClass().getName());
+ // throw new JSONException("Failed to build JSON result. " +
+ // data.getClass().getName());
}
- private static JSONObject buildJsonAudioState(AudioState data) throws JSONException {
+ private static JSONObject buildJsonAudioState(AudioState data)
+ throws JSONException {
JSONObject state = new JSONObject();
state.put("isMuted", data.isMuted);
state.put("AudioRoute", AudioState.audioRouteToString(data.route));
return state;
}
- private static Object buildDisplayMetrics(DisplayMetrics data) throws JSONException {
+ private static Object buildDisplayMetrics(DisplayMetrics data)
+ throws JSONException {
JSONObject dm = new JSONObject();
dm.put("widthPixels", data.widthPixels);
dm.put("heightPixels", data.heightPixels);
@@ -256,7 +258,8 @@
return address;
}
- private static JSONObject buildJsonAddress(Address address) throws JSONException {
+ private static JSONObject buildJsonAddress(Address address)
+ throws JSONException {
JSONObject result = new JSONObject();
result.put("admin_area", address.getAdminArea());
result.put("country_code", address.getCountryCode());
@@ -279,8 +282,8 @@
return result;
}
- private static JSONObject buildJsonBleAdvertiseSettings(AdvertiseSettings advertiseSettings)
- throws JSONException {
+ private static JSONObject buildJsonBleAdvertiseSettings(
+ AdvertiseSettings advertiseSettings) throws JSONException {
JSONObject result = new JSONObject();
result.put("mode", advertiseSettings.getMode());
result.put("txPowerLevel", advertiseSettings.getTxPowerLevel());
@@ -288,22 +291,24 @@
return result;
}
- private static JSONObject buildJsonBleScanResult(android.bluetooth.le.ScanResult scanResult)
- throws JSONException {
+ private static JSONObject buildJsonBleScanResult(
+ android.bluetooth.le.ScanResult scanResult) throws JSONException {
JSONObject result = new JSONObject();
result.put("rssi", scanResult.getRssi());
result.put("timestampNanos", scanResult.getTimestampNanos());
result.put("deviceName", scanResult.getScanRecord().getDeviceName());
result.put("txPowerLevel", scanResult.getScanRecord().getTxPowerLevel());
- result.put("advertiseFlags", scanResult.getScanRecord().getAdvertiseFlags());
+ result.put("advertiseFlags", scanResult.getScanRecord()
+ .getAdvertiseFlags());
ArrayList<String> manufacturerDataList = new ArrayList<String>();
ArrayList<Integer> idList = new ArrayList<Integer>();
if (scanResult.getScanRecord().getManufacturerSpecificData() != null) {
- SparseArray<byte[]> manufacturerSpecificData = scanResult.getScanRecord()
- .getManufacturerSpecificData();
+ SparseArray<byte[]> manufacturerSpecificData = scanResult
+ .getScanRecord().getManufacturerSpecificData();
for (int i = 0; i < manufacturerSpecificData.size(); i++) {
manufacturerDataList.add(ConvertUtils
- .convertByteArrayToString(manufacturerSpecificData.valueAt(i)));
+ .convertByteArrayToString(manufacturerSpecificData
+ .valueAt(i)));
idList.add(manufacturerSpecificData.keyAt(i));
}
}
@@ -312,16 +317,19 @@
ArrayList<String> serviceUuidList = new ArrayList<String>();
ArrayList<String> serviceDataList = new ArrayList<String>();
if (scanResult.getScanRecord().getServiceData() != null) {
- Map<ParcelUuid, byte[]> serviceDataMap = scanResult.getScanRecord().getServiceData();
+ Map<ParcelUuid, byte[]> serviceDataMap = scanResult.getScanRecord()
+ .getServiceData();
for (ParcelUuid serviceUuid : serviceDataMap.keySet()) {
serviceUuidList.add(serviceUuid.toString());
- serviceDataList.add(ConvertUtils.convertByteArrayToString(serviceDataMap
- .get(serviceUuid)));
+ serviceDataList.add(ConvertUtils
+ .convertByteArrayToString(serviceDataMap
+ .get(serviceUuid)));
}
}
result.put("serviceUuidList", serviceUuidList);
result.put("serviceDataList", serviceDataList);
- List<ParcelUuid> serviceUuids = scanResult.getScanRecord().getServiceUuids();
+ List<ParcelUuid> serviceUuids = scanResult.getScanRecord()
+ .getServiceUuids();
String serviceUuidsString = "";
if (serviceUuids != null && serviceUuids.size() > 0) {
for (ParcelUuid uuid : serviceUuids) {
@@ -329,13 +337,15 @@
}
}
result.put("serviceUuids", serviceUuidsString);
- result.put("scanRecord", build(ConvertUtils.convertByteArrayToString(
- scanResult.getScanRecord().getBytes())));
+ result.put("scanRecord",
+ build(ConvertUtils.convertByteArrayToString(scanResult
+ .getScanRecord().getBytes())));
result.put("deviceInfo", build(scanResult.getDevice()));
return result;
}
- private static JSONObject buildJsonBluetoothDevice(BluetoothDevice data) throws JSONException {
+ private static JSONObject buildJsonBluetoothDevice(BluetoothDevice data)
+ throws JSONException {
JSONObject deviceInfo = new JSONObject();
deviceInfo.put("address", data.getAddress());
deviceInfo.put("state", data.getBondState());
@@ -344,8 +354,8 @@
return deviceInfo;
}
- private static Object buildJsonBluetoothGattCharacteristic(BluetoothGattCharacteristic data)
- throws JSONException {
+ private static Object buildJsonBluetoothGattCharacteristic(
+ BluetoothGattCharacteristic data) throws JSONException {
JSONObject result = new JSONObject();
result.put("instanceId", data.getInstanceId());
result.put("permissions", data.getPermissions());
@@ -358,8 +368,8 @@
return result;
}
- private static Object buildJsonBluetoothGattDescriptor(BluetoothGattDescriptor data)
- throws JSONException {
+ private static Object buildJsonBluetoothGattDescriptor(
+ BluetoothGattDescriptor data) throws JSONException {
JSONObject result = new JSONObject();
result.put("instanceId", data.getInstanceId());
result.put("permissions", data.getPermissions());
@@ -369,8 +379,8 @@
return result;
}
- private static Object buildJsonBluetoothGattService(BluetoothGattService data)
- throws JSONException {
+ private static Object buildJsonBluetoothGattService(
+ BluetoothGattService data) throws JSONException {
JSONObject result = new JSONObject();
result.put("instanceId", data.getInstanceId());
result.put("type", data.getType());
@@ -380,7 +390,8 @@
return result;
}
- private static JSONObject buildJsonBundle(Bundle bundle) throws JSONException {
+ private static JSONObject buildJsonBundle(Bundle bundle)
+ throws JSONException {
JSONObject result = new JSONObject();
for (String key : bundle.keySet()) {
result.put(key, build(bundle.get(key)));
@@ -396,7 +407,8 @@
result.put("lac", location.getLac());
result.put("cid", location.getCid());
}
- // TODO(damonkohler): Add support for CdmaCellLocation. Not supported until API level 5.
+ // TODO(damonkohler): Add support for CdmaCellLocation. Not supported
+ // until API level 5.
return result;
}
@@ -424,7 +436,8 @@
return result;
}
- private static <T> JSONArray buildJsonList(final List<T> list) throws JSONException {
+ private static <T> JSONArray buildJsonList(final List<T> list)
+ throws JSONException {
JSONArray result = new JSONArray();
for (T item : list) {
result.put(build(item));
@@ -432,7 +445,8 @@
return result;
}
- private static JSONObject buildJsonLocation(Location location) throws JSONException {
+ private static JSONObject buildJsonLocation(Location location)
+ throws JSONException {
JSONObject result = new JSONObject();
result.put("altitude", location.getAltitude());
result.put("latitude", location.getLatitude());
@@ -445,7 +459,8 @@
return result;
}
- private static JSONObject buildJsonMap(Map<String, ?> map) throws JSONException {
+ private static JSONObject buildJsonMap(Map<String, ?> map)
+ throws JSONException {
JSONObject result = new JSONObject();
for (Entry<String, ?> entry : map.entrySet()) {
result.put(entry.getKey(), build(entry.getValue()));
@@ -453,7 +468,8 @@
return result;
}
- private static JSONObject buildJsonScanResult(ScanResult scanResult) throws JSONException {
+ private static JSONObject buildJsonScanResult(ScanResult scanResult)
+ throws JSONException {
JSONObject result = new JSONObject();
result.put("BSSID", scanResult.BSSID);
result.put("SSID", scanResult.SSID);
@@ -461,13 +477,15 @@
result.put("level", scanResult.level);
result.put("capabilities", scanResult.capabilities);
result.put("timestamp", scanResult.timestamp);
- // The following fields are hidden for now, uncomment when they're unhidden
+ // The following fields are hidden for now, uncomment when they're
+ // unhidden
// result.put("seen", scanResult.seen);
// result.put("distanceCm", scanResult.distanceCm);
// result.put("distanceSdCm", scanResult.distanceSdCm);
// if (scanResult.informationElements != null){
// JSONArray infoEles = new JSONArray();
- // for(ScanResult.InformationElement ie : scanResult.informationElements) {
+ // for(ScanResult.InformationElement ie :
+ // scanResult.informationElements) {
// JSONObject infoEle = new JSONObject();
// infoEle.put("id", ie.id);
// infoEle.put("bytes", Base64Codec.encodeBase64(ie.bytes));
@@ -479,23 +497,25 @@
return result;
}
- private static JSONObject buildJsonScanData(ScanData scanData) throws JSONException {
- JSONObject result = new JSONObject();
- result.put("Id", scanData.getId());
- result.put("Flags", scanData.getFlags());
- JSONArray scanResults = new JSONArray();
- for(ScanResult sr : scanData.getResults()) {
- scanResults.put(buildJsonScanResult(sr));
- }
- result.put("ScanResults",scanResults);
- return result;
- }
-
- private static JSONObject buildWifiActivityEnergyInfo(WifiActivityEnergyInfo data)
+ private static JSONObject buildJsonScanData(ScanData scanData)
throws JSONException {
JSONObject result = new JSONObject();
+ result.put("Id", scanData.getId());
+ result.put("Flags", scanData.getFlags());
+ JSONArray scanResults = new JSONArray();
+ for (ScanResult sr : scanData.getResults()) {
+ scanResults.put(buildJsonScanResult(sr));
+ }
+ result.put("ScanResults", scanResults);
+ return result;
+ }
+
+ private static JSONObject buildWifiActivityEnergyInfo(
+ WifiActivityEnergyInfo data) throws JSONException {
+ JSONObject result = new JSONObject();
result.put("ControllerEnergyUserd", data.getControllerEnergyUsed());
- result.put("ControllerIdleTimeMillis", data.getControllerIdleTimeMillis());
+ result.put("ControllerIdleTimeMillis",
+ data.getControllerIdleTimeMillis());
result.put("ControllerRxTimeMillis", data.getControllerRxTimeMillis());
result.put("ControllerTxTimeMillis", data.getControllerTxTimeMillis());
result.put("StackState", data.getStackState());
@@ -503,7 +523,8 @@
return result;
}
- private static JSONObject buildJsonWifiInfo(WifiInfo data) throws JSONException {
+ private static JSONObject buildJsonWifiInfo(WifiInfo data)
+ throws JSONException {
JSONObject result = new JSONObject();
result.put("hidden_ssid", data.getHiddenSSID());
result.put("ip_address", data.getIpAddress());
@@ -564,7 +585,8 @@
return result;
}
- private static Object buildNetworkInfo(NetworkInfo data) throws JSONException {
+ private static Object buildNetworkInfo(NetworkInfo data)
+ throws JSONException {
JSONObject info = new JSONObject();
info.put("isAvailable", data.isAvailable());
info.put("isConnected", data.isConnected());
@@ -578,23 +600,27 @@
return info;
}
- private static JSONObject buildPhoneAccount(PhoneAccount data) throws JSONException {
+ private static JSONObject buildPhoneAccount(PhoneAccount data)
+ throws JSONException {
JSONObject acct = new JSONObject();
acct.put("Address", data.getAddress().toSafeString());
- acct.put("SubscriptionAddress", data.getSubscriptionAddress().toSafeString());
+ acct.put("SubscriptionAddress", data.getSubscriptionAddress()
+ .toSafeString());
acct.put("Label", data.getLabel().toString());
acct.put("ShortDescription", data.getShortDescription().toString());
return acct;
}
- private static Object buildPhoneAccountHandle(PhoneAccountHandle data) throws JSONException {
+ private static Object buildPhoneAccountHandle(PhoneAccountHandle data)
+ throws JSONException {
JSONObject msg = new JSONObject();
msg.put("id", data.getId());
msg.put("ComponentName", data.getComponentName().flattenToString());
return msg;
}
- private static Object buildSubscriptionInfoRecord(SubscriptionInfo data) throws JSONException {
+ private static Object buildSubscriptionInfoRecord(SubscriptionInfo data)
+ throws JSONException {
JSONObject msg = new JSONObject();
msg.put("subscriptionId", data.getSubscriptionId());
msg.put("iccId", data.getIccId());
@@ -616,10 +642,15 @@
return point;
}
- private static Object buildRttCapabilities(Capabilities data) throws JSONException {
+ private static Object buildRttCapabilities(RttCapabilities data)
+ throws JSONException {
JSONObject cap = new JSONObject();
- cap.put("supportedType", data.supportedType);
- cap.put("supportedPeerType", data.supportedPeerType);
+ cap.put("bwSupported", data.bwSupported);
+ cap.put("lciSupported", data.lciSupported);
+ cap.put("lcrSupported", data.lcrSupported);
+ cap.put("oneSidedRttSupported", data.oneSidedRttSupported);
+ cap.put("preambleSupported", data.preambleSupported);
+ cap.put("twoSided11McRttSupported", data.twoSided11McRttSupported);
return cap;
}
@@ -630,11 +661,13 @@
return msg;
}
- private static Object buildWifiConfiguration(WifiConfiguration data) throws JSONException {
+ private static Object buildWifiConfiguration(WifiConfiguration data)
+ throws JSONException {
JSONObject config = new JSONObject();
config.put("networkId", data.networkId);
// Trim the double quotes if exist
- if (data.SSID.charAt(0) == '"' && data.SSID.charAt(data.SSID.length() - 1) == '"') {
+ if (data.SSID.charAt(0) == '"'
+ && data.SSID.charAt(data.SSID.length() - 1) == '"') {
config.put("SSID", data.SSID.substring(1, data.SSID.length() - 1));
} else {
config.put("SSID", data.SSID);
@@ -654,14 +687,16 @@
return config;
}
- private static JSONObject buildWifiP2pDevice(WifiP2pDevice data) throws JSONException {
+ private static JSONObject buildWifiP2pDevice(WifiP2pDevice data)
+ throws JSONException {
JSONObject deviceInfo = new JSONObject();
deviceInfo.put("Name", data.deviceName);
deviceInfo.put("Address", data.deviceAddress);
return deviceInfo;
}
- private static JSONObject buildWifiP2pGroup(WifiP2pGroup data) throws JSONException {
+ private static JSONObject buildWifiP2pGroup(WifiP2pGroup data)
+ throws JSONException {
JSONObject group = new JSONObject();
Log.d("build p2p group.");
group.put("ClientList", build(data.getClientList()));
@@ -673,7 +708,8 @@
return group;
}
- private static JSONObject buildWifiP2pInfo(WifiP2pInfo data) throws JSONException {
+ private static JSONObject buildWifiP2pInfo(WifiP2pInfo data)
+ throws JSONException {
JSONObject info = new JSONObject();
Log.d("build p2p info.");
info.put("groupFormed", data.groupFormed);