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.ranging.wifi.rtt; 18 19 import static android.net.wifi.rtt.ResponderConfig.CHANNEL_WIDTH_20MHZ; 20 21 import android.annotation.FlaggedApi; 22 import android.annotation.NonNull; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 import android.ranging.RangingCapabilities.TechnologyCapabilities; 26 import android.ranging.RangingManager; 27 28 import com.android.ranging.flags.Flags; 29 30 /** 31 * Represents the capabilities of the WiFi Neighbor Awareness Networking Round Trip Time (NAN-RTT) 32 * ranging. 33 * 34 */ 35 @FlaggedApi(Flags.FLAG_RANGING_RTT_ENABLED) 36 public final class RttRangingCapabilities implements Parcelable, TechnologyCapabilities { 37 38 private final boolean mHasPeriodicRangingHardwareFeature; 39 40 private final int mMaxSupportedBandwidth; 41 42 private final int mMaxSupportedRxChain; 43 RttRangingCapabilities(Builder builder)44 private RttRangingCapabilities(Builder builder) { 45 mHasPeriodicRangingHardwareFeature = builder.mHasPeriodicRangingHardwareFeature; 46 mMaxSupportedBandwidth = builder.mMaxSupportedBandwidth; 47 mMaxSupportedRxChain = builder.mMaxSupportedRxChain; 48 } 49 RttRangingCapabilities(Parcel in)50 private RttRangingCapabilities(Parcel in) { 51 mHasPeriodicRangingHardwareFeature = in.readBoolean(); 52 mMaxSupportedBandwidth = in.readInt(); 53 mMaxSupportedRxChain = in.readInt(); 54 } 55 56 @Override writeToParcel(@onNull Parcel dest, int flags)57 public void writeToParcel(@NonNull Parcel dest, int flags) { 58 dest.writeBoolean(mHasPeriodicRangingHardwareFeature); 59 dest.writeInt(mMaxSupportedBandwidth); 60 dest.writeInt(mMaxSupportedRxChain); 61 } 62 63 @Override describeContents()64 public int describeContents() { 65 return 0; 66 } 67 68 @NonNull 69 public static final Creator<RttRangingCapabilities> CREATOR = 70 new Creator<RttRangingCapabilities>() { 71 @Override 72 public RttRangingCapabilities createFromParcel(Parcel in) { 73 return new RttRangingCapabilities(in); 74 } 75 76 @Override 77 public RttRangingCapabilities[] newArray(int size) { 78 return new RttRangingCapabilities[size]; 79 } 80 }; 81 82 /** 83 * @hide 84 */ 85 @Override getTechnology()86 public @RangingManager.RangingTechnology int getTechnology() { 87 return RangingManager.WIFI_NAN_RTT; 88 } 89 90 /** 91 * Indicates whether the hardware supports periodic ranging feature. 92 * 93 * @return {@code true} if periodic ranging is supported; {@code false} otherwise. 94 */ hasPeriodicRangingHardwareFeature()95 public boolean hasPeriodicRangingHardwareFeature() { 96 return mHasPeriodicRangingHardwareFeature; 97 } 98 99 /** 100 * @hide 101 */ getMaxSupportedBandwidth()102 public int getMaxSupportedBandwidth() { 103 return mMaxSupportedBandwidth; 104 } 105 106 /** 107 * @hide 108 */ getMaxSupportedRxChain()109 public int getMaxSupportedRxChain() { 110 return mMaxSupportedRxChain; 111 } 112 113 /** 114 * Builder for {@link RttRangingCapabilities} 115 * 116 * @hide 117 */ 118 public static class Builder { 119 private boolean mHasPeriodicRangingHardwareFeature = false; 120 private int mMaxSupportedBandwidth = CHANNEL_WIDTH_20MHZ; 121 122 private int mMaxSupportedRxChain = 0; 123 124 @NonNull setMaxSupportedBandwidth(int maxSupportedBandwidth)125 public Builder setMaxSupportedBandwidth(int maxSupportedBandwidth) { 126 mMaxSupportedBandwidth = maxSupportedBandwidth; 127 return this; 128 } 129 130 @NonNull setMaxSupportedRxChain(int maxSupportedRxChain)131 public Builder setMaxSupportedRxChain(int maxSupportedRxChain) { 132 mMaxSupportedRxChain = maxSupportedRxChain; 133 return this; 134 } 135 136 /** 137 * Sets whether hardware supports periodic ranging feature. 138 * 139 * @param periodicRangingHwFeature {@code true} if periodic ranging is supported; 140 * {@code false} otherwise. 141 * @return this {@link Builder} instance for method chaining. 142 */ 143 @NonNull setPeriodicRangingHardwareFeature(boolean periodicRangingHwFeature)144 public Builder setPeriodicRangingHardwareFeature(boolean periodicRangingHwFeature) { 145 mHasPeriodicRangingHardwareFeature = periodicRangingHwFeature; 146 return this; 147 } 148 149 /** 150 * Builds and returns an {@link RttRangingCapabilities} instance configured with the 151 * provided settings. 152 * 153 * @return a new {@link RttRangingCapabilities} instance. 154 */ 155 @NonNull build()156 public RttRangingCapabilities build() { 157 return new RttRangingCapabilities(this); 158 } 159 } 160 161 @Override toString()162 public String toString() { 163 return "RttRangingCapabilities{ " 164 + "mHasPeriodicRangingHwFeature=" 165 + mHasPeriodicRangingHardwareFeature 166 + " }"; 167 } 168 } 169