Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 com.android.mediaframeworktest.integration; |
| 18 | |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 19 | import android.hardware.CameraInfo; |
| 20 | import android.hardware.ICamera; |
| 21 | import android.hardware.ICameraClient; |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 22 | import android.hardware.ICameraService; |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 23 | import android.hardware.ICameraServiceListener; |
Eino-Ville Talvala | 2f1a2e4 | 2013-07-25 17:12:05 -0700 | [diff] [blame] | 24 | import android.hardware.camera2.ICameraDeviceCallbacks; |
| 25 | import android.hardware.camera2.ICameraDeviceUser; |
Eino-Ville Talvala | 70c2207 | 2013-08-27 12:09:04 -0700 | [diff] [blame] | 26 | import android.hardware.camera2.impl.CameraMetadataNative; |
Igor Murashkin | 72f9f0a | 2014-05-14 15:46:10 -0700 | [diff] [blame] | 27 | import android.hardware.camera2.impl.CaptureResultExtras; |
Shuzhen Wang | 0960fb4 | 2018-01-10 20:35:11 -0800 | [diff] [blame] | 28 | import android.hardware.camera2.impl.PhysicalCaptureResultInfo; |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 29 | import android.os.Binder; |
| 30 | import android.os.IBinder; |
| 31 | import android.os.RemoteException; |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 32 | import android.os.ServiceSpecificException; |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 33 | import android.test.AndroidTestCase; |
| 34 | import android.test.suitebuilder.annotation.SmallTest; |
| 35 | import android.util.Log; |
| 36 | |
| 37 | /** |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 38 | * <p> |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 39 | * Junit / Instrumentation test case for the camera2 api |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 40 | * </p> |
| 41 | * <p> |
| 42 | * To run only tests in this class: |
| 43 | * </p> |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 44 | * |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 45 | * <pre> |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 46 | * adb shell am instrument \ |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 47 | * -e class com.android.mediaframeworktest.integration.CameraBinderTest \ |
| 48 | * -w com.android.mediaframeworktest/.MediaFrameworkIntegrationTestRunner |
| 49 | * </pre> |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 50 | */ |
| 51 | public class CameraBinderTest extends AndroidTestCase { |
Igor Murashkin | 4961bc8 | 2014-06-17 12:04:07 -0700 | [diff] [blame] | 52 | private static final int MAX_PARAMETERS_LENGTH = 100; |
| 53 | |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 54 | static String TAG = "CameraBinderTest"; |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 55 | |
Igor Murashkin | 4961bc8 | 2014-06-17 12:04:07 -0700 | [diff] [blame] | 56 | // From ICameraService.h |
| 57 | private static final int API_VERSION_1 = 1; |
| 58 | private static final int API_VERSION_2 = 2; |
| 59 | |
Eino-Ville Talvala | 5717612 | 2015-08-14 13:11:16 -0700 | [diff] [blame] | 60 | private static final int CAMERA_TYPE_BACKWARD_COMPATIBLE = 0; |
| 61 | private static final int CAMERA_TYPE_ALL = 1; |
| 62 | |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 63 | protected CameraBinderTestUtils mUtils; |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 64 | |
| 65 | public CameraBinderTest() { |
| 66 | } |
| 67 | |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 68 | @Override |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 69 | protected void setUp() throws Exception { |
| 70 | super.setUp(); |
| 71 | |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 72 | mUtils = new CameraBinderTestUtils(getContext()); |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @SmallTest |
| 76 | public void testNumberOfCameras() throws Exception { |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 77 | |
Eino-Ville Talvala | 5717612 | 2015-08-14 13:11:16 -0700 | [diff] [blame] | 78 | int numCameras = mUtils.getCameraService().getNumberOfCameras(CAMERA_TYPE_ALL); |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 79 | assertTrue("At least this many cameras: " + mUtils.getGuessedNumCameras(), |
| 80 | numCameras >= mUtils.getGuessedNumCameras()); |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 81 | Log.v(TAG, "Number of cameras " + numCameras); |
| 82 | } |
| 83 | |
| 84 | @SmallTest |
| 85 | public void testCameraInfo() throws Exception { |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 86 | for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) { |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 87 | |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 88 | CameraInfo info = mUtils.getCameraService().getCameraInfo(cameraId); |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 89 | assertTrue("Facing was not set for camera " + cameraId, info.info.facing != -1); |
| 90 | assertTrue("Orientation was not set for camera " + cameraId, |
| 91 | info.info.orientation != -1); |
| 92 | |
| 93 | Log.v(TAG, "Camera " + cameraId + " info: facing " + info.info.facing |
| 94 | + ", orientation " + info.info.orientation); |
| 95 | } |
| 96 | } |
| 97 | |
Igor Murashkin | 4961bc8 | 2014-06-17 12:04:07 -0700 | [diff] [blame] | 98 | @SmallTest |
| 99 | public void testGetLegacyParameters() throws Exception { |
| 100 | for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) { |
| 101 | |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 102 | String parameters = mUtils.getCameraService().getLegacyParameters(cameraId); |
| 103 | assertNotNull(parameters); |
Igor Murashkin | 4961bc8 | 2014-06-17 12:04:07 -0700 | [diff] [blame] | 104 | assertTrue("Parameters should have at least one character in it", |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 105 | parameters.length() > 0); |
Igor Murashkin | 4961bc8 | 2014-06-17 12:04:07 -0700 | [diff] [blame] | 106 | |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 107 | int end = parameters.length(); |
Igor Murashkin | 4961bc8 | 2014-06-17 12:04:07 -0700 | [diff] [blame] | 108 | if (end > MAX_PARAMETERS_LENGTH) { |
| 109 | end = MAX_PARAMETERS_LENGTH; |
| 110 | } |
| 111 | |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 112 | Log.v(TAG, "Camera " + cameraId + " parameters: " + parameters.substring(0, end)); |
Igor Murashkin | 4961bc8 | 2014-06-17 12:04:07 -0700 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
| 116 | /** The camera2 api is only supported on HAL3.2+ devices */ |
| 117 | @SmallTest |
| 118 | public void testSupportsCamera2Api() throws Exception { |
| 119 | for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) { |
Eino-Ville Talvala | 283ae234f | 2016-12-08 13:38:52 -0800 | [diff] [blame] | 120 | boolean supports = mUtils.getCameraService().supportsCameraApi( |
| 121 | String.valueOf(cameraId), API_VERSION_2); |
Igor Murashkin | 4961bc8 | 2014-06-17 12:04:07 -0700 | [diff] [blame] | 122 | |
Igor Murashkin | 4961bc8 | 2014-06-17 12:04:07 -0700 | [diff] [blame] | 123 | Log.v(TAG, "Camera " + cameraId + " supports api2: " + supports); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /** The camera1 api is supported on *all* devices regardless of HAL version */ |
| 128 | @SmallTest |
| 129 | public void testSupportsCamera1Api() throws Exception { |
| 130 | for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) { |
| 131 | |
Eino-Ville Talvala | 283ae234f | 2016-12-08 13:38:52 -0800 | [diff] [blame] | 132 | boolean supports = mUtils.getCameraService().supportsCameraApi( |
| 133 | String.valueOf(cameraId), API_VERSION_1); |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 134 | assertTrue( |
| 135 | "Camera service returned false when queried if it supports camera1 api " + |
| 136 | " for camera ID " + cameraId, supports); |
Igor Murashkin | 4961bc8 | 2014-06-17 12:04:07 -0700 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 140 | static abstract class DummyBase extends Binder implements android.os.IInterface { |
| 141 | @Override |
| 142 | public IBinder asBinder() { |
| 143 | return this; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | static class DummyCameraClient extends DummyBase implements ICameraClient { |
| 148 | } |
| 149 | |
| 150 | @SmallTest |
| 151 | public void testConnect() throws Exception { |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 152 | for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) { |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 153 | |
| 154 | ICameraClient dummyCallbacks = new DummyCameraClient(); |
| 155 | |
| 156 | String clientPackageName = getContext().getPackageName(); |
| 157 | |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 158 | ICamera cameraUser = mUtils.getCameraService() |
Ruben Brunk | 66ef645 | 2013-08-08 13:05:30 -0700 | [diff] [blame] | 159 | .connect(dummyCallbacks, cameraId, clientPackageName, |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 160 | ICameraService.USE_CALLING_UID, |
| 161 | ICameraService.USE_CALLING_PID); |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 162 | assertNotNull(String.format("Camera %s was null", cameraId), cameraUser); |
| 163 | |
| 164 | Log.v(TAG, String.format("Camera %s connected", cameraId)); |
| 165 | |
| 166 | cameraUser.disconnect(); |
| 167 | } |
| 168 | } |
| 169 | |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 170 | @SmallTest |
| 171 | public void testConnectLegacy() throws Exception { |
| 172 | final int CAMERA_HAL_API_VERSION_1_0 = 0x100; |
| 173 | for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) { |
| 174 | ICamera cameraUser = null; |
| 175 | ICameraClient dummyCallbacks = new DummyCameraClient(); |
| 176 | |
| 177 | String clientPackageName = getContext().getPackageName(); |
| 178 | |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 179 | try { |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 180 | cameraUser = mUtils.getCameraService() |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 181 | .connectLegacy(dummyCallbacks, cameraId, CAMERA_HAL_API_VERSION_1_0, |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 182 | clientPackageName, |
| 183 | ICameraService.USE_CALLING_UID); |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 184 | assertNotNull(String.format("Camera %s was null", cameraId), cameraUser); |
| 185 | |
| 186 | Log.v(TAG, String.format("Camera %s connected as HAL1 legacy device", cameraId)); |
| 187 | } catch (RuntimeException e) { |
| 188 | // Not all camera device support openLegacy. |
| 189 | Log.i(TAG, "Unable to open camera as HAL1 legacy camera device " + e); |
| 190 | } finally { |
| 191 | if (cameraUser != null) { |
| 192 | cameraUser.disconnect(); |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
Zhijun He | 693e21d | 2013-07-31 14:16:14 -0700 | [diff] [blame] | 198 | static class DummyCameraDeviceCallbacks extends ICameraDeviceCallbacks.Stub { |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 199 | |
Zhijun He | 438d77e | 2014-04-10 17:09:22 -0700 | [diff] [blame] | 200 | /* |
| 201 | * (non-Javadoc) |
| 202 | * @see |
| 203 | * android.hardware.camera2.ICameraDeviceCallbacks#onCameraError(int, |
| 204 | * android.hardware.camera2.CaptureResultExtras) |
| 205 | */ |
Igor Murashkin | 4961bc8 | 2014-06-17 12:04:07 -0700 | [diff] [blame] | 206 | @Override |
Eino-Ville Talvala | acc0095 | 2014-08-06 14:31:08 -0700 | [diff] [blame] | 207 | public void onDeviceError(int errorCode, CaptureResultExtras resultExtras) |
Eino-Ville Talvala | e841d4e | 2013-09-05 09:04:08 -0700 | [diff] [blame] | 208 | throws RemoteException { |
Zhijun He | 438d77e | 2014-04-10 17:09:22 -0700 | [diff] [blame] | 209 | // TODO Auto-generated method stub |
| 210 | |
| 211 | } |
| 212 | |
| 213 | /* |
| 214 | * (non-Javadoc) |
| 215 | * @see |
| 216 | * android.hardware.camera2.ICameraDeviceCallbacks#onCaptureStarted( |
| 217 | * android.hardware.camera2.CaptureResultExtras, long) |
| 218 | */ |
Igor Murashkin | 4961bc8 | 2014-06-17 12:04:07 -0700 | [diff] [blame] | 219 | @Override |
Zhijun He | 438d77e | 2014-04-10 17:09:22 -0700 | [diff] [blame] | 220 | public void onCaptureStarted(CaptureResultExtras resultExtras, long timestamp) |
| 221 | throws RemoteException { |
| 222 | // TODO Auto-generated method stub |
| 223 | |
| 224 | } |
| 225 | |
| 226 | /* |
| 227 | * (non-Javadoc) |
| 228 | * @see |
| 229 | * android.hardware.camera2.ICameraDeviceCallbacks#onResultReceived( |
| 230 | * android.hardware.camera2.impl.CameraMetadataNative, |
| 231 | * android.hardware.camera2.CaptureResultExtras) |
| 232 | */ |
Igor Murashkin | 4961bc8 | 2014-06-17 12:04:07 -0700 | [diff] [blame] | 233 | @Override |
Shuzhen Wang | 0960fb4 | 2018-01-10 20:35:11 -0800 | [diff] [blame] | 234 | public void onResultReceived(CameraMetadataNative result, CaptureResultExtras resultExtras, |
| 235 | PhysicalCaptureResultInfo physicalResults[]) throws RemoteException { |
Zhijun He | 438d77e | 2014-04-10 17:09:22 -0700 | [diff] [blame] | 236 | // TODO Auto-generated method stub |
| 237 | |
| 238 | } |
| 239 | |
| 240 | /* |
| 241 | * (non-Javadoc) |
| 242 | * @see android.hardware.camera2.ICameraDeviceCallbacks#onCameraIdle() |
| 243 | */ |
Igor Murashkin | 4961bc8 | 2014-06-17 12:04:07 -0700 | [diff] [blame] | 244 | @Override |
Eino-Ville Talvala | acc0095 | 2014-08-06 14:31:08 -0700 | [diff] [blame] | 245 | public void onDeviceIdle() throws RemoteException { |
Zhijun He | 438d77e | 2014-04-10 17:09:22 -0700 | [diff] [blame] | 246 | // TODO Auto-generated method stub |
| 247 | |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 248 | } |
Eino-Ville Talvala | ad916f7 | 2015-04-11 12:09:11 -0700 | [diff] [blame] | 249 | |
| 250 | /* |
| 251 | * (non-Javadoc) |
| 252 | * @see android.hardware.camera2.ICameraDeviceCallbacks#onPrepared() |
| 253 | */ |
| 254 | @Override |
| 255 | public void onPrepared(int streamId) throws RemoteException { |
| 256 | // TODO Auto-generated method stub |
| 257 | |
| 258 | } |
Chien-Yu Chen | 2da496f | 2016-04-14 13:33:00 -0700 | [diff] [blame] | 259 | |
| 260 | /* |
| 261 | * (non-Javadoc) |
Shuzhen Wang | 88f1af2 | 2016-09-30 10:29:28 -0700 | [diff] [blame] | 262 | * @see android.hardware.camera2.ICameraDeviceCallbacks#onRequestQueueEmpty() |
| 263 | */ |
| 264 | @Override |
| 265 | public void onRequestQueueEmpty() throws RemoteException { |
| 266 | // TODO Auto-generated method stub |
| 267 | |
| 268 | } |
| 269 | |
| 270 | /* |
| 271 | * (non-Javadoc) |
Chien-Yu Chen | 2da496f | 2016-04-14 13:33:00 -0700 | [diff] [blame] | 272 | * @see android.hardware.camera2.ICameraDeviceCallbacks#onRepeatingRequestError() |
| 273 | */ |
| 274 | @Override |
Yin-Chia Yeh | 8cd12e9 | 2017-09-05 18:14:21 -0700 | [diff] [blame] | 275 | public void onRepeatingRequestError(long lastFrameNumber, int repeatingRequestId) { |
Chien-Yu Chen | 2da496f | 2016-04-14 13:33:00 -0700 | [diff] [blame] | 276 | // TODO Auto-generated method stub |
| 277 | } |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | @SmallTest |
| 281 | public void testConnectDevice() throws Exception { |
| 282 | for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) { |
| 283 | |
| 284 | ICameraDeviceCallbacks dummyCallbacks = new DummyCameraDeviceCallbacks(); |
| 285 | |
| 286 | String clientPackageName = getContext().getPackageName(); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 287 | String clientAttributionTag = getContext().getAttributionTag(); |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 288 | |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 289 | ICameraDeviceUser cameraUser = |
| 290 | mUtils.getCameraService().connectDevice( |
Eino-Ville Talvala | 283ae234f | 2016-12-08 13:38:52 -0800 | [diff] [blame] | 291 | dummyCallbacks, String.valueOf(cameraId), |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 292 | clientPackageName, clientAttributionTag, |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 293 | ICameraService.USE_CALLING_UID); |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 294 | assertNotNull(String.format("Camera %s was null", cameraId), cameraUser); |
| 295 | |
| 296 | Log.v(TAG, String.format("Camera %s connected", cameraId)); |
| 297 | |
| 298 | cameraUser.disconnect(); |
| 299 | } |
| 300 | } |
| 301 | |
Zhijun He | 693e21d | 2013-07-31 14:16:14 -0700 | [diff] [blame] | 302 | static class DummyCameraServiceListener extends ICameraServiceListener.Stub { |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 303 | @Override |
Eino-Ville Talvala | 283ae234f | 2016-12-08 13:38:52 -0800 | [diff] [blame] | 304 | public void onStatusChanged(int status, String cameraId) |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 305 | throws RemoteException { |
Eino-Ville Talvala | 283ae234f | 2016-12-08 13:38:52 -0800 | [diff] [blame] | 306 | Log.v(TAG, String.format("Camera %s has status changed to 0x%x", cameraId, status)); |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 307 | } |
Chien-Yu Chen | afa9139 | 2015-02-11 11:23:28 -0800 | [diff] [blame] | 308 | public void onTorchStatusChanged(int status, String cameraId) |
| 309 | throws RemoteException { |
| 310 | Log.v(TAG, String.format("Camera %s has torch status changed to 0x%x", |
| 311 | cameraId, status)); |
| 312 | } |
Emilian Peev | 0e971f3 | 2019-02-22 17:34:29 -0800 | [diff] [blame] | 313 | @Override |
Shuzhen Wang | 34bf53f | 2020-01-15 10:49:52 -0800 | [diff] [blame] | 314 | public void onPhysicalCameraStatusChanged(int status, String cameraId, |
| 315 | String physicalCameraId) throws RemoteException { |
| 316 | Log.v(TAG, String.format("Camera %s : %s has status changed to 0x%x", |
| 317 | cameraId, physicalCameraId, status)); |
| 318 | } |
| 319 | @Override |
Emilian Peev | 0e971f3 | 2019-02-22 17:34:29 -0800 | [diff] [blame] | 320 | public void onCameraAccessPrioritiesChanged() { |
| 321 | Log.v(TAG, "Camera access permission change"); |
| 322 | } |
Shuzhen Wang | 6d76d3b | 2020-03-06 11:38:21 -0800 | [diff] [blame] | 323 | @Override |
| 324 | public void onCameraOpened(String cameraId, String clientPackageName) { |
| 325 | Log.v(TAG, String.format("Camera %s is opened by client package %s", |
| 326 | cameraId, clientPackageName)); |
| 327 | } |
| 328 | @Override |
| 329 | public void onCameraClosed(String cameraId) { |
| 330 | Log.v(TAG, String.format("Camera %s is closed", cameraId)); |
| 331 | } |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | /** |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 335 | * <pre> |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 336 | * adb shell am instrument \ |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 337 | * -e class 'com.android.mediaframeworktest.integration.CameraBinderTest#testAddRemoveListeners' \ |
| 338 | * -w com.android.mediaframeworktest/.MediaFrameworkIntegrationTestRunner |
| 339 | * </pre> |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 340 | */ |
| 341 | @SmallTest |
| 342 | public void testAddRemoveListeners() throws Exception { |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 343 | for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) { |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 344 | |
| 345 | ICameraServiceListener listener = new DummyCameraServiceListener(); |
| 346 | |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 347 | try { |
| 348 | mUtils.getCameraService().removeListener(listener); |
| 349 | fail("Listener was removed before added"); |
| 350 | } catch (ServiceSpecificException e) { |
| 351 | assertEquals("Listener was removed before added", |
| 352 | e.errorCode, ICameraService.ERROR_ILLEGAL_ARGUMENT); |
| 353 | } |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 354 | |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 355 | mUtils.getCameraService().addListener(listener); |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 356 | |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 357 | try { |
| 358 | mUtils.getCameraService().addListener(listener); |
| 359 | fail("Listener was wrongly added again"); |
| 360 | } catch (ServiceSpecificException e) { |
| 361 | assertEquals("Listener was wrongly added again", |
| 362 | e.errorCode, ICameraService.ERROR_ALREADY_EXISTS); |
| 363 | } |
| 364 | |
| 365 | mUtils.getCameraService().removeListener(listener); |
| 366 | |
| 367 | try { |
| 368 | mUtils.getCameraService().removeListener(listener); |
| 369 | fail("Listener was wrongly removed twice"); |
| 370 | } catch (ServiceSpecificException e) { |
| 371 | assertEquals("Listener was wrongly removed twice", |
| 372 | e.errorCode, ICameraService.ERROR_ILLEGAL_ARGUMENT); |
| 373 | } |
Igor Murashkin | 4491d68 | 2013-05-31 16:43:48 -0700 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | } |