Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 1 | /* |
| 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 Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 17 | package com.android.server.telecom; |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 18 | |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.content.Intent; |
| 21 | import android.os.UserHandle; |
Brad Ebinger | 953e1af | 2016-10-05 15:45:22 -0700 | [diff] [blame] | 22 | import android.telecom.Log; |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 23 | |
Tyler Gunn | bbd78a7 | 2017-04-30 14:16:07 -0700 | [diff] [blame] | 24 | import com.android.server.telecom.ui.ConfirmCallDialogActivity; |
| 25 | |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 26 | public final class TelecomBroadcastIntentProcessor { |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 27 | /** The action used to send SMS response for the missed call notification. */ |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 28 | public static final String ACTION_SEND_SMS_FROM_NOTIFICATION = |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 29 | "com.android.server.telecom.ACTION_SEND_SMS_FROM_NOTIFICATION"; |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 30 | |
| 31 | /** The action used to call a handle back for the missed call notification. */ |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 32 | public static final String ACTION_CALL_BACK_FROM_NOTIFICATION = |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 33 | "com.android.server.telecom.ACTION_CALL_BACK_FROM_NOTIFICATION"; |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 34 | |
| 35 | /** The action used to clear missed calls. */ |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 36 | public static final String ACTION_CLEAR_MISSED_CALLS = |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 37 | "com.android.server.telecom.ACTION_CLEAR_MISSED_CALLS"; |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 38 | |
Tyler Gunn | 2b17f23 | 2017-03-08 08:51:00 -0800 | [diff] [blame] | 39 | /** |
| 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 Gunn | bbd78a7 | 2017-04-30 14:16:07 -0700 | [diff] [blame] | 53 | /** |
| 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 Mak | a993094 | 2016-01-15 10:57:14 +0000 | [diff] [blame] | 67 | public static final String EXTRA_USERHANDLE = "userhandle"; |
| 68 | |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 69 | private final Context mContext; |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 70 | private final CallsManager mCallsManager; |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 71 | |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 72 | public TelecomBroadcastIntentProcessor(Context context, CallsManager callsManager) { |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 73 | mContext = context; |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 74 | mCallsManager = callsManager; |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | public void processIntent(Intent intent) { |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 78 | String action = intent.getAction(); |
| 79 | |
Tyler Gunn | 2b17f23 | 2017-03-08 08:51:00 -0800 | [diff] [blame] | 80 | 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 Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 89 | |
Tyler Gunn | 2b17f23 | 2017-03-08 08:51:00 -0800 | [diff] [blame] | 90 | MissedCallNotifier missedCallNotifier = mCallsManager.getMissedCallNotifier(); |
Nancy Chen | 6f5c08d | 2014-09-23 16:54:05 -0700 | [diff] [blame] | 91 | |
Tyler Gunn | 2b17f23 | 2017-03-08 08:51:00 -0800 | [diff] [blame] | 92 | // 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 Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 97 | |
Tyler Gunn | 2b17f23 | 2017-03-08 08:51:00 -0800 | [diff] [blame] | 98 | Intent callIntent = new Intent(Intent.ACTION_SENDTO, intent.getData()); |
| 99 | callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 100 | mContext.startActivityAsUser(callIntent, userHandle); |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 101 | |
Tyler Gunn | 2b17f23 | 2017-03-08 08:51:00 -0800 | [diff] [blame] | 102 | // 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 Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 107 | |
Tyler Gunn | 2b17f23 | 2017-03-08 08:51:00 -0800 | [diff] [blame] | 108 | 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 Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 112 | |
Tyler Gunn | 2b17f23 | 2017-03-08 08:51:00 -0800 | [diff] [blame] | 113 | // 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 Gunn | bbd78a7 | 2017-04-30 14:16:07 -0700 | [diff] [blame] | 131 | |
Tyler Gunn | 2b17f23 | 2017-03-08 08:51:00 -0800 | [diff] [blame] | 132 | // 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 Gunn | bbd78a7 | 2017-04-30 14:16:07 -0700 | [diff] [blame] | 140 | } 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 Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 158 | } |
| 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 | } |