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 17 package com.android.server.telecom; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.os.UserHandle; 22 import android.telecom.Log; 23 24 import com.android.server.telecom.ui.ConfirmCallDialogActivity; 25 26 public final class TelecomBroadcastIntentProcessor { 27 /** The action used to send SMS response for the missed call notification. */ 28 public static final String ACTION_SEND_SMS_FROM_NOTIFICATION = 29 "com.android.server.telecom.ACTION_SEND_SMS_FROM_NOTIFICATION"; 30 31 /** The action used to call a handle back for the missed call notification. */ 32 public static final String ACTION_CALL_BACK_FROM_NOTIFICATION = 33 "com.android.server.telecom.ACTION_CALL_BACK_FROM_NOTIFICATION"; 34 35 /** The action used to clear missed calls. */ 36 public static final String ACTION_CLEAR_MISSED_CALLS = 37 "com.android.server.telecom.ACTION_CLEAR_MISSED_CALLS"; 38 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 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 67 public static final String EXTRA_USERHANDLE = "userhandle"; 68 69 private final Context mContext; 70 private final CallsManager mCallsManager; 71 TelecomBroadcastIntentProcessor(Context context, CallsManager callsManager)72 public TelecomBroadcastIntentProcessor(Context context, CallsManager callsManager) { 73 mContext = context; 74 mCallsManager = callsManager; 75 } 76 processIntent(Intent intent)77 public void processIntent(Intent intent) { 78 String action = intent.getAction(); 79 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 } 89 90 MissedCallNotifier missedCallNotifier = mCallsManager.getMissedCallNotifier(); 91 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); 97 98 Intent callIntent = new Intent(Intent.ACTION_SENDTO, intent.getData()); 99 callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 100 mContext.startActivityAsUser(callIntent, userHandle); 101 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); 107 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); 112 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 { 131 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 } 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 } 158 } 159 } 160 161 /** 162 * Closes open system dialogs and the notification shade. 163 */ closeSystemDialogs(Context context)164 private void closeSystemDialogs(Context context) { 165 Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); 166 context.sendBroadcastAsUser(intent, UserHandle.ALL); 167 } 168 } 169