1/*
2 * Copyright (C) 2014 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.services.telephony;
18
19import android.content.Context;
20
21import com.android.internal.telephony.Phone;
22import com.android.internal.telephony.PhoneFactory;
23
24import java.util.ArrayList;
25import java.util.List;
26
27/**
28 * Singleton entry point for the telephony-services app. Initializes ongoing systems relating to
29 * PSTN calls. This is started when the device starts and will be restarted automatically
30 * if it goes away for any reason (e.g., crashes).
31 * This is separate from the actual Application class because we only support one instance of this
32 * app - running as the default user. {@link com.android.phone.PhoneApp} determines whether or not
33 * we are running as the default user and if we are, then initializes and runs this class's
34 * {@link #onCreate}.
35 */
36public class TelephonyGlobals {
37    private static TelephonyGlobals sInstance;
38
39    /** The application context. */
40    private final Context mContext;
41
42    // For supporting MSIM phone, change Phone and TtyManager as 1 to 1
43    private List<TtyManager> mTtyManagers = new ArrayList<>();
44
45    /**
46     * Persists the specified parameters.
47     *
48     * @param context The application context.
49     */
50    public TelephonyGlobals(Context context) {
51        mContext = context.getApplicationContext();
52    }
53
54    public static synchronized TelephonyGlobals getInstance(Context context) {
55        if (sInstance == null) {
56            sInstance = new TelephonyGlobals(context);
57        }
58        return sInstance;
59    }
60
61    public void onCreate() {
62        // Make this work with Multi-SIM devices
63        Phone[] phones = PhoneFactory.getPhones();
64        for (Phone phone : phones) {
65            mTtyManagers.add(new TtyManager(mContext, phone));
66        }
67
68        TelecomAccountRegistry.getInstance(mContext).setupOnBoot();
69    }
70}
71