blob: 1fbad22447da28f352796d93dbb59a104229fb49 [file] [log] [blame]
Ihab Awada64627c2014-08-20 09:36:40 -07001/*
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 R* limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awada64627c2014-08-20 09:36:40 -070018
19import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070020import com.android.internal.telecom.IVideoCallback;
Ihab Awada64627c2014-08-20 09:36:40 -070021
22import android.os.Handler;
23import android.os.Message;
24import android.os.RemoteException;
25
26/**
27 * A component that provides an RPC servant implementation of {@link IVideoCallback},
28 * posting incoming messages on the main thread on a client-supplied delegate object.
29 *
30 * TODO: Generate this and similar classes using a compiler starting from AIDL interfaces.
31 *
32 * @hide
33 */
34final class VideoCallbackServant {
35 private static final int MSG_RECEIVE_SESSION_MODIFY_REQUEST = 0;
36 private static final int MSG_RECEIVE_SESSION_MODIFY_RESPONSE = 1;
37 private static final int MSG_HANDLE_CALL_SESSION_EVENT = 2;
38 private static final int MSG_CHANGE_PEER_DIMENSIONS = 3;
39 private static final int MSG_CHANGE_CALL_DATA_USAGE = 4;
40 private static final int MSG_CHANGE_CAMERA_CAPABILITIES = 5;
Rekha Kumar07366812015-03-24 16:42:31 -070041 private static final int MSG_CHANGE_VIDEO_QUALITY = 6;
Ihab Awada64627c2014-08-20 09:36:40 -070042
43 private final IVideoCallback mDelegate;
44
45 private final Handler mHandler = new Handler() {
46 @Override
47 public void handleMessage(Message msg) {
48 try {
49 internalHandleMessage(msg);
50 } catch (RemoteException e) {
51 }
52 }
53
54 // Internal method defined to centralize handling of RemoteException
55 private void internalHandleMessage(Message msg) throws RemoteException {
56 switch (msg.what) {
57 case MSG_RECEIVE_SESSION_MODIFY_REQUEST: {
58 mDelegate.receiveSessionModifyRequest((VideoProfile) msg.obj);
59 break;
60 }
61 case MSG_RECEIVE_SESSION_MODIFY_RESPONSE: {
62 SomeArgs args = (SomeArgs) msg.obj;
63 try {
64 mDelegate.receiveSessionModifyResponse(
65 args.argi1,
66 (VideoProfile) args.arg1,
67 (VideoProfile) args.arg2);
68 } finally {
69 args.recycle();
70 }
71 break;
72 }
73 case MSG_HANDLE_CALL_SESSION_EVENT: {
74 SomeArgs args = (SomeArgs) msg.obj;
75 try {
76 mDelegate.handleCallSessionEvent(args.argi1);
77 } finally {
78 args.recycle();
79 }
80 break;
81 }
82 case MSG_CHANGE_PEER_DIMENSIONS: {
83 SomeArgs args = (SomeArgs) msg.obj;
84 try {
85 mDelegate.changePeerDimensions(args.argi1, args.argi2);
86 } finally {
87 args.recycle();
88 }
89 break;
90 }
91 case MSG_CHANGE_CALL_DATA_USAGE: {
92 SomeArgs args = (SomeArgs) msg.obj;
93 try {
Rekha Kumar07366812015-03-24 16:42:31 -070094 mDelegate.changeCallDataUsage((long) args.arg1);
Ihab Awada64627c2014-08-20 09:36:40 -070095 } finally {
96 args.recycle();
97 }
98 break;
99 }
100 case MSG_CHANGE_CAMERA_CAPABILITIES: {
Yorke Lee400470f2015-05-12 13:31:25 -0700101 mDelegate.changeCameraCapabilities((VideoProfile.CameraCapabilities) msg.obj);
Ihab Awada64627c2014-08-20 09:36:40 -0700102 break;
103 }
Rekha Kumar07366812015-03-24 16:42:31 -0700104 case MSG_CHANGE_VIDEO_QUALITY: {
105 mDelegate.changeVideoQuality(msg.arg1);
106 break;
107 }
Ihab Awada64627c2014-08-20 09:36:40 -0700108 }
109 }
110 };
111
112 private final IVideoCallback mStub = new IVideoCallback.Stub() {
113 @Override
114 public void receiveSessionModifyRequest(VideoProfile videoProfile) throws RemoteException {
115 mHandler.obtainMessage(MSG_RECEIVE_SESSION_MODIFY_REQUEST, videoProfile).sendToTarget();
116 }
117
118 @Override
119 public void receiveSessionModifyResponse(int status, VideoProfile requestedProfile,
120 VideoProfile responseProfile) throws RemoteException {
121 SomeArgs args = SomeArgs.obtain();
122 args.argi1 = status;
123 args.arg1 = requestedProfile;
124 args.arg2 = responseProfile;
125 mHandler.obtainMessage(MSG_RECEIVE_SESSION_MODIFY_RESPONSE, args).sendToTarget();
126 }
127
128 @Override
129 public void handleCallSessionEvent(int event) throws RemoteException {
130 SomeArgs args = SomeArgs.obtain();
131 args.argi1 = event;
132 mHandler.obtainMessage(MSG_HANDLE_CALL_SESSION_EVENT, args).sendToTarget();
133 }
134
135 @Override
136 public void changePeerDimensions(int width, int height) throws RemoteException {
137 SomeArgs args = SomeArgs.obtain();
138 args.argi1 = width;
139 args.argi2 = height;
140 mHandler.obtainMessage(MSG_CHANGE_PEER_DIMENSIONS, args).sendToTarget();
141 }
142
143 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700144 public void changeCallDataUsage(long dataUsage) throws RemoteException {
Ihab Awada64627c2014-08-20 09:36:40 -0700145 SomeArgs args = SomeArgs.obtain();
Rekha Kumar07366812015-03-24 16:42:31 -0700146 args.arg1 = dataUsage;
Ihab Awada64627c2014-08-20 09:36:40 -0700147 mHandler.obtainMessage(MSG_CHANGE_CALL_DATA_USAGE, args).sendToTarget();
148 }
149
150 @Override
Yorke Lee400470f2015-05-12 13:31:25 -0700151 public void changeCameraCapabilities(
152 VideoProfile.CameraCapabilities cameraCapabilities)
Ihab Awada64627c2014-08-20 09:36:40 -0700153 throws RemoteException {
154 mHandler.obtainMessage(MSG_CHANGE_CAMERA_CAPABILITIES, cameraCapabilities)
155 .sendToTarget();
156 }
Rekha Kumar07366812015-03-24 16:42:31 -0700157
158 @Override
159 public void changeVideoQuality(int videoQuality) throws RemoteException {
160 mHandler.obtainMessage(MSG_CHANGE_VIDEO_QUALITY, videoQuality, 0).sendToTarget();
161 }
Ihab Awada64627c2014-08-20 09:36:40 -0700162 };
163
164 public VideoCallbackServant(IVideoCallback delegate) {
165 mDelegate = delegate;
166 }
167
168 public IVideoCallback getStub() {
169 return mStub;
170 }
171}