• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 package com.android.car.dialer;
17 
18 import android.content.BroadcastReceiver;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.telecom.Call;
22 
23 import com.android.car.dialer.telecom.UiCall;
24 import com.android.car.dialer.telecom.UiCallManager;
25 
26 /**
27  * Performs actions on ongoing calls.
28  */
29 public class CallActionsReceiver extends BroadcastReceiver {
30     /**
31      * Answer the incoming call. No-op if there isn't one.
32      */
33     public static final String ACTION_ANSWER_INCOMING_CALL = "action_answer_incoming_call";
34     /**
35      * Reject the incoming call. No-op if there isn't one.
36      */
37     public static final String ACTION_REJECT_INCOMING_CALL = "action_reject_incoming_call";
38     /**
39      * Call a phone number. This will take advantage of any logic in
40      * {@link UiCallManager#safePlaceCall(String, boolean)}.
41      * However, it will pass null in for CarBluetoothConnectionManager due to the transient
42      * lifecycle of broadcast receivers.
43      */
44     public static final String ACTION_CALL_NUMBER = "action_call_number";
45     /**
46      * Extra to store the number to call.
47      */
48     public static final String EXTRA_PHONE_NUMBER = "extra_phone_number";
49 
50     @Override
onReceive(Context context, Intent intent)51     public void onReceive(Context context, Intent intent) {
52         String action = intent.getAction();
53         if (action == null) {
54             return;
55         }
56 
57         UiCallManager uiCallManager = UiCallManager.getInstance(context);
58 
59         UiCall call;
60         switch(action) {
61             case ACTION_ANSWER_INCOMING_CALL:
62                 call = uiCallManager.getCallWithState(Call.STATE_RINGING);
63                 if (call != null) {
64                     uiCallManager.getInstance(context).answerCall(call);
65                 }
66                 break;
67             case ACTION_REJECT_INCOMING_CALL:
68                 call = uiCallManager.getCallWithState(Call.STATE_RINGING);
69                 if (call != null) {
70                     uiCallManager.getInstance(context).rejectCall(call, false, null);
71                 }
72                 break;
73             case ACTION_CALL_NUMBER:
74                 uiCallManager.safePlaceCall(intent.getStringExtra(EXTRA_PHONE_NUMBER), false);
75                 break;
76         }
77     }
78 }
79