Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7d3fcb43 authored by Etan Cohen's avatar Etan Cohen Committed by Android (Google) Code Review
Browse files

Merge "[RTT2] Add RTT availability API"

parents 4f3fdf5f 58019f52
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -326,6 +326,7 @@
    <protected-broadcast android:name="android.net.wifi.WIFI_CREDENTIAL_CHANGED" />
    <protected-broadcast android:name="android.net.wifi.WIFI_SCAN_AVAILABLE" />
    <protected-broadcast android:name="android.net.wifi.aware.action.WIFI_AWARE_STATE_CHANGED" />
    <protected-broadcast android:name="android.net.wifi.rtt.action.WIFI_RTT_STATE_CHANGED" />
    <protected-broadcast android:name="android.net.wifi.SCAN_RESULTS" />
    <protected-broadcast android:name="android.net.wifi.RSSI_CHANGED" />
    <protected-broadcast android:name="android.net.wifi.STATE_CHANGE" />
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.net.wifi.rtt.RangingRequest;
 */
interface IWifiRttManager
{
    boolean isAvailable();
    void startRanging(in IBinder binder, in String callingPackage, in RangingRequest request,
            in IRttCallback callback);
}
+9 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ import java.util.List;
 */
public abstract class RangingResultCallback {
    /** @hide */
    @IntDef({STATUS_CODE_FAIL})
    @IntDef({STATUS_CODE_FAIL, STATUS_CODE_FAIL_RTT_NOT_AVAILABLE})
    @Retention(RetentionPolicy.SOURCE)
    public @interface RangingOperationStatus {
    }
@@ -46,6 +46,14 @@ public abstract class RangingResultCallback {
     */
    public static final int STATUS_CODE_FAIL = 1;

    /**
     * A failure code for the whole ranging request operation. Indicates that the request failed due
     * to RTT not being available - e.g. Wi-Fi was disabled. Use the
     * {@link WifiRttManager#isAvailable()} and {@link WifiRttManager#ACTION_WIFI_RTT_STATE_CHANGED}
     * to track RTT availability.
     */
    public static final int STATUS_CODE_FAIL_RTT_NOT_AVAILABLE = 2;

    /**
     * Called when a ranging operation failed in whole - i.e. no ranging operation to any of the
     * devices specified in the request was attempted.
+36 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import static android.Manifest.permission.CHANGE_WIFI_STATE;

import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SystemService;
import android.content.Context;
import android.os.Binder;
@@ -22,11 +23,18 @@ import java.util.List;
 * <p>
 * The devices which can be ranged include:
 * <li>Access Points (APs)
 * <li>Wi-Fi Aware peers
 * <p>
 * Ranging requests are triggered using
 * {@link #startRanging(RangingRequest, RangingResultCallback, Handler)}. Results (in case of
 * successful operation) are returned in the {@link RangingResultCallback#onRangingResults(List)}
 * callback.
 * <p>
 *     Wi-Fi RTT may not be usable at some points, e.g. when Wi-Fi is disabled. To validate that
 *     the functionality is available use the {@link #isAvailable()} function. To track
 *     changes in RTT usability register for the {@link #ACTION_WIFI_RTT_STATE_CHANGED}
 *     broadcast. Note that this broadcast is not sticky - you should register for it and then
 *     check the above API to avoid a race condition.
 *
 * @hide RTT_API
 */
@@ -38,12 +46,40 @@ public class WifiRttManager {
    private final Context mContext;
    private final IWifiRttManager mService;

    /**
     * Broadcast intent action to indicate that the state of Wi-Fi RTT availability has changed.
     * Use the {@link #isAvailable()} to query the current status.
     * This broadcast is <b>not</b> sticky, use the {@link #isAvailable()} API after registering
     * the broadcast to check the current state of Wi-Fi RTT.
     * <p>Note: The broadcast is only delivered to registered receivers - no manifest registered
     * components will be launched.
     */
    @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_WIFI_RTT_STATE_CHANGED =
            "android.net.wifi.rtt.action.WIFI_RTT_STATE_CHANGED";

    /** @hide */
    public WifiRttManager(Context context, IWifiRttManager service) {
        mContext = context;
        mService = service;
    }

    /**
     * Returns the current status of RTT API: whether or not RTT is available. To track
     * changes in the state of RTT API register for the
     * {@link #ACTION_WIFI_RTT_STATE_CHANGED} broadcast.
     *
     * @return A boolean indicating whether the app can use the RTT API at this time (true) or
     * not (false).
     */
    public boolean isAvailable() {
        try {
            return mService.isAvailable();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Initiate a request to range to a set of devices specified in the {@link RangingRequest}.
     * Results will be returned in the {@link RangingResultCallback} set of callbacks.