diff options
-rw-r--r-- | api/system-current.txt | 4 | ||||
-rw-r--r-- | core/java/android/app/SystemServiceRegistry.java | 42 | ||||
-rw-r--r-- | telephony/java/android/telephony/TelephonyFrameworkInitializer.java | 71 |
3 files changed, 77 insertions, 40 deletions
diff --git a/api/system-current.txt b/api/system-current.txt index e40fd24fd76e..cb327eb51c61 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -8655,6 +8655,10 @@ package android.telephony { method @Deprecated public static android.telephony.SubscriptionPlan.Builder createRecurringWeekly(java.time.ZonedDateTime); } + public class TelephonyFrameworkInitializer { + method public static void registerServiceWrappers(); + } + public final class TelephonyHistogram implements android.os.Parcelable { ctor public TelephonyHistogram(int, int, int); ctor public TelephonyHistogram(android.telephony.TelephonyHistogram); diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index d0ba879bd10e..d40261f7452a 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -166,12 +166,8 @@ import android.service.persistentdata.IPersistentDataBlockService; import android.service.persistentdata.PersistentDataBlockManager; import android.service.vr.IVrManager; import android.telecom.TelecomManager; -import android.telephony.CarrierConfigManager; -import android.telephony.SubscriptionManager; -import android.telephony.TelephonyManager; +import android.telephony.TelephonyFrameworkInitializer; import android.telephony.TelephonyRegistryManager; -import android.telephony.euicc.EuiccCardManager; -import android.telephony.euicc.EuiccManager; import android.util.ArrayMap; import android.util.Log; import android.view.ContextThemeWrapper; @@ -604,13 +600,6 @@ public final class SystemServiceRegistry { return new SystemUpdateManager(service); }}); - registerService(Context.TELEPHONY_SERVICE, TelephonyManager.class, - new CachedServiceFetcher<TelephonyManager>() { - @Override - public TelephonyManager createService(ContextImpl ctx) { - return new TelephonyManager(ctx.getOuterContext()); - }}); - registerService(Context.TELEPHONY_REGISTRY_SERVICE, TelephonyRegistryManager.class, new CachedServiceFetcher<TelephonyRegistryManager>() { @Override @@ -618,20 +607,6 @@ public final class SystemServiceRegistry { return new TelephonyRegistryManager(ctx); }}); - registerService(Context.TELEPHONY_SUBSCRIPTION_SERVICE, SubscriptionManager.class, - new CachedServiceFetcher<SubscriptionManager>() { - @Override - public SubscriptionManager createService(ContextImpl ctx) throws ServiceNotFoundException { - return new SubscriptionManager(ctx.getOuterContext()); - }}); - - registerService(Context.CARRIER_CONFIG_SERVICE, CarrierConfigManager.class, - new CachedServiceFetcher<CarrierConfigManager>() { - @Override - public CarrierConfigManager createService(ContextImpl ctx) { - return new CarrierConfigManager(ctx.getOuterContext()); - }}); - registerService(Context.TELECOM_SERVICE, TelecomManager.class, new CachedServiceFetcher<TelecomManager>() { @Override @@ -639,20 +614,6 @@ public final class SystemServiceRegistry { return new TelecomManager(ctx.getOuterContext()); }}); - registerService(Context.EUICC_SERVICE, EuiccManager.class, - new CachedServiceFetcher<EuiccManager>() { - @Override - public EuiccManager createService(ContextImpl ctx) { - return new EuiccManager(ctx.getOuterContext()); - }}); - - registerService(Context.EUICC_CARD_SERVICE, EuiccCardManager.class, - new CachedServiceFetcher<EuiccCardManager>() { - @Override - public EuiccCardManager createService(ContextImpl ctx) { - return new EuiccCardManager(ctx.getOuterContext()); - }}); - registerService(Context.UI_MODE_SERVICE, UiModeManager.class, new CachedServiceFetcher<UiModeManager>() { @Override @@ -1301,6 +1262,7 @@ public final class SystemServiceRegistry { JobSchedulerFrameworkInitializer.registerServiceWrappers(); BlobStoreManagerFrameworkInitializer.initialize(); + TelephonyFrameworkInitializer.registerServiceWrappers(); } 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/telephony/java/android/telephony/TelephonyFrameworkInitializer.java b/telephony/java/android/telephony/TelephonyFrameworkInitializer.java new file mode 100644 index 000000000000..b75d53379423 --- /dev/null +++ b/telephony/java/android/telephony/TelephonyFrameworkInitializer.java @@ -0,0 +1,71 @@ +/* + * 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.telephony; + +import android.annotation.SystemApi; +import android.app.SystemServiceRegistry; +import android.content.Context; +import android.telephony.euicc.EuiccCardManager; +import android.telephony.euicc.EuiccManager; + + +/** + * Class for performing registration for all telephony services. + * + * @hide + */ +@SystemApi +public class TelephonyFrameworkInitializer { + + private TelephonyFrameworkInitializer() { + } + + /** + * Called by {@link SystemServiceRegistry}'s static initializer and registers all telephony + * services to {@link Context}, so that {@link Context#getSystemService} can return them. + * + * @throws IllegalStateException if this is called from anywhere besides + * {@link SystemServiceRegistry} + */ + public static void registerServiceWrappers() { + SystemServiceRegistry.registerContextAwareService( + Context.TELEPHONY_SERVICE, + TelephonyManager.class, + context -> new TelephonyManager(context) + ); + SystemServiceRegistry.registerContextAwareService( + Context.TELEPHONY_SUBSCRIPTION_SERVICE, + SubscriptionManager.class, + context -> new SubscriptionManager(context) + ); + SystemServiceRegistry.registerContextAwareService( + Context.CARRIER_CONFIG_SERVICE, + CarrierConfigManager.class, + context -> new CarrierConfigManager(context) + ); + SystemServiceRegistry.registerContextAwareService( + Context.EUICC_SERVICE, + EuiccManager.class, + context -> new EuiccManager(context) + ); + SystemServiceRegistry.registerContextAwareService( + Context.EUICC_CARD_SERVICE, + EuiccCardManager.class, + context -> new EuiccCardManager(context) + ); + } +} |