1 /*
2  * Copyright 2023 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 package android.se.omapi;
17 
18 import android.annotation.FlaggedApi;
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.nfc.Flags;
23 
24 /**
25  * Class for performing registration for SE service.
26  *
27  * @hide
28  */
29 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
30 @FlaggedApi(Flags.FLAG_ENABLE_NFC_MAINLINE)
31 public class SeFrameworkInitializer {
SeFrameworkInitializer()32     private SeFrameworkInitializer() {}
33 
34     private static volatile SeServiceManager sSeServiceManager;
35 
36     /**
37      * Sets an instance of {@link SeServiceManager} that allows
38      * the se mainline module to register/obtain se binder services. This is called
39      * by the platform during the system initialization.
40      *
41      * @param seServiceManager instance of {@link SeServiceManager} that allows
42      * the se/nfc mainline module to register/obtain se binder services.
43      */
44     @FlaggedApi(Flags.FLAG_ENABLE_NFC_MAINLINE)
setSeServiceManager( @onNull SeServiceManager seServiceManager)45     public static void setSeServiceManager(
46             @NonNull SeServiceManager seServiceManager) {
47         if (sSeServiceManager != null) {
48             throw new IllegalStateException("setSeServiceManager called twice!");
49         }
50 
51         if (seServiceManager == null) {
52             throw new IllegalArgumentException("seServiceManager must not be null");
53         }
54 
55         sSeServiceManager = seServiceManager;
56     }
57 
58     /**
59      * Gets an instance of {@link SeServiceManager} that allows
60      * the se mainline module to register/obtain se binder services.
61      *
62      * @return instance of {@link SeServiceManager} that allows
63      * the se/nfc mainline module to register/obtain se binder services.
64      */
65     @FlaggedApi(Flags.FLAG_ENABLE_NFC_MAINLINE)
66     @Nullable
getSeServiceManager()67     public static SeServiceManager getSeServiceManager() {
68         return sSeServiceManager;
69     }
70 }
71