Merge "Expose APIs to register service manager wrappers."

This commit is contained in:
Makoto Onuki
2019-11-26 22:10:33 +00:00
committed by Android (Google) Code Review
3 changed files with 56 additions and 25 deletions

View File

@@ -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.
*
* <p>If this is called from other places, it throws a {@link IllegalStateException).
*
* TODO Make it a system API
*/
public static void registerServiceWrappers() {
SystemServiceRegistry.registerStaticService(

View File

@@ -652,6 +652,29 @@ package android.app {
method public boolean isStatusBarExpansionDisabled();
}
public final class SystemServiceRegistry {
method public static <TServiceClass> void registerContextAwareService(@NonNull String, @NonNull Class<TServiceClass>, @NonNull android.app.SystemServiceRegistry.ContextAwareServiceProducerWithBinder<TServiceClass>);
method public static <TServiceClass> void registerContextAwareService(@NonNull String, @NonNull Class<TServiceClass>, @NonNull android.app.SystemServiceRegistry.ContextAwareServiceProducerWithoutBinder<TServiceClass>);
method public static <TServiceClass> void registerStaticService(@NonNull String, @NonNull Class<TServiceClass>, @NonNull android.app.SystemServiceRegistry.StaticServiceProducerWithBinder<TServiceClass>);
method public static <TServiceClass> void registerStaticService(@NonNull String, @NonNull Class<TServiceClass>, @NonNull android.app.SystemServiceRegistry.StaticServiceProducerWithoutBinder<TServiceClass>);
}
public static interface SystemServiceRegistry.ContextAwareServiceProducerWithBinder<TServiceClass> {
method @NonNull public TServiceClass createService(@NonNull android.content.Context, @NonNull android.os.IBinder);
}
public static interface SystemServiceRegistry.ContextAwareServiceProducerWithoutBinder<TServiceClass> {
method @NonNull public TServiceClass createService(@NonNull android.content.Context);
}
public static interface SystemServiceRegistry.StaticServiceProducerWithBinder<TServiceClass> {
method @NonNull public TServiceClass createService(@NonNull android.os.IBinder);
}
public static interface SystemServiceRegistry.StaticServiceProducerWithoutBinder<TServiceClass> {
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 {

View File

@@ -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 <TServiceClass> type of the service wrapper class.
*
* @hide
*/
//@SystemApi TODO Make it a system API.
public interface StaticServiceProducerNoBinder<TServiceClass> {
@SystemApi
public interface StaticServiceProducerWithoutBinder<TServiceClass> {
/**
* 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<TServiceClass> {
/**
* 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<TServiceClass> {
@SystemApi
public interface ContextAwareServiceProducerWithoutBinder<TServiceClass> {
/**
* 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<TServiceClass> {
/**
* 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 <TServiceClass> void registerStaticService(
@NonNull String serviceName, @NonNull Class<TServiceClass> serviceWrapperClass,
@NonNull StaticServiceProducerWithBinder<TServiceClass> serviceProducer) {
@@ -1361,10 +1365,10 @@ public final class SystemServiceRegistry {
*
* @hide
*/
//@SystemApi TODO Make it a system API.
@SystemApi
public static <TServiceClass> void registerStaticService(
@NonNull String serviceName, @NonNull Class<TServiceClass> serviceWrapperClass,
@NonNull StaticServiceProducerNoBinder<TServiceClass> serviceProducer) {
@NonNull StaticServiceProducerWithoutBinder<TServiceClass> 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 <TServiceClass> void registerContextAwareService(
@NonNull String serviceName, @NonNull Class<TServiceClass> serviceWrapperClass,
@NonNull ContextAwareServiceProducerWithBinder<TServiceClass> serviceProducer) {
@@ -1422,10 +1426,10 @@ public final class SystemServiceRegistry {
*
* @hide
*/
//@SystemApi TODO Make it a system API.
@SystemApi
public static <TServiceClass> void registerContextAwareService(
@NonNull String serviceName, @NonNull Class<TServiceClass> serviceWrapperClass,
@NonNull ContextAwareServiceProducerNoBinder<TServiceClass> serviceProducer) {
@NonNull ContextAwareServiceProducerWithoutBinder<TServiceClass> serviceProducer) {
ensureInitializing("registerContextAwareService");
Preconditions.checkStringNotEmpty(serviceName);
Preconditions.checkNotNull(serviceWrapperClass);