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.secure; 18 19 import android.content.Context; 20 import android.os.Looper; 21 22 import androidx.annotation.NonNull; 23 24 import com.android.server.uwb.discovery.Transport; 25 import com.android.server.uwb.pm.RunningProfileSessionInfo; 26 import com.android.server.uwb.secure.omapi.OmapiConnection; 27 import com.android.server.uwb.secure.omapi.OmapiConnectionImpl; 28 import com.android.server.uwb.secure.provisioning.ProvisioningManager; 29 30 /** 31 * The factory is used to instance the secure session which setup secure channel and 32 * exchange UWB parameters. 33 */ 34 public class SecureFactory { 35 /** 36 * Create the instance of SecureSession for an UWB initiator. 37 */ 38 @NonNull makeInitiatorSecureSession( @onNull Context context, @NonNull Looper workLooper, @NonNull SecureSession.Callback secureSessionCallback, @NonNull RunningProfileSessionInfo runningProfileSessionInfo, @NonNull Transport transport, boolean isController)39 public static SecureSession makeInitiatorSecureSession( 40 @NonNull Context context, 41 @NonNull Looper workLooper, 42 @NonNull SecureSession.Callback secureSessionCallback, 43 @NonNull RunningProfileSessionInfo runningProfileSessionInfo, 44 @NonNull Transport transport, 45 boolean isController) { 46 OmapiConnection omapiConnection = new OmapiConnectionImpl(context); 47 SecureElementChannel secureElementChannel = new SecureElementChannel(omapiConnection); 48 FiRaSecureChannel fiRaSecureChannel = 49 new InitiatorSecureChannel( 50 secureElementChannel, transport, workLooper, runningProfileSessionInfo); 51 if (isController) { 52 return new ControllerInitiatorSession( 53 workLooper, 54 fiRaSecureChannel, 55 secureSessionCallback, 56 runningProfileSessionInfo); 57 } else { 58 return new ControleeInitiatorSession( 59 workLooper, 60 fiRaSecureChannel, 61 secureSessionCallback, 62 runningProfileSessionInfo); 63 } 64 } 65 66 /** 67 * Create the instance of SecureSession for an UWB responder. 68 */ 69 @NonNull makeResponderSecureSession( @onNull Context context, @NonNull Looper workLooper, @NonNull SecureSession.Callback secureSessionCallback, @NonNull RunningProfileSessionInfo runningProfileSessionInfo, @NonNull Transport transport, boolean isController)70 public static SecureSession makeResponderSecureSession( 71 @NonNull Context context, 72 @NonNull Looper workLooper, 73 @NonNull SecureSession.Callback secureSessionCallback, 74 @NonNull RunningProfileSessionInfo runningProfileSessionInfo, 75 @NonNull Transport transport, 76 boolean isController) { 77 OmapiConnection omapiConnection = new OmapiConnectionImpl(context); 78 SecureElementChannel secureElementChannel = new SecureElementChannel(omapiConnection); 79 FiRaSecureChannel fiRaSecureChannel = 80 new ResponderSecureChannel( 81 secureElementChannel, transport, workLooper, runningProfileSessionInfo); 82 if (isController) { 83 return new ControllerResponderSession( 84 workLooper, 85 fiRaSecureChannel, 86 secureSessionCallback, 87 runningProfileSessionInfo); 88 } else { 89 return new ControleeResponderSession( 90 workLooper, 91 fiRaSecureChannel, 92 secureSessionCallback, 93 runningProfileSessionInfo); 94 } 95 } 96 97 /** Creates an instance of the {@link ProvisioningManager}. */ 98 @NonNull makeProvisioningManager( @onNull Context context, @NonNull Looper workLooper)99 public static ProvisioningManager makeProvisioningManager( 100 @NonNull Context context, 101 @NonNull Looper workLooper) { 102 OmapiConnection omapiConnection = new OmapiConnectionImpl(context); 103 SecureElementChannel secureElementChannel = new SecureElementChannel(omapiConnection); 104 105 return new ProvisioningManager(secureElementChannel, workLooper); 106 } 107 } 108