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.oob; 18 19 import android.annotation.FlaggedApi; 20 import android.annotation.NonNull; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 import android.ranging.RangingConfig; 24 25 import com.android.ranging.flags.Flags; 26 27 import java.util.Objects; 28 29 /** 30 * Represents the configuration for an Out-of-Band (OOB) responder in a ranging session. 31 * This class contains configuration and device handle information for establishing 32 * a ranging session with an initiator. 33 */ 34 @FlaggedApi(Flags.FLAG_RANGING_STACK_ENABLED) 35 public final class OobResponderRangingConfig extends RangingConfig implements Parcelable { 36 37 private final android.ranging.oob.DeviceHandle mDeviceHandle; 38 OobResponderRangingConfig(Builder builder)39 private OobResponderRangingConfig(Builder builder) { 40 setRangingSessionType(RangingConfig.RANGING_SESSION_OOB); 41 mDeviceHandle = builder.mDeviceHandle; 42 } 43 44 OobResponderRangingConfig(Parcel in)45 private OobResponderRangingConfig(Parcel in) { 46 setRangingSessionType(in.readInt()); 47 mDeviceHandle = in.readParcelable( 48 DeviceHandle.class.getClassLoader(), android.ranging.oob.DeviceHandle.class); 49 } 50 51 @Override writeToParcel(@onNull Parcel dest, int flags)52 public void writeToParcel(@NonNull Parcel dest, int flags) { 53 dest.writeInt(getRangingSessionType()); 54 dest.writeParcelable(mDeviceHandle, flags); 55 } 56 57 @NonNull 58 public static final Creator<OobResponderRangingConfig> CREATOR = 59 new Creator<OobResponderRangingConfig>() { 60 @Override 61 public OobResponderRangingConfig createFromParcel(Parcel in) { 62 return new OobResponderRangingConfig(in); 63 } 64 65 @Override 66 public OobResponderRangingConfig[] newArray(int size) { 67 return new OobResponderRangingConfig[size]; 68 } 69 }; 70 71 /** 72 * Returns the DeviceHandle associated with this OOB responder. 73 * 74 * @return The DeviceHandle of the OOB responder. 75 */ 76 @NonNull getDeviceHandle()77 public android.ranging.oob.DeviceHandle getDeviceHandle() { 78 return mDeviceHandle; 79 } 80 81 @Override describeContents()82 public int describeContents() { 83 return 0; 84 } 85 86 /** 87 * Builder class for creating instances of {@link OobResponderRangingConfig}. 88 */ 89 public static final class Builder { 90 private final DeviceHandle mDeviceHandle; 91 92 /** 93 * Constructs a new Builder instance with the specified DeviceHandle. 94 * 95 * @param deviceHandle The DeviceHandle to associate with this OOB responder. 96 */ Builder(@onNull DeviceHandle deviceHandle)97 public Builder(@NonNull DeviceHandle deviceHandle) { 98 Objects.requireNonNull(deviceHandle); 99 mDeviceHandle = deviceHandle; 100 } 101 102 /** 103 * Builds an instance of {@link OobResponderRangingConfig} with the provided parameters. 104 * 105 * @return A new OobResponderRangingParams instance. 106 */ 107 @NonNull build()108 public OobResponderRangingConfig build() { 109 return new OobResponderRangingConfig(this); 110 } 111 } 112 113 @Override toString()114 public String toString() { 115 return "OobResponderRangingParams{ " 116 + "mDeviceHandle=" 117 + mDeviceHandle 118 + ", " 119 + super.toString() 120 + ", " 121 + " }"; 122 } 123 } 124