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 android.telecom.cts; 18 19 import android.os.Bundle; 20 import android.telecom.CallAudioState; 21 import android.telecom.Connection; 22 import android.telecom.DisconnectCause; 23 import android.telecom.cts.TestUtils.InvokeCounter; 24 25 import java.util.concurrent.CountDownLatch; 26 27 /** 28 * CTS Test self-managed {@link Connection} implementation. 29 */ 30 public class SelfManagedConnection extends Connection { 31 32 InvokeCounter mCallAudioRouteInvokeCounter = new InvokeCounter("onCallAudioStateChanged"); 33 InvokeCounter mOnShowIncomingUiInvokeCounter = new InvokeCounter( 34 "onShowIncomingUiInvokeCounter"); 35 InvokeCounter mCallEventCounter = new InvokeCounter("onCallEvent"); 36 InvokeCounter mHandoverCompleteCounter = new InvokeCounter("handoverCompleteCounter"); 37 CountDownLatch mOnHoldLatch = new CountDownLatch(1); 38 39 public static abstract class Listener { 40 void onDestroyed(SelfManagedConnection connection) { }; 41 } 42 43 private final boolean mIsIncomingCall; 44 private final Listener mListener; 45 46 public SelfManagedConnection(boolean isIncomingCall, Listener listener) { 47 mIsIncomingCall = isIncomingCall; 48 mListener = listener; 49 } 50 51 public boolean isIncomingCall() { 52 return mIsIncomingCall; 53 } 54 55 public void disconnectAndDestroy() { 56 setDisconnected(new DisconnectCause(DisconnectCause.LOCAL)); 57 destroy(); 58 mListener.onDestroyed(this); 59 } 60 61 @Override 62 public void onCallAudioStateChanged(CallAudioState state) { 63 mCallAudioRouteInvokeCounter.invoke(state); 64 } 65 66 @Override 67 public void onShowIncomingCallUi() { 68 mOnShowIncomingUiInvokeCounter.invoke(); 69 } 70 71 @Override 72 public void onHold() { 73 mOnHoldLatch.countDown(); 74 } 75 76 @Override 77 public void onCallEvent(String event, Bundle extras) { 78 mCallEventCounter.invoke(event, extras); 79 } 80 81 @Override 82 public void onHandoverComplete() { 83 mHandoverCompleteCounter.invoke(); 84 } 85 86 public InvokeCounter getCallAudioStateChangedInvokeCounter() { 87 return mCallAudioRouteInvokeCounter; 88 } 89 90 public InvokeCounter getOnShowIncomingUiInvokeCounter() { 91 return mOnShowIncomingUiInvokeCounter; 92 } 93 94 public InvokeCounter getCallEventCounter() { 95 return mCallEventCounter; 96 } 97 98 public InvokeCounter getHandoverCompleteCounter() { 99 return mHandoverCompleteCounter; 100 } 101 102 public boolean waitOnHold() { 103 mOnHoldLatch = TestUtils.waitForLock(mOnHoldLatch); 104 return mOnHoldLatch != null; 105 } 106 } 107