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