TelephonyComponentFactory.java revision 27f471647b2da3ff50620a766c048ebef8d45ae1
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.IDeviceIdleController;
22import android.os.PowerManager;
23import android.os.ServiceManager;
24
25import com.android.ims.ImsManager;
26import com.android.internal.telephony.cdma.CdmaSubscriptionSourceManager;
27import com.android.internal.telephony.cdma.EriManager;
28import com.android.internal.telephony.dataconnection.DcTracker;
29import com.android.internal.telephony.uicc.IccCardProxy;
30
31/**
32 * This class has one-line methods to instantiate objects only. The purpose is to make code
33 * unit-test friendly and use this class as a way to do dependency injection. Instantiating objects
34 * this way makes it easier to mock them in tests.
35 */
36public class TelephonyComponentFactory {
37    private static TelephonyComponentFactory sInstance;
38
39    public static TelephonyComponentFactory getInstance() {
40        if (sInstance == null) {
41            sInstance = new TelephonyComponentFactory();
42        }
43        return sInstance;
44    }
45
46    public GsmCdmaCallTracker makeGsmCdmaCallTracker(GsmCdmaPhone phone) {
47        return new GsmCdmaCallTracker(phone);
48    }
49
50    public SmsStorageMonitor makeSmsStorageMonitor(Phone phone) {
51        return new SmsStorageMonitor(phone);
52    }
53
54    public SmsUsageMonitor makeSmsUsageMonitor(Context context) {
55        return new SmsUsageMonitor(context);
56    }
57
58    public ServiceStateTracker makeServiceStateTracker(GsmCdmaPhone phone, CommandsInterface ci) {
59        return new ServiceStateTracker(phone, ci);
60    }
61
62    public DcTracker makeDcTracker(Phone phone) {
63        return new DcTracker(phone);
64    }
65
66    public IccPhoneBookInterfaceManager makeIccPhoneBookInterfaceManager(Phone phone) {
67        return new IccPhoneBookInterfaceManager(phone);
68    }
69
70    public IccSmsInterfaceManager makeIccSmsInterfaceManager(Phone phone) {
71        return new IccSmsInterfaceManager(phone);
72    }
73
74    public IccCardProxy makeIccCardProxy(Context context, CommandsInterface ci, int phoneId) {
75        return new IccCardProxy(context, ci, phoneId);
76    }
77
78    public EriManager makeEriManager(Phone phone, Context context, int eriFileSource) {
79        return new EriManager(phone, context, eriFileSource);
80    }
81
82    public WspTypeDecoder makeWspTypeDecoder(byte[] pdu) {
83        return new WspTypeDecoder(pdu);
84    }
85
86    /**
87     * Create a tracker for a single-part SMS.
88     */
89    public InboundSmsTracker makeInboundSmsTracker(byte[] pdu, long timestamp, int destPort,
90            boolean is3gpp2, boolean is3gpp2WapPdu, String address) {
91        return new InboundSmsTracker(pdu, timestamp, destPort, is3gpp2, is3gpp2WapPdu, address);
92    }
93
94    /**
95     * Create a tracker for a multi-part SMS.
96     */
97    public InboundSmsTracker makeInboundSmsTracker(byte[] pdu, long timestamp, int destPort,
98            boolean is3gpp2, String address, int referenceNumber, int sequenceNumber,
99            int messageCount, boolean is3gpp2WapPdu) {
100        return new InboundSmsTracker(pdu, timestamp, destPort, is3gpp2, address, referenceNumber,
101                sequenceNumber, messageCount, is3gpp2WapPdu);
102    }
103
104    public CdmaSubscriptionSourceManager
105    getCdmaSubscriptionSourceManagerInstance(Context context, CommandsInterface ci, Handler h,
106                                             int what, Object obj) {
107        return CdmaSubscriptionSourceManager.getInstance(context, ci, h, what, obj);
108    }
109
110    public IDeviceIdleController getIDeviceIdleController() {
111        return IDeviceIdleController.Stub.asInterface(
112                ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
113    }
114}
115