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 
17 package android.car.hardware.camera;
18 
19 import android.annotation.SystemApi;
20 import android.car.CarNotConnectedException;
21 import android.graphics.Rect;
22 import android.os.RemoteException;
23 import android.util.Log;
24 
25 /**
26  * API for controlling camera system in cars
27  * @hide
28  */
29 @SystemApi
30 public class CarCamera {
31     public final static String TAG = CarCamera.class.getSimpleName();
32     public final int mCameraType;
33     private final ICarCamera mService;
34 
CarCamera(ICarCamera service, int cameraType)35     public CarCamera(ICarCamera service, int cameraType) {
36         mService = service;
37         mCameraType = cameraType;
38     }
39 
getCapabilities()40     public int getCapabilities() throws CarNotConnectedException {
41         try {
42             return mService.getCapabilities(mCameraType);
43         } catch (RemoteException e) {
44             Log.e(TAG, "Exception in getCapabilities", e);
45             throw new CarNotConnectedException(e);
46         }
47     }
48 
getCameraCrop()49     public Rect getCameraCrop() throws CarNotConnectedException {
50         try {
51             return mService.getCameraCrop(mCameraType);
52         } catch (RemoteException e) {
53             Log.e(TAG, "Exception in getCameraCrop", e);
54             throw new CarNotConnectedException(e);
55         }
56     }
57 
setCameraCrop(Rect rect)58     public void setCameraCrop(Rect rect) throws CarNotConnectedException {
59         try {
60             mService.setCameraCrop(mCameraType, rect);
61         } catch (RemoteException e) {
62             Log.e(TAG, "Exception in setCameraCrop", e);
63             throw new CarNotConnectedException(e);
64         }
65     }
66 
getCameraPosition()67     public Rect getCameraPosition() throws CarNotConnectedException {
68         try {
69             return mService.getCameraPosition(mCameraType);
70         } catch (RemoteException e) {
71             Log.e(TAG, "Exception in getCameraPosition", e);
72             throw new CarNotConnectedException(e);
73         }
74     }
75 
setCameraPosition(Rect rect)76     public void setCameraPosition(Rect rect) throws CarNotConnectedException {
77         try {
78             mService.setCameraPosition(mCameraType, rect);
79         } catch (RemoteException e) {
80             Log.e(TAG, "Exception in setCameraPosition", e);
81         }
82     }
83 
getCameraState()84     public CarCameraState getCameraState() throws CarNotConnectedException {
85         try {
86             return mService.getCameraState(mCameraType);
87         } catch (RemoteException e) {
88             Log.e(TAG, "Exception in getCameraState", e);
89             throw new CarNotConnectedException(e);
90         }
91     }
92 
setCameraState(CarCameraState state)93     public void setCameraState(CarCameraState state) throws CarNotConnectedException {
94         try {
95             mService.setCameraState(mCameraType, state);
96         } catch (RemoteException e) {
97             Log.e(TAG, "Exception in setCameraState", e);
98             throw new CarNotConnectedException(e);
99         }
100     }
101 }
102