Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 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.Car; |
| 21 | import android.car.CarManagerBase; |
Vitalii Tomkiv | 235f8ac | 2016-04-04 11:26:49 -0700 | [diff] [blame] | 22 | import android.car.CarNotConnectedException; |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 23 | import android.content.Context; |
| 24 | import android.os.IBinder; |
| 25 | import android.os.RemoteException; |
| 26 | import android.util.Log; |
| 27 | |
| 28 | /** |
| 29 | * API for controlling camera system in cars |
Vitalii Tomkiv | 280b572 | 2016-03-17 16:17:21 -0700 | [diff] [blame] | 30 | * @hide |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 31 | */ |
| 32 | @SystemApi |
Keun-young Park | 4cf6911 | 2016-10-04 10:02:59 -0700 | [diff] [blame] | 33 | public final class CarCameraManager implements CarManagerBase { |
Vitalii Tomkiv | 1b1247b | 2016-09-30 11:27:19 -0700 | [diff] [blame] | 34 | private final static boolean DBG = false; |
| 35 | private final static String TAG = CarCameraManager.class.getSimpleName(); |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 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 | */ |
Vitalii Tomkiv | 235f8ac | 2016-04-04 11:26:49 -0700 | [diff] [blame] | 55 | public CarCameraManager(IBinder service, Context context) throws CarNotConnectedException{ |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 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; |
Vitalii Tomkiv | 235f8ac | 2016-04-04 11:26:49 -0700 | [diff] [blame] | 62 | throw new CarNotConnectedException(e); |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * |
| 68 | * @return Array of CAR_CAMERA_TYPE_* telling which cameras are present |
| 69 | */ |
Keun-young Park | 150d8de | 2016-10-07 15:48:11 -0700 | [diff] [blame] | 70 | public int[] getCameraList() throws CarNotConnectedException { |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 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 |
Jason Tholstrup | d72b535 | 2016-09-22 16:32:14 -0700 | [diff] [blame] | 78 | * @throws CarNotConnectedException if the connection to the car service has been lost. |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 79 | */ |
Vitalii Tomkiv | 235f8ac | 2016-04-04 11:26:49 -0700 | [diff] [blame] | 80 | public int getCameraCapabilities(int cameraType) throws CarNotConnectedException { |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 81 | int capabilities; |
| 82 | try { |
| 83 | capabilities = mService.getCapabilities(cameraType); |
| 84 | } catch (RemoteException e) { |
| 85 | Log.e(TAG, "Exception in getCameraCapabilities", e); |
Vitalii Tomkiv | 235f8ac | 2016-04-04 11:26:49 -0700 | [diff] [blame] | 86 | throw new CarNotConnectedException(e); |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 87 | } |
| 88 | return capabilities; |
| 89 | } |
| 90 | |
Keun-young Park | 150d8de | 2016-10-07 15:48:11 -0700 | [diff] [blame] | 91 | public CarCamera openCamera(int cameraType) throws CarNotConnectedException { |
Steve Paik | 875616c | 2016-02-05 10:55:59 -0800 | [diff] [blame] | 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 | } |