blob: fd357082fdeb51bdf90d4bdf6545e7ebeeb9f31c [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;
Ihab Awad69eb0f52014-07-18 11:20:37 -070020import android.content.ComponentName;
21import android.net.Uri;
Amith Yamasani60e75842014-05-23 10:09:14 -070022import android.os.UserHandle;
Ihab Awad69eb0f52014-07-18 11:20:37 -070023import android.telecomm.PhoneAccount;
24import android.telecomm.PhoneAccountMetadata;
25import android.telephony.PhoneNumberUtils;
Santos Cordon049b7b62014-01-30 05:34:26 -080026
27/**
28 * Top-level Application class for Telecomm.
29 */
30public final class TelecommApp extends Application {
31
Santos Cordona0e5f1a2014-03-31 21:43:00 -070032 /** Singleton instance of TelecommApp. */
Santos Cordon049b7b62014-01-30 05:34:26 -080033 private static TelecommApp sInstance;
34
Santos Cordona0e5f1a2014-03-31 21:43:00 -070035 /**
36 * Missed call notifier. Exists here so that the instance can be shared with
37 * {@link TelecommBroadcastReceiver}.
38 */
39 private MissedCallNotifier mMissedCallNotifier;
40
Santos Cordon176ae282014-07-14 02:02:14 -070041 /**
Ihab Awad104f8062014-07-17 11:29:35 -070042 * Maintains the list of registered {@link android.telecomm.PhoneAccount}s.
Santos Cordon176ae282014-07-14 02:02:14 -070043 */
44 private PhoneAccountRegistrar mPhoneAccountRegistrar;
45
Santos Cordon049b7b62014-01-30 05:34:26 -080046 /** {@inheritDoc} */
47 @Override public void onCreate() {
48 super.onCreate();
49 sInstance = this;
Santos Cordonae193062014-05-21 21:21:49 -070050
Santos Cordona0e5f1a2014-03-31 21:43:00 -070051 mMissedCallNotifier = new MissedCallNotifier(this);
Santos Cordon176ae282014-07-14 02:02:14 -070052 mPhoneAccountRegistrar = new PhoneAccountRegistrar(this);
53
Ihab Awad69eb0f52014-07-18 11:20:37 -070054 addHangoutsAccount();
55
Amith Yamasani60e75842014-05-23 10:09:14 -070056 if (UserHandle.myUserId() == UserHandle.USER_OWNER) {
Santos Cordon176ae282014-07-14 02:02:14 -070057 TelecommServiceImpl.init(mMissedCallNotifier, mPhoneAccountRegistrar);
Amith Yamasani60e75842014-05-23 10:09:14 -070058 }
Santos Cordon049b7b62014-01-30 05:34:26 -080059 }
60
61 public static TelecommApp getInstance() {
62 if (null == sInstance) {
63 throw new IllegalStateException("No TelecommApp running.");
64 }
65 return sInstance;
66 }
Santos Cordona0e5f1a2014-03-31 21:43:00 -070067
68 MissedCallNotifier getMissedCallNotifier() {
69 return mMissedCallNotifier;
70 }
Ihab Awad104f8062014-07-17 11:29:35 -070071
72 PhoneAccountRegistrar getPhoneAccountRegistrar() {
73 return mPhoneAccountRegistrar;
74 }
Ihab Awad69eb0f52014-07-18 11:20:37 -070075
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),
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 Cordon049b7b62014-01-30 05:34:26 -080096}