Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.telecomm; |
| 18 | |
| 19 | import android.app.Application; |
Amith Yamasani | 60e7584 | 2014-05-23 10:09:14 -0700 | [diff] [blame] | 20 | import android.os.UserHandle; |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * Top-level Application class for Telecomm. |
| 24 | */ |
| 25 | public final class TelecommApp extends Application { |
| 26 | |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 27 | /** Singleton instance of TelecommApp. */ |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 28 | private static TelecommApp sInstance; |
| 29 | |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 30 | /** |
| 31 | * Missed call notifier. Exists here so that the instance can be shared with |
| 32 | * {@link TelecommBroadcastReceiver}. |
| 33 | */ |
| 34 | private MissedCallNotifier mMissedCallNotifier; |
| 35 | |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 36 | /** |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 37 | * Maintains the list of registered {@link android.telecomm.PhoneAccount}s. |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 38 | */ |
| 39 | private PhoneAccountRegistrar mPhoneAccountRegistrar; |
| 40 | |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 41 | /** {@inheritDoc} */ |
| 42 | @Override public void onCreate() { |
| 43 | super.onCreate(); |
| 44 | sInstance = this; |
Santos Cordon | ae19306 | 2014-05-21 21:21:49 -0700 | [diff] [blame] | 45 | |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 46 | mMissedCallNotifier = new MissedCallNotifier(this); |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 47 | mPhoneAccountRegistrar = new PhoneAccountRegistrar(this); |
| 48 | |
Amith Yamasani | 60e7584 | 2014-05-23 10:09:14 -0700 | [diff] [blame] | 49 | if (UserHandle.myUserId() == UserHandle.USER_OWNER) { |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 50 | TelecommServiceImpl.init(mMissedCallNotifier, mPhoneAccountRegistrar); |
Amith Yamasani | 60e7584 | 2014-05-23 10:09:14 -0700 | [diff] [blame] | 51 | } |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | public static TelecommApp getInstance() { |
| 55 | if (null == sInstance) { |
| 56 | throw new IllegalStateException("No TelecommApp running."); |
| 57 | } |
| 58 | return sInstance; |
| 59 | } |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 60 | |
| 61 | MissedCallNotifier getMissedCallNotifier() { |
| 62 | return mMissedCallNotifier; |
| 63 | } |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 64 | |
| 65 | PhoneAccountRegistrar getPhoneAccountRegistrar() { |
| 66 | return mPhoneAccountRegistrar; |
| 67 | } |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 68 | } |