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 if (mRemoteDevice.asBinder() != null) { 59 mRemoteDevice.asBinder().unlinkToDeath(recipient, flags); 60 } 61 } 62 63 public void disconnect() { 64 try { 65 mRemoteDevice.disconnect(); 66 } catch (RemoteException t) { 67 // ignore binder errors for disconnect 68 } 69 } 70 71 public SubmitInfo submitRequest(CaptureRequest request, boolean streaming) 72 throws CameraAccessException { 73 try { 74 return mRemoteDevice.submitRequest(request, streaming); 75 } catch (Throwable t) { 76 CameraManager.throwAsPublicException(t); 77 throw new UnsupportedOperationException("Unexpected exception", t); 78 } 79 } 80 81 public SubmitInfo submitRequestList(CaptureRequest[] requestList, boolean streaming) 82 throws CameraAccessException { 83 try { 84 return mRemoteDevice.submitRequestList(requestList, streaming); 85 } catch (Throwable t) { 86 CameraManager.throwAsPublicException(t); 87 throw new UnsupportedOperationException("Unexpected exception", t); 88 } 89 } 90 91 public long cancelRequest(int requestId) throws CameraAccessException { 92 try { 93 return mRemoteDevice.cancelRequest(requestId); 94 } catch (Throwable t) { 95 CameraManager.throwAsPublicException(t); 96 throw new UnsupportedOperationException("Unexpected exception", t); 97 } 98 } 99 100 public void beginConfigure() throws CameraAccessException { 101 try { 102 mRemoteDevice.beginConfigure(); 103 } catch (Throwable t) { 104 CameraManager.throwAsPublicException(t); 105 throw new UnsupportedOperationException("Unexpected exception", t); 106 } 107 } 108 109 public void endConfigure(boolean isConstrainedHighSpeed) throws CameraAccessException { 110 try { 111 mRemoteDevice.endConfigure(isConstrainedHighSpeed); 112 } catch (Throwable t) { 113 CameraManager.throwAsPublicException(t); 114 throw new UnsupportedOperationException("Unexpected exception", t); 115 } 116 } 117 118 public void deleteStream(int streamId) throws CameraAccessException { 119 try { 120 mRemoteDevice.deleteStream(streamId); 121 } catch (Throwable t) { 122 CameraManager.throwAsPublicException(t); 123 throw new UnsupportedOperationException("Unexpected exception", t); 124 } 125 } 126 127 public int createStream(OutputConfiguration outputConfiguration) 128 throws CameraAccessException { 129 try { 130 return mRemoteDevice.createStream(outputConfiguration); 131 } catch (Throwable t) { 132 CameraManager.throwAsPublicException(t); 133 throw new UnsupportedOperationException("Unexpected exception", t); 134 } 135 } 136 137 public int createInputStream(int width, int height, int format) throws CameraAccessException { 138 try { 139 return mRemoteDevice.createInputStream(width, height, format); 140 } catch (Throwable t) { 141 CameraManager.throwAsPublicException(t); 142 throw new UnsupportedOperationException("Unexpected exception", t); 143 } 144 } 145 146 public Surface getInputSurface() throws CameraAccessException { 147 try { 148 return mRemoteDevice.getInputSurface(); 149 } catch (Throwable t) { 150 CameraManager.throwAsPublicException(t); 151 throw new UnsupportedOperationException("Unexpected exception", t); 152 } 153 } 154 155 public CameraMetadataNative createDefaultRequest(int templateId) throws CameraAccessException { 156 try { 157 return mRemoteDevice.createDefaultRequest(templateId); 158 } catch (Throwable t) { 159 CameraManager.throwAsPublicException(t); 160 throw new UnsupportedOperationException("Unexpected exception", t); 161 } 162 } 163 164 public CameraMetadataNative getCameraInfo() throws CameraAccessException { 165 try { 166 return mRemoteDevice.getCameraInfo(); 167 } catch (Throwable t) { 168 CameraManager.throwAsPublicException(t); 169 throw new UnsupportedOperationException("Unexpected exception", t); 170 } 171 } 172 173 public void waitUntilIdle() throws CameraAccessException { 174 try { 175 mRemoteDevice.waitUntilIdle(); 176 } catch (Throwable t) { 177 CameraManager.throwAsPublicException(t); 178 throw new UnsupportedOperationException("Unexpected exception", t); 179 } 180 } 181 182 public long flush() throws CameraAccessException { 183 try { 184 return mRemoteDevice.flush(); 185 } catch (Throwable t) { 186 CameraManager.throwAsPublicException(t); 187 throw new UnsupportedOperationException("Unexpected exception", t); 188 } 189 } 190 191 public void prepare(int streamId) throws CameraAccessException { 192 try { 193 mRemoteDevice.prepare(streamId); 194 } catch (Throwable t) { 195 CameraManager.throwAsPublicException(t); 196 throw new UnsupportedOperationException("Unexpected exception", t); 197 } 198 } 199 200 public void tearDown(int streamId) throws CameraAccessException { 201 try { 202 mRemoteDevice.tearDown(streamId); 203 } catch (Throwable t) { 204 CameraManager.throwAsPublicException(t); 205 throw new UnsupportedOperationException("Unexpected exception", t); 206 } 207 } 208 209 public void prepare2(int maxCount, int streamId) throws CameraAccessException { 210 try { 211 mRemoteDevice.prepare2(maxCount, streamId); 212 } catch (Throwable t) { 213 CameraManager.throwAsPublicException(t); 214 throw new UnsupportedOperationException("Unexpected exception", t); 215 } 216 } 217 218 219} 220