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