summaryrefslogtreecommitdiff
path: root/wifi/java/android/net
diff options
context:
space:
mode:
Diffstat (limited to 'wifi/java/android/net')
-rw-r--r--wifi/java/android/net/wifi/IRttManager.aidl28
-rw-r--r--wifi/java/android/net/wifi/RttManager.java114
-rw-r--r--wifi/java/android/net/wifi/ScanResult.java21
-rw-r--r--wifi/java/android/net/wifi/WifiConfiguration.java4
-rw-r--r--wifi/java/android/net/wifi/WifiManager.java24
-rw-r--r--wifi/java/android/net/wifi/WpsInfo.java59
-rw-r--r--wifi/java/android/net/wifi/rtt/LocationCivic.java118
-rw-r--r--wifi/java/android/net/wifi/rtt/LocationConfigurationInformation.java272
-rw-r--r--wifi/java/android/net/wifi/rtt/RangingRequest.java34
-rw-r--r--wifi/java/android/net/wifi/rtt/RangingResult.java94
-rw-r--r--wifi/java/android/net/wifi/rtt/RangingResultCallback.java11
-rw-r--r--wifi/java/android/net/wifi/rtt/WifiRttManager.java69
12 files changed, 231 insertions, 617 deletions
diff --git a/wifi/java/android/net/wifi/IRttManager.aidl b/wifi/java/android/net/wifi/IRttManager.aidl
deleted file mode 100644
index 383180995b21..000000000000
--- a/wifi/java/android/net/wifi/IRttManager.aidl
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.net.wifi;
-import android.os.Messenger;
-import android.net.wifi.RttManager;
-
-/**
- * {@hide}
- */
-interface IRttManager
-{
- Messenger getMessenger(in IBinder binder, out int[] key);
- RttManager.RttCapabilities getRttCapabilities();
-}
diff --git a/wifi/java/android/net/wifi/RttManager.java b/wifi/java/android/net/wifi/RttManager.java
index fe63aa1bf79b..b5273dd39c54 100644
--- a/wifi/java/android/net/wifi/RttManager.java
+++ b/wifi/java/android/net/wifi/RttManager.java
@@ -12,9 +12,9 @@ import android.net.wifi.rtt.RangingRequest;
import android.net.wifi.rtt.RangingResult;
import android.net.wifi.rtt.RangingResultCallback;
import android.net.wifi.rtt.WifiRttManager;
-import android.os.Looper;
import android.os.Parcel;
import android.os.Parcelable;
+import android.os.SystemClock;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
@@ -24,6 +24,7 @@ import java.util.List;
/** @hide */
@SystemApi
+@Deprecated
@SystemService(Context.WIFI_RTT_SERVICE)
public class RttManager {
@@ -181,6 +182,7 @@ public class RttManager {
/**
* This class describe the RTT capability of the Hardware
*/
+ @Deprecated
public static class RttCapabilities implements Parcelable {
/** @deprecated It is not supported*/
@Deprecated
@@ -314,12 +316,16 @@ public class RttManager {
};
}
+ /**
+ * This method is deprecated. Please use the {@link WifiRttManager} API.
+ */
@RequiresPermission(Manifest.permission.LOCATION_HARDWARE)
public RttCapabilities getRttCapabilities() {
return mRttCapabilities;
}
/** specifies parameters for RTT request */
+ @Deprecated
public static class RttParams {
/**
* type of destination device being ranged
@@ -502,6 +508,7 @@ public class RttManager {
}
/** pseudo-private class used to parcel arguments */
+ @Deprecated
public static class ParcelableRttParams implements Parcelable {
@NonNull
@@ -589,12 +596,14 @@ public class RttManager {
};
}
+ @Deprecated
public static class WifiInformationElement {
/** Information Element ID 0xFF means element is invalid. */
public byte id;
public byte[] data;
}
/** specifies RTT results */
+ @Deprecated
public static class RttResult {
/** mac address of the device being ranged. */
public String bssid;
@@ -746,6 +755,7 @@ public class RttManager {
/** pseudo-private class used to parcel results. */
+ @Deprecated
public static class ParcelableRttResults implements Parcelable {
public RttResult mResults[];
@@ -838,8 +848,8 @@ public class RttManager {
}
dest.writeByte(result.LCR.id);
if (result.LCR.id != (byte) 0xFF) {
- dest.writeInt((byte) result.LCR.data.length);
- dest.writeByte(result.LCR.id);
+ dest.writeByte((byte) result.LCR.data.length);
+ dest.writeByteArray(result.LCR.data);
}
dest.writeByte(result.secure ? (byte) 1 : 0);
}
@@ -911,7 +921,7 @@ public class RttManager {
};
}
-
+ @Deprecated
public static interface RttListener {
public void onSuccess(RttResult[] results);
public void onFailure(int reason, String description);
@@ -919,52 +929,11 @@ public class RttManager {
}
/**
- * A parcelable that contains rtt client information.
- *
- * @hide
- */
- public static class RttClient implements Parcelable {
- // Package name of RttClient.
- private final String mPackageName;
-
- public RttClient(String packageName) {
- mPackageName = packageName;
- }
-
- protected RttClient(Parcel in) {
- mPackageName = in.readString();
- }
-
- public static final Creator<RttManager.RttClient> CREATOR =
- new Creator<RttManager.RttClient>() {
- @Override
- public RttManager.RttClient createFromParcel(Parcel in) {
- return new RttManager.RttClient(in);
- }
-
- @Override
- public RttManager.RttClient[] newArray(int size) {
- return new RttManager.RttClient[size];
- }
- };
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel parcel, int i) {
- parcel.writeString(mPackageName);
- }
-
- public String getPackageName() {
- return mPackageName;
- }
- }
-
- /**
* Request to start an RTT ranging
+ * <p>
+ * This method is deprecated. Please use the
+ * {@link WifiRttManager#startRanging(RangingRequest, java.util.concurrent.Executor, RangingResultCallback)}
+ * API.
*
* @param params -- RTT request Parameters
* @param listener -- Call back to inform RTT result
@@ -1000,7 +969,9 @@ public class RttManager {
android.net.wifi.rtt.ResponderConfig.fromScanResult(reconstructed));
}
try {
- mNewService.startRanging(builder.build(), new RangingResultCallback() {
+ mNewService.startRanging(builder.build(),
+ mContext.getMainExecutor(),
+ new RangingResultCallback() {
@Override
public void onRangingFailure(int code) {
int localCode = REASON_UNSPECIFIED;
@@ -1018,15 +989,20 @@ public class RttManager {
legacyResults[i] = new RttResult();
legacyResults[i].status = result.getStatus();
legacyResults[i].bssid = result.getMacAddress().toString();
- legacyResults[i].distance = result.getDistanceMm() / 10;
- legacyResults[i].distanceStandardDeviation =
- result.getDistanceStdDevMm() / 10;
- legacyResults[i].rssi = result.getRssi();
- legacyResults[i].ts = result.getRangingTimestampUs();
+ if (result.getStatus() == RangingResult.STATUS_SUCCESS) {
+ legacyResults[i].distance = result.getDistanceMm() / 10;
+ legacyResults[i].distanceStandardDeviation =
+ result.getDistanceStdDevMm() / 10;
+ legacyResults[i].rssi = result.getRssi() * -2;
+ legacyResults[i].ts = result.getRangingTimestampMillis() * 1000;
+ } else {
+ // just in case legacy API needed some relatively real timestamp
+ legacyResults[i].ts = SystemClock.elapsedRealtime() * 1000;
+ }
}
listener.onSuccess(legacyResults);
}
- }, null);
+ });
} catch (IllegalArgumentException e) {
Log.e(TAG, "startRanging: invalid arguments - " + e);
listener.onFailure(REASON_INVALID_REQUEST, e.getMessage());
@@ -1036,6 +1012,10 @@ public class RttManager {
}
}
+ /**
+ * This method is deprecated and performs no function. Please use the {@link WifiRttManager}
+ * API.
+ */
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
public void stopRanging(RttListener listener) {
Log.e(TAG, "stopRanging: unsupported operation - nop");
@@ -1050,6 +1030,7 @@ public class RttManager {
* The client can freely destroy or reuse the callback after {@link RttManager#disableResponder}
* is called.
*/
+ @Deprecated
public abstract static class ResponderCallback {
/** Callback when responder is enabled. */
public abstract void onResponderEnabled(ResponderConfig config);
@@ -1065,6 +1046,10 @@ public class RttManager {
* Note calling this method with the same callback when the responder is already enabled won't
* change the responder state, a cached {@link ResponderConfig} from the last enabling will be
* returned through the callback.
+ * <p>
+ * This method is deprecated and will throw an {@link UnsupportedOperationException}
+ * exception. Please use the {@link WifiRttManager} API to perform a Wi-Fi Aware peer-to-peer
+ * ranging.
*
* @param callback Callback for responder enabling/disabling result.
* @throws IllegalArgumentException If {@code callback} is null.
@@ -1081,6 +1066,10 @@ public class RttManager {
* <p>
* Calling this method when responder isn't enabled won't have any effect. The callback can be
* reused for enabling responder after this method is called.
+ * <p>
+ * This method is deprecated and will throw an {@link UnsupportedOperationException}
+ * exception. Please use the {@link WifiRttManager} API to perform a Wi-Fi Aware peer-to-peer
+ * ranging.
*
* @param callback The same callback used for enabling responder.
* @throws IllegalArgumentException If {@code callback} is null.
@@ -1097,6 +1086,7 @@ public class RttManager {
*
* @see ScanResult
*/
+ @Deprecated
public static class ResponderConfig implements Parcelable {
// TODO: make all fields final once we can get mac address from responder HAL APIs.
@@ -1202,8 +1192,8 @@ public class RttManager {
/** @hide */
public static final int CMD_OP_REG_BINDER = BASE + 9;
- private final Context mContext;
private final WifiRttManager mNewService;
+ private final Context mContext;
private RttCapabilities mRttCapabilities;
/**
@@ -1211,17 +1201,15 @@ public class RttManager {
* Applications will almost always want to use
* {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve
* the standard {@link android.content.Context#WIFI_RTT_SERVICE Context.WIFI_RTT_SERVICE}.
- * @param context the application context
- * @param service the Binder interface
- * @param looper Looper for running the callbacks.
+ * @param service the new WifiRttManager service
*
* @hide
*/
- public RttManager(Context context, IRttManager service, Looper looper) {
+ public RttManager(Context context, WifiRttManager service) {
+ mNewService = service;
mContext = context;
- mNewService = (WifiRttManager) mContext.getSystemService(Context.WIFI_RTT_RANGING_SERVICE);
- boolean rttSupported = mContext.getPackageManager().hasSystemFeature(
+ boolean rttSupported = context.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_WIFI_RTT);
mRttCapabilities = new RttCapabilities();
diff --git a/wifi/java/android/net/wifi/ScanResult.java b/wifi/java/android/net/wifi/ScanResult.java
index c46789cab50e..8024bf08b1d4 100644
--- a/wifi/java/android/net/wifi/ScanResult.java
+++ b/wifi/java/android/net/wifi/ScanResult.java
@@ -273,27 +273,6 @@ public class ScanResult implements Parcelable {
public RadioChainInfo[] radioChainInfos;
/**
- * @hide
- * Update RSSI of the scan result
- * @param previousRssi
- * @param previousSeen
- * @param maxAge
- */
- public void averageRssi(int previousRssi, long previousSeen, int maxAge) {
-
- if (seen == 0) {
- seen = System.currentTimeMillis();
- }
- long age = seen - previousSeen;
-
- if (previousSeen > 0 && age > 0 && age < maxAge/2) {
- // Average the RSSI with previously seen instances of this scan result
- double alpha = 0.5 - (double) age / (double) maxAge;
- level = (int) ((double) level * (1 - alpha) + (double) previousRssi * alpha);
- }
- }
-
- /**
* Status indicating the scan result does not correspond to a user's saved configuration
* @hide
* @removed
diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java
index 7da2656761c1..ddcf327b9dd1 100644
--- a/wifi/java/android/net/wifi/WifiConfiguration.java
+++ b/wifi/java/android/net/wifi/WifiConfiguration.java
@@ -917,6 +917,9 @@ public class WifiConfiguration implements Parcelable {
* Does not guarantee that the returned address is valid for use.
*/
public MacAddress getRandomizedMacAddress() {
+ if (mRandomizedMacAddress == null) {
+ mRandomizedMacAddress = MacAddress.ALL_ZEROS_ADDRESS;
+ }
return mRandomizedMacAddress;
}
@@ -1617,6 +1620,7 @@ public class WifiConfiguration implements Parcelable {
creatorUid = -1;
shared = true;
dtimInterval = 0;
+ mRandomizedMacAddress = MacAddress.ALL_ZEROS_ADDRESS;
}
/**
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index 3396857acbe8..8ccccf4c7e5a 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -99,35 +99,45 @@ public class WifiManager {
// Supplicant error codes:
/**
* The error code if there was a problem authenticating.
+ * @deprecated This is no longer supported.
*/
+ @Deprecated
public static final int ERROR_AUTHENTICATING = 1;
/**
* The reason code if there is no error during authentication.
* It could also imply that there no authentication in progress,
* this reason code also serves as a reset value.
+ * @deprecated This is no longer supported.
* @hide
*/
+ @Deprecated
public static final int ERROR_AUTH_FAILURE_NONE = 0;
/**
* The reason code if there was a timeout authenticating.
+ * @deprecated This is no longer supported.
* @hide
*/
+ @Deprecated
public static final int ERROR_AUTH_FAILURE_TIMEOUT = 1;
/**
* The reason code if there was a wrong password while
* authenticating.
+ * @deprecated This is no longer supported.
* @hide
*/
+ @Deprecated
public static final int ERROR_AUTH_FAILURE_WRONG_PSWD = 2;
/**
* The reason code if there was EAP failure while
* authenticating.
+ * @deprecated This is no longer supported.
* @hide
*/
+ @Deprecated
public static final int ERROR_AUTH_FAILURE_EAP_FAILURE = 3;
/**
@@ -565,8 +575,10 @@ public class WifiManager {
* to perform Wi-Fi operations) or the connection to the supplicant has been
* lost. One extra provides the connection state as a boolean, where {@code true}
* means CONNECTED.
+ * @deprecated This is no longer supported.
* @see #EXTRA_SUPPLICANT_CONNECTED
*/
+ @Deprecated
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String SUPPLICANT_CONNECTION_CHANGE_ACTION =
"android.net.wifi.supplicant.CONNECTION_CHANGE";
@@ -575,7 +587,9 @@ public class WifiManager {
* the supplicant daemon has been gained or lost. {@code true} means
* a connection now exists.
* Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
+ * @deprecated This is no longer supported.
*/
+ @Deprecated
public static final String EXTRA_SUPPLICANT_CONNECTED = "connected";
/**
* Broadcast intent action indicating that the state of Wi-Fi connectivity
@@ -612,7 +626,9 @@ public class WifiManager {
* the overall state of connectivity.
* @see #EXTRA_NEW_STATE
* @see #EXTRA_SUPPLICANT_ERROR
+ * @deprecated This is no longer supported.
*/
+ @Deprecated
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String SUPPLICANT_STATE_CHANGED_ACTION =
"android.net.wifi.supplicant.STATE_CHANGE";
@@ -620,7 +636,9 @@ public class WifiManager {
* The lookup key for a {@link SupplicantState} describing the new state
* Retrieve with
* {@link android.content.Intent#getParcelableExtra(String)}.
+ * @deprecated This is no longer supported.
*/
+ @Deprecated
public static final String EXTRA_NEW_STATE = "newState";
/**
@@ -629,7 +647,9 @@ public class WifiManager {
* Retrieve with
* {@link android.content.Intent#getIntExtra(String, int)}.
* @see #ERROR_AUTHENTICATING
+ * @deprecated This is no longer supported.
*/
+ @Deprecated
public static final String EXTRA_SUPPLICANT_ERROR = "supplicantError";
/**
@@ -638,8 +658,10 @@ public class WifiManager {
* Retrieve with
* {@link android.content.Intent#getIntExtra(String, int)}.
* @see #ERROR_AUTH_FAILURE_#REASON_CODE
+ * @deprecated This is no longer supported.
* @hide
*/
+ @Deprecated
public static final String EXTRA_SUPPLICANT_ERROR_REASON = "supplicantErrorReason";
/**
@@ -3636,8 +3658,10 @@ public class WifiManager {
* Restore state from the older version of back up data.
* The old backup data was essentially a backup of wpa_supplicant.conf
* and ipconfig.txt file.
+ * @deprecated this is no longer supported.
* @hide
*/
+ @Deprecated
public void restoreSupplicantBackupData(byte[] supplicantData, byte[] ipConfigData) {
try {
mService.restoreSupplicantBackupData(supplicantData, ipConfigData);
diff --git a/wifi/java/android/net/wifi/WpsInfo.java b/wifi/java/android/net/wifi/WpsInfo.java
index ae2e77171367..d12cce174192 100644
--- a/wifi/java/android/net/wifi/WpsInfo.java
+++ b/wifi/java/android/net/wifi/WpsInfo.java
@@ -21,37 +21,58 @@ import android.os.Parcel;
/**
* A class representing Wi-Fi Protected Setup
- *
+ * @deprecated This class is no longer supported.
* {@see WifiP2pConfig}
*/
+@Deprecated
public class WpsInfo implements Parcelable {
- /** Push button configuration */
+ /** Push button configuration
+ * @deprecated This is no longer supported.*/
+ @Deprecated
public static final int PBC = 0;
- /** Display pin method configuration - pin is generated and displayed on device */
+ /** Display pin method configuration - pin is generated and displayed on device
+ * @deprecated This is no longer supported.*/
+ @Deprecated
public static final int DISPLAY = 1;
- /** Keypad pin method configuration - pin is entered on device */
+ /** Keypad pin method configuration - pin is entered on device
+ * @deprecated This is no longer supported.*/
+ @Deprecated
public static final int KEYPAD = 2;
- /** Label pin method configuration - pin is labelled on device */
+ /** Label pin method configuration - pin is labelled on device
+ * @deprecated This is no longer supported.*/
+ @Deprecated
public static final int LABEL = 3;
- /** Invalid configuration */
+ /** Invalid configuration
+ * @deprecated This is no longer supported.*/
+ @Deprecated
public static final int INVALID = 4;
- /** Wi-Fi Protected Setup. www.wi-fi.org/wifi-protected-setup has details */
+ /** Wi-Fi Protected Setup. www.wi-fi.org/wifi-protected-setup has details
+ * @deprecated This is no longer supported.*/
+ @Deprecated
public int setup;
- /** Passed with pin method KEYPAD */
+ /** Passed with pin method KEYPAD
+ * @deprecated This is no longer supported.*/
+ @Deprecated
public String BSSID;
- /** Passed with pin method configuration */
+ /** Passed with pin method configuration
+ * @deprecated This is no longer supported.*/
+ @Deprecated
public String pin;
+ /** @deprecated This API is no longer supported.*/
+ @Deprecated
public WpsInfo() {
setup = INVALID;
BSSID = null;
pin = null;
}
+ /** @deprecated This API is no longer supported.*/
+ @Deprecated
public String toString() {
StringBuffer sbuf = new StringBuffer();
sbuf.append(" setup: ").append(setup);
@@ -63,12 +84,16 @@ public class WpsInfo implements Parcelable {
return sbuf.toString();
}
- /** Implement the Parcelable interface */
+ /** Implement the Parcelable interface
+ * @deprecated This API is no longer supported.*/
+ @Deprecated
public int describeContents() {
return 0;
}
- /* Copy constructor */
+ /* Copy constructor
+ * @deprecated This API is no longer supported.*/
+ @Deprecated
public WpsInfo(WpsInfo source) {
if (source != null) {
setup = source.setup;
@@ -77,16 +102,22 @@ public class WpsInfo implements Parcelable {
}
}
- /** Implement the Parcelable interface */
+ /** Implement the Parcelable interface
+ * @deprecated This API is no longer supported. */
+ @Deprecated
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(setup);
dest.writeString(BSSID);
dest.writeString(pin);
}
- /** Implement the Parcelable interface */
+ /** Implement the Parcelable interface
+ * @deprecated This API is no longer supported.*/
+ @Deprecated
public static final Creator<WpsInfo> CREATOR =
new Creator<WpsInfo>() {
+ /** @deprecated This API is nolonger supported.*/
+ @Deprecated
public WpsInfo createFromParcel(Parcel in) {
WpsInfo config = new WpsInfo();
config.setup = in.readInt();
@@ -95,6 +126,8 @@ public class WpsInfo implements Parcelable {
return config;
}
+ /** @deprecated This API is nolonger supported.*/
+ @Deprecated
public WpsInfo[] newArray(int size) {
return new WpsInfo[size];
}
diff --git a/wifi/java/android/net/wifi/rtt/LocationCivic.java b/wifi/java/android/net/wifi/rtt/LocationCivic.java
deleted file mode 100644
index 610edb6399b4..000000000000
--- a/wifi/java/android/net/wifi/rtt/LocationCivic.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.net.wifi.rtt;
-
-import android.annotation.Nullable;
-import android.os.Parcel;
-import android.os.Parcelable;
-
-import java.util.Arrays;
-import java.util.Objects;
-
-/**
- * Location Civic Report (LCR).
- * <p>
- * The information matches the IEEE 802.11-2016 LCR report.
- * <p>
- * Note: depending on the mechanism by which this information is returned (i.e. the API which
- * returns an instance of this class) it is possibly Self Reported (by the peer). In such a case
- * the information is NOT validated - use with caution. Consider validating it with other sources
- * of information before using it.
- */
-public final class LocationCivic implements Parcelable {
- private final byte[] mData;
-
- /**
- * Parse the raw LCR information element (byte array) and extract the LocationCivic structure.
- *
- * Note: any parsing errors or invalid/unexpected errors will result in a null being returned.
- *
- * @hide
- */
- @Nullable
- public static LocationCivic parseInformationElement(byte id, byte[] data) {
- // TODO
- return null;
- }
-
- /** @hide */
- public LocationCivic(byte[] data) {
- mData = data;
- }
-
- /**
- * Return the Location Civic data reported by the peer.
- *
- * @return An arbitrary location information.
- */
- public byte[] getData() {
- return mData;
- }
-
- /** @hide */
- @Override
- public int describeContents() {
- return 0;
- }
-
- /** @hide */
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeByteArray(mData);
- }
-
- public static final Parcelable.Creator<LocationCivic> CREATOR =
- new Parcelable.Creator<LocationCivic>() {
- @Override
- public LocationCivic[] newArray(int size) {
- return new LocationCivic[size];
- }
-
- @Override
- public LocationCivic createFromParcel(Parcel in) {
- byte[] data = in.createByteArray();
-
- return new LocationCivic(data);
- }
- };
-
- /** @hide */
- @Override
- public String toString() {
- return new StringBuilder("LCR: data=").append(Arrays.toString(mData)).toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
-
- if (!(o instanceof LocationCivic)) {
- return false;
- }
-
- LocationCivic lhs = (LocationCivic) o;
-
- return Arrays.equals(mData, lhs.mData);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(mData);
- }
-}
diff --git a/wifi/java/android/net/wifi/rtt/LocationConfigurationInformation.java b/wifi/java/android/net/wifi/rtt/LocationConfigurationInformation.java
deleted file mode 100644
index 8aba56aa0ee7..000000000000
--- a/wifi/java/android/net/wifi/rtt/LocationConfigurationInformation.java
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.net.wifi.rtt;
-
-import android.annotation.IntDef;
-import android.annotation.Nullable;
-import android.os.Parcel;
-import android.os.Parcelable;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.util.Objects;
-
-/**
- * The Device Location Configuration Information (LCI) specifies the location information of a peer
- * device (e.g. an Access Point).
- * <p>
- * The information matches the IEEE 802.11-2016 LCI report (Location configuration information
- * report).
- * <p>
- * Note: depending on the mechanism by which this information is returned (i.e. the API which
- * returns an instance of this class) it is possibly Self Reported (by the peer). In such a case
- * the information is NOT validated - use with caution. Consider validating it with other sources
- * of information before using it.
- */
-public final class LocationConfigurationInformation implements Parcelable {
- /** @hide */
- @IntDef({
- ALTITUDE_UNKNOWN, ALTITUDE_IN_METERS, ALTITUDE_IN_FLOORS })
- @Retention(RetentionPolicy.SOURCE)
- public @interface AltitudeTypes {
- }
-
- /**
- * Define an Altitude Type returned by {@link #getAltitudeType()}. Indicates that the location
- * does not specify an altitude or altitude uncertainty. The corresponding methods,
- * {@link #getAltitude()} and {@link #getAltitudeUncertainty()} are not valid and will throw
- * an exception.
- */
- public static final int ALTITUDE_UNKNOWN = 0;
-
- /**
- * Define an Altitude Type returned by {@link #getAltitudeType()}. Indicates that the location
- * specifies the altitude and altitude uncertainty in meters. The corresponding methods,
- * {@link #getAltitude()} and {@link #getAltitudeUncertainty()} return a valid value in meters.
- */
- public static final int ALTITUDE_IN_METERS = 1;
-
- /**
- * Define an Altitude Type returned by {@link #getAltitudeType()}. Indicates that the
- * location specifies the altitude in floors, and does not specify an altitude uncertainty.
- * The {@link #getAltitude()} method returns valid value in floors, and the
- * {@link #getAltitudeUncertainty()} method is not valid and will throw an exception.
- */
- public static final int ALTITUDE_IN_FLOORS = 2;
-
- private final double mLatitude;
- private final double mLatitudeUncertainty;
- private final double mLongitude;
- private final double mLongitudeUncertainty;
- private final int mAltitudeType;
- private final double mAltitude;
- private final double mAltitudeUncertainty;
-
- /**
- * Parse the raw LCI information element (byte array) and extract the
- * LocationConfigurationInformation structure.
- *
- * Note: any parsing errors or invalid/unexpected errors will result in a null being returned.
- *
- * @hide
- */
- @Nullable
- public static LocationConfigurationInformation parseInformationElement(byte id, byte[] data) {
- // TODO
- return null;
- }
-
- /** @hide */
- public LocationConfigurationInformation(double latitude, double latitudeUncertainty,
- double longitude, double longitudeUncertainty, @AltitudeTypes int altitudeType,
- double altitude, double altitudeUncertainty) {
- mLatitude = latitude;
- mLatitudeUncertainty = latitudeUncertainty;
- mLongitude = longitude;
- mLongitudeUncertainty = longitudeUncertainty;
- mAltitudeType = altitudeType;
- mAltitude = altitude;
- mAltitudeUncertainty = altitudeUncertainty;
- }
-
- /**
- * Get latitude in degrees. Values are per WGS 84 reference system. Valid values are between
- * -90 and 90.
- *
- * @return Latitude in degrees.
- */
- public double getLatitude() {
- return mLatitude;
- }
-
- /**
- * Get the uncertainty of the latitude {@link #getLatitude()} in degrees. A value of 0 indicates
- * an unknown uncertainty.
- *
- * @return Uncertainty of the latitude in degrees.
- */
- public double getLatitudeUncertainty() {
- return mLatitudeUncertainty;
- }
-
- /**
- * Get longitude in degrees. Values are per WGS 84 reference system. Valid values are between
- * -180 and 180.
- *
- * @return Longitude in degrees.
- */
- public double getLongitude() {
- return mLongitude;
- }
-
- /**
- * Get the uncertainty of the longitude {@link #getLongitude()} ()} in degrees. A value of 0
- * indicates an unknown uncertainty.
- *
- * @return Uncertainty of the longitude in degrees.
- */
- public double getLongitudeUncertainty() {
- return mLongitudeUncertainty;
- }
-
- /**
- * Specifies the type of the altitude measurement returned by {@link #getAltitude()} and
- * {@link #getAltitudeUncertainty()}. The possible values are:
- * <li>{@link #ALTITUDE_UNKNOWN}: The altitude and altitude uncertainty are not provided.
- * <li>{@link #ALTITUDE_IN_METERS}: The altitude and altitude uncertainty are provided in
- * meters. Values are per WGS 84 reference system.
- * <li>{@link #ALTITUDE_IN_FLOORS}: The altitude is provided in floors, the altitude uncertainty
- * is not provided.
- *
- * @return The type of the altitude and altitude uncertainty.
- */
- public @AltitudeTypes int getAltitudeType() {
- return mAltitudeType;
- }
-
- /**
- * The altitude is interpreted according to the {@link #getAltitudeType()}. The possible values
- * are:
- * <li>{@link #ALTITUDE_UNKNOWN}: The altitude is not provided - this method will throw an
- * exception.
- * <li>{@link #ALTITUDE_IN_METERS}: The altitude is provided in meters. Values are per WGS 84
- * reference system.
- * <li>{@link #ALTITUDE_IN_FLOORS}: The altitude is provided in floors.
- *
- * @return Altitude value whose meaning is specified by {@link #getAltitudeType()}.
- */
- public double getAltitude() {
- if (mAltitudeType == ALTITUDE_UNKNOWN) {
- throw new IllegalStateException(
- "getAltitude(): invoked on an invalid type: getAltitudeType()==UNKNOWN");
- }
- return mAltitude;
- }
-
- /**
- * Only valid if the the {@link #getAltitudeType()} is equal to {@link #ALTITUDE_IN_METERS} -
- * otherwise this method will throw an exception.
- * <p>
- * Get the uncertainty of the altitude {@link #getAltitude()} in meters. A value of 0
- * indicates an unknown uncertainty.
- *
- * @return Uncertainty of the altitude in meters.
- */
- public double getAltitudeUncertainty() {
- if (mAltitudeType != ALTITUDE_IN_METERS) {
- throw new IllegalStateException(
- "getAltitude(): invoked on an invalid type: getAltitudeType()!=IN_METERS");
- }
- return mAltitudeUncertainty;
- }
-
- /** @hide */
- @Override
- public int describeContents() {
- return 0;
- }
-
- /** @hide */
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeDouble(mLatitude);
- dest.writeDouble(mLatitudeUncertainty);
- dest.writeDouble(mLongitude);
- dest.writeDouble(mLongitudeUncertainty);
- dest.writeInt(mAltitudeType);
- dest.writeDouble(mAltitude);
- dest.writeDouble(mAltitudeUncertainty);
- }
-
- public static final Creator<LocationConfigurationInformation> CREATOR =
- new Creator<LocationConfigurationInformation>() {
- @Override
- public LocationConfigurationInformation[] newArray(int size) {
- return new LocationConfigurationInformation[size];
- }
-
- @Override
- public LocationConfigurationInformation createFromParcel(Parcel in) {
- double latitude = in.readDouble();
- double latitudeUnc = in.readDouble();
- double longitude = in.readDouble();
- double longitudeUnc = in.readDouble();
- int altitudeType = in.readInt();
- double altitude = in.readDouble();
- double altitudeUnc = in.readDouble();
-
- return new LocationConfigurationInformation(latitude, latitudeUnc, longitude,
- longitudeUnc, altitudeType, altitude, altitudeUnc);
- }
- };
-
- /** @hide */
- @Override
- public String toString() {
- return new StringBuilder("LCI: latitude=").append(mLatitude).append(
- ", latitudeUncertainty=").append(mLatitudeUncertainty).append(
- ", longitude=").append(mLongitude).append(", longitudeUncertainty=").append(
- mLongitudeUncertainty).append(", altitudeType=").append(mAltitudeType).append(
- ", altitude=").append(mAltitude).append(", altitudeUncertainty=").append(
- mAltitudeUncertainty).toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
-
- if (!(o instanceof LocationConfigurationInformation)) {
- return false;
- }
-
- LocationConfigurationInformation lhs = (LocationConfigurationInformation) o;
-
- return mLatitude == lhs.mLatitude && mLatitudeUncertainty == lhs.mLatitudeUncertainty
- && mLongitude == lhs.mLongitude
- && mLongitudeUncertainty == lhs.mLongitudeUncertainty
- && mAltitudeType == lhs.mAltitudeType && mAltitude == lhs.mAltitude
- && mAltitudeUncertainty == lhs.mAltitudeUncertainty;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(mLatitude, mLatitudeUncertainty, mLongitude, mLongitudeUncertainty,
- mAltitudeType, mAltitude, mAltitudeUncertainty);
- }
-}
diff --git a/wifi/java/android/net/wifi/rtt/RangingRequest.java b/wifi/java/android/net/wifi/rtt/RangingRequest.java
index 32f21b9cbc79..339233b26e6b 100644
--- a/wifi/java/android/net/wifi/rtt/RangingRequest.java
+++ b/wifi/java/android/net/wifi/rtt/RangingRequest.java
@@ -37,7 +37,7 @@ import java.util.StringJoiner;
* Defines the ranging request to other devices. The ranging request is built using
* {@link RangingRequest.Builder}.
* A ranging request is executed using
- * {@link WifiRttManager#startRanging(RangingRequest, RangingResultCallback, Handler)}.
+ * {@link WifiRttManager#startRanging(RangingRequest, java.util.concurrent.Executor, RangingResultCallback)}.
* <p>
* The ranging request is a batch request - specifying a set of devices (specified using
* {@link RangingRequest.Builder#addAccessPoint(ScanResult)} and
@@ -122,6 +122,11 @@ public final class RangingRequest implements Parcelable {
* Add the device specified by the {@link ScanResult} to the list of devices with
* which to measure range. The total number of peers added to a request cannot exceed the
* limit specified by {@link #getMaxPeers()}.
+ * <p>
+ * Ranging may not be supported if the Access Point does not support IEEE 802.11mc. Use
+ * {@link ScanResult#is80211mcResponder()} to verify the Access Point's capabilities. If
+ * not supported the result status will be
+ * {@link RangingResult#STATUS_RESPONDER_DOES_NOT_SUPPORT_IEEE80211MC}.
*
* @param apInfo Information of an Access Point (AP) obtained in a Scan Result.
* @return The builder to facilitate chaining
@@ -138,6 +143,11 @@ public final class RangingRequest implements Parcelable {
* Add the devices specified by the {@link ScanResult}s to the list of devices with
* which to measure range. The total number of peers added to a request cannot exceed the
* limit specified by {@link #getMaxPeers()}.
+ * <p>
+ * Ranging may not be supported if the Access Point does not support IEEE 802.11mc. Use
+ * {@link ScanResult#is80211mcResponder()} to verify the Access Point's capabilities. If
+ * not supported the result status will be
+ * {@link RangingResult#STATUS_RESPONDER_DOES_NOT_SUPPORT_IEEE80211MC}.
*
* @param apInfos Information of an Access Points (APs) obtained in a Scan Result.
* @return The builder to facilitate chaining
@@ -156,14 +166,18 @@ public final class RangingRequest implements Parcelable {
/**
* Add the device specified by the {@code peerMacAddress} to the list of devices with
* which to measure range.
- *
+ * <p>
* The MAC address may be obtained out-of-band from a peer Wi-Fi Aware device. A Wi-Fi
* Aware device may obtain its MAC address using the {@link IdentityChangedListener}
* provided to
* {@link WifiAwareManager#attach(AttachCallback, IdentityChangedListener, Handler)}.
- *
- * * Note: in order to use this API the device must support Wi-Fi Aware
- * {@link android.net.wifi.aware}.
+ * <p>
+ * Note: in order to use this API the device must support Wi-Fi Aware
+ * {@link android.net.wifi.aware}. The peer device which is being ranged to must be
+ * configured to publish a service (with any name) with:
+ * <li>Type {@link android.net.wifi.aware.PublishConfig#PUBLISH_TYPE_UNSOLICITED}.
+ * <li>Ranging enabled
+ * {@link android.net.wifi.aware.PublishConfig.Builder#setRangingEnabled(boolean)}.
*
* @param peerMacAddress The MAC address of the Wi-Fi Aware peer.
* @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
@@ -179,12 +193,16 @@ public final class RangingRequest implements Parcelable {
/**
* Add a device specified by a {@link PeerHandle} to the list of devices with which to
* measure range.
- *
+ * <p>
* The {@link PeerHandle} may be obtained as part of the Wi-Fi Aware discovery process. E.g.
* using {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle, byte[], List)}.
- *
+ * <p>
* Note: in order to use this API the device must support Wi-Fi Aware
- * {@link android.net.wifi.aware}.
+ * {@link android.net.wifi.aware}. The peer device which is being ranged to must be
+ * configured to publish a service (with any name) with:
+ * <li>Type {@link android.net.wifi.aware.PublishConfig#PUBLISH_TYPE_UNSOLICITED}.
+ * <li>Ranging enabled
+ * {@link android.net.wifi.aware.PublishConfig.Builder#setRangingEnabled(boolean)}.
*
* @param peerHandle The peer handler of the peer Wi-Fi Aware device.
* @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
diff --git a/wifi/java/android/net/wifi/rtt/RangingResult.java b/wifi/java/android/net/wifi/rtt/RangingResult.java
index 201833bff431..936a1f2b6a47 100644
--- a/wifi/java/android/net/wifi/rtt/RangingResult.java
+++ b/wifi/java/android/net/wifi/rtt/RangingResult.java
@@ -19,6 +19,7 @@ package android.net.wifi.rtt;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.SystemApi;
import android.net.MacAddress;
import android.net.wifi.aware.PeerHandle;
import android.os.Handler;
@@ -27,22 +28,24 @@ import android.os.Parcelable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.Arrays;
import java.util.List;
import java.util.Objects;
/**
* Ranging result for a request started by
- * {@link WifiRttManager#startRanging(RangingRequest, RangingResultCallback, Handler)}. Results are
- * returned in {@link RangingResultCallback#onRangingResults(List)}.
+ * {@link WifiRttManager#startRanging(RangingRequest, java.util.concurrent.Executor, RangingResultCallback)}.
+ * Results are returned in {@link RangingResultCallback#onRangingResults(List)}.
* <p>
* A ranging result is the distance measurement result for a single device specified in the
* {@link RangingRequest}.
*/
public final class RangingResult implements Parcelable {
private static final String TAG = "RangingResult";
+ private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
/** @hide */
- @IntDef({STATUS_SUCCESS, STATUS_FAIL})
+ @IntDef({STATUS_SUCCESS, STATUS_FAIL, STATUS_RESPONDER_DOES_NOT_SUPPORT_IEEE80211MC})
@Retention(RetentionPolicy.SOURCE)
public @interface RangeResultStatus {
}
@@ -59,43 +62,52 @@ public final class RangingResult implements Parcelable {
*/
public static final int STATUS_FAIL = 1;
+ /**
+ * Individual range request status, {@link #getStatus()}. Indicates that the ranging operation
+ * failed because the specified peer does not support IEEE 802.11mc RTT operations. Support by
+ * an Access Point can be confirmed using
+ * {@link android.net.wifi.ScanResult#is80211mcResponder()}.
+ * <p>
+ * On such a failure, the individual result fields of {@link RangingResult} such as
+ * {@link RangingResult#getDistanceMm()} are invalid.
+ */
+ public static final int STATUS_RESPONDER_DOES_NOT_SUPPORT_IEEE80211MC = 2;
+
private final int mStatus;
private final MacAddress mMac;
private final PeerHandle mPeerHandle;
private final int mDistanceMm;
private final int mDistanceStdDevMm;
private final int mRssi;
- private final LocationConfigurationInformation mLci;
- private final LocationCivic mLcr;
+ private final byte[] mLci;
+ private final byte[] mLcr;
private final long mTimestamp;
/** @hide */
public RangingResult(@RangeResultStatus int status, @NonNull MacAddress mac, int distanceMm,
- int distanceStdDevMm, int rssi, LocationConfigurationInformation lci, LocationCivic lcr,
- long timestamp) {
+ int distanceStdDevMm, int rssi, byte[] lci, byte[] lcr, long timestamp) {
mStatus = status;
mMac = mac;
mPeerHandle = null;
mDistanceMm = distanceMm;
mDistanceStdDevMm = distanceStdDevMm;
mRssi = rssi;
- mLci = lci;
- mLcr = lcr;
+ mLci = lci == null ? EMPTY_BYTE_ARRAY : lci;
+ mLcr = lcr == null ? EMPTY_BYTE_ARRAY : lcr;
mTimestamp = timestamp;
}
/** @hide */
public RangingResult(@RangeResultStatus int status, PeerHandle peerHandle, int distanceMm,
- int distanceStdDevMm, int rssi, LocationConfigurationInformation lci, LocationCivic lcr,
- long timestamp) {
+ int distanceStdDevMm, int rssi, byte[] lci, byte[] lcr, long timestamp) {
mStatus = status;
mMac = null;
mPeerHandle = peerHandle;
mDistanceMm = distanceMm;
mDistanceStdDevMm = distanceStdDevMm;
mRssi = rssi;
- mLci = lci;
- mLcr = lcr;
+ mLci = lci == null ? EMPTY_BYTE_ARRAY : lci;
+ mLcr = lcr == null ? EMPTY_BYTE_ARRAY : lcr;
mTimestamp = timestamp;
}
@@ -163,7 +175,7 @@ public final class RangingResult implements Parcelable {
}
/**
- * @return The average RSSI (in units of -0.5dB) observed during the RTT measurement.
+ * @return The average RSSI, in units of dBm, observed during the RTT measurement.
* <p>
* Only valid if {@link #getStatus()} returns {@link #STATUS_SUCCESS}, otherwise will throw an
* exception.
@@ -181,13 +193,15 @@ public final class RangingResult implements Parcelable {
* <p>
* Note: the information is NOT validated - use with caution. Consider validating it with
* other sources of information before using it.
+ *
+ * @hide
*/
- @Nullable
- public LocationConfigurationInformation getReportedLocationConfigurationInformation() {
+ @SystemApi
+ @NonNull
+ public byte[] getLci() {
if (mStatus != STATUS_SUCCESS) {
throw new IllegalStateException(
- "getReportedLocationConfigurationInformation(): invoked on an invalid result: "
- + "getStatus()=" + mStatus);
+ "getLci(): invoked on an invalid result: getStatus()=" + mStatus);
}
return mLci;
}
@@ -197,9 +211,12 @@ public final class RangingResult implements Parcelable {
* <p>
* Note: the information is NOT validated - use with caution. Consider validating it with
* other sources of information before using it.
+ *
+ * @hide
*/
- @Nullable
- public LocationCivic getReportedLocationCivic() {
+ @SystemApi
+ @NonNull
+ public byte[] getLcr() {
if (mStatus != STATUS_SUCCESS) {
throw new IllegalStateException(
"getReportedLocationCivic(): invoked on an invalid result: getStatus()="
@@ -209,15 +226,18 @@ public final class RangingResult implements Parcelable {
}
/**
- * @return The timestamp, in us since boot, at which the ranging operation was performed.
+ * @return The timestamp at which the ranging operation was performed. The timestamp is in
+ * milliseconds since boot, including time spent in sleep, corresponding to values provided by
+ * {@link android.os.SystemClock#elapsedRealtime()}.
* <p>
* Only valid if {@link #getStatus()} returns {@link #STATUS_SUCCESS}, otherwise will throw an
* exception.
*/
- public long getRangingTimestampUs() {
+ public long getRangingTimestampMillis() {
if (mStatus != STATUS_SUCCESS) {
throw new IllegalStateException(
- "getRangingTimestamp(): invoked on an invalid result: getStatus()=" + mStatus);
+ "getRangingTimestampMillis(): invoked on an invalid result: getStatus()="
+ + mStatus);
}
return mTimestamp;
}
@@ -245,18 +265,8 @@ public final class RangingResult implements Parcelable {
dest.writeInt(mDistanceMm);
dest.writeInt(mDistanceStdDevMm);
dest.writeInt(mRssi);
- if (mLci == null) {
- dest.writeBoolean(false);
- } else {
- dest.writeBoolean(true);
- mLci.writeToParcel(dest, flags);
- }
- if (mLcr == null) {
- dest.writeBoolean(false);
- } else {
- dest.writeBoolean(true);
- mLcr.writeToParcel(dest, flags);
- }
+ dest.writeByteArray(mLci);
+ dest.writeByteArray(mLcr);
dest.writeLong(mTimestamp);
}
@@ -282,16 +292,8 @@ public final class RangingResult implements Parcelable {
int distanceMm = in.readInt();
int distanceStdDevMm = in.readInt();
int rssi = in.readInt();
- boolean lciPresent = in.readBoolean();
- LocationConfigurationInformation lci = null;
- if (lciPresent) {
- lci = LocationConfigurationInformation.CREATOR.createFromParcel(in);
- }
- boolean lcrPresent = in.readBoolean();
- LocationCivic lcr = null;
- if (lcrPresent) {
- lcr = LocationCivic.CREATOR.createFromParcel(in);
- }
+ byte[] lci = in.createByteArray();
+ byte[] lcr = in.createByteArray();
long timestamp = in.readLong();
if (peerHandlePresent) {
return new RangingResult(status, peerHandle, distanceMm, distanceStdDevMm, rssi,
@@ -329,7 +331,7 @@ public final class RangingResult implements Parcelable {
return mStatus == lhs.mStatus && Objects.equals(mMac, lhs.mMac) && Objects.equals(
mPeerHandle, lhs.mPeerHandle) && mDistanceMm == lhs.mDistanceMm
&& mDistanceStdDevMm == lhs.mDistanceStdDevMm && mRssi == lhs.mRssi
- && Objects.equals(mLci, lhs.mLci) && Objects.equals(mLcr, lhs.mLcr)
+ && Arrays.equals(mLci, lhs.mLci) && Arrays.equals(mLcr, lhs.mLcr)
&& mTimestamp == lhs.mTimestamp;
}
diff --git a/wifi/java/android/net/wifi/rtt/RangingResultCallback.java b/wifi/java/android/net/wifi/rtt/RangingResultCallback.java
index 9639dc803a7d..fa7d79ec0a8c 100644
--- a/wifi/java/android/net/wifi/rtt/RangingResultCallback.java
+++ b/wifi/java/android/net/wifi/rtt/RangingResultCallback.java
@@ -18,7 +18,6 @@ package android.net.wifi.rtt;
import android.annotation.IntDef;
import android.annotation.NonNull;
-import android.os.Handler;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -26,11 +25,11 @@ import java.util.List;
/**
* Base class for ranging result callbacks. Should be extended by applications and set when calling
- * {@link WifiRttManager#startRanging(RangingRequest, RangingResultCallback, Handler)}. If the
- * ranging operation fails in whole (not attempted) then {@link #onRangingFailure(int)} will be
- * called with a failure code. If the ranging operation is performed for each of the requested
- * peers then the {@link #onRangingResults(List)} will be called with the set of results (@link
- * {@link RangingResult}, each of which has its own success/failure code
+ * {@link WifiRttManager#startRanging(RangingRequest, java.util.concurrent.Executor, RangingResultCallback)}.
+ * If the ranging operation fails in whole (not attempted) then {@link #onRangingFailure(int)}
+ * will be called with a failure code. If the ranging operation is performed for each of the
+ * requested peers then the {@link #onRangingResults(List)} will be called with the set of
+ * results (@link {@link RangingResult}, each of which has its own success/failure code
* {@link RangingResult#getStatus()}.
*/
public abstract class RangingResultCallback {
diff --git a/wifi/java/android/net/wifi/rtt/WifiRttManager.java b/wifi/java/android/net/wifi/rtt/WifiRttManager.java
index ec6c46ec4a7d..d119579f51b2 100644
--- a/wifi/java/android/net/wifi/rtt/WifiRttManager.java
+++ b/wifi/java/android/net/wifi/rtt/WifiRttManager.java
@@ -21,6 +21,7 @@ import static android.Manifest.permission.ACCESS_WIFI_STATE;
import static android.Manifest.permission.CHANGE_WIFI_STATE;
import static android.Manifest.permission.LOCATION_HARDWARE;
+import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
@@ -29,13 +30,12 @@ import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.content.Context;
import android.os.Binder;
-import android.os.Handler;
-import android.os.Looper;
import android.os.RemoteException;
import android.os.WorkSource;
import android.util.Log;
import java.util.List;
+import java.util.concurrent.Executor;
/**
* This class provides the primary API for measuring distance (range) to other devices using the
@@ -46,7 +46,7 @@ import java.util.List;
* <li>Wi-Fi Aware peers
* <p>
* Ranging requests are triggered using
- * {@link #startRanging(RangingRequest, RangingResultCallback, Handler)}. Results (in case of
+ * {@link #startRanging(RangingRequest, Executor, RangingResultCallback)}. Results (in case of
* successful operation) are returned in the {@link RangingResultCallback#onRangingResults(List)}
* callback.
* <p>
@@ -106,15 +106,13 @@ public class WifiRttManager {
*
* @param request A request specifying a set of devices whose distance measurements are
* requested.
+ * @param executor The Executor on which to run the callback.
* @param callback A callback for the result of the ranging request.
- * @param handler The Handler on whose thread to execute the callbacks of the {@code
- * callback} object. If a null is provided then the application's main thread
- * will be used.
*/
@RequiresPermission(allOf = {ACCESS_COARSE_LOCATION, CHANGE_WIFI_STATE, ACCESS_WIFI_STATE})
public void startRanging(@NonNull RangingRequest request,
- @NonNull RangingResultCallback callback, @Nullable Handler handler) {
- startRanging(null, request, callback, handler);
+ @NonNull @CallbackExecutor Executor executor, @NonNull RangingResultCallback callback) {
+ startRanging(null, request, executor, callback);
}
/**
@@ -124,10 +122,8 @@ public class WifiRttManager {
* @param workSource A mechanism to specify an alternative work-source for the request.
* @param request A request specifying a set of devices whose distance measurements are
* requested.
+ * @param executor The Executor on which to run the callback.
* @param callback A callback for the result of the ranging request.
- * @param handler The Handler on whose thread to execute the callbacks of the {@code
- * callback} object. If a null is provided then the application's main thread
- * will be used.
*
* @hide
*/
@@ -135,21 +131,36 @@ public class WifiRttManager {
@RequiresPermission(allOf = {LOCATION_HARDWARE, ACCESS_COARSE_LOCATION, CHANGE_WIFI_STATE,
ACCESS_WIFI_STATE})
public void startRanging(@Nullable WorkSource workSource, @NonNull RangingRequest request,
- @NonNull RangingResultCallback callback, @Nullable Handler handler) {
+ @NonNull @CallbackExecutor Executor executor, @NonNull RangingResultCallback callback) {
if (VDBG) {
Log.v(TAG, "startRanging: workSource=" + workSource + ", request=" + request
- + ", callback=" + callback + ", handler=" + handler);
+ + ", callback=" + callback + ", executor=" + executor);
}
+ if (executor == null) {
+ throw new IllegalArgumentException("Null executor provided");
+ }
if (callback == null) {
throw new IllegalArgumentException("Null callback provided");
}
- Looper looper = (handler == null) ? Looper.getMainLooper() : handler.getLooper();
Binder binder = new Binder();
try {
mService.startRanging(binder, mContext.getOpPackageName(), workSource, request,
- new RttCallbackProxy(looper, callback));
+ new IRttCallback.Stub() {
+ @Override
+ public void onRangingFailure(int status) throws RemoteException {
+ clearCallingIdentity();
+ executor.execute(() -> callback.onRangingFailure(status));
+ }
+
+ @Override
+ public void onRangingResults(List<RangingResult> results)
+ throws RemoteException {
+ clearCallingIdentity();
+ executor.execute(() -> callback.onRangingResults(results));
+ }
+ });
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -157,7 +168,7 @@ public class WifiRttManager {
/**
* Cancel all ranging requests for the specified work sources. The requests have been requested
- * using {@link #startRanging(WorkSource, RangingRequest, RangingResultCallback, Handler)}.
+ * using {@link #startRanging(WorkSource, RangingRequest, Executor, RangingResultCallback)}.
*
* @param workSource The work-sources of the requesters.
*
@@ -176,30 +187,4 @@ public class WifiRttManager {
throw e.rethrowFromSystemServer();
}
}
-
- private static class RttCallbackProxy extends IRttCallback.Stub {
- private final Handler mHandler;
- private final RangingResultCallback mCallback;
-
- RttCallbackProxy(Looper looper, RangingResultCallback callback) {
- mHandler = new Handler(looper);
- mCallback = callback;
- }
-
- @Override
- public void onRangingFailure(int status) throws RemoteException {
- if (VDBG) Log.v(TAG, "RttCallbackProxy: onRangingFailure: status=" + status);
- mHandler.post(() -> {
- mCallback.onRangingFailure(status);
- });
- }
-
- @Override
- public void onRangingResults(List<RangingResult> results) throws RemoteException {
- if (VDBG) Log.v(TAG, "RttCallbackProxy: onRanginResults: results=" + results);
- mHandler.post(() -> {
- mCallback.onRangingResults(results);
- });
- }
- }
}