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; |
Ihab Awad | 69eb0f5 | 2014-07-18 11:20:37 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
| 21 | import android.net.Uri; |
Amith Yamasani | 60e7584 | 2014-05-23 10:09:14 -0700 | [diff] [blame] | 22 | import android.os.UserHandle; |
Ihab Awad | 69eb0f5 | 2014-07-18 11:20:37 -0700 | [diff] [blame] | 23 | import android.telecomm.PhoneAccount; |
| 24 | import android.telecomm.PhoneAccountMetadata; |
| 25 | import android.telephony.PhoneNumberUtils; |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Top-level Application class for Telecomm. |
| 29 | */ |
| 30 | public final class TelecommApp extends Application { |
| 31 | |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 32 | /** Singleton instance of TelecommApp. */ |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 33 | private static TelecommApp sInstance; |
| 34 | |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 35 | /** |
| 36 | * Missed call notifier. Exists here so that the instance can be shared with |
| 37 | * {@link TelecommBroadcastReceiver}. |
| 38 | */ |
| 39 | private MissedCallNotifier mMissedCallNotifier; |
| 40 | |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 41 | /** |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 42 | * Maintains the list of registered {@link android.telecomm.PhoneAccount}s. |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 43 | */ |
| 44 | private PhoneAccountRegistrar mPhoneAccountRegistrar; |
| 45 | |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 46 | /** {@inheritDoc} */ |
| 47 | @Override public void onCreate() { |
| 48 | super.onCreate(); |
| 49 | sInstance = this; |
Santos Cordon | ae19306 | 2014-05-21 21:21:49 -0700 | [diff] [blame] | 50 | |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 51 | mMissedCallNotifier = new MissedCallNotifier(this); |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 52 | mPhoneAccountRegistrar = new PhoneAccountRegistrar(this); |
| 53 | |
Ihab Awad | 69eb0f5 | 2014-07-18 11:20:37 -0700 | [diff] [blame] | 54 | addHangoutsAccount(); |
| 55 | |
Amith Yamasani | 60e7584 | 2014-05-23 10:09:14 -0700 | [diff] [blame] | 56 | if (UserHandle.myUserId() == UserHandle.USER_OWNER) { |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 57 | TelecommServiceImpl.init(mMissedCallNotifier, mPhoneAccountRegistrar); |
Amith Yamasani | 60e7584 | 2014-05-23 10:09:14 -0700 | [diff] [blame] | 58 | } |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | public static TelecommApp getInstance() { |
| 62 | if (null == sInstance) { |
| 63 | throw new IllegalStateException("No TelecommApp running."); |
| 64 | } |
| 65 | return sInstance; |
| 66 | } |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 67 | |
| 68 | MissedCallNotifier getMissedCallNotifier() { |
| 69 | return mMissedCallNotifier; |
| 70 | } |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 71 | |
| 72 | PhoneAccountRegistrar getPhoneAccountRegistrar() { |
| 73 | return mPhoneAccountRegistrar; |
| 74 | } |
Ihab Awad | 69eb0f5 | 2014-07-18 11:20:37 -0700 | [diff] [blame] | 75 | |
| 76 | private void addHangoutsAccount() { |
| 77 | // TODO: STOPSHIP. We are adding a hacked PhoneAccount to ensure that Wi-Fi calling in |
| 78 | // Hangouts continues to work. This needs to be replaced with proper Wi-Fi calling wiring |
| 79 | // to the appropriate Connection Services. |
| 80 | PhoneAccountMetadata hangouts = new PhoneAccountMetadata( |
| 81 | new PhoneAccount( |
| 82 | new ComponentName( |
| 83 | "com.google.android.talk", |
| 84 | "com.google.android.apps.babel.telephony.TeleConnectionService"), |
| 85 | "null_id"), |
| 86 | Uri.fromParts("tel", "null_uri", null), |
Evan Charlton | 484f8d6 | 2014-07-18 14:06:58 -0700 | [diff] [blame^] | 87 | "650-253-0000", |
Ihab Awad | 69eb0f5 | 2014-07-18 11:20:37 -0700 | [diff] [blame] | 88 | PhoneAccountMetadata.CAPABILITY_CALL_PROVIDER, |
| 89 | R.drawable.stat_sys_phone_call, |
| 90 | "Wi-Fi calling", |
| 91 | "Wi-Fi calling by Google Hangouts", |
| 92 | false); |
| 93 | mPhoneAccountRegistrar.clearAccounts( |
| 94 | hangouts.getAccount().getComponentName().getPackageName()); |
| 95 | mPhoneAccountRegistrar.registerPhoneAccount(hangouts); |
| 96 | } |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 97 | } |