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