ImsVideoCallProviderWrapper.java revision 085d0bde9eae677d403b9725f4e0f7ea22a6cf60
1/* 2 * Copyright (C) 2014 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 android.net.Uri; 20import android.os.Handler; 21import android.os.IBinder; 22import android.os.Looper; 23import android.os.Message; 24import android.os.RemoteException; 25import android.telecom.CameraCapabilities; 26import android.telecom.Connection; 27import android.telecom.VideoProfile; 28import android.view.Surface; 29 30import com.android.internal.os.SomeArgs; 31 32/** 33 * Subclass implementation of {@link Connection.VideoProvider}. This intermediates and 34 * communicates with the actual implementation of the video call provider in the IMS service; it is 35 * in essence, a wrapper around the IMS's video call provider implementation. 36 * 37 * This class maintains a binder by which the ImsVideoCallProvider's implementation can communicate 38 * its intent to invoke callbacks. In this class, the message across this binder is handled, and 39 * the superclass's methods are used to execute the callbacks. 40 * 41 * @hide 42 */ 43public class ImsVideoCallProviderWrapper extends Connection.VideoProvider { 44 private static final int MSG_RECEIVE_SESSION_MODIFY_REQUEST = 1; 45 private static final int MSG_RECEIVE_SESSION_MODIFY_RESPONSE = 2; 46 private static final int MSG_HANDLE_CALL_SESSION_EVENT = 3; 47 private static final int MSG_CHANGE_PEER_DIMENSIONS = 4; 48 private static final int MSG_CHANGE_CALL_DATA_USAGE = 5; 49 private static final int MSG_CHANGE_CAMERA_CAPABILITIES = 6; 50 private static final int MSG_CHANGE_VIDEO_QUALITY = 7; 51 52 private final IImsVideoCallProvider mVideoCallProvider; 53 private final ImsVideoCallCallback mBinder; 54 55 private IBinder.DeathRecipient mDeathRecipient = new IBinder.DeathRecipient() { 56 @Override 57 public void binderDied() { 58 mVideoCallProvider.asBinder().unlinkToDeath(this, 0); 59 } 60 }; 61 62 /** 63 * IImsVideoCallCallback stub implementation. 64 */ 65 private final class ImsVideoCallCallback extends IImsVideoCallCallback.Stub { 66 @Override 67 public void receiveSessionModifyRequest(VideoProfile VideoProfile) { 68 mHandler.obtainMessage(MSG_RECEIVE_SESSION_MODIFY_REQUEST, 69 VideoProfile).sendToTarget(); 70 } 71 72 @Override 73 public void receiveSessionModifyResponse( 74 int status, VideoProfile requestProfile, VideoProfile responseProfile) { 75 SomeArgs args = SomeArgs.obtain(); 76 args.arg1 = status; 77 args.arg2 = requestProfile; 78 args.arg3 = responseProfile; 79 mHandler.obtainMessage(MSG_RECEIVE_SESSION_MODIFY_RESPONSE, args).sendToTarget(); 80 } 81 82 @Override 83 public void handleCallSessionEvent(int event) { 84 mHandler.obtainMessage(MSG_HANDLE_CALL_SESSION_EVENT, event).sendToTarget(); 85 } 86 87 @Override 88 public void changePeerDimensions(int width, int height) { 89 SomeArgs args = SomeArgs.obtain(); 90 args.arg1 = width; 91 args.arg2 = height; 92 mHandler.obtainMessage(MSG_CHANGE_PEER_DIMENSIONS, args).sendToTarget(); 93 } 94 95 @Override 96 public void changeVideoQuality(int videoQuality) { 97 mHandler.obtainMessage(MSG_CHANGE_VIDEO_QUALITY, videoQuality, 0).sendToTarget(); 98 } 99 100 @Override 101 public void changeCallDataUsage(long dataUsage) { 102 mHandler.obtainMessage(MSG_CHANGE_CALL_DATA_USAGE, dataUsage).sendToTarget(); 103 } 104 105 @Override 106 public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) { 107 mHandler.obtainMessage(MSG_CHANGE_CAMERA_CAPABILITIES, 108 cameraCapabilities).sendToTarget(); 109 } 110 } 111 112 /** Default handler used to consolidate binder method calls onto a single thread. */ 113 private final Handler mHandler = new Handler(Looper.getMainLooper()) { 114 @Override 115 public void handleMessage(Message msg) { 116 SomeArgs args; 117 switch (msg.what) { 118 case MSG_RECEIVE_SESSION_MODIFY_REQUEST: 119 receiveSessionModifyRequest((VideoProfile) msg.obj); 120 break; 121 case MSG_RECEIVE_SESSION_MODIFY_RESPONSE: 122 args = (SomeArgs) msg.obj; 123 try { 124 int status = (int) args.arg1; 125 VideoProfile requestProfile = (VideoProfile) args.arg2; 126 VideoProfile responseProfile = (VideoProfile) args.arg3; 127 128 receiveSessionModifyResponse(status, requestProfile, responseProfile); 129 } finally { 130 args.recycle(); 131 } 132 break; 133 case MSG_HANDLE_CALL_SESSION_EVENT: 134 handleCallSessionEvent((int) msg.obj); 135 break; 136 case MSG_CHANGE_PEER_DIMENSIONS: 137 args = (SomeArgs) msg.obj; 138 try { 139 int width = (int) args.arg1; 140 int height = (int) args.arg2; 141 changePeerDimensions(width, height); 142 } finally { 143 args.recycle(); 144 } 145 break; 146 case MSG_CHANGE_CALL_DATA_USAGE: 147 changeCallDataUsage((long) msg.obj); 148 break; 149 case MSG_CHANGE_CAMERA_CAPABILITIES: 150 changeCameraCapabilities((CameraCapabilities) msg.obj); 151 break; 152 case MSG_CHANGE_VIDEO_QUALITY: 153 changeVideoQuality(msg.arg1); 154 break; 155 default: 156 break; 157 } 158 } 159 }; 160 161 /** 162 * Instantiates an instance of the ImsVideoCallProvider, taking in the binder for IMS's video 163 * call provider implementation. 164 * 165 * @param VideoProvider 166 */ 167 public ImsVideoCallProviderWrapper(IImsVideoCallProvider VideoProvider) 168 throws RemoteException { 169 mVideoCallProvider = VideoProvider; 170 mVideoCallProvider.asBinder().linkToDeath(mDeathRecipient, 0); 171 172 mBinder = new ImsVideoCallCallback(); 173 mVideoCallProvider.setCallback(mBinder); 174 } 175 176 /** @inheritDoc */ 177 public void onSetCamera(String cameraId) { 178 try { 179 mVideoCallProvider.setCamera(cameraId); 180 } catch (RemoteException e) { 181 } 182 } 183 184 /** @inheritDoc */ 185 public void onSetPreviewSurface(Surface surface) { 186 try { 187 mVideoCallProvider.setPreviewSurface(surface); 188 } catch (RemoteException e) { 189 } 190 } 191 192 /** @inheritDoc */ 193 public void onSetDisplaySurface(Surface surface) { 194 try { 195 mVideoCallProvider.setDisplaySurface(surface); 196 } catch (RemoteException e) { 197 } 198 } 199 200 /** @inheritDoc */ 201 public void onSetDeviceOrientation(int rotation) { 202 try { 203 mVideoCallProvider.setDeviceOrientation(rotation); 204 } catch (RemoteException e) { 205 } 206 } 207 208 /** @inheritDoc */ 209 public void onSetZoom(float value) { 210 try { 211 mVideoCallProvider.setZoom(value); 212 } catch (RemoteException e) { 213 } 214 } 215 216 /** @inheritDoc */ 217 public void onSendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) { 218 try { 219 mVideoCallProvider.sendSessionModifyRequest(fromProfile, toProfile); 220 } catch (RemoteException e) { 221 } 222 } 223 224 /** @inheritDoc */ 225 public void onSendSessionModifyResponse(VideoProfile responseProfile) { 226 try { 227 mVideoCallProvider.sendSessionModifyResponse(responseProfile); 228 } catch (RemoteException e) { 229 } 230 } 231 232 /** @inheritDoc */ 233 public void onRequestCameraCapabilities() { 234 try { 235 mVideoCallProvider.requestCameraCapabilities(); 236 } catch (RemoteException e) { 237 } 238 } 239 240 /** @inheritDoc */ 241 public void onRequestConnectionDataUsage() { 242 try { 243 mVideoCallProvider.requestCallDataUsage(); 244 } catch (RemoteException e) { 245 } 246 } 247 248 /** @inheritDoc */ 249 public void onSetPauseImage(Uri uri) { 250 try { 251 mVideoCallProvider.setPauseImage(uri); 252 } catch (RemoteException e) { 253 } 254 } 255} 256