blob: b02a8f8ed7dddf4f0bf99cd2c6fec5e8f1f2996e [file] [log] [blame]
Santos Cordon049b7b62014-01-30 05:34:26 -08001/*
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.telecomm;
18
19import android.app.Application;
Amith Yamasani60e75842014-05-23 10:09:14 -070020import android.os.UserHandle;
Santos Cordon049b7b62014-01-30 05:34:26 -080021
22/**
23 * Top-level Application class for Telecomm.
24 */
25public final class TelecommApp extends Application {
26
Santos Cordona0e5f1a2014-03-31 21:43:00 -070027 /** Singleton instance of TelecommApp. */
Santos Cordon049b7b62014-01-30 05:34:26 -080028 private static TelecommApp sInstance;
29
Santos Cordona0e5f1a2014-03-31 21:43:00 -070030 /**
31 * Missed call notifier. Exists here so that the instance can be shared with
32 * {@link TelecommBroadcastReceiver}.
33 */
34 private MissedCallNotifier mMissedCallNotifier;
35
Santos Cordon176ae282014-07-14 02:02:14 -070036 /**
Ihab Awad104f8062014-07-17 11:29:35 -070037 * Maintains the list of registered {@link android.telecomm.PhoneAccount}s.
Santos Cordon176ae282014-07-14 02:02:14 -070038 */
39 private PhoneAccountRegistrar mPhoneAccountRegistrar;
40
Santos Cordon049b7b62014-01-30 05:34:26 -080041 /** {@inheritDoc} */
42 @Override public void onCreate() {
43 super.onCreate();
44 sInstance = this;
Santos Cordonae193062014-05-21 21:21:49 -070045
Santos Cordona0e5f1a2014-03-31 21:43:00 -070046 mMissedCallNotifier = new MissedCallNotifier(this);
Santos Cordon176ae282014-07-14 02:02:14 -070047 mPhoneAccountRegistrar = new PhoneAccountRegistrar(this);
48
Amith Yamasani60e75842014-05-23 10:09:14 -070049 if (UserHandle.myUserId() == UserHandle.USER_OWNER) {
Santos Cordon176ae282014-07-14 02:02:14 -070050 TelecommServiceImpl.init(mMissedCallNotifier, mPhoneAccountRegistrar);
Amith Yamasani60e75842014-05-23 10:09:14 -070051 }
Santos Cordon049b7b62014-01-30 05:34:26 -080052 }
53
54 public static TelecommApp getInstance() {
55 if (null == sInstance) {
56 throw new IllegalStateException("No TelecommApp running.");
57 }
58 return sInstance;
59 }
Santos Cordona0e5f1a2014-03-31 21:43:00 -070060
61 MissedCallNotifier getMissedCallNotifier() {
62 return mMissedCallNotifier;
63 }
Ihab Awad104f8062014-07-17 11:29:35 -070064
65 PhoneAccountRegistrar getPhoneAccountRegistrar() {
66 return mPhoneAccountRegistrar;
67 }
Santos Cordon049b7b62014-01-30 05:34:26 -080068}