From 0ceb3e03943530ff14b0df709d915d402c6819ae Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Mon, 18 Nov 2019 10:37:10 -0800 Subject: [PATCH] Expose APIs to register service manager wrappers. Bug: 143788029 Test: boot & tree hugger Change-Id: I6a1ce9d9603ce79d2ddb14f2a946fb51be25a9e4 --- .../job/JobSchedulerFrameworkInitializer.java | 4 +- api/system-current.txt | 27 ++++++++++ .../android/app/SystemServiceRegistry.java | 50 ++++++++++--------- 3 files changed, 56 insertions(+), 25 deletions(-) diff --git a/apex/jobscheduler/framework/java/android/app/job/JobSchedulerFrameworkInitializer.java b/apex/jobscheduler/framework/java/android/app/job/JobSchedulerFrameworkInitializer.java index 3835d93ebeb92..0c4fcb4ec1b00 100644 --- a/apex/jobscheduler/framework/java/android/app/job/JobSchedulerFrameworkInitializer.java +++ b/apex/jobscheduler/framework/java/android/app/job/JobSchedulerFrameworkInitializer.java @@ -16,6 +16,7 @@ package android.app.job; +import android.annotation.SystemApi; import android.app.JobSchedulerImpl; import android.app.SystemServiceRegistry; import android.content.Context; @@ -28,6 +29,7 @@ import android.os.PowerWhitelistManager; * * @hide */ +@SystemApi public class JobSchedulerFrameworkInitializer { private JobSchedulerFrameworkInitializer() { } @@ -38,8 +40,6 @@ public class JobSchedulerFrameworkInitializer { * {@link Context#getSystemService} can return them. * *

If this is called from other places, it throws a {@link IllegalStateException). - * - * TODO Make it a system API */ public static void registerServiceWrappers() { SystemServiceRegistry.registerStaticService( diff --git a/api/system-current.txt b/api/system-current.txt index b306c0f2539e9..97c5b07d73262 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -652,6 +652,29 @@ package android.app { method public boolean isStatusBarExpansionDisabled(); } + public final class SystemServiceRegistry { + method public static void registerContextAwareService(@NonNull String, @NonNull Class, @NonNull android.app.SystemServiceRegistry.ContextAwareServiceProducerWithBinder); + method public static void registerContextAwareService(@NonNull String, @NonNull Class, @NonNull android.app.SystemServiceRegistry.ContextAwareServiceProducerWithoutBinder); + method public static void registerStaticService(@NonNull String, @NonNull Class, @NonNull android.app.SystemServiceRegistry.StaticServiceProducerWithBinder); + method public static void registerStaticService(@NonNull String, @NonNull Class, @NonNull android.app.SystemServiceRegistry.StaticServiceProducerWithoutBinder); + } + + public static interface SystemServiceRegistry.ContextAwareServiceProducerWithBinder { + method @NonNull public TServiceClass createService(@NonNull android.content.Context, @NonNull android.os.IBinder); + } + + public static interface SystemServiceRegistry.ContextAwareServiceProducerWithoutBinder { + method @NonNull public TServiceClass createService(@NonNull android.content.Context); + } + + public static interface SystemServiceRegistry.StaticServiceProducerWithBinder { + method @NonNull public TServiceClass createService(@NonNull android.os.IBinder); + } + + public static interface SystemServiceRegistry.StaticServiceProducerWithoutBinder { + method @NonNull public TServiceClass createService(); + } + public class UiModeManager { method @RequiresPermission(android.Manifest.permission.ENTER_CAR_MODE_PRIORITIZED) public void enableCarMode(@IntRange(from=0) int, int); field public static final String ACTION_ENTER_CAR_MODE_PRIORITIZED = "android.app.action.ENTER_CAR_MODE_PRIORITIZED"; @@ -1091,6 +1114,10 @@ package android.app.job { method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public abstract int scheduleAsPackage(@NonNull android.app.job.JobInfo, @NonNull String, int, String); } + public class JobSchedulerFrameworkInitializer { + method public static void registerServiceWrappers(); + } + } package android.app.prediction { diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index 0bfd2c6f5f706..d9b3d3bf57e80 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -19,6 +19,7 @@ package android.app; import android.accounts.AccountManager; import android.accounts.IAccountManager; import android.annotation.NonNull; +import android.annotation.SystemApi; import android.app.ContextImpl.ServiceInitializationState; import android.app.admin.DevicePolicyManager; import android.app.admin.IDevicePolicyManager; @@ -193,6 +194,7 @@ import java.util.Map; * * @hide */ +@SystemApi public final class SystemServiceRegistry { private static final String TAG = "SystemServiceRegistry"; @@ -1191,7 +1193,6 @@ public final class SystemServiceRegistry { try { // Note: the following functions need to be @SystemApis, once they become mainline // modules. - JobSchedulerFrameworkInitializer.registerServiceWrappers(); BlobStoreManagerFrameworkInitializer.initialize(); TelephonyFrameworkInitializer.registerServiceWrappers(); @@ -1246,18 +1247,20 @@ public final class SystemServiceRegistry { /** * Callback interface used as a parameter to {@link #registerStaticService( - * String, Class, StaticServiceProducerNoBinder)}, which generates a service wrapper instance - * that's not tied to any context and does not take a service binder object in the constructor. + * String, Class, StaticServiceProducerWithoutBinder)}, which generates a service wrapper + * instance that's not tied to any context and does not take a service binder object in the + * constructor. * * @param type of the service wrapper class. * * @hide */ - //@SystemApi TODO Make it a system API. - public interface StaticServiceProducerNoBinder { + @SystemApi + public interface StaticServiceProducerWithoutBinder { /** * Return a new service wrapper of type {@code TServiceClass}. */ + @NonNull TServiceClass createService(); } @@ -1270,18 +1273,19 @@ public final class SystemServiceRegistry { * * @hide */ - //@SystemApi TODO Make it a system API. + @SystemApi public interface StaticServiceProducerWithBinder { /** * Return a new service wrapper of type {@code TServiceClass} backed by a given * service binder object. */ - TServiceClass createService(IBinder serviceBinder); + @NonNull + TServiceClass createService(@NonNull IBinder serviceBinder); } /** * Callback interface used as a parameter to {@link #registerContextAwareService( - * String, Class, ContextAwareServiceProducerNoBinder)}, + * String, Class, ContextAwareServiceProducerWithoutBinder)}, * which generates a service wrapper instance * that's tied to a specific context and does not take a service binder object in the * constructor. @@ -1290,15 +1294,15 @@ public final class SystemServiceRegistry { * * @hide */ - //@SystemApi TODO Make it a system API. - public interface ContextAwareServiceProducerNoBinder { + @SystemApi + public interface ContextAwareServiceProducerWithoutBinder { /** * Return a new service wrapper of type {@code TServiceClass} tied to a given * {@code context}. - * - * TODO Do we need to pass the "base context" too? */ - TServiceClass createService(Context context); + @NonNull + //TODO Do we need to pass the "base context" too? + TServiceClass createService(@NonNull Context context); } /** @@ -1311,15 +1315,15 @@ public final class SystemServiceRegistry { * * @hide */ - //@SystemApi TODO Make it a system API. + @SystemApi public interface ContextAwareServiceProducerWithBinder { /** * Return a new service wrapper of type {@code TServiceClass} backed by a given * service binder object that's tied to a given {@code context}. - * - * TODO Do we need to pass the "base context" too? */ - TServiceClass createService(Context context, IBinder serviceBinder); + @NonNull + //TODO Do we need to pass the "base context" too? + TServiceClass createService(@NonNull Context context, @NonNull IBinder serviceBinder); } /** @@ -1337,7 +1341,7 @@ public final class SystemServiceRegistry { * * @hide */ - //@SystemApi TODO Make it a system API. + @SystemApi public static void registerStaticService( @NonNull String serviceName, @NonNull Class serviceWrapperClass, @NonNull StaticServiceProducerWithBinder serviceProducer) { @@ -1361,10 +1365,10 @@ public final class SystemServiceRegistry { * * @hide */ - //@SystemApi TODO Make it a system API. + @SystemApi public static void registerStaticService( @NonNull String serviceName, @NonNull Class serviceWrapperClass, - @NonNull StaticServiceProducerNoBinder serviceProducer) { + @NonNull StaticServiceProducerWithoutBinder serviceProducer) { ensureInitializing("registerStaticService"); Preconditions.checkStringNotEmpty(serviceName); Preconditions.checkNotNull(serviceWrapperClass); @@ -1394,7 +1398,7 @@ public final class SystemServiceRegistry { * * @hide */ - //@SystemApi TODO Make it a system API. + @SystemApi public static void registerContextAwareService( @NonNull String serviceName, @NonNull Class serviceWrapperClass, @NonNull ContextAwareServiceProducerWithBinder serviceProducer) { @@ -1422,10 +1426,10 @@ public final class SystemServiceRegistry { * * @hide */ - //@SystemApi TODO Make it a system API. + @SystemApi public static void registerContextAwareService( @NonNull String serviceName, @NonNull Class serviceWrapperClass, - @NonNull ContextAwareServiceProducerNoBinder serviceProducer) { + @NonNull ContextAwareServiceProducerWithoutBinder serviceProducer) { ensureInitializing("registerContextAwareService"); Preconditions.checkStringNotEmpty(serviceName); Preconditions.checkNotNull(serviceWrapperClass);