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