blob: eed670d25d8290df3570fa755ef827ac79ddc08b [file] [log] [blame]
Steve Paik875616c2016-02-05 10:55:59 -08001/*
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.car.hardware.camera;
18
19import android.annotation.SystemApi;
20import android.car.Car;
21import android.car.CarManagerBase;
Vitalii Tomkiv235f8ac2016-04-04 11:26:49 -070022import android.car.CarNotConnectedException;
Steve Paik875616c2016-02-05 10:55:59 -080023import android.content.Context;
24import android.os.IBinder;
25import android.os.RemoteException;
26import android.util.Log;
27
28/**
29 * API for controlling camera system in cars
Vitalii Tomkiv280b5722016-03-17 16:17:21 -070030 * @hide
Steve Paik875616c2016-02-05 10:55:59 -080031 */
32@SystemApi
Keun-young Park4cf69112016-10-04 10:02:59 -070033public final class CarCameraManager implements CarManagerBase {
Vitalii Tomkiv1b1247b2016-09-30 11:27:19 -070034 private final static boolean DBG = false;
35 private final static String TAG = CarCameraManager.class.getSimpleName();
Steve Paik875616c2016-02-05 10:55:59 -080036
37 // Camera capabilities flags
38 public static final int ANDROID_OVERLAY_SUPPORT_FLAG = 0x1;
39 public static final int CAMERA_CROP_SUPPORT_FLAG = 0x2;
40 public static final int CAMERA_POSITIONING_SUPPORT_FLAG = 0x4;
41
42 // Camera types
43 public static final int CAR_CAMERA_TYPE_NONE = 0;
44 public static final int CAR_CAMERA_TYPE_RVC = 1;
45
46 private int[] mCameraList;
47 private final ICarCamera mService;
48
49 /**
50 * Get an instance of the CarCameraManager.
51 *
52 * Should not be obtained directly by clients, use {@link Car.getCarManager()} instead.
53 * @hide
54 */
Vitalii Tomkiv235f8ac2016-04-04 11:26:49 -070055 public CarCameraManager(IBinder service, Context context) throws CarNotConnectedException{
Steve Paik875616c2016-02-05 10:55:59 -080056 mService = ICarCamera.Stub.asInterface(service);
57 try {
58 mCameraList = mService.getCameraList();
59 } catch (RemoteException e) {
60 Log.e(TAG, "Exception in getCameraList", e);
61 mCameraList = null;
Vitalii Tomkiv235f8ac2016-04-04 11:26:49 -070062 throw new CarNotConnectedException(e);
Steve Paik875616c2016-02-05 10:55:59 -080063 }
64 }
65
66 /**
67 *
68 * @return Array of CAR_CAMERA_TYPE_* telling which cameras are present
69 */
Keun-young Park150d8de2016-10-07 15:48:11 -070070 public int[] getCameraList() throws CarNotConnectedException {
Steve Paik875616c2016-02-05 10:55:59 -080071 return mCameraList;
72 }
73
74 /**
75 *
76 * @param cameraType Camera type to query capabilites
77 * @return Bitmask of camera capabilities available for this device
Jason Tholstrupd72b5352016-09-22 16:32:14 -070078 * @throws CarNotConnectedException if the connection to the car service has been lost.
Steve Paik875616c2016-02-05 10:55:59 -080079 */
Vitalii Tomkiv235f8ac2016-04-04 11:26:49 -070080 public int getCameraCapabilities(int cameraType) throws CarNotConnectedException {
Steve Paik875616c2016-02-05 10:55:59 -080081 int capabilities;
82 try {
83 capabilities = mService.getCapabilities(cameraType);
84 } catch (RemoteException e) {
85 Log.e(TAG, "Exception in getCameraCapabilities", e);
Vitalii Tomkiv235f8ac2016-04-04 11:26:49 -070086 throw new CarNotConnectedException(e);
Steve Paik875616c2016-02-05 10:55:59 -080087 }
88 return capabilities;
89 }
90
Keun-young Park150d8de2016-10-07 15:48:11 -070091 public CarCamera openCamera(int cameraType) throws CarNotConnectedException {
Steve Paik875616c2016-02-05 10:55:59 -080092 CarCamera camera = null;
93
94 // Find cameraType in the list of available cameras
95 for (int i : mCameraList) {
96 if(i == cameraType) {
97 camera = new CarCamera(mService, cameraType);
98 break;
99 }
100 }
101 return camera;
102 }
103
104 public void closeCamera(CarCamera camera) {
105 // TODO: What should we do?
106 }
107
108 /** @hide */
109 @Override
110 public void onCarDisconnected() {
111 }
112}