blob: 3110d469cbc1aa026a8eed50f04acdf8c3bf77eb [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;
22
23/**
Tyler Gunn7cc70b42014-09-12 22:17:27 -070024 * Handles miscellaneous Telecom broadcast intents. This should be visible from outside, but
Santos Cordona0e5f1a2014-03-31 21:43:00 -070025 * should not be in the "exported" state.
26 */
Ihab Awad78a5e6b2015-02-06 10:13:05 -080027public final class TelecomBroadcastIntentProcessor {
Santos Cordona0e5f1a2014-03-31 21:43:00 -070028 /** The action used to send SMS response for the missed call notification. */
29 static final String ACTION_SEND_SMS_FROM_NOTIFICATION =
Tyler Gunn7cc70b42014-09-12 22:17:27 -070030 "com.android.server.telecom.ACTION_SEND_SMS_FROM_NOTIFICATION";
Santos Cordona0e5f1a2014-03-31 21:43:00 -070031
32 /** The action used to call a handle back for the missed call notification. */
33 static final String ACTION_CALL_BACK_FROM_NOTIFICATION =
Tyler Gunn7cc70b42014-09-12 22:17:27 -070034 "com.android.server.telecom.ACTION_CALL_BACK_FROM_NOTIFICATION";
Santos Cordona0e5f1a2014-03-31 21:43:00 -070035
36 /** The action used to clear missed calls. */
37 static final String ACTION_CLEAR_MISSED_CALLS =
Tyler Gunn7cc70b42014-09-12 22:17:27 -070038 "com.android.server.telecom.ACTION_CLEAR_MISSED_CALLS";
Santos Cordona0e5f1a2014-03-31 21:43:00 -070039
Ihab Awad78a5e6b2015-02-06 10:13:05 -080040 private final Context mContext;
41
42 public TelecomBroadcastIntentProcessor(Context context) {
43 mContext = context;
44 }
45
46 public void processIntent(Intent intent) {
Santos Cordona0e5f1a2014-03-31 21:43:00 -070047 String action = intent.getAction();
48
49 Log.v(this, "Action received: %s.", action);
50
Ihab Awad78a5e6b2015-02-06 10:13:05 -080051 MissedCallNotifier missedCallNotifier = TelecomSystem.getInstance()
52 .getCallsManager().getMissedCallNotifier();
Nancy Chen6f5c08d2014-09-23 16:54:05 -070053
Santos Cordona0e5f1a2014-03-31 21:43:00 -070054 // Send an SMS from the missed call notification.
55 if (ACTION_SEND_SMS_FROM_NOTIFICATION.equals(action)) {
56 // Close the notification shade and the notification itself.
Ihab Awad78a5e6b2015-02-06 10:13:05 -080057 closeSystemDialogs(mContext);
Nancy Chen6f5c08d2014-09-23 16:54:05 -070058 missedCallNotifier.clearMissedCalls();
Santos Cordona0e5f1a2014-03-31 21:43:00 -070059
60 Intent callIntent = new Intent(Intent.ACTION_SENDTO, intent.getData());
61 callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Ihab Awad78a5e6b2015-02-06 10:13:05 -080062 mContext.startActivity(callIntent);
Santos Cordona0e5f1a2014-03-31 21:43:00 -070063
64 // Call back recent caller from the missed call notification.
65 } else if (ACTION_CALL_BACK_FROM_NOTIFICATION.equals(action)) {
66 // Close the notification shade and the notification itself.
Ihab Awad78a5e6b2015-02-06 10:13:05 -080067 closeSystemDialogs(mContext);
Nancy Chen6f5c08d2014-09-23 16:54:05 -070068 missedCallNotifier.clearMissedCalls();
Santos Cordona0e5f1a2014-03-31 21:43:00 -070069
70 Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, intent.getData());
71 callIntent.setFlags(
72 Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Ihab Awad78a5e6b2015-02-06 10:13:05 -080073 mContext.startActivity(callIntent);
Santos Cordona0e5f1a2014-03-31 21:43:00 -070074
75 // Clear the missed call notification and call log entries.
76 } else if (ACTION_CLEAR_MISSED_CALLS.equals(action)) {
Nancy Chen6f5c08d2014-09-23 16:54:05 -070077 missedCallNotifier.clearMissedCalls();
Santos Cordona0e5f1a2014-03-31 21:43:00 -070078 }
79 }
80
81 /**
82 * Closes open system dialogs and the notification shade.
83 */
84 private void closeSystemDialogs(Context context) {
85 Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
86 context.sendBroadcastAsUser(intent, UserHandle.ALL);
87 }
88}