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 android.net.wifi.rtt;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 
22 import java.lang.annotation.Retention;
23 import java.lang.annotation.RetentionPolicy;
24 import java.util.List;
25 
26 /**
27  * Base class for ranging result callbacks. Should be extended by applications and set when calling
28  * {@link WifiRttManager#startRanging(RangingRequest, java.util.concurrent.Executor, RangingResultCallback)}.
29  * If the ranging operation fails in whole (not attempted) then {@link #onRangingFailure(int)}
30  * will be called with a failure code. If the ranging operation is performed for each of the
31  * requested peers then the {@link #onRangingResults(List)} will be called with the set of
32  * results (@link {@link RangingResult}, each of which has its own success/failure code
33  * {@link RangingResult#getStatus()}.
34  */
35 public abstract class RangingResultCallback {
36     /** @hide */
37     @IntDef({STATUS_CODE_FAIL, STATUS_CODE_FAIL_RTT_NOT_AVAILABLE})
38     @Retention(RetentionPolicy.SOURCE)
39     public @interface RangingOperationStatus {
40     }
41 
42     /**
43      * A failure code for the whole ranging request operation. Indicates a failure.
44      */
45     public static final int STATUS_CODE_FAIL = 1;
46 
47     /**
48      * A failure code for the whole ranging request operation. Indicates that the request failed due
49      * to RTT not being available - e.g. Wi-Fi was disabled. Use the
50      * {@link WifiRttManager#isAvailable()} and {@link WifiRttManager#ACTION_WIFI_RTT_STATE_CHANGED}
51      * to track RTT availability.
52      */
53     public static final int STATUS_CODE_FAIL_RTT_NOT_AVAILABLE = 2;
54 
55     /**
56      * Called when a ranging operation failed in whole - i.e. no ranging operation to any of the
57      * devices specified in the request was attempted.
58      *
59      * @param code A status code indicating the type of failure.
60      */
onRangingFailure(@angingOperationStatus int code)61     public abstract void onRangingFailure(@RangingOperationStatus int code);
62 
63     /**
64      * Called when a ranging operation was executed. The list of results corresponds to devices
65      * specified in the ranging request.
66      *
67      * @param results List of range measurements, one per requested device.
68      */
onRangingResults(@onNull List<RangingResult> results)69     public abstract void onRangingResults(@NonNull List<RangingResult> results);
70 }
71