| /* |
| * Copyright (C) 2015 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package com.android.internal.telephony; |
| |
| import android.content.Context; |
| import android.database.Cursor; |
| import android.os.Handler; |
| import android.os.IDeviceIdleController; |
| import android.os.Looper; |
| import android.os.ServiceManager; |
| import android.telephony.AccessNetworkConstants.TransportType; |
| |
| import com.android.internal.telephony.cdma.CdmaSubscriptionSourceManager; |
| import com.android.internal.telephony.cdma.EriManager; |
| import com.android.internal.telephony.dataconnection.DcTracker; |
| import com.android.internal.telephony.imsphone.ImsExternalCallTracker; |
| import com.android.internal.telephony.imsphone.ImsPhone; |
| import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
| import com.android.internal.telephony.uicc.IccCardStatus; |
| import com.android.internal.telephony.uicc.UiccCard; |
| import com.android.internal.telephony.uicc.UiccProfile; |
| |
| /** |
| * This class has one-line methods to instantiate objects only. The purpose is to make code |
| * unit-test friendly and use this class as a way to do dependency injection. Instantiating objects |
| * this way makes it easier to mock them in tests. |
| */ |
| public class TelephonyComponentFactory { |
| private static TelephonyComponentFactory sInstance; |
| |
| public static TelephonyComponentFactory getInstance() { |
| if (sInstance == null) { |
| sInstance = new TelephonyComponentFactory(); |
| } |
| return sInstance; |
| } |
| |
| public GsmCdmaCallTracker makeGsmCdmaCallTracker(GsmCdmaPhone phone) { |
| return new GsmCdmaCallTracker(phone); |
| } |
| |
| public SmsStorageMonitor makeSmsStorageMonitor(Phone phone) { |
| return new SmsStorageMonitor(phone); |
| } |
| |
| public SmsUsageMonitor makeSmsUsageMonitor(Context context) { |
| return new SmsUsageMonitor(context); |
| } |
| |
| public ServiceStateTracker makeServiceStateTracker(GsmCdmaPhone phone, CommandsInterface ci) { |
| return new ServiceStateTracker(phone, ci); |
| } |
| |
| /** |
| * Sets the NitzStateMachine implementation to use during implementation. This boolean |
| * should be removed once the new implementation is stable. |
| */ |
| static final boolean USE_NEW_NITZ_STATE_MACHINE = true; |
| |
| /** |
| * Returns a new {@link NitzStateMachine} instance. |
| */ |
| public NitzStateMachine makeNitzStateMachine(GsmCdmaPhone phone) { |
| return USE_NEW_NITZ_STATE_MACHINE |
| ? new NewNitzStateMachine(phone) |
| : new OldNitzStateMachine(phone); |
| } |
| |
| public SimActivationTracker makeSimActivationTracker(Phone phone) { |
| return new SimActivationTracker(phone); |
| } |
| |
| public DcTracker makeDcTracker(Phone phone) { |
| return new DcTracker(phone, TransportType.WWAN); |
| } |
| |
| public CarrierSignalAgent makeCarrierSignalAgent(Phone phone) { |
| return new CarrierSignalAgent(phone); |
| } |
| |
| public CarrierActionAgent makeCarrierActionAgent(Phone phone) { |
| return new CarrierActionAgent(phone); |
| } |
| |
| public CarrierIdentifier makeCarrierIdentifier(Phone phone) { |
| return new CarrierIdentifier(phone); |
| } |
| |
| public IccPhoneBookInterfaceManager makeIccPhoneBookInterfaceManager(Phone phone) { |
| return new IccPhoneBookInterfaceManager(phone); |
| } |
| |
| public IccSmsInterfaceManager makeIccSmsInterfaceManager(Phone phone) { |
| return new IccSmsInterfaceManager(phone); |
| } |
| |
| /** |
| * Create a new UiccProfile object. |
| */ |
| public UiccProfile makeUiccProfile(Context context, CommandsInterface ci, IccCardStatus ics, |
| int phoneId, UiccCard uiccCard, Object lock) { |
| return new UiccProfile(context, ci, ics, phoneId, uiccCard, lock); |
| } |
| |
| public EriManager makeEriManager(Phone phone, Context context, int eriFileSource) { |
| return new EriManager(phone, context, eriFileSource); |
| } |
| |
| public WspTypeDecoder makeWspTypeDecoder(byte[] pdu) { |
| return new WspTypeDecoder(pdu); |
| } |
| |
| /** |
| * Create a tracker for a single-part SMS. |
| */ |
| public InboundSmsTracker makeInboundSmsTracker(byte[] pdu, long timestamp, int destPort, |
| boolean is3gpp2, boolean is3gpp2WapPdu, String address, String displayAddr, |
| String messageBody) { |
| return new InboundSmsTracker(pdu, timestamp, destPort, is3gpp2, is3gpp2WapPdu, address, |
| displayAddr, messageBody); |
| } |
| |
| /** |
| * Create a tracker for a multi-part SMS. |
| */ |
| public InboundSmsTracker makeInboundSmsTracker(byte[] pdu, long timestamp, int destPort, |
| boolean is3gpp2, String address, String displayAddr, int referenceNumber, int sequenceNumber, |
| int messageCount, boolean is3gpp2WapPdu, String messageBody) { |
| return new InboundSmsTracker(pdu, timestamp, destPort, is3gpp2, address, displayAddr, |
| referenceNumber, sequenceNumber, messageCount, is3gpp2WapPdu, messageBody); |
| } |
| |
| /** |
| * Create a tracker from a row of raw table |
| */ |
| public InboundSmsTracker makeInboundSmsTracker(Cursor cursor, boolean isCurrentFormat3gpp2) { |
| return new InboundSmsTracker(cursor, isCurrentFormat3gpp2); |
| } |
| |
| public ImsPhoneCallTracker makeImsPhoneCallTracker(ImsPhone imsPhone) { |
| return new ImsPhoneCallTracker(imsPhone); |
| } |
| |
| public ImsExternalCallTracker makeImsExternalCallTracker(ImsPhone imsPhone) { |
| |
| return new ImsExternalCallTracker(imsPhone); |
| } |
| |
| /** |
| * Create an AppSmsManager for per-app SMS message. |
| */ |
| public AppSmsManager makeAppSmsManager(Context context) { |
| return new AppSmsManager(context); |
| } |
| |
| public DeviceStateMonitor makeDeviceStateMonitor(Phone phone) { |
| return new DeviceStateMonitor(phone); |
| } |
| |
| public CdmaSubscriptionSourceManager |
| getCdmaSubscriptionSourceManagerInstance(Context context, CommandsInterface ci, Handler h, |
| int what, Object obj) { |
| return CdmaSubscriptionSourceManager.getInstance(context, ci, h, what, obj); |
| } |
| |
| public IDeviceIdleController getIDeviceIdleController() { |
| return IDeviceIdleController.Stub.asInterface( |
| ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| } |
| public LocaleTracker makeLocaleTracker(Phone phone, Looper looper) { |
| return new LocaleTracker(phone, looper); |
| } |
| } |