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.car.hardware.camera;
18
19import android.annotation.SystemApi;
20import android.car.Car;
21import android.car.CarManagerBase;
22import android.car.CarNotConnectedException;
23import 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
30 * @hide
31 */
32@SystemApi
33public class CarCameraManager implements CarManagerBase {
34    public final static boolean DBG = true;
35    public final static String TAG = CarCameraManager.class.getSimpleName();
36
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     */
55    public CarCameraManager(IBinder service, Context context) throws CarNotConnectedException{
56        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;
62            throw new CarNotConnectedException(e);
63        }
64    }
65
66    /**
67     *
68     * @return Array of CAR_CAMERA_TYPE_* telling which cameras are present
69     */
70    public int[] getCameraList() {
71        return mCameraList;
72    }
73
74    /**
75     *
76     * @param cameraType Camera type to query capabilites
77     * @return Bitmask of camera capabilities available for this device
78     * @throws CarNotConnectedException
79     */
80    public int getCameraCapabilities(int cameraType) throws CarNotConnectedException {
81        int capabilities;
82        try {
83            capabilities = mService.getCapabilities(cameraType);
84        } catch (RemoteException e) {
85            Log.e(TAG, "Exception in getCameraCapabilities", e);
86            throw new CarNotConnectedException(e);
87        }
88        return capabilities;
89    }
90
91    public CarCamera openCamera(int cameraType) {
92        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}
113