1 /*
2  * Copyright (C) 2023 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.bedstead.testapp;
18 
19 import android.content.Intent;
20 import android.os.IBinder;
21 import android.telecom.Call;
22 import android.telecom.InCallService;
23 
24 import com.android.eventlib.events.CustomEvent;
25 import com.android.eventlib.events.services.ServiceBoundEvent;
26 
27 /**
28  * Test {@link InCallService} to receive updates about Call events during tests
29  *
30  * TODO(b/276891195): Move this to EventLib
31  */
32 public class TestInCallService extends InCallService {
33 
34     public static String TAG = "TestInCallService";
35     private final Call.Callback mCallBack = new Call.Callback() {
36         @Override
37         public void onStateChanged(Call call, int state) {
38             CustomEvent.logger(getApplicationContext()).setTag(TAG).setData(
39                     "onStateChanged:" + state).log();
40             if (state == Call.STATE_ACTIVE) {
41                 call.disconnect();
42             }
43         }
44     };
45 
46     @Override
onBind(Intent intent)47     public IBinder onBind(Intent intent) {
48         ServiceBoundEvent.logger(this, getClass().getName(), intent).log();
49         return super.onBind(intent);
50     }
51 
52     @Override
onCallAdded(Call call)53     public void onCallAdded(Call call) {
54         call.registerCallback(mCallBack);
55     }
56 }
57