1 /*
2  * Copyright (C) 2017 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.testapps;
18 
19 import android.app.NotificationManager;
20 import android.content.BroadcastReceiver;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.telecom.Log;
24 import android.telephony.DisconnectCause;
25 
26 /**
27  * Handles actions from the self-managed calling sample app incoming call UX.
28  */
29 public class SelfManagedCallNotificationReceiver extends BroadcastReceiver {
30     public static final String ACTION_ANSWER_CALL =
31             "com.android.server.telecom.testapps.action.ANSWER_CALL";
32     public static final String ACTION_REJECT_CALL =
33             "com.android.server.telecom.testapps.action.REJECT_CALL";
34 
35     @Override
onReceive(Context context, Intent intent)36     public void onReceive(Context context, Intent intent) {
37         String action = intent.getAction();
38         int callId = intent.getIntExtra(IncomingSelfManagedCallActivity.EXTRA_CALL_ID, 0);
39         NotificationManager notificationManager = context.getSystemService(
40                 NotificationManager.class);
41         SelfManagedConnection connection = SelfManagedCallList.getInstance()
42                 .getConnectionById(callId);
43         switch (action) {
44             case ACTION_ANSWER_CALL:
45                 Log.i(this, "onReceive - answerCall %d", callId);
46                 if (connection != null) {
47                     connection.setConnectionActive();
48                 }
49                 notificationManager.cancel(SelfManagedConnection.CALL_NOTIFICATION, callId);
50                 break;
51 
52             case ACTION_REJECT_CALL:
53                 Log.i(this, "onReceive - rejectCall %d", callId);
54                 if (connection != null) {
55                     connection.setConnectionDisconnected(DisconnectCause.INCOMING_REJECTED);
56                     connection.destroy();
57                 }
58                 notificationManager.cancel(SelfManagedConnection.CALL_NOTIFICATION, callId);
59                 break;
60         }
61     }
62 }
63