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 | |
| 19 | import android.content.BroadcastReceiver; |
| 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.os.UserHandle; |
| 23 | |
| 24 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 25 | * Handles miscellaneous Telecom broadcast intents. This should be visible from outside, but |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 26 | * should not be in the "exported" state. |
| 27 | */ |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 28 | public final class TelecomBroadcastReceiver extends BroadcastReceiver { |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 29 | /** The action used to send SMS response for the missed call notification. */ |
| 30 | static final String ACTION_SEND_SMS_FROM_NOTIFICATION = |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 31 | "com.android.server.telecom.ACTION_SEND_SMS_FROM_NOTIFICATION"; |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 32 | |
| 33 | /** The action used to call a handle back for the missed call notification. */ |
| 34 | static final String ACTION_CALL_BACK_FROM_NOTIFICATION = |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 35 | "com.android.server.telecom.ACTION_CALL_BACK_FROM_NOTIFICATION"; |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 36 | |
| 37 | /** The action used to clear missed calls. */ |
| 38 | static final String ACTION_CLEAR_MISSED_CALLS = |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 39 | "com.android.server.telecom.ACTION_CLEAR_MISSED_CALLS"; |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 40 | |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 41 | /** {@inheritDoc} */ |
| 42 | @Override |
| 43 | public void onReceive(Context context, Intent intent) { |
| 44 | String action = intent.getAction(); |
| 45 | |
| 46 | Log.v(this, "Action received: %s.", action); |
| 47 | |
Nancy Chen | 6f5c08d | 2014-09-23 16:54:05 -0700 | [diff] [blame^] | 48 | MissedCallNotifier missedCallNotifier = CallsManager.getInstance().getMissedCallNotifier(); |
| 49 | |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 50 | // Send an SMS from the missed call notification. |
| 51 | if (ACTION_SEND_SMS_FROM_NOTIFICATION.equals(action)) { |
| 52 | // Close the notification shade and the notification itself. |
| 53 | closeSystemDialogs(context); |
Nancy Chen | 6f5c08d | 2014-09-23 16:54:05 -0700 | [diff] [blame^] | 54 | missedCallNotifier.clearMissedCalls(); |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 55 | |
| 56 | Intent callIntent = new Intent(Intent.ACTION_SENDTO, intent.getData()); |
| 57 | callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 58 | context.startActivity(callIntent); |
| 59 | |
| 60 | // Call back recent caller from the missed call notification. |
| 61 | } else if (ACTION_CALL_BACK_FROM_NOTIFICATION.equals(action)) { |
| 62 | // Close the notification shade and the notification itself. |
| 63 | closeSystemDialogs(context); |
Nancy Chen | 6f5c08d | 2014-09-23 16:54:05 -0700 | [diff] [blame^] | 64 | missedCallNotifier.clearMissedCalls(); |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 65 | |
| 66 | Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, intent.getData()); |
| 67 | callIntent.setFlags( |
| 68 | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 69 | context.startActivity(callIntent); |
| 70 | |
| 71 | // Clear the missed call notification and call log entries. |
| 72 | } else if (ACTION_CLEAR_MISSED_CALLS.equals(action)) { |
Nancy Chen | 6f5c08d | 2014-09-23 16:54:05 -0700 | [diff] [blame^] | 73 | missedCallNotifier.clearMissedCalls(); |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Closes open system dialogs and the notification shade. |
| 79 | */ |
| 80 | private void closeSystemDialogs(Context context) { |
| 81 | Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 82 | context.sendBroadcastAsUser(intent, UserHandle.ALL); |
| 83 | } |
| 84 | } |