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
2378a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awadpublic final class TelecomBroadcastIntentProcessor {
24a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    /** The action used to send SMS response for the missed call notification. */
258de76915ea2772faeb41705aaaeb65f5b3478ac4Ihab Awad    public static final String ACTION_SEND_SMS_FROM_NOTIFICATION =
267cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunn            "com.android.server.telecom.ACTION_SEND_SMS_FROM_NOTIFICATION";
27a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
28a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    /** The action used to call a handle back for the missed call notification. */
298de76915ea2772faeb41705aaaeb65f5b3478ac4Ihab Awad    public static final String ACTION_CALL_BACK_FROM_NOTIFICATION =
307cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunn            "com.android.server.telecom.ACTION_CALL_BACK_FROM_NOTIFICATION";
31a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
32a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon    /** The action used to clear missed calls. */
338de76915ea2772faeb41705aaaeb65f5b3478ac4Ihab Awad    public static final String ACTION_CLEAR_MISSED_CALLS =
347cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunn            "com.android.server.telecom.ACTION_CLEAR_MISSED_CALLS";
35a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
3678a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad    private final Context mContext;
378de76915ea2772faeb41705aaaeb65f5b3478ac4Ihab Awad    private final CallsManager mCallsManager;
3878a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad
398de76915ea2772faeb41705aaaeb65f5b3478ac4Ihab Awad    public TelecomBroadcastIntentProcessor(Context context, CallsManager callsManager) {
4078a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad        mContext = context;
418de76915ea2772faeb41705aaaeb65f5b3478ac4Ihab Awad        mCallsManager = callsManager;
4278a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad    }
4378a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad
4478a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad    public void processIntent(Intent intent) {
45a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        String action = intent.getAction();
46a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
47a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        Log.v(this, "Action received: %s.", action);
48a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
498de76915ea2772faeb41705aaaeb65f5b3478ac4Ihab Awad        MissedCallNotifier missedCallNotifier = mCallsManager.getMissedCallNotifier();
506f5c08d34fed66b8937bd5051372c1e9466b6095Nancy Chen
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.
5478a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad            closeSystemDialogs(mContext);
556f5c08d34fed66b8937bd5051372c1e9466b6095Nancy Chen            missedCallNotifier.clearMissedCalls();
56a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
57a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            Intent callIntent = new Intent(Intent.ACTION_SENDTO, intent.getData());
58a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon            callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
59d0361407fceb58b3b9b93cd462877de6e1d54045Nancy Chen            mContext.startActivityAsUser(callIntent, UserHandle.CURRENT);
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.
6478a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad            closeSystemDialogs(mContext);
656f5c08d34fed66b8937bd5051372c1e9466b6095Nancy Chen            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);
70d0361407fceb58b3b9b93cd462877de6e1d54045Nancy Chen            mContext.startActivityAsUser(callIntent, UserHandle.CURRENT);
71a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon
72a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        // Clear the missed call notification and call log entries.
73a0e5f1aa917decf6921e372a3fd5a43da51adecbSantos Cordon        } else if (ACTION_CLEAR_MISSED_CALLS.equals(action)) {
746f5c08d34fed66b8937bd5051372c1e9466b6095Nancy Chen            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