1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
|
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.android.ims.internal;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.telecom.Connection;
import android.telecom.VideoProfile;
import android.telecom.VideoProfile.CameraCapabilities;
import android.view.Surface;
import com.android.internal.os.SomeArgs;
/**
* @hide
*/
public abstract class ImsVideoCallProvider {
private static final int MSG_SET_CALLBACK = 1;
private static final int MSG_SET_CAMERA = 2;
private static final int MSG_SET_PREVIEW_SURFACE = 3;
private static final int MSG_SET_DISPLAY_SURFACE = 4;
private static final int MSG_SET_DEVICE_ORIENTATION = 5;
private static final int MSG_SET_ZOOM = 6;
private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
private static final int MSG_REQUEST_CALL_DATA_USAGE = 10;
private static final int MSG_SET_PAUSE_IMAGE = 11;
private final ImsVideoCallProviderBinder mBinder;
private IImsVideoCallCallback mCallback;
/**
* Default handler used to consolidate binder method calls onto a single thread.
*/
private final Handler mProviderHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_SET_CALLBACK:
mCallback = (IImsVideoCallCallback) msg.obj;
break;
case MSG_SET_CAMERA:
{
SomeArgs args = (SomeArgs) msg.obj;
try {
onSetCamera((String) args.arg1);
onSetCamera((String) args.arg1, args.argi1);
} finally {
args.recycle();
}
break;
}
case MSG_SET_PREVIEW_SURFACE:
onSetPreviewSurface((Surface) msg.obj);
break;
case MSG_SET_DISPLAY_SURFACE:
onSetDisplaySurface((Surface) msg.obj);
break;
case MSG_SET_DEVICE_ORIENTATION:
onSetDeviceOrientation(msg.arg1);
break;
case MSG_SET_ZOOM:
onSetZoom((Float) msg.obj);
break;
case MSG_SEND_SESSION_MODIFY_REQUEST: {
SomeArgs args = (SomeArgs) msg.obj;
try {
VideoProfile fromProfile = (VideoProfile) args.arg1;
VideoProfile toProfile = (VideoProfile) args.arg2;
onSendSessionModifyRequest(fromProfile, toProfile);
} finally {
args.recycle();
}
break;
}
case MSG_SEND_SESSION_MODIFY_RESPONSE:
onSendSessionModifyResponse((VideoProfile) msg.obj);
break;
case MSG_REQUEST_CAMERA_CAPABILITIES:
onRequestCameraCapabilities();
break;
case MSG_REQUEST_CALL_DATA_USAGE:
onRequestCallDataUsage();
break;
case MSG_SET_PAUSE_IMAGE:
onSetPauseImage((Uri) msg.obj);
break;
default:
break;
}
}
};
/**
* IImsVideoCallProvider stub implementation.
*/
private final class ImsVideoCallProviderBinder extends IImsVideoCallProvider.Stub {
public void setCallback(IImsVideoCallCallback callback) {
mProviderHandler.obtainMessage(MSG_SET_CALLBACK, callback).sendToTarget();
}
public void setCamera(String cameraId, int uid) {
SomeArgs args = SomeArgs.obtain();
args.arg1 = cameraId;
args.argi1 = uid;
mProviderHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
}
public void setPreviewSurface(Surface surface) {
mProviderHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
}
public void setDisplaySurface(Surface surface) {
mProviderHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
}
public void setDeviceOrientation(int rotation) {
mProviderHandler.obtainMessage(MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
}
public void setZoom(float value) {
mProviderHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
}
public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
SomeArgs args = SomeArgs.obtain();
args.arg1 = fromProfile;
args.arg2 = toProfile;
mProviderHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
}
public void sendSessionModifyResponse(VideoProfile responseProfile) {
mProviderHandler.obtainMessage(
MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
}
public void requestCameraCapabilities() {
mProviderHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
}
public void requestCallDataUsage() {
mProviderHandler.obtainMessage(MSG_REQUEST_CALL_DATA_USAGE).sendToTarget();
}
public void setPauseImage(Uri uri) {
mProviderHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
}
}
public ImsVideoCallProvider() {
mBinder = new ImsVideoCallProviderBinder();
}
/**
* Returns binder object which can be used across IPC methods.
*/
public final IImsVideoCallProvider getInterface() {
return mBinder;
}
/** @see Connection.VideoProvider#onSetCamera */
public abstract void onSetCamera(String cameraId);
/**
* Similar to {@link #onSetCamera(String)}, except includes the UID of the calling process which
* the IMS service uses when opening the camera. This ensures camera permissions are verified
* by the camera service.
*
* @param cameraId The id of the camera to be opened.
* @param uid The uid of the caller, used when opening the camera for permission verification.
* @see Connection.VideoProvider#onSetCamera
*/
public void onSetCamera(String cameraId, int uid) {
}
/** @see Connection.VideoProvider#onSetPreviewSurface */
public abstract void onSetPreviewSurface(Surface surface);
/** @see Connection.VideoProvider#onSetDisplaySurface */
public abstract void onSetDisplaySurface(Surface surface);
/** @see Connection.VideoProvider#onSetDeviceOrientation */
public abstract void onSetDeviceOrientation(int rotation);
/** @see Connection.VideoProvider#onSetZoom */
public abstract void onSetZoom(float value);
/** @see Connection.VideoProvider#onSendSessionModifyRequest */
public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
VideoProfile toProfile);
/** @see Connection.VideoProvider#onSendSessionModifyResponse */
public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
/** @see Connection.VideoProvider#onRequestCameraCapabilities */
public abstract void onRequestCameraCapabilities();
/** @see Connection.VideoProvider#onRequestCallDataUsage */
public abstract void onRequestCallDataUsage();
/** @see Connection.VideoProvider#onSetPauseImage */
public abstract void onSetPauseImage(Uri uri);
/** @see Connection.VideoProvider#receiveSessionModifyRequest */
public void receiveSessionModifyRequest(VideoProfile VideoProfile) {
if (mCallback != null) {
try {
mCallback.receiveSessionModifyRequest(VideoProfile);
} catch (RemoteException ignored) {
}
}
}
/** @see Connection.VideoProvider#receiveSessionModifyResponse */
public void receiveSessionModifyResponse(
int status, VideoProfile requestedProfile, VideoProfile responseProfile) {
if (mCallback != null) {
try {
mCallback.receiveSessionModifyResponse(status, requestedProfile, responseProfile);
} catch (RemoteException ignored) {
}
}
}
/** @see Connection.VideoProvider#handleCallSessionEvent */
public void handleCallSessionEvent(int event) {
if (mCallback != null) {
try {
mCallback.handleCallSessionEvent(event);
} catch (RemoteException ignored) {
}
}
}
/** @see Connection.VideoProvider#changePeerDimensions */
public void changePeerDimensions(int width, int height) {
if (mCallback != null) {
try {
mCallback.changePeerDimensions(width, height);
} catch (RemoteException ignored) {
}
}
}
/** @see Connection.VideoProvider#changeCallDataUsage */
public void changeCallDataUsage(long dataUsage) {
if (mCallback != null) {
try {
mCallback.changeCallDataUsage(dataUsage);
} catch (RemoteException ignored) {
}
}
}
/** @see Connection.VideoProvider#changeCameraCapabilities */
public void changeCameraCapabilities(CameraCapabilities CameraCapabilities) {
if (mCallback != null) {
try {
mCallback.changeCameraCapabilities(CameraCapabilities);
} catch (RemoteException ignored) {
}
}
}
/** @see Connection.VideoProvider#changeVideoQuality */
public void changeVideoQuality(int videoQuality) {
if (mCallback != null) {
try {
mCallback.changeVideoQuality(videoQuality);
} catch (RemoteException ignored) {
}
}
}
}
|