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