1a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad/* 2a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * Copyright (C) 2014 The Android Open Source Project 3a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * 4a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * Licensed under the Apache License, Version 2.0 (the "License"); 5a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * you may not use this file except in compliance with the License. 6a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * You may obtain a copy of the License at 7a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * 8a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * http://www.apache.org/licenses/LICENSE-2.0 9a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * 10a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * Unless required by applicable law or agreed to in writing, software 11a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * distributed under the License is distributed on an "AS IS" BASIS, 12a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * See the License for the specific language governing permissions and 14a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad R* limitations under the License. 15a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad */ 16a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 17ef9f6f957d897ea0ed82114185b8fa3fefd4917bTyler Gunnpackage android.telecom; 18a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 19a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awadimport com.android.internal.os.SomeArgs; 20ef9f6f957d897ea0ed82114185b8fa3fefd4917bTyler Gunnimport com.android.internal.telecom.IVideoCallback; 21a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 22a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awadimport android.os.Handler; 23a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awadimport android.os.Message; 24a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awadimport android.os.RemoteException; 25a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 26a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad/** 27a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * A component that provides an RPC servant implementation of {@link IVideoCallback}, 28a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * posting incoming messages on the main thread on a client-supplied delegate object. 29a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * 30a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * TODO: Generate this and similar classes using a compiler starting from AIDL interfaces. 31a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * 32a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad * @hide 33a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad */ 34a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awadfinal class VideoCallbackServant { 35a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad private static final int MSG_RECEIVE_SESSION_MODIFY_REQUEST = 0; 36a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad private static final int MSG_RECEIVE_SESSION_MODIFY_RESPONSE = 1; 37a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad private static final int MSG_HANDLE_CALL_SESSION_EVENT = 2; 38a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad private static final int MSG_CHANGE_PEER_DIMENSIONS = 3; 39a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad private static final int MSG_CHANGE_CALL_DATA_USAGE = 4; 40a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad private static final int MSG_CHANGE_CAMERA_CAPABILITIES = 5; 41a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 42a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad private final IVideoCallback mDelegate; 43a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 44a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad private final Handler mHandler = new Handler() { 45a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad @Override 46a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad public void handleMessage(Message msg) { 47a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad try { 48a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad internalHandleMessage(msg); 49a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } catch (RemoteException e) { 50a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 51a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 52a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 53a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad // Internal method defined to centralize handling of RemoteException 54a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad private void internalHandleMessage(Message msg) throws RemoteException { 55a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad switch (msg.what) { 56a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad case MSG_RECEIVE_SESSION_MODIFY_REQUEST: { 57a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mDelegate.receiveSessionModifyRequest((VideoProfile) msg.obj); 58a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad break; 59a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 60a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad case MSG_RECEIVE_SESSION_MODIFY_RESPONSE: { 61a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad SomeArgs args = (SomeArgs) msg.obj; 62a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad try { 63a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mDelegate.receiveSessionModifyResponse( 64a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.argi1, 65a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad (VideoProfile) args.arg1, 66a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad (VideoProfile) args.arg2); 67a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } finally { 68a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.recycle(); 69a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 70a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad break; 71a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 72a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad case MSG_HANDLE_CALL_SESSION_EVENT: { 73a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad SomeArgs args = (SomeArgs) msg.obj; 74a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad try { 75a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mDelegate.handleCallSessionEvent(args.argi1); 76a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } finally { 77a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.recycle(); 78a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 79a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad break; 80a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 81a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad case MSG_CHANGE_PEER_DIMENSIONS: { 82a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad SomeArgs args = (SomeArgs) msg.obj; 83a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad try { 84a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mDelegate.changePeerDimensions(args.argi1, args.argi2); 85a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } finally { 86a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.recycle(); 87a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 88a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad break; 89a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 90a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad case MSG_CHANGE_CALL_DATA_USAGE: { 91a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad SomeArgs args = (SomeArgs) msg.obj; 92a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad try { 93a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mDelegate.changeCallDataUsage(args.argi1); 94a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } finally { 95a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.recycle(); 96a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 97a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad break; 98a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 99a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad case MSG_CHANGE_CAMERA_CAPABILITIES: { 100a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mDelegate.changeCameraCapabilities((CameraCapabilities) msg.obj); 101a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad break; 102a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 103a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 104a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 105a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad }; 106a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 107a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad private final IVideoCallback mStub = new IVideoCallback.Stub() { 108a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad @Override 109a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad public void receiveSessionModifyRequest(VideoProfile videoProfile) throws RemoteException { 110a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mHandler.obtainMessage(MSG_RECEIVE_SESSION_MODIFY_REQUEST, videoProfile).sendToTarget(); 111a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 112a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 113a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad @Override 114a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad public void receiveSessionModifyResponse(int status, VideoProfile requestedProfile, 115a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad VideoProfile responseProfile) throws RemoteException { 116a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad SomeArgs args = SomeArgs.obtain(); 117a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.argi1 = status; 118a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.arg1 = requestedProfile; 119a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.arg2 = responseProfile; 120a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mHandler.obtainMessage(MSG_RECEIVE_SESSION_MODIFY_RESPONSE, args).sendToTarget(); 121a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 122a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 123a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad @Override 124a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad public void handleCallSessionEvent(int event) throws RemoteException { 125a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad SomeArgs args = SomeArgs.obtain(); 126a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.argi1 = event; 127a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mHandler.obtainMessage(MSG_HANDLE_CALL_SESSION_EVENT, args).sendToTarget(); 128a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 129a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 130a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad @Override 131a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad public void changePeerDimensions(int width, int height) throws RemoteException { 132a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad SomeArgs args = SomeArgs.obtain(); 133a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.argi1 = width; 134a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.argi2 = height; 135a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mHandler.obtainMessage(MSG_CHANGE_PEER_DIMENSIONS, args).sendToTarget(); 136a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 137a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 138a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad @Override 139a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad public void changeCallDataUsage(int dataUsage) throws RemoteException { 140a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad SomeArgs args = SomeArgs.obtain(); 141a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.argi1 = dataUsage; 142a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mHandler.obtainMessage(MSG_CHANGE_CALL_DATA_USAGE, args).sendToTarget(); 143a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 144a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 145a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad @Override 146a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) 147a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad throws RemoteException { 148a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mHandler.obtainMessage(MSG_CHANGE_CAMERA_CAPABILITIES, cameraCapabilities) 149a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad .sendToTarget(); 150a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 151a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad }; 152a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 153a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad public VideoCallbackServant(IVideoCallback delegate) { 154a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mDelegate = delegate; 155a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 156a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 157a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad public IVideoCallback getStub() { 158a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad return mStub; 159a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 160a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad} 161