1 /* 2 * Copyright (C) 2022 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 com.android.server.uwb.pm; 18 19 import androidx.annotation.NonNull; 20 21 import com.android.server.uwb.secure.csml.ControleeInfo; 22 import com.android.server.uwb.secure.csml.UwbCapability; 23 import com.android.server.uwb.util.ObjectIdentifier; 24 25 import java.util.List; 26 import java.util.Optional; 27 28 /** 29 * Provides the session information for this profile 30 */ 31 public class RunningProfileSessionInfo { 32 /** see {@link ControleeInfo} required by the controlee */ 33 @NonNull 34 public final Optional<ControleeInfo> controleeInfo; 35 /** see {@link UwbCapability} */ 36 @NonNull 37 public final UwbCapability uwbCapability; 38 /** The possible ADF OIDs used in the responder device, required by initiator. */ 39 @NonNull 40 public final Optional<List<ObjectIdentifier>> selectableOidsOfResponder; 41 /** 42 * The OID of ADF which was provisioned successfully for the current profile, 43 * required by initiator. 44 */ 45 @NonNull 46 public final ObjectIdentifier oidOfProvisionedAdf; 47 /** The UWB session ID for multicast case, required by controller */ 48 @NonNull 49 public final Optional<Integer> sharedPrimarySessionId; 50 /** The UWB session ID for multicast case, required by controller */ 51 @NonNull 52 public final Optional<byte[]> sharedPrimarySessionKeyInfo; 53 /** The secure blob can be loaded into the FiRa applet. */ 54 @NonNull 55 public final Optional<byte[]> secureBlob; 56 RunningProfileSessionInfo( Optional<ControleeInfo> controleeInfo, UwbCapability uwbCapability, ObjectIdentifier oidOfProvisionedAdf, Optional<List<ObjectIdentifier>> selectableOidsOfResponder, Optional<Integer> sharedPrimarySessionId, Optional<byte[]> sharedPrimarySessionKeyInfo, Optional<byte[]> secureBlob)57 private RunningProfileSessionInfo( 58 Optional<ControleeInfo> controleeInfo, 59 UwbCapability uwbCapability, 60 ObjectIdentifier oidOfProvisionedAdf, 61 Optional<List<ObjectIdentifier>> selectableOidsOfResponder, 62 Optional<Integer> sharedPrimarySessionId, 63 Optional<byte[]> sharedPrimarySessionKeyInfo, 64 Optional<byte[]> secureBlob) { 65 this.controleeInfo = controleeInfo; 66 this.uwbCapability = uwbCapability; 67 this.oidOfProvisionedAdf = oidOfProvisionedAdf; 68 this.selectableOidsOfResponder = selectableOidsOfResponder; 69 this.sharedPrimarySessionId = sharedPrimarySessionId; 70 this.sharedPrimarySessionKeyInfo = sharedPrimarySessionKeyInfo; 71 this.secureBlob = secureBlob; 72 } 73 74 /** Builder for the {@link RunningProfileSessionInfo} */ 75 public static class Builder { 76 private Optional<ControleeInfo> mControleeInfo; 77 private UwbCapability mUwbCapability; 78 private Optional<List<ObjectIdentifier>> mSelectableOidsOfResponder = Optional.empty(); 79 private ObjectIdentifier mOidOfProvisionedAdf; 80 private Optional<Integer> mSharedPrimarySessionId = Optional.empty(); 81 private Optional<byte[]> mSecureBlob = Optional.empty(); 82 private Optional<byte[]> mSharedPrimarySessionKeyInfo = Optional.empty(); 83 84 /** The constructor {@link RunningProfileSessionInfo.Builder} */ Builder(@onNull UwbCapability uwbCapability, @NonNull ObjectIdentifier oidOfProvisionedAdf)85 public Builder(@NonNull UwbCapability uwbCapability, 86 @NonNull ObjectIdentifier oidOfProvisionedAdf) { 87 this.mUwbCapability = uwbCapability; 88 this.mOidOfProvisionedAdf = oidOfProvisionedAdf; 89 } 90 91 /** Sets the {@link ControleeInfo}. */ 92 @NonNull setControleeInfo(@onNull ControleeInfo controleeInfo)93 public Builder setControleeInfo(@NonNull ControleeInfo controleeInfo) { 94 this.mControleeInfo = Optional.of(controleeInfo); 95 return this; 96 } 97 98 /** Sets the possible ADF OIDs used in the responder device. */ 99 @NonNull setSelectableOidsOfResponder( @onNull List<ObjectIdentifier> selectableOidsOfResponder)100 public Builder setSelectableOidsOfResponder( 101 @NonNull List<ObjectIdentifier> selectableOidsOfResponder) { 102 this.mSelectableOidsOfResponder = Optional.of(selectableOidsOfResponder); 103 return this; 104 } 105 106 /** Sets the UWB session ID and session key info for multicast case. */ 107 @NonNull setSharedPrimarySessionIdAndSessionKeyInfo( int sharedPrimarySessionId, @NonNull byte[] sharedPrimarySessionKeyInfo)108 public Builder setSharedPrimarySessionIdAndSessionKeyInfo( 109 int sharedPrimarySessionId, 110 @NonNull byte[] sharedPrimarySessionKeyInfo) { 111 this.mSharedPrimarySessionId = Optional.of(sharedPrimarySessionId); 112 this.mSharedPrimarySessionKeyInfo = Optional.of(sharedPrimarySessionKeyInfo); 113 return this; 114 } 115 116 /** Sets the secure blob can be loaded into the FiRa applet. */ 117 @NonNull setSecureBlob(@onNull byte[] secureBlob)118 public Builder setSecureBlob(@NonNull byte[] secureBlob) { 119 mSecureBlob = Optional.of(secureBlob); 120 return this; 121 } 122 123 /** Builds the instance of {@link RunningProfileSessionInfo} */ 124 @NonNull build()125 public RunningProfileSessionInfo build() { 126 return new RunningProfileSessionInfo( 127 mControleeInfo, 128 mUwbCapability, 129 mOidOfProvisionedAdf, 130 mSelectableOidsOfResponder, 131 mSharedPrimarySessionId, 132 mSharedPrimarySessionKeyInfo, 133 mSecureBlob); 134 } 135 } 136 } 137