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