TelephonyComponentFactory.java revision 30646d039eb54def9efd55fc54772e111b5ef115
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.os.Handler; 21import android.os.PowerManager; 22 23import com.android.ims.ImsManager; 24import com.android.internal.telephony.cdma.CdmaSubscriptionSourceManager; 25import com.android.internal.telephony.cdma.EriManager; 26import com.android.internal.telephony.dataconnection.DcTracker; 27import com.android.internal.telephony.uicc.IccCardProxy; 28 29/** 30 * This class has one-line methods to instantiate objects only. The purpose is to make code 31 * unit-test friendly and use this class as a way to do dependency injection. Instantiating objects 32 * this way makes it easier to mock them in tests. 33 */ 34public class TelephonyComponentFactory { 35 private static TelephonyComponentFactory sInstance; 36 37 public static TelephonyComponentFactory getInstance() { 38 if (sInstance == null) { 39 sInstance = new TelephonyComponentFactory(); 40 } 41 return sInstance; 42 } 43 44 public GsmCdmaCallTracker makeGsmCdmaCallTracker(GsmCdmaPhone phone) { 45 return new GsmCdmaCallTracker(phone); 46 } 47 48 public SmsStorageMonitor makeSmsStorageMonitor(Phone phone) { 49 return new SmsStorageMonitor(phone); 50 } 51 52 public SmsUsageMonitor makeSmsUsageMonitor(Context context) { 53 return new SmsUsageMonitor(context); 54 } 55 56 public ServiceStateTracker makeServiceStateTracker(GsmCdmaPhone phone, CommandsInterface ci) { 57 return new ServiceStateTracker(phone, ci); 58 } 59 60 public DcTracker makeDcTracker(Phone phone) { 61 return new DcTracker(phone); 62 } 63 64 public IccPhoneBookInterfaceManager makeIccPhoneBookInterfaceManager(Phone phone) { 65 return new IccPhoneBookInterfaceManager(phone); 66 } 67 68 public IccSmsInterfaceManager makeIccSmsInterfaceManager(Phone phone) { 69 return new IccSmsInterfaceManager(phone); 70 } 71 72 public IccCardProxy makeIccCardProxy(Context context, CommandsInterface ci, int phoneId) { 73 return new IccCardProxy(context, ci, phoneId); 74 } 75 76 public EriManager makeEriManager(Phone phone, Context context, int eriFileSource) { 77 return new EriManager(phone, context, eriFileSource); 78 } 79 80 public CdmaSubscriptionSourceManager 81 getCdmaSubscriptionSourceManagerInstance(Context context, CommandsInterface ci, Handler h, 82 int what, Object obj) { 83 return CdmaSubscriptionSourceManager.getInstance(context, ci, h, what, obj); 84 } 85} 86