blob: cf7b8df4f5e29b24c5607fa7f6db66afbf8c6aa0 [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;
Evan Charlton94d01622014-07-20 12:32:05 -070023import android.telecomm.PhoneAccount;
Evan Charlton89176372014-07-19 18:23:09 -070024import android.telecomm.PhoneAccountHandle;
Santos Cordon049b7b62014-01-30 05:34:26 -080025
26/**
27 * Top-level Application class for Telecomm.
28 */
29public final class TelecommApp extends Application {
30
Santos Cordona0e5f1a2014-03-31 21:43:00 -070031 /** Singleton instance of TelecommApp. */
Santos Cordon049b7b62014-01-30 05:34:26 -080032 private static TelecommApp sInstance;
33
Santos Cordona0e5f1a2014-03-31 21:43:00 -070034 /**
35 * Missed call notifier. Exists here so that the instance can be shared with
36 * {@link TelecommBroadcastReceiver}.
37 */
38 private MissedCallNotifier mMissedCallNotifier;
39
Santos Cordon176ae282014-07-14 02:02:14 -070040 /**
Evan Charlton89176372014-07-19 18:23:09 -070041 * Maintains the list of registered {@link android.telecomm.PhoneAccountHandle}s.
Santos Cordon176ae282014-07-14 02:02:14 -070042 */
43 private PhoneAccountRegistrar mPhoneAccountRegistrar;
44
Santos Cordon049b7b62014-01-30 05:34:26 -080045 /** {@inheritDoc} */
46 @Override public void onCreate() {
47 super.onCreate();
48 sInstance = this;
Santos Cordonae193062014-05-21 21:21:49 -070049
Santos Cordona0e5f1a2014-03-31 21:43:00 -070050 mMissedCallNotifier = new MissedCallNotifier(this);
Santos Cordon176ae282014-07-14 02:02:14 -070051 mPhoneAccountRegistrar = new PhoneAccountRegistrar(this);
52
Ihab Awad69eb0f52014-07-18 11:20:37 -070053 addHangoutsAccount();
54
Amith Yamasani60e75842014-05-23 10:09:14 -070055 if (UserHandle.myUserId() == UserHandle.USER_OWNER) {
Santos Cordon176ae282014-07-14 02:02:14 -070056 TelecommServiceImpl.init(mMissedCallNotifier, mPhoneAccountRegistrar);
Amith Yamasani60e75842014-05-23 10:09:14 -070057 }
Santos Cordon049b7b62014-01-30 05:34:26 -080058 }
59
60 public static TelecommApp getInstance() {
61 if (null == sInstance) {
62 throw new IllegalStateException("No TelecommApp running.");
63 }
64 return sInstance;
65 }
Santos Cordona0e5f1a2014-03-31 21:43:00 -070066
67 MissedCallNotifier getMissedCallNotifier() {
68 return mMissedCallNotifier;
69 }
Ihab Awad104f8062014-07-17 11:29:35 -070070
71 PhoneAccountRegistrar getPhoneAccountRegistrar() {
72 return mPhoneAccountRegistrar;
73 }
Ihab Awad69eb0f52014-07-18 11:20:37 -070074
75 private void addHangoutsAccount() {
Evan Charlton89176372014-07-19 18:23:09 -070076 // TODO: STOPSHIP. We are adding a hacked PhoneAccountHandle to ensure that Wi-Fi calling in
Ihab Awad69eb0f52014-07-18 11:20:37 -070077 // Hangouts continues to work. This needs to be replaced with proper Wi-Fi calling wiring
78 // to the appropriate Connection Services.
Evan Charlton94d01622014-07-20 12:32:05 -070079 PhoneAccount hangouts = new PhoneAccount(
Evan Charlton89176372014-07-19 18:23:09 -070080 new PhoneAccountHandle(
Ihab Awad69eb0f52014-07-18 11:20:37 -070081 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 Charlton484f8d62014-07-18 14:06:58 -070086 "650-253-0000",
Evan Charlton94d01622014-07-20 12:32:05 -070087 PhoneAccount.CAPABILITY_CALL_PROVIDER,
Ihab Awad69eb0f52014-07-18 11:20:37 -070088 R.drawable.stat_sys_phone_call,
89 "Wi-Fi calling",
90 "Wi-Fi calling by Google Hangouts",
91 false);
92 mPhoneAccountRegistrar.clearAccounts(
Evan Charlton94d01622014-07-20 12:32:05 -070093 hangouts.getAccountHandle().getComponentName().getPackageName());
Ihab Awad69eb0f52014-07-18 11:20:37 -070094 mPhoneAccountRegistrar.registerPhoneAccount(hangouts);
95 }
Santos Cordon049b7b62014-01-30 05:34:26 -080096}