diff --git a/api/module-lib-current.txt b/api/module-lib-current.txt index 69b52693aa464..63159edb8aeca 100644 --- a/api/module-lib-current.txt +++ b/api/module-lib-current.txt @@ -9,6 +9,14 @@ package android.annotation { } +package android.content.rollback { + + public class RollbackManagerFrameworkInitializer { + method public static void initialize(); + } + +} + package android.net { public final class TetheredClient implements android.os.Parcelable { diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index be07b3725bded..4a7f5eecde132 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -67,8 +67,7 @@ import android.content.pm.LauncherApps; import android.content.pm.PackageManager; import android.content.pm.ShortcutManager; import android.content.res.Resources; -import android.content.rollback.IRollbackManager; -import android.content.rollback.RollbackManager; +import android.content.rollback.RollbackManagerFrameworkInitializer; import android.debug.AdbManager; import android.debug.IAdbManager; import android.hardware.ConsumerIrManager; @@ -1250,16 +1249,6 @@ public final class SystemServiceRegistry { return new RoleControllerManager(ctx.getOuterContext()); }}); - registerService(Context.ROLLBACK_SERVICE, RollbackManager.class, - new CachedServiceFetcher() { - @Override - public RollbackManager createService(ContextImpl ctx) - throws ServiceNotFoundException { - IBinder b = ServiceManager.getServiceOrThrow(Context.ROLLBACK_SERVICE); - return new RollbackManager(ctx.getOuterContext(), - IRollbackManager.Stub.asInterface(b)); - }}); - registerService(Context.DYNAMIC_SYSTEM_SERVICE, DynamicSystemManager.class, new CachedServiceFetcher() { @Override @@ -1346,6 +1335,7 @@ public final class SystemServiceRegistry { AppSearchManagerFrameworkInitializer.initialize(); WifiFrameworkInitializer.registerServiceWrappers(); StatsFrameworkInitializer.registerServiceWrappers(); + RollbackManagerFrameworkInitializer.initialize(); } finally { // If any of the above code throws, we're in a pretty bad shape and the process // will likely crash, but we'll reset it just in case there's an exception handler... diff --git a/core/java/android/content/rollback/RollbackManagerFrameworkInitializer.java b/core/java/android/content/rollback/RollbackManagerFrameworkInitializer.java new file mode 100644 index 0000000000000..c5e4f99475504 --- /dev/null +++ b/core/java/android/content/rollback/RollbackManagerFrameworkInitializer.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2020 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.content.rollback; + +import android.annotation.SystemApi; +import android.app.SystemServiceRegistry; +import android.content.Context; + +/** + * Class holding initialization code for the RollbackManager module. + * + * @hide + */ +@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) +public class RollbackManagerFrameworkInitializer { + private RollbackManagerFrameworkInitializer() {} + + /** + * Called by {@link SystemServiceRegistry}'s static initializer and registers RollbackManager + * to {@link Context}, so that {@link Context#getSystemService} can return it. + * + * @throws IllegalStateException if this is called from anywhere besides + * {@link SystemServiceRegistry} + */ + public static void initialize() { + SystemServiceRegistry.registerContextAwareService( + Context.ROLLBACK_SERVICE, RollbackManager.class, + (context, b) -> new RollbackManager(context, IRollbackManager.Stub.asInterface(b))); + } +}