1 /* 2 * Copyright (c) 2013 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.ims; 18 19 import java.util.ArrayList; 20 21 import com.android.ims.internal.ICallGroup; 22 import com.android.ims.internal.ICall; 23 24 /** 25 * Manages all IMS calls which are established hereafter the initial 1-to-1 call is established. 26 * It's for providing the dummy calls which are disconnected with the IMS network after 27 * merged or extended to the conference. 28 * 29 * @hide 30 */ 31 public class ImsCallGroup implements ICallGroup { 32 private Object mLockObj = new Object(); 33 private ImsCall mOwner; 34 private ImsCall mNeutralReferrer; 35 private ArrayList<ICall> mReferrers = new ArrayList<ICall>(); 36 37 public ImsCallGroup() { 38 } 39 40 @Override 41 public ICall getNeutralReferrer() { 42 synchronized(mLockObj) { 43 return mNeutralReferrer; 44 } 45 } 46 47 @Override 48 public ICall getOwner() { 49 synchronized(mLockObj) { 50 return mOwner; 51 } 52 } 53 54 @Override 55 public ArrayList<ICall> getReferrers() { 56 synchronized(mLockObj) { 57 return mReferrers; 58 } 59 } 60 61 @Override 62 public boolean hasReferrer() { 63 synchronized(mLockObj) { 64 return !mReferrers.isEmpty(); 65 } 66 } 67 68 @Override 69 public boolean isOwner(ICall call) { 70 ImsCall owner; 71 72 synchronized(mLockObj) { 73 owner = mOwner; 74 } 75 76 if ((call == null) || (owner == null)) { 77 return false; 78 } 79 80 if (!(call instanceof ImsCall)) { 81 return false; 82 } 83 84 return isSameCall(owner, (ImsCall)call); 85 } 86 87 @Override 88 public boolean isReferrer(ICall call) { 89 if (call == null) { 90 return false; 91 } 92 93 if (!(call instanceof ImsCall)) { 94 return false; 95 } 96 97 synchronized(mLockObj) { 98 for (ICall c : mReferrers) { 99 if ((c != null) && isSameCall((ImsCall)c, (ImsCall)call)) { 100 return true; 101 } 102 } 103 } 104 105 return false; 106 } 107 108 @Override 109 public void addReferrer(ICall call) { 110 if (call == null) { 111 return; 112 } 113 114 if (!(call instanceof ImsCall)) { 115 return; 116 } 117 118 // If the call is already present, ignore it 119 if (isReferrer(call)) { 120 return; 121 } 122 123 synchronized(mLockObj) { 124 mReferrers.add(call); 125 } 126 } 127 128 @Override 129 public void removeReferrer(ICall call) { 130 if (call == null) { 131 return; 132 } 133 134 if (!(call instanceof ImsCall)) { 135 return; 136 } 137 138 synchronized(mLockObj) { 139 mReferrers.remove(call); 140 } 141 } 142 143 @Override 144 public void setNeutralReferrer(ICall call) { 145 if ((call != null) && !(call instanceof ImsCall)) { 146 return; 147 } 148 149 synchronized(mLockObj) { 150 mNeutralReferrer = (ImsCall)call; 151 } 152 } 153 154 @Override 155 public void setOwner(ICall call) { 156 if ((call != null) && !(call instanceof ImsCall)) { 157 return; 158 } 159 160 synchronized(mLockObj) { 161 mOwner = (ImsCall)call; 162 } 163 } 164 165 @Override 166 public ICall getReferrer(String name) { 167 if ((name == null) || (name.isEmpty())) { 168 return null; 169 } 170 171 ArrayList<ICall> referrers = getReferrers(); 172 173 if (referrers == null) { 174 return null; 175 } 176 177 for (ICall call : referrers) { 178 if ((call != null) && call.checkIfRemoteUserIsSame(name)) { 179 return call; 180 } 181 } 182 183 return null; 184 } 185 186 private boolean isSameCall(ImsCall call1, ImsCall call2) { 187 if ((call1 == null) || (call2 == null)) { 188 return false; 189 } 190 191 return call1.equalsTo(call2); 192 } 193 } 194