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 android.telecom.cts.cuj; 18 19 import android.content.Intent; 20 import android.os.IBinder; 21 import android.telecom.Call; 22 import android.telecom.InCallService; 23 import android.util.Log; 24 25 import java.util.List; 26 import java.util.Map; 27 import java.util.concurrent.ConcurrentHashMap; 28 29 public class CujInCallService extends InCallService { 30 private static final String TAG = CujInCallService.class.getSimpleName(); 31 public static boolean sIsServiceBound = false; 32 public static final Map<String, Call> sCallIdToCall = new ConcurrentHashMap(); 33 public static Call sLastCall = null; 34 35 @Override onBind(Intent intent)36 public IBinder onBind(Intent intent) { 37 Log.i(TAG, "onBind"); 38 sIsServiceBound = true; 39 return super.onBind(intent); 40 } 41 42 @Override onUnbind(Intent intent)43 public boolean onUnbind(Intent intent) { 44 Log.i(TAG, "onUnbind"); 45 sIsServiceBound = false; 46 sLastCall = null; 47 sCallIdToCall.clear(); 48 return super.onUnbind(intent); 49 } 50 51 @Override onCallAdded(Call call)52 public void onCallAdded(Call call) { 53 Log.i(TAG, String.format("onCallAdded: call=[%s]", call)); 54 sCallIdToCall.put(call.getDetails().getId(), call); 55 if (call.getDetails().getState() == Call.STATE_SELECT_PHONE_ACCOUNT) { 56 Log.w(TAG, "Call moved into STATE_SELECT_PHONE_ACCOUNT unexpectedly, disconnecting: " 57 + call); 58 // If this unexpected state happens, the test and calls could get stuck. Manually 59 // disconnect here until we support moving into SELECT_PHONE_ACCOUNT 60 call.disconnect(); 61 } 62 sLastCall = call; 63 } 64 65 @Override onCallRemoved(Call call)66 public void onCallRemoved(Call call) { 67 Log.i(TAG, String.format("onCallRemoved: call=[%s]", call)); 68 sCallIdToCall.remove(call.getDetails().getId()); 69 } 70 isServiceBound()71 public static boolean isServiceBound() { 72 return sIsServiceBound; 73 } 74 getCurrentCallCount()75 public static int getCurrentCallCount() { 76 return sCallIdToCall.size(); 77 } 78 getOngoingCalls()79 public static List<Call> getOngoingCalls() { 80 return sCallIdToCall.values().stream().toList(); 81 } 82 getLastAddedCall()83 public static Call getLastAddedCall() { 84 return sLastCall; 85 } 86 } 87 88