Home | History | Annotate | Download | only in telephony
      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.Looper;
     24 import android.os.ServiceManager;
     25 import android.telephony.AccessNetworkConstants.TransportType;
     26 
     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.uicc.IccCardStatus;
     34 import com.android.internal.telephony.uicc.UiccCard;
     35 import com.android.internal.telephony.uicc.UiccProfile;
     36 
     37 /**
     38  * This class has one-line methods to instantiate objects only. The purpose is to make code
     39  * unit-test friendly and use this class as a way to do dependency injection. Instantiating objects
     40  * this way makes it easier to mock them in tests.
     41  */
     42 public class TelephonyComponentFactory {
     43     private static TelephonyComponentFactory sInstance;
     44 
     45     public static TelephonyComponentFactory getInstance() {
     46         if (sInstance == null) {
     47             sInstance = new TelephonyComponentFactory();
     48         }
     49         return sInstance;
     50     }
     51 
     52     public GsmCdmaCallTracker makeGsmCdmaCallTracker(GsmCdmaPhone phone) {
     53         return new GsmCdmaCallTracker(phone);
     54     }
     55 
     56     public SmsStorageMonitor makeSmsStorageMonitor(Phone phone) {
     57         return new SmsStorageMonitor(phone);
     58     }
     59 
     60     public SmsUsageMonitor makeSmsUsageMonitor(Context context) {
     61         return new SmsUsageMonitor(context);
     62     }
     63 
     64     public ServiceStateTracker makeServiceStateTracker(GsmCdmaPhone phone, CommandsInterface ci) {
     65         return new ServiceStateTracker(phone, ci);
     66     }
     67 
     68     /**
     69      * Returns a new {@link NitzStateMachine} instance.
     70      */
     71     public NitzStateMachine makeNitzStateMachine(GsmCdmaPhone phone) {
     72         return new NitzStateMachine(phone);
     73     }
     74 
     75     public SimActivationTracker makeSimActivationTracker(Phone phone) {
     76         return new SimActivationTracker(phone);
     77     }
     78 
     79     public DcTracker makeDcTracker(Phone phone) {
     80         return new DcTracker(phone, TransportType.WWAN);
     81     }
     82 
     83     public CarrierSignalAgent makeCarrierSignalAgent(Phone phone) {
     84         return new CarrierSignalAgent(phone);
     85     }
     86 
     87     public CarrierActionAgent makeCarrierActionAgent(Phone phone) {
     88         return new CarrierActionAgent(phone);
     89     }
     90 
     91     public CarrierIdentifier makeCarrierIdentifier(Phone phone) {
     92         return new CarrierIdentifier(phone);
     93     }
     94 
     95     public IccPhoneBookInterfaceManager makeIccPhoneBookInterfaceManager(Phone phone) {
     96         return new IccPhoneBookInterfaceManager(phone);
     97     }
     98 
     99     public IccSmsInterfaceManager makeIccSmsInterfaceManager(Phone phone) {
    100         return new IccSmsInterfaceManager(phone);
    101     }
    102 
    103     /**
    104      * Create a new UiccProfile object.
    105      */
    106     public UiccProfile makeUiccProfile(Context context, CommandsInterface ci, IccCardStatus ics,
    107                                        int phoneId, UiccCard uiccCard, Object lock) {
    108         return new UiccProfile(context, ci, ics, phoneId, uiccCard, lock);
    109     }
    110 
    111     public EriManager makeEriManager(Phone phone, Context context, int eriFileSource) {
    112         return new EriManager(phone, context, eriFileSource);
    113     }
    114 
    115     public WspTypeDecoder makeWspTypeDecoder(byte[] pdu) {
    116         return new WspTypeDecoder(pdu);
    117     }
    118 
    119     /**
    120      * Create a tracker for a single-part SMS.
    121      */
    122     public InboundSmsTracker makeInboundSmsTracker(byte[] pdu, long timestamp, int destPort,
    123             boolean is3gpp2, boolean is3gpp2WapPdu, String address, String displayAddr,
    124             String messageBody) {
    125         return new InboundSmsTracker(pdu, timestamp, destPort, is3gpp2, is3gpp2WapPdu, address,
    126                 displayAddr, messageBody);
    127     }
    128 
    129     /**
    130      * Create a tracker for a multi-part SMS.
    131      */
    132     public InboundSmsTracker makeInboundSmsTracker(byte[] pdu, long timestamp, int destPort,
    133             boolean is3gpp2, String address, String displayAddr, int referenceNumber, int sequenceNumber,
    134             int messageCount, boolean is3gpp2WapPdu, String messageBody) {
    135         return new InboundSmsTracker(pdu, timestamp, destPort, is3gpp2, address, displayAddr,
    136                 referenceNumber, sequenceNumber, messageCount, is3gpp2WapPdu, messageBody);
    137     }
    138 
    139     /**
    140      * Create a tracker from a row of raw table
    141      */
    142     public InboundSmsTracker makeInboundSmsTracker(Cursor cursor, boolean isCurrentFormat3gpp2) {
    143         return new InboundSmsTracker(cursor, isCurrentFormat3gpp2);
    144     }
    145 
    146     public ImsPhoneCallTracker makeImsPhoneCallTracker(ImsPhone imsPhone) {
    147         return new ImsPhoneCallTracker(imsPhone);
    148     }
    149 
    150     public ImsExternalCallTracker makeImsExternalCallTracker(ImsPhone imsPhone) {
    151 
    152         return new ImsExternalCallTracker(imsPhone);
    153     }
    154 
    155     /**
    156      * Create an AppSmsManager for per-app SMS message.
    157      */
    158     public AppSmsManager makeAppSmsManager(Context context) {
    159         return new AppSmsManager(context);
    160     }
    161 
    162     public DeviceStateMonitor makeDeviceStateMonitor(Phone phone) {
    163         return new DeviceStateMonitor(phone);
    164     }
    165 
    166     public CdmaSubscriptionSourceManager
    167     getCdmaSubscriptionSourceManagerInstance(Context context, CommandsInterface ci, Handler h,
    168                                              int what, Object obj) {
    169         return CdmaSubscriptionSourceManager.getInstance(context, ci, h, what, obj);
    170     }
    171 
    172     public IDeviceIdleController getIDeviceIdleController() {
    173         return IDeviceIdleController.Stub.asInterface(
    174                 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
    175     }
    176 
    177     public LocaleTracker makeLocaleTracker(Phone phone, Looper looper) {
    178         return new LocaleTracker(phone, looper);
    179     }
    180 }
    181