Santos Cordon | 76faae5 | 2013-12-12 18:55:50 -0800 | [diff] [blame] | 1 | /* |
| 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 Lee | 7c65acd | 2014-06-04 11:11:03 -0700 | [diff] [blame] | 17 | package com.android.telecomm.testapps; |
Santos Cordon | 76faae5 | 2013-12-12 18:55:50 -0800 | [diff] [blame] | 18 | |
| 19 | import android.content.BroadcastReceiver; |
Tyler Gunn | 0a388fc | 2014-07-17 12:21:17 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
Santos Cordon | 76faae5 | 2013-12-12 18:55:50 -0800 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
Tyler Gunn | 0a388fc | 2014-07-17 12:21:17 -0700 | [diff] [blame] | 23 | import android.os.Bundle; |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 24 | import android.telecomm.PhoneAccountHandle; |
Evan Charlton | b35fc31 | 2014-07-19 15:02:55 -0700 | [diff] [blame] | 25 | import android.telecomm.TelecommManager; |
Santos Cordon | 76faae5 | 2013-12-12 18:55:50 -0800 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * This class receives the notification callback intents used to update call states for |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 29 | * {@link TestConnectionService}. |
Santos Cordon | 76faae5 | 2013-12-12 18:55:50 -0800 | [diff] [blame] | 30 | */ |
| 31 | public class CallNotificationReceiver extends BroadcastReceiver { |
Santos Cordon | 76faae5 | 2013-12-12 18:55:50 -0800 | [diff] [blame] | 32 | /** |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 33 | * Exit intent action is sent when the user clicks the "exit" action of the |
| 34 | * TestConnectionService notification. Used to cancel (remove) the notification. |
Santos Cordon | 76faae5 | 2013-12-12 18:55:50 -0800 | [diff] [blame] | 35 | */ |
Santos Cordon | c80a98c | 2014-02-19 02:59:34 -0800 | [diff] [blame] | 36 | static final String ACTION_CALL_SERVICE_EXIT = |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 37 | "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 Gunn | 0a388fc | 2014-07-17 12:21:17 -0700 | [diff] [blame] | 42 | 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 Cordon | 76faae5 | 2013-12-12 18:55:50 -0800 | [diff] [blame] | 46 | |
| 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 Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 52 | 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 Gunn | 0a388fc | 2014-07-17 12:21:17 -0700 | [diff] [blame] | 57 | } else if (ACTION_VIDEO_CALL.equals(action)) { |
| 58 | sendIncomingCallIntent(context, true); |
| 59 | } else if (ACTION_AUDIO_CALL.equals(action)) { |
| 60 | sendIncomingCallIntent(context, false); |
Santos Cordon | 76faae5 | 2013-12-12 18:55:50 -0800 | [diff] [blame] | 61 | } |
| 62 | } |
Tyler Gunn | 0a388fc | 2014-07-17 12:21:17 -0700 | [diff] [blame] | 63 | |
| 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 Cordon | fd86bd4 | 2014-07-19 14:59:04 -0700 | [diff] [blame] | 71 | PhoneAccountHandle phoneAccount = new PhoneAccountHandle( |
Tyler Gunn | 0a388fc | 2014-07-17 12:21:17 -0700 | [diff] [blame] | 72 | new ComponentName(context, TestConnectionService.class), |
Sailesh Nepal | e4ef521 | 2014-08-09 16:45:21 -0700 | [diff] [blame] | 73 | CallServiceNotifier.CALL_PROVIDER_ID); |
Tyler Gunn | 0a388fc | 2014-07-17 12:21:17 -0700 | [diff] [blame] | 74 | |
| 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 Cordon | fd86bd4 | 2014-07-19 14:59:04 -0700 | [diff] [blame] | 80 | TelecommManager.from(context).addNewIncomingCall(phoneAccount, extras); |
Tyler Gunn | 0a388fc | 2014-07-17 12:21:17 -0700 | [diff] [blame] | 81 | } |
Santos Cordon | 76faae5 | 2013-12-12 18:55:50 -0800 | [diff] [blame] | 82 | } |