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; 4107366813cdf3768dcd69a1f744023747564d654aRekha Kumar private static final int MSG_CHANGE_VIDEO_QUALITY = 6; 42a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 43a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad private final IVideoCallback mDelegate; 44a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 45a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad private final Handler mHandler = new Handler() { 46a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad @Override 47a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad public void handleMessage(Message msg) { 48a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad try { 49a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad internalHandleMessage(msg); 50a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } catch (RemoteException e) { 51a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 52a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 53a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 54a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad // Internal method defined to centralize handling of RemoteException 55a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad private void internalHandleMessage(Message msg) throws RemoteException { 56a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad switch (msg.what) { 57a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad case MSG_RECEIVE_SESSION_MODIFY_REQUEST: { 58a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mDelegate.receiveSessionModifyRequest((VideoProfile) msg.obj); 59a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad break; 60a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 61a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad case MSG_RECEIVE_SESSION_MODIFY_RESPONSE: { 62a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad SomeArgs args = (SomeArgs) msg.obj; 63a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad try { 64a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mDelegate.receiveSessionModifyResponse( 65a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.argi1, 66a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad (VideoProfile) args.arg1, 67a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad (VideoProfile) args.arg2); 68a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } finally { 69a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.recycle(); 70a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 71a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad break; 72a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 73a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad case MSG_HANDLE_CALL_SESSION_EVENT: { 74a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad SomeArgs args = (SomeArgs) msg.obj; 75a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad try { 76a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mDelegate.handleCallSessionEvent(args.argi1); 77a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } finally { 78a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.recycle(); 79a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 80a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad break; 81a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 82a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad case MSG_CHANGE_PEER_DIMENSIONS: { 83a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad SomeArgs args = (SomeArgs) msg.obj; 84a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad try { 85a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mDelegate.changePeerDimensions(args.argi1, args.argi2); 86a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } finally { 87a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.recycle(); 88a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 89a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad break; 90a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 91a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad case MSG_CHANGE_CALL_DATA_USAGE: { 92a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad SomeArgs args = (SomeArgs) msg.obj; 93a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad try { 9407366813cdf3768dcd69a1f744023747564d654aRekha Kumar mDelegate.changeCallDataUsage((long) args.arg1); 95a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } finally { 96a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.recycle(); 97a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 98a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad break; 99a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 100a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad case MSG_CHANGE_CAMERA_CAPABILITIES: { 101400470fab932fe3374149ab89386e460ea161002Yorke Lee mDelegate.changeCameraCapabilities((VideoProfile.CameraCapabilities) msg.obj); 102a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad break; 103a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 10407366813cdf3768dcd69a1f744023747564d654aRekha Kumar case MSG_CHANGE_VIDEO_QUALITY: { 10507366813cdf3768dcd69a1f744023747564d654aRekha Kumar mDelegate.changeVideoQuality(msg.arg1); 10607366813cdf3768dcd69a1f744023747564d654aRekha Kumar break; 10707366813cdf3768dcd69a1f744023747564d654aRekha Kumar } 108a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 109a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 110a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad }; 111a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 112a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad private final IVideoCallback mStub = new IVideoCallback.Stub() { 113a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad @Override 114a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad public void receiveSessionModifyRequest(VideoProfile videoProfile) throws RemoteException { 115a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mHandler.obtainMessage(MSG_RECEIVE_SESSION_MODIFY_REQUEST, videoProfile).sendToTarget(); 116a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 117a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 118a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad @Override 119a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad public void receiveSessionModifyResponse(int status, VideoProfile requestedProfile, 120a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad VideoProfile responseProfile) throws RemoteException { 121a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad SomeArgs args = SomeArgs.obtain(); 122a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.argi1 = status; 123a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.arg1 = requestedProfile; 124a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.arg2 = responseProfile; 125a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mHandler.obtainMessage(MSG_RECEIVE_SESSION_MODIFY_RESPONSE, args).sendToTarget(); 126a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 127a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 128a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad @Override 129a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad public void handleCallSessionEvent(int event) throws RemoteException { 130a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad SomeArgs args = SomeArgs.obtain(); 131a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.argi1 = event; 132a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mHandler.obtainMessage(MSG_HANDLE_CALL_SESSION_EVENT, args).sendToTarget(); 133a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 134a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 135a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad @Override 136a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad public void changePeerDimensions(int width, int height) throws RemoteException { 137a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad SomeArgs args = SomeArgs.obtain(); 138a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.argi1 = width; 139a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad args.argi2 = height; 140a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mHandler.obtainMessage(MSG_CHANGE_PEER_DIMENSIONS, args).sendToTarget(); 141a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 142a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 143a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad @Override 14407366813cdf3768dcd69a1f744023747564d654aRekha Kumar public void changeCallDataUsage(long dataUsage) throws RemoteException { 145a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad SomeArgs args = SomeArgs.obtain(); 14607366813cdf3768dcd69a1f744023747564d654aRekha Kumar args.arg1 = dataUsage; 147a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mHandler.obtainMessage(MSG_CHANGE_CALL_DATA_USAGE, args).sendToTarget(); 148a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 149a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 150a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad @Override 151400470fab932fe3374149ab89386e460ea161002Yorke Lee public void changeCameraCapabilities( 152400470fab932fe3374149ab89386e460ea161002Yorke Lee VideoProfile.CameraCapabilities cameraCapabilities) 153a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad throws RemoteException { 154a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mHandler.obtainMessage(MSG_CHANGE_CAMERA_CAPABILITIES, cameraCapabilities) 155a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad .sendToTarget(); 156a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 15707366813cdf3768dcd69a1f744023747564d654aRekha Kumar 15807366813cdf3768dcd69a1f744023747564d654aRekha Kumar @Override 15907366813cdf3768dcd69a1f744023747564d654aRekha Kumar public void changeVideoQuality(int videoQuality) throws RemoteException { 16007366813cdf3768dcd69a1f744023747564d654aRekha Kumar mHandler.obtainMessage(MSG_CHANGE_VIDEO_QUALITY, videoQuality, 0).sendToTarget(); 16107366813cdf3768dcd69a1f744023747564d654aRekha Kumar } 162a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad }; 163a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 164a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad public VideoCallbackServant(IVideoCallback delegate) { 165a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad mDelegate = delegate; 166a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 167a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad 168a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad public IVideoCallback getStub() { 169a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad return mStub; 170a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad } 171a64627c2d3330f6bee8055b2e51ffaf8a122ef2bIhab Awad} 172