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