blob: e941c2df262e9792d15c03964b8768dc8be1c5ff [file] [log] [blame]
Santos Cordon76faae52013-12-12 18:55:50 -08001/*
2 * Copyright (C) 2013 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
Yorke Lee7c65acd2014-06-04 11:11:03 -070017package com.android.telecomm.testapps;
Santos Cordon76faae52013-12-12 18:55:50 -080018
19import android.content.BroadcastReceiver;
Tyler Gunn0a388fc2014-07-17 12:21:17 -070020import android.content.ComponentName;
Santos Cordon76faae52013-12-12 18:55:50 -080021import android.content.Context;
22import android.content.Intent;
Tyler Gunn0a388fc2014-07-17 12:21:17 -070023import android.os.Bundle;
Evan Charlton89176372014-07-19 18:23:09 -070024import android.telecomm.PhoneAccountHandle;
Evan Charltonb35fc312014-07-19 15:02:55 -070025import android.telecomm.TelecommManager;
Santos Cordon76faae52013-12-12 18:55:50 -080026
27/**
28 * This class receives the notification callback intents used to update call states for
Sailesh Nepal905dfba2014-07-14 08:20:41 -070029 * {@link TestConnectionService}.
Santos Cordon76faae52013-12-12 18:55:50 -080030 */
31public class CallNotificationReceiver extends BroadcastReceiver {
Santos Cordon76faae52013-12-12 18:55:50 -080032 /**
Sailesh Nepal905dfba2014-07-14 08:20:41 -070033 * Exit intent action is sent when the user clicks the "exit" action of the
34 * TestConnectionService notification. Used to cancel (remove) the notification.
Santos Cordon76faae52013-12-12 18:55:50 -080035 */
Santos Cordonc80a98c2014-02-19 02:59:34 -080036 static final String ACTION_CALL_SERVICE_EXIT =
Santos Cordon176ae282014-07-14 02:02:14 -070037 "com.android.telecomm.testapps.ACTION_CALL_SERVICE_EXIT";
38 static final String ACTION_REGISTER_PHONE_ACCOUNT =
39 "com.android.telecomm.testapps.ACTION_REGISTER_PHONE_ACCOUNT";
40 static final String ACTION_SHOW_ALL_PHONE_ACCOUNTS =
41 "com.android.telecomm.testapps.ACTION_SHOW_ALL_PHONE_ACCOUNTS";
Tyler Gunn0a388fc2014-07-17 12:21:17 -070042 static final String ACTION_VIDEO_CALL =
43 "com.android.telecomm.testapps.ACTION_VIDEO_CALL";
44 static final String ACTION_AUDIO_CALL =
45 "com.android.telecomm.testapps.ACTION_AUDIO_CALL";
Santos Cordon76faae52013-12-12 18:55:50 -080046
47 /** {@inheritDoc} */
48 @Override
49 public void onReceive(Context context, Intent intent) {
50 String action = intent.getAction();
51 if (ACTION_CALL_SERVICE_EXIT.equals(action)) {
Santos Cordon176ae282014-07-14 02:02:14 -070052 CallServiceNotifier.getInstance().cancelNotifications(context);
53 } else if (ACTION_REGISTER_PHONE_ACCOUNT.equals(action)) {
54 CallServiceNotifier.getInstance().registerPhoneAccount(context);
55 } else if (ACTION_SHOW_ALL_PHONE_ACCOUNTS.equals(action)) {
56 CallServiceNotifier.getInstance().showAllPhoneAccounts(context);
Tyler Gunn0a388fc2014-07-17 12:21:17 -070057 } else if (ACTION_VIDEO_CALL.equals(action)) {
58 sendIncomingCallIntent(context, true);
59 } else if (ACTION_AUDIO_CALL.equals(action)) {
60 sendIncomingCallIntent(context, false);
Santos Cordon76faae52013-12-12 18:55:50 -080061 }
62 }
Tyler Gunn0a388fc2014-07-17 12:21:17 -070063
64 /**
65 * Creates the intent to add an incoming call through Telecomm.
66 *
67 * @param context The current context.
68 * @param isVideoCall {@code True} if this is a video call.
69 */
70 private void sendIncomingCallIntent(Context context, boolean isVideoCall) {
Santos Cordonfd86bd42014-07-19 14:59:04 -070071 PhoneAccountHandle phoneAccount = new PhoneAccountHandle(
Tyler Gunn0a388fc2014-07-17 12:21:17 -070072 new ComponentName(context, TestConnectionService.class),
Sailesh Nepale4ef5212014-08-09 16:45:21 -070073 CallServiceNotifier.CALL_PROVIDER_ID);
Tyler Gunn0a388fc2014-07-17 12:21:17 -070074
75 // For the purposes of testing, indicate whether the incoming call is a video call by
76 // stashing an indicator in the EXTRA_INCOMING_CALL_EXTRAS.
77 Bundle extras = new Bundle();
78 extras.putBoolean(TestConnectionService.IS_VIDEO_CALL, isVideoCall);
79
Santos Cordonfd86bd42014-07-19 14:59:04 -070080 TelecommManager.from(context).addNewIncomingCall(phoneAccount, extras);
Tyler Gunn0a388fc2014-07-17 12:21:17 -070081 }
Santos Cordon76faae52013-12-12 18:55:50 -080082}