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.p2p; 18 19 import android.annotation.FlaggedApi; 20 import android.annotation.NonNull; 21 import android.annotation.RequiresApi; 22 import android.annotation.SystemApi; 23 import android.net.wifi.OuiKeyedData; 24 import android.net.wifi.ParcelUtil; 25 import android.os.Build; 26 import android.os.Parcel; 27 import android.os.Parcelable; 28 29 import com.android.modules.utils.build.SdkLevel; 30 import com.android.wifi.flags.Flags; 31 32 import java.util.ArrayList; 33 import java.util.Collections; 34 import java.util.List; 35 36 /** 37 * A class representing Wi-Fi P2P extended listen parameters. 38 * @hide 39 */ 40 @SystemApi 41 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) 42 public final class WifiP2pExtListenParams implements Parcelable { 43 /** List of {@link OuiKeyedData} providing vendor-specific configuration data. */ 44 private @NonNull List<OuiKeyedData> mVendorData; 45 WifiP2pExtListenParams(@onNull List<OuiKeyedData> vendorData)46 private WifiP2pExtListenParams(@NonNull List<OuiKeyedData> vendorData) { 47 mVendorData = new ArrayList<>(vendorData); 48 } 49 50 /** 51 * Get the vendor-provided configuration data, if it exists. See {@link 52 * Builder#setVendorData(List)} 53 * 54 * @return Vendor configuration data, or empty list if it does not exist. 55 */ 56 @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) 57 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) 58 @NonNull getVendorData()59 public List<OuiKeyedData> getVendorData() { 60 if (!SdkLevel.isAtLeastV()) { 61 throw new UnsupportedOperationException(); 62 } 63 return mVendorData; 64 } 65 66 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) 67 @Override toString()68 public String toString() { 69 StringBuffer sbuf = new StringBuffer(); 70 sbuf.append("\n vendorData: ").append(mVendorData); 71 return sbuf.toString(); 72 } 73 74 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) 75 @Override describeContents()76 public int describeContents() { 77 return 0; 78 } 79 80 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) 81 @Override writeToParcel(@onNull Parcel dest, int flags)82 public void writeToParcel(@NonNull Parcel dest, int flags) { 83 dest.writeList(mVendorData); 84 } 85 86 /** @hide */ WifiP2pExtListenParams(@onNull Parcel in)87 WifiP2pExtListenParams(@NonNull Parcel in) { 88 this.mVendorData = ParcelUtil.readOuiKeyedDataList(in); 89 } 90 91 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) 92 @NonNull 93 public static final Creator<WifiP2pExtListenParams> CREATOR = 94 new Creator<WifiP2pExtListenParams>() { 95 public WifiP2pExtListenParams createFromParcel(Parcel in) { 96 return new WifiP2pExtListenParams(in); 97 } 98 99 public WifiP2pExtListenParams[] newArray(int size) { 100 return new WifiP2pExtListenParams[size]; 101 } 102 }; 103 104 /** 105 * Builder for {@link WifiP2pExtListenParams}. 106 */ 107 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) 108 public static final class Builder { 109 private @NonNull List<OuiKeyedData> mVendorData = Collections.emptyList(); 110 111 /** 112 * Constructor for {@link Builder}. 113 */ 114 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) Builder()115 public Builder() { 116 } 117 118 /** 119 * Set additional vendor-provided configuration data. 120 * 121 * @param vendorData List of {@link android.net.wifi.OuiKeyedData} containing the 122 * vendor-provided configuration data. Note that multiple elements with 123 * the same OUI are allowed. 124 * @return Builder for chaining. 125 */ 126 @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) 127 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) 128 @NonNull setVendorData(@onNull List<OuiKeyedData> vendorData)129 public Builder setVendorData(@NonNull List<OuiKeyedData> vendorData) { 130 if (!SdkLevel.isAtLeastV()) { 131 throw new UnsupportedOperationException(); 132 } 133 if (vendorData == null) { 134 throw new IllegalArgumentException("setVendorData received a null value"); 135 } 136 mVendorData = vendorData; 137 return this; 138 } 139 140 /** 141 * Construct a WifiP2pExtListenParams object with the specified parameters. 142 */ 143 @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API) 144 @NonNull build()145 public WifiP2pExtListenParams build() { 146 return new WifiP2pExtListenParams(mVendorData); 147 } 148 } 149 } 150