TestCallList.java revision ac30f08f0ef02e67d77a2f01c9d1018fe61a1605
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 17package com.android.server.telecom.testapps; 18 19import android.telecom.Call; 20import android.telecom.CameraCapabilities; 21import android.telecom.InCallService; 22import android.telecom.VideoProfile; 23import android.util.ArrayMap; 24import android.util.ArraySet; 25import android.util.Log; 26 27import java.util.Map; 28import java.util.Set; 29 30/** 31 * Maintains a list of calls received via the {@link TestInCallServiceImpl}. 32 */ 33public class TestCallList extends Call.Listener { 34 private static final TestCallList INSTANCE = new TestCallList(); 35 private static final String TAG = "TestCallList"; 36 37 private class TestVideoCallListener extends InCallService.VideoCall.Callback { 38 private Call mCall; 39 40 public TestVideoCallListener(Call call) { 41 mCall = call; 42 } 43 44 @Override 45 public void onSessionModifyRequestReceived(VideoProfile videoProfile) { 46 Log.v(TAG, 47 "onSessionModifyRequestReceived: videoState = " + videoProfile.getVideoState() 48 + " call = " + mCall); 49 } 50 51 @Override 52 public void onSessionModifyResponseReceived(int status, VideoProfile requestedProfile, 53 VideoProfile responseProfile) { 54 Log.v(TAG, 55 "onSessionModifyResponseReceived: status = " + status + " videoState = " 56 + responseProfile.getVideoState() 57 + " call = " + mCall); 58 } 59 60 @Override 61 public void onCallSessionEvent(int event) { 62 63 } 64 65 @Override 66 public void onPeerDimensionsChanged(int width, int height) { 67 68 } 69 70 @Override 71 public void onVideoQualityChanged(int videoQuality) { 72 Log.v(TAG, 73 "onVideoQualityChanged: videoQuality = " + videoQuality + " call = " + mCall); 74 } 75 76 @Override 77 public void onCallDataUsageChanged(long dataUsage) { 78 79 } 80 81 @Override 82 public void onCameraCapabilitiesChanged(CameraCapabilities cameraCapabilities) { 83 84 } 85 } 86 87 // The calls the call list knows about. 88 private Set<Call> mCalls = new ArraySet<Call>(); 89 private Map<Call, TestVideoCallListener> mVideoCallListeners = 90 new ArrayMap<Call, TestVideoCallListener>(); 91 92 /** 93 * Singleton accessor. 94 */ 95 public static TestCallList getInstance() { 96 return INSTANCE; 97 } 98 99 public void addCall(Call call) { 100 if (mCalls.contains(call)) { 101 Log.e(TAG, "addCall: Call already added."); 102 return; 103 } 104 Log.v(TAG, "addCall: " + call + " " + System.identityHashCode(this)); 105 mCalls.add(call); 106 call.addListener(this); 107 } 108 109 public void removeCall(Call call) { 110 if (!mCalls.contains(call)) { 111 Log.e(TAG, "removeCall: Call cannot be removed -- doesn't exist."); 112 return; 113 } 114 Log.v(TAG, "removeCall: " + call); 115 mCalls.remove(call); 116 call.removeListener(this); 117 } 118 119 public void clearCalls() { 120 mCalls.clear(); 121 for (Call call : mVideoCallListeners.keySet()) { 122 if (call.getVideoCall() != null) { 123 call.getVideoCall().destroy(); 124 } 125 } 126 mVideoCallListeners.clear(); 127 } 128 129 /** 130 * For any video calls tracked, sends an upgrade to video request. 131 */ 132 public void sendUpgradeToVideoRequest(int videoState) { 133 Log.v(TAG, "sendUpgradeToVideoRequest : videoState = " + videoState); 134 135 for (Call call : mCalls) { 136 InCallService.VideoCall videoCall = call.getVideoCall(); 137 Log.v(TAG, "sendUpgradeToVideoRequest: checkCall "+call); 138 if (videoCall == null) { 139 continue; 140 } 141 142 Log.v(TAG, "send upgrade to video request for call: " + call); 143 videoCall.sendSessionModifyRequest(new VideoProfile(videoState)); 144 } 145 } 146 147 @Override 148 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) { 149 Log.v(TAG, "onVideoCallChanged: call = " + call + " " + System.identityHashCode(this)); 150 if (videoCall != null) { 151 if (!mVideoCallListeners.containsKey(call)) { 152 TestVideoCallListener listener = new TestVideoCallListener(call); 153 videoCall.registerCallback(listener); 154 mVideoCallListeners.put(call, listener); 155 Log.v(TAG, "onVideoCallChanged: added new listener"); 156 } 157 } 158 } 159} 160