ICameraDeviceUserWrapper.java revision 5d2d7788f1759b0f3d2c057af0b3ea61b0354fee
1/*
2 * Copyright (C) 2016 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
17package android.hardware.camera2.impl;
18
19import static android.hardware.camera2.CameraAccessException.CAMERA_DISABLED;
20import static android.hardware.camera2.CameraAccessException.CAMERA_DISCONNECTED;
21import static android.hardware.camera2.CameraAccessException.CAMERA_IN_USE;
22import static android.hardware.camera2.CameraAccessException.CAMERA_ERROR;
23import static android.hardware.camera2.CameraAccessException.MAX_CAMERAS_IN_USE;
24import static android.hardware.camera2.CameraAccessException.CAMERA_DEPRECATED_HAL;
25
26import android.hardware.ICameraService;
27import android.hardware.camera2.CameraManager;
28import android.hardware.camera2.CameraAccessException;
29import android.hardware.camera2.CaptureRequest;
30import android.hardware.camera2.ICameraDeviceUser;
31import android.hardware.camera2.impl.CameraMetadataNative;
32import android.hardware.camera2.params.OutputConfiguration;
33import android.hardware.camera2.utils.SubmitInfo;
34import android.os.RemoteException;
35import android.view.Surface;
36
37/**
38 * A wrapper around ICameraDeviceUser.
39 *
40 * Mainly used to convert ServiceSpecificExceptions to the correct
41 * checked / unchecked exception.
42 *
43 * @hide
44 */
45public class ICameraDeviceUserWrapper {
46
47    private final ICameraDeviceUser mRemoteDevice;
48
49    public ICameraDeviceUserWrapper(ICameraDeviceUser remoteDevice) {
50        if (remoteDevice == null) {
51            throw new NullPointerException("Remote device may not be null");
52        }
53        mRemoteDevice = remoteDevice;
54    }
55
56    public void disconnect()  {
57        try {
58            mRemoteDevice.disconnect();
59        } catch (RemoteException t) {
60            // ignore binder errors for disconnect
61        }
62    }
63
64    public SubmitInfo submitRequest(CaptureRequest request, boolean streaming)
65            throws CameraAccessException  {
66        try {
67            return mRemoteDevice.submitRequest(request, streaming);
68        } catch (Throwable t) {
69            CameraManager.throwAsPublicException(t);
70            throw new UnsupportedOperationException("Unexpected exception", t);
71        }
72    }
73
74    public SubmitInfo submitRequestList(CaptureRequest[] requestList, boolean streaming)
75            throws CameraAccessException {
76        try {
77            return mRemoteDevice.submitRequestList(requestList, streaming);
78        } catch (Throwable t) {
79            CameraManager.throwAsPublicException(t);
80            throw new UnsupportedOperationException("Unexpected exception", t);
81        }
82    }
83
84    public long cancelRequest(int requestId) throws CameraAccessException {
85        try {
86            return mRemoteDevice.cancelRequest(requestId);
87        } catch (Throwable t) {
88            CameraManager.throwAsPublicException(t);
89            throw new UnsupportedOperationException("Unexpected exception", t);
90        }
91    }
92
93    public void beginConfigure() throws CameraAccessException {
94        try {
95            mRemoteDevice.beginConfigure();
96        } catch (Throwable t) {
97            CameraManager.throwAsPublicException(t);
98            throw new UnsupportedOperationException("Unexpected exception", t);
99        }
100    }
101
102    public void endConfigure(boolean isConstrainedHighSpeed) throws CameraAccessException {
103        try {
104            mRemoteDevice.endConfigure(isConstrainedHighSpeed);
105        } catch (Throwable t) {
106            CameraManager.throwAsPublicException(t);
107            throw new UnsupportedOperationException("Unexpected exception", t);
108        }
109    }
110
111    public void deleteStream(int streamId) throws CameraAccessException {
112        try {
113            mRemoteDevice.deleteStream(streamId);
114        } catch (Throwable t) {
115            CameraManager.throwAsPublicException(t);
116            throw new UnsupportedOperationException("Unexpected exception", t);
117        }
118    }
119
120    public int createStream(OutputConfiguration outputConfiguration)
121            throws CameraAccessException {
122        try {
123            return mRemoteDevice.createStream(outputConfiguration);
124        } catch (Throwable t) {
125            CameraManager.throwAsPublicException(t);
126            throw new UnsupportedOperationException("Unexpected exception", t);
127        }
128    }
129
130    public int createInputStream(int width, int height, int format) throws CameraAccessException {
131        try {
132            return mRemoteDevice.createInputStream(width, height, format);
133        } catch (Throwable t) {
134            CameraManager.throwAsPublicException(t);
135            throw new UnsupportedOperationException("Unexpected exception", t);
136        }
137    }
138
139    public Surface getInputSurface() throws CameraAccessException {
140        try {
141            return mRemoteDevice.getInputSurface();
142        } catch (Throwable t) {
143            CameraManager.throwAsPublicException(t);
144            throw new UnsupportedOperationException("Unexpected exception", t);
145        }
146    }
147
148    public CameraMetadataNative createDefaultRequest(int templateId) throws CameraAccessException {
149        try {
150            return mRemoteDevice.createDefaultRequest(templateId);
151        } catch (Throwable t) {
152            CameraManager.throwAsPublicException(t);
153            throw new UnsupportedOperationException("Unexpected exception", t);
154        }
155    }
156
157    public CameraMetadataNative getCameraInfo() throws CameraAccessException {
158        try {
159            return mRemoteDevice.getCameraInfo();
160        } catch (Throwable t) {
161            CameraManager.throwAsPublicException(t);
162            throw new UnsupportedOperationException("Unexpected exception", t);
163        }
164    }
165
166    public void waitUntilIdle() throws CameraAccessException {
167        try {
168            mRemoteDevice.waitUntilIdle();
169        } catch (Throwable t) {
170            CameraManager.throwAsPublicException(t);
171            throw new UnsupportedOperationException("Unexpected exception", t);
172        }
173    }
174
175    public long flush() throws CameraAccessException {
176        try {
177            return mRemoteDevice.flush();
178        } catch (Throwable t) {
179            CameraManager.throwAsPublicException(t);
180            throw new UnsupportedOperationException("Unexpected exception", t);
181        }
182    }
183
184    public void prepare(int streamId) throws CameraAccessException {
185        try {
186            mRemoteDevice.prepare(streamId);
187        } catch (Throwable t) {
188            CameraManager.throwAsPublicException(t);
189            throw new UnsupportedOperationException("Unexpected exception", t);
190        }
191    }
192
193    public void tearDown(int streamId) throws CameraAccessException {
194        try {
195            mRemoteDevice.tearDown(streamId);
196        } catch (Throwable t) {
197            CameraManager.throwAsPublicException(t);
198            throw new UnsupportedOperationException("Unexpected exception", t);
199        }
200    }
201
202    public void prepare2(int maxCount, int streamId) throws CameraAccessException {
203        try {
204            mRemoteDevice.prepare2(maxCount, streamId);
205        } catch (Throwable t) {
206            CameraManager.throwAsPublicException(t);
207            throw new UnsupportedOperationException("Unexpected exception", t);
208        }
209    }
210
211
212}
213