TelephonyComponentFactory.java revision 6a7fb078d1cacba7cf2e83b71242bb5c4c27c975
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.ServiceManager; 24 25import com.android.internal.telephony.cdma.CdmaSubscriptionSourceManager; 26import com.android.internal.telephony.cdma.EriManager; 27import com.android.internal.telephony.dataconnection.DcTracker; 28import com.android.internal.telephony.imsphone.ImsExternalCallTracker; 29import com.android.internal.telephony.imsphone.ImsPhone; 30import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; 31import 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 */ 38public class TelephonyComponentFactory { 39 private static TelephonyComponentFactory sInstance; 40 41 public static TelephonyComponentFactory getInstance() { 42 if (sInstance == null) { 43 sInstance = new TelephonyComponentFactory(); 44 } 45 return sInstance; 46 } 47 48 public GsmCdmaCallTracker makeGsmCdmaCallTracker(GsmCdmaPhone phone) { 49 return new GsmCdmaCallTracker(phone); 50 } 51 52 public SmsStorageMonitor makeSmsStorageMonitor(Phone phone) { 53 return new SmsStorageMonitor(phone); 54 } 55 56 public SmsUsageMonitor makeSmsUsageMonitor(Context context) { 57 return new SmsUsageMonitor(context); 58 } 59 60 public ServiceStateTracker makeServiceStateTracker(GsmCdmaPhone phone, CommandsInterface ci) { 61 return new ServiceStateTracker(phone, ci); 62 } 63 64 public DcTracker makeDcTracker(Phone phone) { 65 return new DcTracker(phone); 66 } 67 68 public CarrierSignalAgent makeCarrierSignalAgent(Phone phone) { 69 return new CarrierSignalAgent(phone); 70 } 71 72 public CarrierActionAgent makeCarrierActionAgent(Phone phone) { 73 return new CarrierActionAgent(phone); 74 } 75 76 public IccPhoneBookInterfaceManager makeIccPhoneBookInterfaceManager(Phone phone) { 77 return new IccPhoneBookInterfaceManager(phone); 78 } 79 80 public IccSmsInterfaceManager makeIccSmsInterfaceManager(Phone phone) { 81 return new IccSmsInterfaceManager(phone); 82 } 83 84 public IccCardProxy makeIccCardProxy(Context context, CommandsInterface ci, int phoneId) { 85 return new IccCardProxy(context, ci, phoneId); 86 } 87 88 public EriManager makeEriManager(Phone phone, Context context, int eriFileSource) { 89 return new EriManager(phone, context, eriFileSource); 90 } 91 92 public WspTypeDecoder makeWspTypeDecoder(byte[] pdu) { 93 return new WspTypeDecoder(pdu); 94 } 95 96 /** 97 * Create a tracker for a single-part SMS. 98 */ 99 public InboundSmsTracker makeInboundSmsTracker(byte[] pdu, long timestamp, int destPort, 100 boolean is3gpp2, boolean is3gpp2WapPdu, String address, String messageBody) { 101 return new InboundSmsTracker(pdu, timestamp, destPort, is3gpp2, is3gpp2WapPdu, address, 102 messageBody); 103 } 104 105 /** 106 * Create a tracker for a multi-part SMS. 107 */ 108 public InboundSmsTracker makeInboundSmsTracker(byte[] pdu, long timestamp, int destPort, 109 boolean is3gpp2, String address, int referenceNumber, int sequenceNumber, 110 int messageCount, boolean is3gpp2WapPdu, String messageBody) { 111 return new InboundSmsTracker(pdu, timestamp, destPort, is3gpp2, address, referenceNumber, 112 sequenceNumber, messageCount, is3gpp2WapPdu, messageBody); 113 } 114 115 /** 116 * Create a tracker from a row of raw table 117 */ 118 public InboundSmsTracker makeInboundSmsTracker(Cursor cursor, boolean isCurrentFormat3gpp2) { 119 return new InboundSmsTracker(cursor, isCurrentFormat3gpp2); 120 } 121 122 public ImsPhoneCallTracker makeImsPhoneCallTracker(ImsPhone imsPhone) { 123 return new ImsPhoneCallTracker(imsPhone); 124 } 125 126 public ImsExternalCallTracker makeImsExternalCallTracker(ImsPhone imsPhone) { 127 128 return new ImsExternalCallTracker(imsPhone); 129 } 130 131 /** 132 * Create an AppSmsManager for per-app SMS message. 133 */ 134 public AppSmsManager makeAppSmsManager(Context context) { 135 return new AppSmsManager(context); 136 } 137 138 public CdmaSubscriptionSourceManager 139 getCdmaSubscriptionSourceManagerInstance(Context context, CommandsInterface ci, Handler h, 140 int what, Object obj) { 141 return CdmaSubscriptionSourceManager.getInstance(context, ci, h, what, obj); 142 } 143 144 public IDeviceIdleController getIDeviceIdleController() { 145 return IDeviceIdleController.Stub.asInterface( 146 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); 147 } 148} 149