CallGroupManager.java revision ef36ef67e009449300b0150c60c9f637e205d79e
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
17package com.android.ims.internal;
18
19import java.util.ArrayList;
20
21/**
22 * Manages CallGroup objects.
23 *
24 * @hide
25 */
26public class CallGroupManager {
27    private static CallGroupManager mCallGroupManager = new CallGroupManager();
28    private Object mLockObj = new Object();
29    private ArrayList<CallGroup> mCallGroups = new ArrayList<CallGroup>();
30
31    private CallGroupManager() {
32    }
33
34    public static CallGroupManager getInstance() {
35        return mCallGroupManager;
36    }
37
38    public CallGroup createCallGroup(ICallGroup callGroup) {
39        CallGroup cg = new CallGroup(callGroup);
40
41        synchronized(mLockObj) {
42            mCallGroups.add(cg);
43        }
44
45        return cg;
46    }
47
48    public void destroyCallGroup(CallGroup cg) {
49        if (cg == null) {
50            return;
51        }
52
53        synchronized(mLockObj) {
54            mCallGroups.remove(cg);
55        }
56    }
57
58    public CallGroup getCallGroupAsOwner(ICall call) {
59        synchronized(mLockObj) {
60            for (CallGroup cg : mCallGroups) {
61                if (cg.isOwner(call)) {
62                    return cg;
63                }
64            }
65        }
66
67        return null;
68    }
69
70    public CallGroup getCallGroupAsReferrer(ICall call) {
71        synchronized(mLockObj) {
72            for (CallGroup cg : mCallGroups) {
73                if (cg.isReferrer(call)) {
74                    return cg;
75                }
76            }
77        }
78
79        return null;
80    }
81}
82