TelecomBroadcastIntentProcessor.java revision 7cc70b4f0ad1064a4a0dce6056ad82b205887160
1a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon/*
2a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon * Copyright (C) 2014 The Android Open Source Project
3a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon *
4a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon * Licensed under the Apache License, Version 2.0 (the "License");
5a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon * you may not use this file except in compliance with the License.
6a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon * You may obtain a copy of the License at
7a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon *
8a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon *      http://www.apache.org/licenses/LICENSE-2.0
9a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon *
10a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon * Unless required by applicable law or agreed to in writing, software
11a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon * distributed under the License is distributed on an "AS IS" BASIS,
12a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon * See the License for the specific language governing permissions and
14a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon * limitations under the License.
15a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon */
16a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
177cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunnpackage com.android.server.telecom;
18a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
19a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordonimport android.content.BroadcastReceiver;
20a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordonimport android.content.Context;
21a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordonimport android.content.Intent;
22a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordonimport android.os.UserHandle;
23a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
24a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon/**
257cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunn * Handles miscellaneous Telecom broadcast intents. This should be visible from outside, but
26a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon * should not be in the "exported" state.
27a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon */
287cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunnpublic final class TelecomBroadcastReceiver extends BroadcastReceiver {
29a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    /** The action used to send SMS response for the missed call notification. */
30a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    static final String ACTION_SEND_SMS_FROM_NOTIFICATION =
317cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunn            "com.android.server.telecom.ACTION_SEND_SMS_FROM_NOTIFICATION";
32a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
33a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    /** The action used to call a handle back for the missed call notification. */
34a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    static final String ACTION_CALL_BACK_FROM_NOTIFICATION =
357cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunn            "com.android.server.telecom.ACTION_CALL_BACK_FROM_NOTIFICATION";
36a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
37a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    /** The action used to clear missed calls. */
38a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    static final String ACTION_CLEAR_MISSED_CALLS =
397cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunn            "com.android.server.telecom.ACTION_CLEAR_MISSED_CALLS";
40a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
41a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
42a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    /** {@inheritDoc} */
43a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    @Override
44a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    public void onReceive(Context context, Intent intent) {
45a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        String action = intent.getAction();
46a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
47a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        Log.v(this, "Action received: %s.", action);
48a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
497cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunn        MissedCallNotifier missedCallNotifier = TelecomApp.getInstance().getMissedCallNotifier();
50a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
51a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        // Send an SMS from the missed call notification.
52a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        if (ACTION_SEND_SMS_FROM_NOTIFICATION.equals(action)) {
53a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            // Close the notification shade and the notification itself.
54a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            closeSystemDialogs(context);
55a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            missedCallNotifier.clearMissedCalls();
56a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
57a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            Intent callIntent = new Intent(Intent.ACTION_SENDTO, intent.getData());
58a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
59a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            context.startActivity(callIntent);
60a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
61a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        // Call back recent caller from the missed call notification.
62a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        } else if (ACTION_CALL_BACK_FROM_NOTIFICATION.equals(action)) {
63a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            // Close the notification shade and the notification itself.
64a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            closeSystemDialogs(context);
65a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            missedCallNotifier.clearMissedCalls();
66a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
67a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, intent.getData());
68a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            callIntent.setFlags(
69a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon                    Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
70a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            context.startActivity(callIntent);
71a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
72a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        // Clear the missed call notification and call log entries.
73a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        } else if (ACTION_CLEAR_MISSED_CALLS.equals(action)) {
74a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            missedCallNotifier.clearMissedCalls();
75a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        }
76a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    }
77a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
78a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    /**
79a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon     * Closes open system dialogs and the notification shade.
80a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon     */
81a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    private void closeSystemDialogs(Context context) {
82a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
83a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        context.sendBroadcastAsUser(intent, UserHandle.ALL);
84a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    }
85a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon}
86