1 /*
2  * Copyright (C) 2024 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.twt;
18 
19 import android.annotation.FlaggedApi;
20 import android.annotation.IntDef;
21 import android.annotation.NonNull;
22 import android.annotation.SystemApi;
23 
24 import com.android.wifi.flags.Flags;
25 
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 
29 /**
30  * API interface for target wake time (TWT) session Callback.
31  *
32  * @hide
33  */
34 @SystemApi
35 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API)
36 public interface TwtSessionCallback {
37     /**
38      * Generic error
39      */
40     int TWT_ERROR_CODE_FAIL = 0;
41     /**
42      * AP does not support TWT
43      */
44     int TWT_ERROR_CODE_AP_NOT_SUPPORTED = 1;
45     /**
46      * AP is blocklisted due to interoperability issue reported with TWT
47      */
48     int TWT_ERROR_CODE_AP_OUI_BLOCKLISTED = 2;
49     /**
50      * AP rejects TWT request
51      */
52     int TWT_ERROR_CODE_AP_REJECTED = 3;
53     /**
54      * Invalid parameters
55      */
56     int TWT_ERROR_CODE_INVALID_PARAMS = 4;
57     /**
58      * Maximum TWT sessions reached
59      */
60     int TWT_ERROR_CODE_MAX_SESSIONS_REACHED = 5;
61     /**
62      * TWT is not available now
63      */
64     int TWT_ERROR_CODE_NOT_AVAILABLE = 6;
65     /**
66      * TWT is not supported by the local device
67      */
68     int TWT_ERROR_CODE_NOT_SUPPORTED = 7;
69     /**
70      * TWT operation Timed out
71      */
72     int TWT_ERROR_CODE_TIMEOUT = 8;
73 
74     /**
75      * @hide
76      */
77     @IntDef(prefix = {"TWT_ERROR_CODE_"}, value = {TWT_ERROR_CODE_FAIL,
78             TWT_ERROR_CODE_AP_NOT_SUPPORTED, TWT_ERROR_CODE_AP_OUI_BLOCKLISTED,
79             TWT_ERROR_CODE_AP_REJECTED, TWT_ERROR_CODE_INVALID_PARAMS,
80             TWT_ERROR_CODE_MAX_SESSIONS_REACHED, TWT_ERROR_CODE_NOT_AVAILABLE,
81             TWT_ERROR_CODE_NOT_SUPPORTED, TWT_ERROR_CODE_TIMEOUT})
82     @Retention(RetentionPolicy.SOURCE)
83     @interface TwtErrorCode {
84     }
85 
86     /**
87      * Unknown reason code
88      */
89     int TWT_REASON_CODE_UNKNOWN = 0;
90     /**
91      * Locally requested
92      */
93     int TWT_REASON_CODE_LOCALLY_REQUESTED = 1;
94     /**
95      * Internally initiated by the driver or firmware
96      */
97     int TWT_REASON_CODE_INTERNALLY_INITIATED = 2;
98     /**
99      * Peer initiated
100      */
101     int TWT_REASON_CODE_PEER_INITIATED = 3;
102 
103     /**
104      * @hide
105      */
106     @IntDef(prefix = {"TWT_REASON_CODE_"}, value = {TWT_REASON_CODE_UNKNOWN,
107             TWT_REASON_CODE_LOCALLY_REQUESTED, TWT_REASON_CODE_INTERNALLY_INITIATED,
108             TWT_REASON_CODE_PEER_INITIATED})
109     @Retention(RetentionPolicy.SOURCE)
110     @interface TwtReasonCode {
111     }
112 
113     /**
114      * Called when a TWT operation fails.
115      *
116      * @param errorCode error code
117      */
118     @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API)
onFailure(@wtSessionCallback.TwtErrorCode int errorCode)119     void onFailure(@TwtSessionCallback.TwtErrorCode int errorCode);
120 
121     /**
122      * Called when a TWT session is torn down or closed. Check the
123      * {@link TwtReasonCode} for more details.
124      *
125      * @param reasonCode reason for TWT session teardown
126      */
127     @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API)
onTeardown(@wtSessionCallback.TwtReasonCode int reasonCode)128     void onTeardown(@TwtSessionCallback.TwtReasonCode int reasonCode);
129 
130     /**
131      * Called when the TWT session is created.
132      *
133      * @param twtSession TWT session
134      */
135     @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API)
onCreate(@onNull TwtSession twtSession)136     void onCreate(@NonNull TwtSession twtSession);
137 }
138