TelephonyComponentFactory.java revision 0a567c9ed954f295df83c753239646c6f6a04128
1/*
2 * Copyright (C) 2015 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
17package com.android.internal.telephony;
18
19import android.content.Context;
20import android.os.Handler;
21import android.os.PowerManager;
22
23import com.android.ims.ImsManager;
24import com.android.internal.telephony.cdma.CdmaSubscriptionSourceManager;
25import com.android.internal.telephony.cdma.EriManager;
26import com.android.internal.telephony.dataconnection.DcTracker;
27import com.android.internal.telephony.uicc.IccCardProxy;
28
29/**
30 * This class has one-line methods to instantiate objects only. The purpose is to make code
31 * unit-test friendly and use this class as a way to do dependency injection. Instantiating objects
32 * this way makes it easier to mock them in tests.
33 */
34public class TelephonyComponentFactory {
35    private static TelephonyComponentFactory sInstance;
36
37    public static TelephonyComponentFactory getInstance() {
38        if (sInstance == null) {
39            sInstance = new TelephonyComponentFactory();
40        }
41        return sInstance;
42    }
43
44    public GsmCdmaCallTracker makeGsmCdmaCallTracker(GsmCdmaPhone phone) {
45        return new GsmCdmaCallTracker(phone);
46    }
47
48    public SmsStorageMonitor makeSmsStorageMonitor(Phone phone) {
49        return new SmsStorageMonitor(phone);
50    }
51
52    public SmsUsageMonitor makeSmsUsageMonitor(Context context) {
53        return new SmsUsageMonitor(context);
54    }
55
56    public ServiceStateTracker makeServiceStateTracker(GsmCdmaPhone phone, CommandsInterface ci) {
57        return new ServiceStateTracker(phone, ci);
58    }
59
60    public DcTracker makeDcTracker(Phone phone) {
61        return new DcTracker(phone);
62    }
63
64    public IccPhoneBookInterfaceManager makeIccPhoneBookInterfaceManager(Phone phone) {
65        return new IccPhoneBookInterfaceManager(phone);
66    }
67
68    public PhoneSubInfo makePhoneSubInfo(Phone phone) {
69        return new PhoneSubInfo(phone);
70    }
71
72    public IccPhoneBookInterfaceManagerProxy makeIccPhoneBookInterfaceManagerProxy(
73            IccPhoneBookInterfaceManager iccPhoneBookInterfaceManager) {
74        return new IccPhoneBookInterfaceManagerProxy(iccPhoneBookInterfaceManager);
75    }
76
77    public PhoneSubInfoProxy makePhoneSubInfoProxy(PhoneSubInfo phoneSubInfo) {
78        return new PhoneSubInfoProxy(phoneSubInfo);
79    }
80
81    public IccSmsInterfaceManager makeIccSmsInterfaceManager(Phone phone) {
82        return new IccSmsInterfaceManager(phone);
83    }
84
85    public IccCardProxy makeIccCardProxy(Context context, CommandsInterface ci, int phoneId) {
86        return new IccCardProxy(context, ci, phoneId);
87    }
88
89    public EriManager makeEriManager(Phone phone, Context context, int eriFileSource) {
90        return new EriManager(phone, context, eriFileSource);
91    }
92
93    public CdmaSubscriptionSourceManager
94    getCdmaSubscriptionSourceManagerInstance(Context context, CommandsInterface ci, Handler h,
95                                             int what, Object obj) {
96        return CdmaSubscriptionSourceManager.getInstance(context, ci, h, what, obj);
97    }
98}
99