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 static android.net.wifi.MloLink.INVALID_MLO_LINK_ID; 20 import static android.net.wifi.MloLink.MAX_MLO_LINK_ID; 21 import static android.net.wifi.MloLink.MIN_MLO_LINK_ID; 22 23 import android.annotation.FlaggedApi; 24 import android.annotation.IntRange; 25 import android.annotation.NonNull; 26 import android.annotation.SystemApi; 27 import android.net.wifi.MloLink; 28 import android.os.Parcel; 29 import android.os.Parcelable; 30 31 import com.android.wifi.flags.Flags; 32 33 /** 34 * Defines target wake time (TWT) request class. 35 * 36 * @hide 37 */ 38 @SystemApi 39 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) 40 public final class TwtRequest implements Parcelable { 41 private final int mMinWakeDurationMicros; 42 private final int mMaxWakeDurationMicros; 43 private final long mMinWakeIntervalMicros; 44 private final long mMaxWakeIntervalMicros; 45 private final int mLinkId; 46 TwtRequest(TwtRequest.Builder builder)47 private TwtRequest(TwtRequest.Builder builder) { 48 mMinWakeDurationMicros = builder.mMinWakeDurationMicros; 49 mMaxWakeDurationMicros = builder.mMaxWakeDurationMicros; 50 mMinWakeIntervalMicros = builder.mMinWakeIntervalMicros; 51 mMaxWakeIntervalMicros = builder.mMaxWakeIntervalMicros; 52 mLinkId = builder.mLinkId; 53 } 54 55 /** 56 * Get minimum TWT wake duration in microseconds. 57 * 58 * @return Minimum wake duration in microseconds 59 */ 60 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) getMinWakeDurationMicros()61 public int getMinWakeDurationMicros() { 62 return mMinWakeDurationMicros; 63 } 64 65 /** 66 * Get maximum TWT wake duration in microseconds. 67 * 68 * @return Maximum wake duration in microseconds 69 */ 70 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) getMaxWakeDurationMicros()71 public int getMaxWakeDurationMicros() { 72 return mMaxWakeDurationMicros; 73 } 74 75 /** 76 * Get minimum TWT wake interval in microseconds. 77 * 78 * @return Minimum wake interval in microseconds 79 */ 80 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) getMinWakeIntervalMicros()81 public long getMinWakeIntervalMicros() { 82 return mMinWakeIntervalMicros; 83 } 84 85 /** 86 * Get maximum TWT wake interval in microseconds. 87 * 88 * @return Maximum wake interval in microseconds 89 */ 90 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) getMaxWakeIntervalMicros()91 public long getMaxWakeIntervalMicros() { 92 return mMaxWakeIntervalMicros; 93 } 94 95 96 /** 97 * Get link id (valid only in case of Multi-link operation). 98 * 99 * @return MLO link id in the range {@link MloLink#MIN_MLO_LINK_ID} to 100 * {@link MloLink#MAX_MLO_LINK_ID}. Returns {@link MloLink#INVALID_MLO_LINK_ID} if not set. 101 */ 102 @IntRange(from = INVALID_MLO_LINK_ID, to = MAX_MLO_LINK_ID) 103 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) getLinkId()104 public int getLinkId() { 105 return mLinkId; 106 } 107 108 @NonNull 109 public static final Creator<TwtRequest> CREATOR = new Creator<TwtRequest>() { 110 @Override 111 public TwtRequest createFromParcel(Parcel in) { 112 Builder builder = new TwtRequest.Builder(in.readInt(), in.readInt(), in.readLong(), 113 in.readLong()); 114 int mloLinkId = in.readInt(); 115 if (mloLinkId >= MIN_MLO_LINK_ID && mloLinkId <= MAX_MLO_LINK_ID) { 116 builder.setLinkId(mloLinkId); 117 } 118 return builder.build(); 119 } 120 121 @Override 122 public TwtRequest[] newArray(int size) { 123 return new TwtRequest[size]; 124 } 125 }; 126 127 128 /** 129 * Describe the kinds of special objects contained in this Parcelable 130 * instance's marshaled representation. 131 * 132 * @return a bitmask indicating the set of special object types marshaled 133 * by this Parcelable object instance. 134 */ 135 @Override describeContents()136 public int describeContents() { 137 return 0; 138 } 139 140 /** 141 * Flatten this object in to a Parcel. 142 * 143 * @param dest The Parcel in which the object should be written. 144 * @param flags Additional flags about how the object should be written. 145 * May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}. 146 */ 147 @Override writeToParcel(@onNull Parcel dest, int flags)148 public void writeToParcel(@NonNull Parcel dest, int flags) { 149 dest.writeInt(mMinWakeDurationMicros); 150 dest.writeInt(mMaxWakeDurationMicros); 151 dest.writeLong(mMinWakeIntervalMicros); 152 dest.writeLong(mMinWakeIntervalMicros); 153 dest.writeInt(mLinkId); 154 } 155 156 /** 157 * Builder class used to construct {@link TwtRequest} objects. 158 * 159 */ 160 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) 161 public static final class Builder { 162 private final int mMinWakeDurationMicros; 163 private final int mMaxWakeDurationMicros; 164 private final long mMinWakeIntervalMicros; 165 private final long mMaxWakeIntervalMicros; 166 private int mLinkId = INVALID_MLO_LINK_ID; 167 168 /** 169 * Set link id (valid only in case of Multi-link operation). 170 * 171 * @param linkId Link id, which should be in the range {@link MloLink#MIN_MLO_LINK_ID} to 172 * {@link MloLink#MAX_MLO_LINK_ID} 173 * @return The builder to facilitate chaining 174 * @throws IllegalArgumentException if argument is invalid 175 */ 176 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) 177 @NonNull setLinkId( @ntRangefrom = MIN_MLO_LINK_ID, to = MAX_MLO_LINK_ID) int linkId)178 public TwtRequest.Builder setLinkId( 179 @IntRange(from = MIN_MLO_LINK_ID, to = MAX_MLO_LINK_ID) int linkId) { 180 if (linkId < MIN_MLO_LINK_ID || linkId > MAX_MLO_LINK_ID) { 181 throw new IllegalArgumentException("linkId is out of range"); 182 } 183 mLinkId = linkId; 184 return this; 185 } 186 187 /** 188 * Constructor for {@link TwtRequest.Builder}. 189 * 190 * @param minWakeDurationMicros Minimum TWT wake duration in microseconds. 191 * @param maxWakeDurationMicros Maximum TWT wake duration in microseconds 192 * @param minWakeIntervalMicros Minimum TWT wake interval in microseconds 193 * @param maxWakeIntervalMicros Maximum TWT wake interval in microseconds 194 */ 195 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) Builder(int minWakeDurationMicros, int maxWakeDurationMicros, long minWakeIntervalMicros, long maxWakeIntervalMicros)196 public Builder(int minWakeDurationMicros, int maxWakeDurationMicros, 197 long minWakeIntervalMicros, long maxWakeIntervalMicros) { 198 mMinWakeDurationMicros = minWakeDurationMicros; 199 mMaxWakeDurationMicros = maxWakeDurationMicros; 200 mMinWakeIntervalMicros = minWakeIntervalMicros; 201 mMaxWakeIntervalMicros = maxWakeIntervalMicros; 202 } 203 204 /** 205 * Build {@link TwtRequest} given the current configurations made on the builder. 206 */ 207 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) 208 @NonNull build()209 public TwtRequest build() { 210 return new TwtRequest(this); 211 } 212 } 213 } 214