diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-08-23 15:38:42 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-08-23 15:38:42 +0000 |
commit | 903102c43014cccea9d0365a0700bd617faf2453 (patch) | |
tree | 9572fa68b10f6fd2eacea3d4734555f6d3b8f108 | |
parent | 635c8934dcf385af5d506c8f52839b523454a681 (diff) | |
parent | 7d6d9ca359e8e85a21191dad51967abdfe19f539 (diff) |
Merge "Don't refer to DeviceIdle from SystemServiceRegistry"
-rw-r--r-- | api/test-current.txt | 1 | ||||
-rw-r--r-- | config/preloaded-classes | 1 | ||||
-rw-r--r-- | config/preloaded-classes-extra | 1 | ||||
-rw-r--r-- | core/java/android/app/DeviceIdleFrameworkInitializer.java | 36 | ||||
-rw-r--r-- | core/java/android/app/SystemServiceRegistry.java | 34 | ||||
-rw-r--r-- | core/java/android/content/Context.java | 1 |
6 files changed, 59 insertions, 15 deletions
diff --git a/api/test-current.txt b/api/test-current.txt index 4eda495d34d1..7e1c67de2c16 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -664,6 +664,7 @@ package android.content { method public void setContentCaptureOptions(@Nullable android.content.ContentCaptureOptions); field public static final String BUGREPORT_SERVICE = "bugreport"; field public static final String CONTENT_CAPTURE_MANAGER_SERVICE = "content_capture"; + field public static final String DEVICE_IDLE_CONTROLLER = "deviceidle"; field public static final String PERMISSION_SERVICE = "permission"; field public static final String ROLLBACK_SERVICE = "rollback"; field public static final String STATUS_BAR_SERVICE = "statusbar"; diff --git a/config/preloaded-classes b/config/preloaded-classes index ea50999e9d56..778a4d7bcda7 100644 --- a/config/preloaded-classes +++ b/config/preloaded-classes @@ -200,6 +200,7 @@ android.app.ContentProviderHolder android.app.ContextImpl$1 android.app.ContextImpl$ApplicationContentResolver android.app.ContextImpl +android.app.DeviceIdleFrameworkInitializer android.app.DexLoadReporter android.app.Dialog$ListenersHandler android.app.Dialog diff --git a/config/preloaded-classes-extra b/config/preloaded-classes-extra index 94849fb97433..4bfa873f63f2 100644 --- a/config/preloaded-classes-extra +++ b/config/preloaded-classes-extra @@ -1,5 +1,6 @@ # JobSchedulerFrameworkInitializer must always be preloaded because it registers the job scheduler # service wrapper to SystemServiceRegistry. +android.app.DeviceIdleFrameworkInitializer android.app.job.JobSchedulerFrameworkInitializer android.icu.impl.coll.CollationRoot android.icu.impl.IDNA2003 diff --git a/core/java/android/app/DeviceIdleFrameworkInitializer.java b/core/java/android/app/DeviceIdleFrameworkInitializer.java new file mode 100644 index 000000000000..b304afb7ddeb --- /dev/null +++ b/core/java/android/app/DeviceIdleFrameworkInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.app; + +import android.content.Context; +import android.os.DeviceIdleManager; +import android.os.IDeviceIdleController; + +/** + * This class needs to be pre-loaded by zygote. This is where the device idle manager wrapper + * is registered. + * + * @hide + */ +public class DeviceIdleFrameworkInitializer { + static { + SystemServiceRegistry.registerCachedService( + Context.DEVICE_IDLE_CONTROLLER, DeviceIdleManager.class, + (context, b) -> new DeviceIdleManager( + context.getOuterContext(), IDeviceIdleController.Stub.asInterface(b))); + } +} diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index 635b9b02a944..e4fd5665d318 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -127,12 +127,10 @@ import android.os.BatteryManager; import android.os.BatteryStats; import android.os.BugreportManager; import android.os.Build; -import android.os.DeviceIdleManager; import android.os.DropBoxManager; import android.os.HardwarePropertiesManager; import android.os.IBatteryPropertiesRegistrar; import android.os.IBinder; -import android.os.IDeviceIdleController; import android.os.IDumpstate; import android.os.IHardwarePropertiesManager; import android.os.IPowerManager; @@ -195,6 +193,7 @@ import com.android.internal.os.IDropBoxManagerService; import com.android.internal.policy.PhoneLayoutInflater; import java.util.Map; +import java.util.function.BiFunction; import java.util.function.Function; /** @@ -1219,17 +1218,6 @@ public final class SystemServiceRegistry { } }); - registerService(Context.DEVICE_IDLE_CONTROLLER, DeviceIdleManager.class, - new CachedServiceFetcher<DeviceIdleManager>() { - @Override - public DeviceIdleManager createService(ContextImpl ctx) - throws ServiceNotFoundException { - IDeviceIdleController service = IDeviceIdleController.Stub.asInterface( - ServiceManager.getServiceOrThrow( - Context.DEVICE_IDLE_CONTROLLER)); - return new DeviceIdleManager(ctx.getOuterContext(), service); - }}); - registerService(Context.TIME_DETECTOR_SERVICE, TimeDetector.class, new CachedServiceFetcher<TimeDetector>() { @Override @@ -1330,9 +1318,9 @@ public final class SystemServiceRegistry { * * @hide */ - public static <T> void registerStaticService(String serviceName, Class<T> serviceClass, + public static <T> void registerStaticService(String serviceName, Class<T> serviceWrapperClass, Function<IBinder, T> serviceFetcher) { - registerService(serviceName, serviceClass, + registerService(serviceName, serviceWrapperClass, new StaticServiceFetcher<T>() { @Override public T createService() throws ServiceNotFoundException { @@ -1342,6 +1330,22 @@ public final class SystemServiceRegistry { } /** + * APEX modules will use it to register their service wrapper. + * + * @hide + */ + public static <T> void registerCachedService(String serviceName, Class<T> serviceWrapperClass, + BiFunction<ContextImpl, IBinder, T> serviceFetcher) { + registerService(serviceName, serviceWrapperClass, + new CachedServiceFetcher<T>() { + @Override + public T createService(ContextImpl ctx) throws ServiceNotFoundException { + IBinder b = ServiceManager.getServiceOrThrow(serviceName); + return serviceFetcher.apply(ctx, b); + }}); + } + + /** * Base interface for classes that fetch services. * These objects must only be created during static initialization. */ diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index 2c53faa5c890..a3e940b709ac 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -4190,6 +4190,7 @@ public abstract class Context { * @see #getSystemService(String) * @hide */ + @TestApi public static final String DEVICE_IDLE_CONTROLLER = "deviceidle"; /** |