• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.art;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.os.ArtModuleServiceManager;
23 import android.os.Build;
24 
25 import androidx.annotation.RequiresApi;
26 
27 import com.android.internal.annotations.GuardedBy;
28 
29 import java.util.Objects;
30 
31 /**
32  * Class for performing registration for the ART mainline module.
33  *
34  * @hide
35  */
36 @SystemApi(client = SystemApi.Client.SYSTEM_SERVER)
37 @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
38 public class ArtModuleServiceInitializer {
ArtModuleServiceInitializer()39     private ArtModuleServiceInitializer() {}
40 
41     @NonNull private static Object sLock = new Object();
42 
43     // The static field is associated with the class and the class loader that loads it. In the
44     // Pre-reboot Dexopt case, this class is loaded by a separate class loader, so it doesn't share
45     // the same static field with the class outside of the class loader.
46     @GuardedBy("sLock") @Nullable private static ArtModuleServiceManager sArtModuleServiceManager;
47 
48     /**
49      * Sets an instance of {@link ArtModuleServiceManager} that allows the ART mainline module to
50      * obtain ART binder services. This is called by the platform during the system server
51      * initialization.
52      */
setArtModuleServiceManager( @onNull ArtModuleServiceManager artModuleServiceManager)53     public static void setArtModuleServiceManager(
54             @NonNull ArtModuleServiceManager artModuleServiceManager) {
55         synchronized (sLock) {
56             if (sArtModuleServiceManager != null) {
57                 throw new IllegalStateException("ArtModuleServiceManager is already set");
58             }
59             sArtModuleServiceManager = artModuleServiceManager;
60         }
61     }
62 
63     /** @hide */
64     @NonNull
getArtModuleServiceManager()65     public static ArtModuleServiceManager getArtModuleServiceManager() {
66         synchronized (sLock) {
67             return Objects.requireNonNull(sArtModuleServiceManager);
68         }
69     }
70 }
71