blob: a51ef733117ea107254b05435a12be44f316b173 [file] [log] [blame]
Santos Cordona0e5f1a2014-03-31 21:43:00 -07001/*
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
Tyler Gunn7cc70b42014-09-12 22:17:27 -070017package com.android.server.telecom;
Santos Cordona0e5f1a2014-03-31 21:43:00 -070018
Santos Cordona0e5f1a2014-03-31 21:43:00 -070019import android.content.Context;
20import android.content.Intent;
21import android.os.UserHandle;
Brad Ebinger953e1af2016-10-05 15:45:22 -070022import android.telecom.Log;
Santos Cordona0e5f1a2014-03-31 21:43:00 -070023
Tyler Gunnbbd78a72017-04-30 14:16:07 -070024import com.android.server.telecom.ui.ConfirmCallDialogActivity;
25
Ihab Awad78a5e6b2015-02-06 10:13:05 -080026public final class TelecomBroadcastIntentProcessor {
Santos Cordona0e5f1a2014-03-31 21:43:00 -070027 /** The action used to send SMS response for the missed call notification. */
Ihab Awad8de76912015-02-17 12:25:52 -080028 public static final String ACTION_SEND_SMS_FROM_NOTIFICATION =
Tyler Gunn7cc70b42014-09-12 22:17:27 -070029 "com.android.server.telecom.ACTION_SEND_SMS_FROM_NOTIFICATION";
Santos Cordona0e5f1a2014-03-31 21:43:00 -070030
31 /** The action used to call a handle back for the missed call notification. */
Ihab Awad8de76912015-02-17 12:25:52 -080032 public static final String ACTION_CALL_BACK_FROM_NOTIFICATION =
Tyler Gunn7cc70b42014-09-12 22:17:27 -070033 "com.android.server.telecom.ACTION_CALL_BACK_FROM_NOTIFICATION";
Santos Cordona0e5f1a2014-03-31 21:43:00 -070034
35 /** The action used to clear missed calls. */
Ihab Awad8de76912015-02-17 12:25:52 -080036 public static final String ACTION_CLEAR_MISSED_CALLS =
Tyler Gunn7cc70b42014-09-12 22:17:27 -070037 "com.android.server.telecom.ACTION_CLEAR_MISSED_CALLS";
Santos Cordona0e5f1a2014-03-31 21:43:00 -070038
Tyler Gunn2b17f232017-03-08 08:51:00 -080039 /**
40 * The action used to answer the current incoming call displayed by
41 * {@link com.android.server.telecom.ui.IncomingCallNotifier}.
42 */
43 public static final String ACTION_ANSWER_FROM_NOTIFICATION =
44 "com.android.server.telecom.ACTION_ANSWER_FROM_NOTIFICATION";
45
46 /**
47 * The action used to reject the current incoming call displayed by
48 * {@link com.android.server.telecom.ui.IncomingCallNotifier}.
49 */
50 public static final String ACTION_REJECT_FROM_NOTIFICATION =
51 "com.android.server.telecom.ACTION_REJECT_FROM_NOTIFICATION";
52
Tyler Gunnbbd78a72017-04-30 14:16:07 -070053 /**
54 * The action used to proceed with a call being confirmed via
55 * {@link com.android.server.telecom.ui.ConfirmCallDialogActivity}.
56 */
57 public static final String ACTION_PROCEED_WITH_CALL =
58 "com.android.server.telecom.PROCEED_WITH_CALL";
59
60 /**
61 * The action used to cancel a call being confirmed via
62 * {@link com.android.server.telecom.ui.ConfirmCallDialogActivity}.
63 */
64 public static final String ACTION_CANCEL_CALL =
65 "com.android.server.telecom.CANCEL_CALL";
66
Tony Maka9930942016-01-15 10:57:14 +000067 public static final String EXTRA_USERHANDLE = "userhandle";
68
Ihab Awad78a5e6b2015-02-06 10:13:05 -080069 private final Context mContext;
Ihab Awad8de76912015-02-17 12:25:52 -080070 private final CallsManager mCallsManager;
Ihab Awad78a5e6b2015-02-06 10:13:05 -080071
Ihab Awad8de76912015-02-17 12:25:52 -080072 public TelecomBroadcastIntentProcessor(Context context, CallsManager callsManager) {
Ihab Awad78a5e6b2015-02-06 10:13:05 -080073 mContext = context;
Ihab Awad8de76912015-02-17 12:25:52 -080074 mCallsManager = callsManager;
Ihab Awad78a5e6b2015-02-06 10:13:05 -080075 }
76
77 public void processIntent(Intent intent) {
Santos Cordona0e5f1a2014-03-31 21:43:00 -070078 String action = intent.getAction();
79
Tyler Gunn2b17f232017-03-08 08:51:00 -080080 if (ACTION_SEND_SMS_FROM_NOTIFICATION.equals(action) ||
81 ACTION_CALL_BACK_FROM_NOTIFICATION.equals(action) ||
82 ACTION_CLEAR_MISSED_CALLS.equals(action)) {
83 Log.v(this, "Action received: %s.", action);
84 UserHandle userHandle = intent.getParcelableExtra(EXTRA_USERHANDLE);
85 if (userHandle == null) {
86 Log.d(this, "user handle can't be null, not processing the broadcast");
87 return;
88 }
Santos Cordona0e5f1a2014-03-31 21:43:00 -070089
Tyler Gunn2b17f232017-03-08 08:51:00 -080090 MissedCallNotifier missedCallNotifier = mCallsManager.getMissedCallNotifier();
Nancy Chen6f5c08d2014-09-23 16:54:05 -070091
Tyler Gunn2b17f232017-03-08 08:51:00 -080092 // Send an SMS from the missed call notification.
93 if (ACTION_SEND_SMS_FROM_NOTIFICATION.equals(action)) {
94 // Close the notification shade and the notification itself.
95 closeSystemDialogs(mContext);
96 missedCallNotifier.clearMissedCalls(userHandle);
Santos Cordona0e5f1a2014-03-31 21:43:00 -070097
Tyler Gunn2b17f232017-03-08 08:51:00 -080098 Intent callIntent = new Intent(Intent.ACTION_SENDTO, intent.getData());
99 callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
100 mContext.startActivityAsUser(callIntent, userHandle);
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700101
Tyler Gunn2b17f232017-03-08 08:51:00 -0800102 // Call back recent caller from the missed call notification.
103 } else if (ACTION_CALL_BACK_FROM_NOTIFICATION.equals(action)) {
104 // Close the notification shade and the notification itself.
105 closeSystemDialogs(mContext);
106 missedCallNotifier.clearMissedCalls(userHandle);
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700107
Tyler Gunn2b17f232017-03-08 08:51:00 -0800108 Intent callIntent = new Intent(Intent.ACTION_CALL, intent.getData());
109 callIntent.setFlags(
110 Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
111 mContext.startActivityAsUser(callIntent, userHandle);
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700112
Tyler Gunn2b17f232017-03-08 08:51:00 -0800113 // Clear the missed call notification and call log entries.
114 } else if (ACTION_CLEAR_MISSED_CALLS.equals(action)) {
115 missedCallNotifier.clearMissedCalls(userHandle);
116 }
117 } else if (ACTION_ANSWER_FROM_NOTIFICATION.equals(action)) {
118 Log.startSession("TBIP.aAFM");
119 try {
120 // Answer the current ringing call.
121 Call incomingCall = mCallsManager.getIncomingCallNotifier().getIncomingCall();
122 if (incomingCall != null) {
123 mCallsManager.answerCall(incomingCall, incomingCall.getVideoState());
124 }
125 } finally {
126 Log.endSession();
127 }
128 } else if (ACTION_REJECT_FROM_NOTIFICATION.equals(action)) {
129 Log.startSession("TBIP.aRFM");
130 try {
Tyler Gunnbbd78a72017-04-30 14:16:07 -0700131
Tyler Gunn2b17f232017-03-08 08:51:00 -0800132 // Reject the current ringing call.
133 Call incomingCall = mCallsManager.getIncomingCallNotifier().getIncomingCall();
134 if (incomingCall != null) {
135 mCallsManager.rejectCall(incomingCall, false /* isRejectWithMessage */, null);
136 }
137 } finally {
138 Log.endSession();
139 }
Tyler Gunnbbd78a72017-04-30 14:16:07 -0700140 } else if (ACTION_PROCEED_WITH_CALL.equals(action)) {
141 Log.startSession("TBIP.aPWC");
142 try {
143 String callId = intent.getStringExtra(
144 ConfirmCallDialogActivity.EXTRA_OUTGOING_CALL_ID);
145 mCallsManager.confirmPendingCall(callId);
146 } finally {
147 Log.endSession();
148 }
149 } else if (ACTION_CANCEL_CALL.equals(action)) {
150 Log.startSession("TBIP.aCC");
151 try {
152 String callId = intent.getStringExtra(
153 ConfirmCallDialogActivity.EXTRA_OUTGOING_CALL_ID);
154 mCallsManager.cancelPendingCall(callId);
155 } finally {
156 Log.endSession();
157 }
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700158 }
159 }
160
161 /**
162 * Closes open system dialogs and the notification shade.
163 */
164 private void closeSystemDialogs(Context context) {
165 Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
166 context.sendBroadcastAsUser(intent, UserHandle.ALL);
167 }
168}