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.usd; 18 19 import android.annotation.FlaggedApi; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.annotation.SystemApi; 23 import android.net.wifi.flags.Flags; 24 25 /** 26 * A class providing information about a USD discovery session with a specific peer. 27 * 28 * @hide 29 */ 30 @SystemApi 31 @FlaggedApi(Flags.FLAG_USD) 32 public class DiscoveryResult { 33 private final int mPeerId; 34 private final byte[] mServiceSpecificInfo; 35 @Config.ServiceProtoType 36 private final int mServiceProtoType; 37 private final boolean mIsFsdEnabled; 38 DiscoveryResult(Builder builder)39 private DiscoveryResult(Builder builder) { 40 mPeerId = builder.mPeerId; 41 mServiceSpecificInfo = builder.mServiceSpecificInfo; 42 mServiceProtoType = builder.mServiceProtoType; 43 mIsFsdEnabled = builder.mIsFsdEnabled; 44 } 45 46 /** 47 * Get the peer id. 48 */ getPeerId()49 public int getPeerId() { 50 return mPeerId; 51 } 52 53 /** 54 * Get the service specific info from the peer. If null, service discovery is without service 55 * specific info. 56 */ 57 @Nullable getServiceSpecificInfo()58 public byte[] getServiceSpecificInfo() { 59 return mServiceSpecificInfo; 60 } 61 62 /** 63 * Get service specific protocol type {@code (SERVICE_PROTO_TYPE_*)}. 64 */ 65 @Config.ServiceProtoType getServiceProtoType()66 public int getServiceProtoType() { 67 return mServiceProtoType; 68 } 69 70 /** 71 * Return whether Further Service Discovery (FSD) is enabled or not. 72 */ isFsdEnabled()73 public boolean isFsdEnabled() { 74 return mIsFsdEnabled; 75 } 76 77 /** 78 * {@code DiscoveryResult} builder static inner class. 79 */ 80 @FlaggedApi(Flags.FLAG_USD) 81 public static final class Builder { 82 private final int mPeerId; 83 private byte[] mServiceSpecificInfo; 84 private int mServiceProtoType; 85 private boolean mIsFsdEnabled; 86 87 /** 88 * Builder constructor. 89 * 90 * @param peerId an id of the peer 91 */ Builder(int peerId)92 public Builder(int peerId) { 93 mPeerId = peerId; 94 } 95 96 97 /** 98 * Sets the service specific information and returns a reference to this Builder enabling 99 * method chaining. 100 * 101 * @param serviceSpecificInfo the {@code serviceSpecificInfo} to set 102 * @return a reference to this Builder 103 */ 104 @NonNull setServiceSpecificInfo(@onNull byte[] serviceSpecificInfo)105 public Builder setServiceSpecificInfo(@NonNull byte[] serviceSpecificInfo) { 106 this.mServiceSpecificInfo = serviceSpecificInfo; 107 return this; 108 } 109 110 /** 111 * Sets the service protocol type and returns a reference to this Builder enabling method 112 * chaining. 113 * 114 * @param serviceProtoType the {@code serviceProtoType} to set 115 * @return a reference to this Builder 116 */ 117 @NonNull setServiceProtoType(@onfig.ServiceProtoType int serviceProtoType)118 public Builder setServiceProtoType(@Config.ServiceProtoType int serviceProtoType) { 119 this.mServiceProtoType = serviceProtoType; 120 return this; 121 } 122 123 /** 124 * Sets whether Further Service Discovery (FSD) is enabled or not and returns a reference 125 * to this Builder enabling method chaining. 126 * 127 * @param isFsdEnabled the {@code isFsdEnabled} to set 128 * @return a reference to this Builder 129 */ 130 @NonNull setFsdEnabled(boolean isFsdEnabled)131 public Builder setFsdEnabled(boolean isFsdEnabled) { 132 this.mIsFsdEnabled = isFsdEnabled; 133 return this; 134 } 135 136 /** 137 * Returns a {@code DiscoveryResult} built from the parameters previously set. 138 * 139 * @return a {@code DiscoveryResult} built with parameters of this {@code DiscoveryResult 140 * .Builder} 141 */ 142 @NonNull build()143 public DiscoveryResult build() { 144 return new DiscoveryResult(this); 145 } 146 } 147 } 148