1a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon/*
2a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon * Copyright (C) 2014 The Android Open Source Project
3a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon *
4a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon * Licensed under the Apache License, Version 2.0 (the "License");
5a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon * you may not use this file except in compliance with the License.
6a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon * You may obtain a copy of the License at
7a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon *
8a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon *      http://www.apache.org/licenses/LICENSE-2.0
9a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon *
10a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon * Unless required by applicable law or agreed to in writing, software
11a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon * distributed under the License is distributed on an "AS IS" BASIS,
12a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon * See the License for the specific language governing permissions and
14a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon * limitations under the License.
15a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon */
16a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon
17a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordonpackage com.android.services.telephony;
18a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon
192afb2bebbb9c88f5ab8752f602a9148e14d14009Santos Cordonimport android.content.Context;
202afb2bebbb9c88f5ab8752f602a9148e14d14009Santos Cordon
21bf900546674f25be845130119aa332ef8b17a399Sailesh Nepalimport com.android.internal.telephony.Phone;
222afb2bebbb9c88f5ab8752f602a9148e14d14009Santos Cordonimport com.android.internal.telephony.PhoneFactory;
232afb2bebbb9c88f5ab8752f602a9148e14d14009Santos Cordon
24a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon/**
25a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon * Singleton entry point for the telephony-services app. Initializes ongoing systems relating to
26bf900546674f25be845130119aa332ef8b17a399Sailesh Nepal * PSTN calls. This is started when the device starts and will be restarted automatically
27a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon * if it goes away for any reason (e.g., crashes).
28a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon * This is separate from the actual Application class because we only support one instance of this
29a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon * app - running as the default user. {@link com.android.phone.PhoneApp} determines whether or not
30a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon * we are running as the default user and if we are, then initializes and runs this class's
31a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon * {@link #onCreate}.
32a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon */
33a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordonpublic class TelephonyGlobals {
347debf0174288630f54813c7ec43ebc6df0a9c69dSantos Cordon    private static TelephonyGlobals sInstance;
357debf0174288630f54813c7ec43ebc6df0a9c69dSantos Cordon
362afb2bebbb9c88f5ab8752f602a9148e14d14009Santos Cordon    /** The application context. */
372afb2bebbb9c88f5ab8752f602a9148e14d14009Santos Cordon    private final Context mContext;
382afb2bebbb9c88f5ab8752f602a9148e14d14009Santos Cordon
39bf900546674f25be845130119aa332ef8b17a399Sailesh Nepal    private TtyManager mTtyManager;
40bf900546674f25be845130119aa332ef8b17a399Sailesh Nepal
412afb2bebbb9c88f5ab8752f602a9148e14d14009Santos Cordon    /**
422afb2bebbb9c88f5ab8752f602a9148e14d14009Santos Cordon     * Persists the specified parameters.
432afb2bebbb9c88f5ab8752f602a9148e14d14009Santos Cordon     *
442afb2bebbb9c88f5ab8752f602a9148e14d14009Santos Cordon     * @param context The application context.
452afb2bebbb9c88f5ab8752f602a9148e14d14009Santos Cordon     */
462afb2bebbb9c88f5ab8752f602a9148e14d14009Santos Cordon    public TelephonyGlobals(Context context) {
472afb2bebbb9c88f5ab8752f602a9148e14d14009Santos Cordon        mContext = context.getApplicationContext();
482afb2bebbb9c88f5ab8752f602a9148e14d14009Santos Cordon    }
492afb2bebbb9c88f5ab8752f602a9148e14d14009Santos Cordon
507debf0174288630f54813c7ec43ebc6df0a9c69dSantos Cordon    public static synchronized TelephonyGlobals getInstance(Context context) {
517debf0174288630f54813c7ec43ebc6df0a9c69dSantos Cordon        if (sInstance == null) {
527debf0174288630f54813c7ec43ebc6df0a9c69dSantos Cordon            sInstance = new TelephonyGlobals(context);
537debf0174288630f54813c7ec43ebc6df0a9c69dSantos Cordon        }
547debf0174288630f54813c7ec43ebc6df0a9c69dSantos Cordon        return sInstance;
557debf0174288630f54813c7ec43ebc6df0a9c69dSantos Cordon    }
56bf900546674f25be845130119aa332ef8b17a399Sailesh Nepal
577debf0174288630f54813c7ec43ebc6df0a9c69dSantos Cordon    public void onCreate() {
587debf0174288630f54813c7ec43ebc6df0a9c69dSantos Cordon        // TODO: Make this work with Multi-SIM devices
59bf900546674f25be845130119aa332ef8b17a399Sailesh Nepal        Phone phone = PhoneFactory.getDefaultPhone();
60bf900546674f25be845130119aa332ef8b17a399Sailesh Nepal        if (phone != null) {
61bf900546674f25be845130119aa332ef8b17a399Sailesh Nepal            mTtyManager = new TtyManager(mContext, phone);
62bf900546674f25be845130119aa332ef8b17a399Sailesh Nepal        }
63e3b3e4df2ca751ff55a34aa95c2722dca1a91924Santos Cordon
644d45d1cf58a2003378fd35912d6d73a00001bf06Tyler Gunn        TelecomAccountRegistry.getInstance(mContext).setupOnBoot();
652afb2bebbb9c88f5ab8752f602a9148e14d14009Santos Cordon    }
66a9ec9655639c3a90e294f8177ba44e8eb7df24a5Santos Cordon}
67