Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 58fd3eb3 authored by Jayachandran C's avatar Jayachandran C Committed by Jayachandran Chinnakkannu
Browse files

Remove access to the telephony manager constructors from SystemRegisteryService

Introduce a new system API called TelephonyFrameworkInitializer
and invoke from SystemRegisteryService for registering the services

Bug: 144892231
Test: Telephony Sanity
      atest frameworks/opt/telephony/tests/telephonytests/

Change-Id: Ic1a2f66948c53f6426be733563fb050b67dcb320
parent 2f6c5fe3
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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);
+2 −40
Original line number Diff line number Diff line
@@ -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...
+71 −0
Original line number Diff line number Diff line
/*
 * 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)
        );
    }
}