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 17 package android.telecom.cts; 18 19 import android.telecom.Conference; 20 import android.telecom.Connection; 21 import android.telecom.DisconnectCause; 22 import android.telecom.PhoneAccountHandle; 23 import android.telecom.RemoteConference; 24 import android.telecom.TelecomManager; 25 26 /** 27 * {@link Conference} subclass that immediately performs any state changes that are a result of 28 * callbacks sent from Telecom. 29 */ 30 public class MockConference extends Conference { 31 32 private RemoteConference mRemoteConference = null; 33 private String mDtmfString = ""; 34 MockConference(PhoneAccountHandle phoneAccount)35 public MockConference(PhoneAccountHandle phoneAccount) { 36 super(phoneAccount); 37 } 38 MockConference(MockConnection a, MockConnection b)39 public MockConference(MockConnection a, MockConnection b) { 40 super(a.getPhoneAccountHandle()); 41 addConnection(a); 42 addConnection(b); 43 // a is the primary connection, so inherit the properties from it. 44 setConnectionCapabilities(a.getConnectionCapabilities()); 45 setStatusHints(a.getStatusHints()); 46 setExtras(a.getExtras()); 47 } 48 49 @Override onDisconnect()50 public void onDisconnect() { 51 super.onDisconnect(); 52 for (Connection c : getConnections()) { 53 c.setDisconnected(new DisconnectCause(DisconnectCause.REMOTE)); 54 c.destroy(); 55 } 56 destroy(); 57 if (mRemoteConference != null) { 58 mRemoteConference.disconnect(); 59 } 60 } 61 62 @Override onSeparate(Connection connection)63 public void onSeparate(Connection connection) { 64 super.onSeparate(connection); 65 if (getConnections().contains(connection)) { 66 removeConnection(connection); 67 } 68 if (mRemoteConference != null) { 69 mRemoteConference.separate(((MockConnection)connection).getRemoteConnection()); 70 } 71 } 72 73 @Override onMerge()74 public void onMerge() { 75 super.onMerge(); 76 // Let's just change the connection display name for testing that onMerge was invoked. 77 for (Connection c : getConnections()) { 78 c.setCallerDisplayName( 79 TestUtils.MERGE_CALLER_NAME, TelecomManager.PRESENTATION_ALLOWED); 80 } 81 if (mRemoteConference != null) { 82 mRemoteConference.merge(); 83 } 84 } 85 86 @Override onSwap()87 public void onSwap() { 88 super.onSwap(); 89 // Let's just change the connection display name for testing that onSwap was invoked. 90 for (Connection c : getConnections()) { 91 c.setCallerDisplayName( 92 TestUtils.SWAP_CALLER_NAME, TelecomManager.PRESENTATION_ALLOWED); 93 } 94 if (mRemoteConference != null) { 95 mRemoteConference.swap(); 96 } 97 } 98 99 @Override onHold()100 public void onHold() { 101 super.onHold(); 102 for (Connection c : getConnections()) { 103 c.setOnHold(); 104 } 105 setOnHold(); 106 if (mRemoteConference != null) { 107 mRemoteConference.hold(); 108 } 109 } 110 111 @Override onUnhold()112 public void onUnhold() { 113 super.onUnhold(); 114 for (Connection c : getConnections()) { 115 c.setActive(); 116 } 117 setActive(); 118 if (mRemoteConference != null) { 119 mRemoteConference.unhold(); 120 } 121 } 122 123 @Override onPlayDtmfTone(char c)124 public void onPlayDtmfTone(char c) { 125 super.onPlayDtmfTone(c); 126 mDtmfString += c; 127 if (mRemoteConference != null) { 128 mRemoteConference.playDtmfTone(c); 129 } 130 } 131 132 @Override onStopDtmfTone()133 public void onStopDtmfTone() { 134 super.onStopDtmfTone(); 135 mDtmfString += "."; 136 if (mRemoteConference != null) { 137 mRemoteConference.stopDtmfTone(); 138 } 139 } 140 setRemoteConference(RemoteConference remoteConference)141 public void setRemoteConference(RemoteConference remoteConference) { 142 mRemoteConference = remoteConference; 143 } 144 getRemoteConference()145 public RemoteConference getRemoteConference() { 146 return mRemoteConference; 147 } 148 getDtmfString()149 public String getDtmfString() { 150 return mDtmfString; 151 } 152 } 153