1/*
2 * Copyright (C) 2015 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.incallui;
18
19import android.content.BroadcastReceiver;
20import android.content.Context;
21import android.content.Intent;
22import android.telecom.VideoProfile;
23
24/**
25 * Accepts broadcast Intents which will be prepared by {@link StatusBarNotifier} and thus
26 * sent from the notification manager.
27 * This should be visible from outside, but shouldn't be exported.
28 */
29public class NotificationBroadcastReceiver extends BroadcastReceiver {
30
31    /**
32     * Intent Action used for hanging up the current call from Notification bar. This will
33     * choose first ringing call, first active call, or first background call (typically in
34     * STATE_HOLDING state).
35     */
36    public static final String ACTION_DECLINE_INCOMING_CALL =
37            "com.android.incallui.ACTION_DECLINE_INCOMING_CALL";
38    public static final String ACTION_HANG_UP_ONGOING_CALL =
39            "com.android.incallui.ACTION_HANG_UP_ONGOING_CALL";
40    public static final String ACTION_ANSWER_VIDEO_INCOMING_CALL =
41            "com.android.incallui.ACTION_ANSWER_VIDEO_INCOMING_CALL";
42    public static final String ACTION_ANSWER_VOICE_INCOMING_CALL =
43            "com.android.incallui.ACTION_ANSWER_VOICE_INCOMING_CALL";
44    public static final String ACTION_ACCEPT_VIDEO_UPGRADE_REQUEST =
45            "com.android.incallui.ACTION_ACCEPT_VIDEO_UPGRADE_REQUEST";
46    public static final String ACTION_DECLINE_VIDEO_UPGRADE_REQUEST =
47            "com.android.incallui.ACTION_DECLINE_VIDEO_UPGRADE_REQUEST";
48
49    @Override
50    public void onReceive(Context context, Intent intent) {
51        final String action = intent.getAction();
52        Log.i(this, "Broadcast from Notification: " + action);
53
54        // TODO: Commands of this nature should exist in the CallList.
55        if (action.equals(ACTION_ANSWER_VIDEO_INCOMING_CALL)) {
56            InCallPresenter.getInstance().answerIncomingCall(
57                    context, VideoProfile.STATE_BIDIRECTIONAL);
58        } else if (action.equals(ACTION_ANSWER_VOICE_INCOMING_CALL)) {
59            InCallPresenter.getInstance().answerIncomingCall(
60                    context, VideoProfile.STATE_AUDIO_ONLY);
61        } else if (action.equals(ACTION_DECLINE_INCOMING_CALL)) {
62            InCallPresenter.getInstance().declineIncomingCall(context);
63        } else if (action.equals(ACTION_HANG_UP_ONGOING_CALL)) {
64            InCallPresenter.getInstance().hangUpOngoingCall(context);
65        } else if (action.equals(ACTION_ACCEPT_VIDEO_UPGRADE_REQUEST)) {
66            //TODO: Change calltype after adding support for TX and RX
67            InCallPresenter.getInstance().acceptUpgradeRequest(
68                    VideoProfile.STATE_BIDIRECTIONAL, context);
69        } else if (action.equals(ACTION_DECLINE_VIDEO_UPGRADE_REQUEST)) {
70            InCallPresenter.getInstance().declineUpgradeRequest(context);
71        }
72    }
73
74}
75