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 package android.os; 17 18 import android.annotation.FlaggedApi; 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.SystemApi; 22 import android.content.pm.Flags; 23 24 /** 25 * Provides a way to register and obtain the system service binder objects managed by the ART 26 * mainline module. 27 * 28 * Only the ART mainline module will be able to access an instance of this class. 29 * 30 * @hide 31 */ 32 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) 33 public class ArtModuleServiceManager { 34 /** @hide */ ArtModuleServiceManager()35 public ArtModuleServiceManager() {} 36 37 /** A class that exposes the method to obtain each system service. */ 38 public static final class ServiceRegisterer { 39 @NonNull private final String mServiceName; 40 41 /** @hide */ ServiceRegisterer(@onNull String serviceName)42 public ServiceRegisterer(@NonNull String serviceName) { 43 mServiceName = serviceName; 44 } 45 46 /** 47 * Returns the service from the service manager. 48 * 49 * If the service is not running, servicemanager will attempt to start it, and this function 50 * will wait for it to be ready. 51 * 52 * @return {@code null} only if there are permission problems or fatal errors. 53 */ 54 @Nullable waitForService()55 public IBinder waitForService() { 56 return ServiceManager.waitForService(mServiceName); 57 } 58 } 59 60 /** Returns {@link ServiceRegisterer} for the "artd" service. */ 61 @NonNull getArtdServiceRegisterer()62 public ServiceRegisterer getArtdServiceRegisterer() { 63 return new ServiceRegisterer("artd"); 64 } 65 66 /** Returns {@link ServiceRegisterer} for the "artd_pre_reboot" service. */ 67 @NonNull 68 @FlaggedApi(Flags.FLAG_USE_ART_SERVICE_V2) getArtdPreRebootServiceRegisterer()69 public ServiceRegisterer getArtdPreRebootServiceRegisterer() { 70 return new ServiceRegisterer("artd_pre_reboot"); 71 } 72 73 /** Returns {@link ServiceRegisterer} for the "dexopt_chroot_setup" service. */ 74 @NonNull 75 @FlaggedApi(Flags.FLAG_USE_ART_SERVICE_V2) getDexoptChrootSetupServiceRegisterer()76 public ServiceRegisterer getDexoptChrootSetupServiceRegisterer() { 77 return new ServiceRegisterer("dexopt_chroot_setup"); 78 } 79 } 80