Home | History | Annotate | Download | only in telecom
      1 /*
      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 
     17 package com.android.server.telecom;
     18 
     19 import android.content.Context;
     20 import android.content.Intent;
     21 import android.os.UserHandle;
     22 
     23 public final class TelecomBroadcastIntentProcessor {
     24     /** The action used to send SMS response for the missed call notification. */
     25     public static final String ACTION_SEND_SMS_FROM_NOTIFICATION =
     26             "com.android.server.telecom.ACTION_SEND_SMS_FROM_NOTIFICATION";
     27 
     28     /** The action used to call a handle back for the missed call notification. */
     29     public static final String ACTION_CALL_BACK_FROM_NOTIFICATION =
     30             "com.android.server.telecom.ACTION_CALL_BACK_FROM_NOTIFICATION";
     31 
     32     /** The action used to clear missed calls. */
     33     public static final String ACTION_CLEAR_MISSED_CALLS =
     34             "com.android.server.telecom.ACTION_CLEAR_MISSED_CALLS";
     35 
     36     public static final String EXTRA_USERHANDLE = "userhandle";
     37 
     38     private final Context mContext;
     39     private final CallsManager mCallsManager;
     40 
     41     public TelecomBroadcastIntentProcessor(Context context, CallsManager callsManager) {
     42         mContext = context;
     43         mCallsManager = callsManager;
     44     }
     45 
     46     public void processIntent(Intent intent) {
     47         String action = intent.getAction();
     48 
     49         Log.v(this, "Action received: %s.", action);
     50         UserHandle userHandle = intent.getParcelableExtra(EXTRA_USERHANDLE);
     51         if (userHandle == null) {
     52             Log.d(this, "user handle can't be null, not processing the broadcast");
     53             return;
     54         }
     55 
     56         MissedCallNotifier missedCallNotifier = mCallsManager.getMissedCallNotifier();
     57 
     58         // Send an SMS from the missed call notification.
     59         if (ACTION_SEND_SMS_FROM_NOTIFICATION.equals(action)) {
     60             // Close the notification shade and the notification itself.
     61             closeSystemDialogs(mContext);
     62             missedCallNotifier.clearMissedCalls(userHandle);
     63 
     64             Intent callIntent = new Intent(Intent.ACTION_SENDTO, intent.getData());
     65             callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     66             mContext.startActivityAsUser(callIntent, userHandle);
     67 
     68         // Call back recent caller from the missed call notification.
     69         } else if (ACTION_CALL_BACK_FROM_NOTIFICATION.equals(action)) {
     70             // Close the notification shade and the notification itself.
     71             closeSystemDialogs(mContext);
     72             missedCallNotifier.clearMissedCalls(userHandle);
     73 
     74             Intent callIntent = new Intent(Intent.ACTION_CALL, intent.getData());
     75             callIntent.setFlags(
     76                     Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
     77             mContext.startActivityAsUser(callIntent, userHandle);
     78 
     79         // Clear the missed call notification and call log entries.
     80         } else if (ACTION_CLEAR_MISSED_CALLS.equals(action)) {
     81             missedCallNotifier.clearMissedCalls(userHandle);
     82         }
     83     }
     84 
     85     /**
     86      * Closes open system dialogs and the notification shade.
     87      */
     88     private void closeSystemDialogs(Context context) {
     89         Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
     90         context.sendBroadcastAsUser(intent, UserHandle.ALL);
     91     }
     92 }
     93