TelecomBroadcastIntentProcessor.java revision 78a5e6b9c1595c81f72d7a822617cb78db224e48
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.Context;
20a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordonimport android.content.Intent;
21a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordonimport android.os.UserHandle;
22a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
23a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon/**
247cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunn * Handles miscellaneous Telecom broadcast intents. This should be visible from outside, but
25a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon * should not be in the "exported" state.
26a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon */
2778a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awadpublic final class TelecomBroadcastIntentProcessor {
28a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    /** The action used to send SMS response for the missed call notification. */
29a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    static final String ACTION_SEND_SMS_FROM_NOTIFICATION =
307cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunn            "com.android.server.telecom.ACTION_SEND_SMS_FROM_NOTIFICATION";
31a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
32a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    /** The action used to call a handle back for the missed call notification. */
33a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    static final String ACTION_CALL_BACK_FROM_NOTIFICATION =
347cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunn            "com.android.server.telecom.ACTION_CALL_BACK_FROM_NOTIFICATION";
35a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
36a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    /** The action used to clear missed calls. */
37a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    static final String ACTION_CLEAR_MISSED_CALLS =
387cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunn            "com.android.server.telecom.ACTION_CLEAR_MISSED_CALLS";
39a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
4078a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad    private final Context mContext;
4178a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad
4278a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad    public TelecomBroadcastIntentProcessor(Context context) {
4378a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad        mContext = context;
4478a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad    }
4578a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad
4678a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad    public void processIntent(Intent intent) {
47a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        String action = intent.getAction();
48a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
49a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        Log.v(this, "Action received: %s.", action);
50a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
5178a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad        MissedCallNotifier missedCallNotifier = TelecomSystem.getInstance()
5278a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad                .getCallsManager().getMissedCallNotifier();
536f5c08d34fed66b8937bd5051372c1e9466b6095Nancy Chen
54a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        // Send an SMS from the missed call notification.
55a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        if (ACTION_SEND_SMS_FROM_NOTIFICATION.equals(action)) {
56a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            // Close the notification shade and the notification itself.
5778a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad            closeSystemDialogs(mContext);
586f5c08d34fed66b8937bd5051372c1e9466b6095Nancy Chen            missedCallNotifier.clearMissedCalls();
59a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
60a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            Intent callIntent = new Intent(Intent.ACTION_SENDTO, intent.getData());
61a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
6278a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad            mContext.startActivity(callIntent);
63a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
64a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        // Call back recent caller from the missed call notification.
65a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        } else if (ACTION_CALL_BACK_FROM_NOTIFICATION.equals(action)) {
66a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            // Close the notification shade and the notification itself.
6778a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad            closeSystemDialogs(mContext);
686f5c08d34fed66b8937bd5051372c1e9466b6095Nancy Chen            missedCallNotifier.clearMissedCalls();
69a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
70a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, intent.getData());
71a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            callIntent.setFlags(
72a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon                    Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
7378a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad            mContext.startActivity(callIntent);
74a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
75a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        // Clear the missed call notification and call log entries.
76a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        } else if (ACTION_CLEAR_MISSED_CALLS.equals(action)) {
776f5c08d34fed66b8937bd5051372c1e9466b6095Nancy Chen            missedCallNotifier.clearMissedCalls();
78a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        }
79a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    }
80a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
81a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    /**
82a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon     * Closes open system dialogs and the notification shade.
83a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon     */
84a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    private void closeSystemDialogs(Context context) {
85a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
86a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        context.sendBroadcastAsUser(intent, UserHandle.ALL);
87a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    }
88a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon}
89