• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.telephony;
18 
19 import android.annotation.NonNull;
20 import android.app.SystemServiceRegistry;
21 import android.content.Context;
22 import android.os.TelephonyServiceManager;
23 import android.telephony.euicc.EuiccCardManager;
24 import android.telephony.euicc.EuiccManager;
25 import android.telephony.ims.ImsManager;
26 
27 import com.android.internal.util.Preconditions;
28 
29 
30 /**
31  * Class for performing registration for all telephony services.
32  *
33  * @hide
34  */
35 public class TelephonyFrameworkInitializer {
36 
TelephonyFrameworkInitializer()37     private TelephonyFrameworkInitializer() {
38     }
39 
40     private static volatile TelephonyServiceManager sTelephonyServiceManager;
41 
42     /**
43      * Sets an instance of {@link TelephonyServiceManager} that allows
44      * the telephony mainline module to register/obtain telephony binder services. This is called
45      * by the platform during the system initialization.
46      *
47      * @param telephonyServiceManager instance of {@link TelephonyServiceManager} that allows
48      * the telephony mainline module to register/obtain telephony binder services.
49      */
setTelephonyServiceManager( @onNull TelephonyServiceManager telephonyServiceManager)50     public static void setTelephonyServiceManager(
51             @NonNull TelephonyServiceManager telephonyServiceManager) {
52         Preconditions.checkState(sTelephonyServiceManager == null,
53                 "setTelephonyServiceManager called twice!");
54         sTelephonyServiceManager = Preconditions.checkNotNull(telephonyServiceManager);
55     }
56 
57     /**
58      * Called by {@link SystemServiceRegistry}'s static initializer and registers all telephony
59      * services to {@link Context}, so that {@link Context#getSystemService} can return them.
60      *
61      * @throws IllegalStateException if this is called from anywhere besides
62      * {@link SystemServiceRegistry}
63      */
registerServiceWrappers()64     public static void registerServiceWrappers() {
65         SystemServiceRegistry.registerContextAwareService(
66                 Context.TELEPHONY_SERVICE,
67                 TelephonyManager.class,
68                 context -> new TelephonyManager(context)
69         );
70         SystemServiceRegistry.registerContextAwareService(
71                 Context.TELEPHONY_SUBSCRIPTION_SERVICE,
72                 SubscriptionManager.class,
73                 context -> new SubscriptionManager(context)
74         );
75         SystemServiceRegistry.registerContextAwareService(
76                 Context.CARRIER_CONFIG_SERVICE,
77                 CarrierConfigManager.class,
78                 context -> new CarrierConfigManager(context)
79         );
80         SystemServiceRegistry.registerContextAwareService(
81                 Context.EUICC_SERVICE,
82                 EuiccManager.class,
83                 context -> new EuiccManager(context)
84         );
85         SystemServiceRegistry.registerContextAwareService(
86                 Context.EUICC_CARD_SERVICE,
87                 EuiccCardManager.class,
88                 context -> new EuiccCardManager(context)
89         );
90         SystemServiceRegistry.registerContextAwareService(
91                 Context.TELEPHONY_IMS_SERVICE,
92                 ImsManager.class,
93                 context -> new ImsManager(context)
94         );
95         SystemServiceRegistry.registerContextAwareService(
96                 Context.SMS_SERVICE,
97                 SmsManager.class,
98                 context -> SmsManager.getSmsManagerForContextAndSubscriptionId(context,
99                         SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)
100         );
101     }
102 
103     /** @hide */
getTelephonyServiceManager()104     public static TelephonyServiceManager getTelephonyServiceManager() {
105         return sTelephonyServiceManager;
106     }
107 }
108