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