ImsVideoCallProvider.java revision 33d827a95dcb4e007c3e94a591fe1c02fe3d7836
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 com.android.internal.os.SomeArgs; 20 21import android.os.Handler; 22import android.os.Looper; 23import android.os.Message; 24import android.os.RemoteException; 25import android.telecom.Connection; 26import android.telecom.VideoProfile; 27import android.telecom.VideoProfile.CameraCapabilities; 28import android.view.Surface; 29 30public abstract class ImsVideoCallProvider { 31 private static final int MSG_SET_CALLBACK = 1; 32 private static final int MSG_SET_CAMERA = 2; 33 private static final int MSG_SET_PREVIEW_SURFACE = 3; 34 private static final int MSG_SET_DISPLAY_SURFACE = 4; 35 private static final int MSG_SET_DEVICE_ORIENTATION = 5; 36 private static final int MSG_SET_ZOOM = 6; 37 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7; 38 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8; 39 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9; 40 private static final int MSG_REQUEST_CALL_DATA_USAGE = 10; 41 private static final int MSG_SET_PAUSE_IMAGE = 11; 42 43 private final ImsVideoCallProviderBinder mBinder; 44 45 private IImsVideoCallCallback mCallback; 46 47 /** 48 * Default handler used to consolidate binder method calls onto a single thread. 49 */ 50 private final Handler mProviderHandler = new Handler(Looper.getMainLooper()) { 51 @Override 52 public void handleMessage(Message msg) { 53 switch (msg.what) { 54 case MSG_SET_CALLBACK: 55 mCallback = (IImsVideoCallCallback) msg.obj; 56 break; 57 case MSG_SET_CAMERA: 58 onSetCamera((String) msg.obj); 59 break; 60 case MSG_SET_PREVIEW_SURFACE: 61 onSetPreviewSurface((Surface) msg.obj); 62 break; 63 case MSG_SET_DISPLAY_SURFACE: 64 onSetDisplaySurface((Surface) msg.obj); 65 break; 66 case MSG_SET_DEVICE_ORIENTATION: 67 onSetDeviceOrientation(msg.arg1); 68 break; 69 case MSG_SET_ZOOM: 70 onSetZoom((Float) msg.obj); 71 break; 72 case MSG_SEND_SESSION_MODIFY_REQUEST: { 73 SomeArgs args = (SomeArgs) msg.obj; 74 try { 75 VideoProfile fromProfile = (VideoProfile) args.arg1; 76 VideoProfile toProfile = (VideoProfile) args.arg2; 77 78 onSendSessionModifyRequest(fromProfile, toProfile); 79 } finally { 80 args.recycle(); 81 } 82 break; 83 } 84 case MSG_SEND_SESSION_MODIFY_RESPONSE: 85 onSendSessionModifyResponse((VideoProfile) msg.obj); 86 break; 87 case MSG_REQUEST_CAMERA_CAPABILITIES: 88 onRequestCameraCapabilities(); 89 break; 90 case MSG_REQUEST_CALL_DATA_USAGE: 91 onRequestCallDataUsage(); 92 break; 93 case MSG_SET_PAUSE_IMAGE: 94 onSetPauseImage((String) msg.obj); 95 break; 96 default: 97 break; 98 } 99 } 100 }; 101 102 /** 103 * IImsVideoCallProvider stub implementation. 104 */ 105 private final class ImsVideoCallProviderBinder extends IImsVideoCallProvider.Stub { 106 public void setCallback(IImsVideoCallCallback callback) { 107 mProviderHandler.obtainMessage(MSG_SET_CALLBACK, callback).sendToTarget(); 108 } 109 110 public void setCamera(String cameraId) { 111 mProviderHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget(); 112 } 113 114 public void setPreviewSurface(Surface surface) { 115 mProviderHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget(); 116 } 117 118 public void setDisplaySurface(Surface surface) { 119 mProviderHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget(); 120 } 121 122 public void setDeviceOrientation(int rotation) { 123 mProviderHandler.obtainMessage(MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget(); 124 } 125 126 public void setZoom(float value) { 127 mProviderHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget(); 128 } 129 130 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) { 131 SomeArgs args = SomeArgs.obtain(); 132 args.arg1 = fromProfile; 133 args.arg2 = toProfile; 134 mProviderHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget(); 135 } 136 137 public void sendSessionModifyResponse(VideoProfile responseProfile) { 138 mProviderHandler.obtainMessage( 139 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget(); 140 } 141 142 public void requestCameraCapabilities() { 143 mProviderHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget(); 144 } 145 146 public void requestCallDataUsage() { 147 mProviderHandler.obtainMessage(MSG_REQUEST_CALL_DATA_USAGE).sendToTarget(); 148 } 149 150 public void setPauseImage(String uri) { 151 mProviderHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget(); 152 } 153 } 154 155 public ImsVideoCallProvider() { 156 mBinder = new ImsVideoCallProviderBinder(); 157 } 158 159 /** 160 * Returns binder object which can be used across IPC methods. 161 */ 162 public final IImsVideoCallProvider getInterface() { 163 return mBinder; 164 } 165 166 /** @see Connection.VideoProvider#onSetCamera */ 167 public abstract void onSetCamera(String cameraId); 168 169 /** @see Connection.VideoProvider#onSetPreviewSurface */ 170 public abstract void onSetPreviewSurface(Surface surface); 171 172 /** @see Connection.VideoProvider#onSetDisplaySurface */ 173 public abstract void onSetDisplaySurface(Surface surface); 174 175 /** @see Connection.VideoProvider#onSetDeviceOrientation */ 176 public abstract void onSetDeviceOrientation(int rotation); 177 178 /** @see Connection.VideoProvider#onSetZoom */ 179 public abstract void onSetZoom(float value); 180 181 /** @see Connection.VideoProvider#onSendSessionModifyRequest */ 182 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile, 183 VideoProfile toProfile); 184 185 /** @see Connection.VideoProvider#onSendSessionModifyResponse */ 186 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile); 187 188 /** @see Connection.VideoProvider#onRequestCameraCapabilities */ 189 public abstract void onRequestCameraCapabilities(); 190 191 /** @see Connection.VideoProvider#onRequestCallDataUsage */ 192 public abstract void onRequestCallDataUsage(); 193 194 /** @see Connection.VideoProvider#onSetPauseImage */ 195 public abstract void onSetPauseImage(String uri); 196 197 /** @see Connection.VideoProvider#receiveSessionModifyRequest */ 198 public void receiveSessionModifyRequest(VideoProfile VideoProfile) { 199 if (mCallback != null) { 200 try { 201 mCallback.receiveSessionModifyRequest(VideoProfile); 202 } catch (RemoteException ignored) { 203 } 204 } 205 } 206 207 /** @see Connection.VideoProvider#receiveSessionModifyResponse */ 208 public void receiveSessionModifyResponse( 209 int status, VideoProfile requestedProfile, VideoProfile responseProfile) { 210 if (mCallback != null) { 211 try { 212 mCallback.receiveSessionModifyResponse(status, requestedProfile, responseProfile); 213 } catch (RemoteException ignored) { 214 } 215 } 216 } 217 218 /** @see Connection.VideoProvider#handleCallSessionEvent */ 219 public void handleCallSessionEvent(int event) { 220 if (mCallback != null) { 221 try { 222 mCallback.handleCallSessionEvent(event); 223 } catch (RemoteException ignored) { 224 } 225 } 226 } 227 228 /** @see Connection.VideoProvider#changePeerDimensions */ 229 public void changePeerDimensions(int width, int height) { 230 if (mCallback != null) { 231 try { 232 mCallback.changePeerDimensions(width, height); 233 } catch (RemoteException ignored) { 234 } 235 } 236 } 237 238 /** @see Connection.VideoProvider#changeCallDataUsage */ 239 public void changeCallDataUsage(long dataUsage) { 240 if (mCallback != null) { 241 try { 242 mCallback.changeCallDataUsage(dataUsage); 243 } catch (RemoteException ignored) { 244 } 245 } 246 } 247 248 /** @see Connection.VideoProvider#changeCameraCapabilities */ 249 public void changeCameraCapabilities(CameraCapabilities CameraCapabilities) { 250 if (mCallback != null) { 251 try { 252 mCallback.changeCameraCapabilities(CameraCapabilities); 253 } catch (RemoteException ignored) { 254 } 255 } 256 } 257 258 /** @see Connection.VideoProvider#changeVideoQuality */ 259 public void changeVideoQuality(int videoQuality) { 260 if (mCallback != null) { 261 try { 262 mCallback.changeVideoQuality(videoQuality); 263 } catch (RemoteException ignored) { 264 } 265 } 266 } 267} 268