1 /* 2 * Copyright (C) 2022 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.telephony.ims.cts; 18 19 import java.util.Map; 20 import java.util.concurrent.ConcurrentHashMap; 21 22 public class ConferenceHelper { 23 24 private static final String TAG = "ConferenceHelper"; 25 26 private TestImsCallSessionImpl mConfSession = null; 27 private TestImsCallSessionImpl mForeGroundSession = null; 28 private TestImsCallSessionImpl mBackGroundSession = null; 29 30 private final ConcurrentHashMap<String, TestImsCallSessionImpl> mSessions = 31 new ConcurrentHashMap<String, TestImsCallSessionImpl>(); 32 addSession(TestImsCallSessionImpl session)33 public void addSession(TestImsCallSessionImpl session) { 34 synchronized (mSessions) { 35 mSessions.put(session.getCallId(), session); 36 } 37 } 38 39 // delete the call session used for merge to connect the conference call. removeSession(TestImsCallSessionImpl session)40 public void removeSession(TestImsCallSessionImpl session) { 41 synchronized (mSessions) { 42 mSessions.remove(session.getCallId(), session); 43 } 44 } 45 getActiveSession(String callId)46 public TestImsCallSessionImpl getActiveSession(String callId) { 47 synchronized (mSessions) { 48 if (mSessions.isEmpty()) { 49 return null; 50 } 51 52 for (Map.Entry<String, TestImsCallSessionImpl> entry : mSessions.entrySet()) { 53 if (entry.getKey().equals(callId)) { 54 return entry.getValue(); 55 } 56 } 57 } 58 59 return null; 60 } 61 getHoldSession()62 public TestImsCallSessionImpl getHoldSession() { 63 synchronized (mSessions) { 64 if (mSessions.isEmpty()) { 65 return null; 66 } 67 68 for (Map.Entry<String, TestImsCallSessionImpl> entry : mSessions.entrySet()) { 69 TestImsCallSessionImpl callSession = entry.getValue(); 70 boolean isOnHold = callSession.isSessionOnHold(); 71 String foreGroundSessionCallId = mForeGroundSession.getCallId(); 72 73 if (isOnHold && !callSession.getCallId().equals(foreGroundSessionCallId)) { 74 return callSession; 75 } 76 } 77 } 78 79 return null; 80 } 81 setConferenceSession(TestImsCallSessionImpl session)82 public void setConferenceSession(TestImsCallSessionImpl session) { 83 mConfSession = session; 84 } 85 setForeGroundSession(TestImsCallSessionImpl session)86 public void setForeGroundSession(TestImsCallSessionImpl session) { 87 mForeGroundSession = session; 88 } 89 setBackGroundSession(TestImsCallSessionImpl session)90 public void setBackGroundSession(TestImsCallSessionImpl session) { 91 mBackGroundSession = session; 92 } 93 getConferenceSession()94 public TestImsCallSessionImpl getConferenceSession() { 95 return mConfSession; 96 } 97 getForeGroundSession()98 public TestImsCallSessionImpl getForeGroundSession() { 99 return mForeGroundSession; 100 } 101 getBackGroundSession()102 public TestImsCallSessionImpl getBackGroundSession() { 103 return mBackGroundSession; 104 } 105 clearSessions()106 public void clearSessions() { 107 mConfSession = null; 108 mForeGroundSession = null; 109 mBackGroundSession = null; 110 mSessions.clear(); 111 } 112 } 113