CameraBinderTestpublic class CameraBinderTest extends android.test.AndroidTestCase
Junit / Instrumentation test case for the camera2 api
To run only tests in this class:
adb shell am instrument \
-e class com.android.mediaframeworktest.integration.CameraBinderTest \
-w com.android.mediaframeworktest/.MediaFrameworkIntegrationTestRunner
|
Fields Summary |
---|
private static final int | MAX_PARAMETERS_LENGTH | static String | TAG | private static final int | API_VERSION_1 | private static final int | API_VERSION_2 | protected CameraBinderTestUtils | mUtils |
Constructors Summary |
---|
public CameraBinderTest()
|
Methods Summary |
---|
protected void | setUp()
super.setUp();
mUtils = new CameraBinderTestUtils(getContext());
| public void | testAddRemoveListeners()
adb shell am instrument \
-e class 'com.android.mediaframeworktest.integration.CameraBinderTest#testAddRemoveListeners' \
-w com.android.mediaframeworktest/.MediaFrameworkIntegrationTestRunner
for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) {
ICameraServiceListener listener = new DummyCameraServiceListener();
assertTrue(
"Listener was removed before added",
mUtils.getCameraService().removeListener(listener) ==
CameraBinderTestUtils.BAD_VALUE);
assertTrue("Listener was not added",
mUtils.getCameraService().addListener(listener) ==
CameraBinderTestUtils.NO_ERROR);
assertTrue(
"Listener was wrongly added again",
mUtils.getCameraService().addListener(listener) ==
CameraBinderTestUtils.ALREADY_EXISTS);
assertTrue(
"Listener was not removed",
mUtils.getCameraService().removeListener(listener) ==
CameraBinderTestUtils.NO_ERROR);
assertTrue(
"Listener was wrongly removed again",
mUtils.getCameraService().removeListener(listener) ==
CameraBinderTestUtils.BAD_VALUE);
}
| public void | testCameraInfo()
for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) {
CameraInfo info = new CameraInfo();
info.info.facing = -1;
info.info.orientation = -1;
assertTrue(
"Camera service returned info for camera " + cameraId,
mUtils.getCameraService().getCameraInfo(cameraId, info) ==
CameraBinderTestUtils.NO_ERROR);
assertTrue("Facing was not set for camera " + cameraId, info.info.facing != -1);
assertTrue("Orientation was not set for camera " + cameraId,
info.info.orientation != -1);
Log.v(TAG, "Camera " + cameraId + " info: facing " + info.info.facing
+ ", orientation " + info.info.orientation);
}
| public void | testConnect()
for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) {
ICameraClient dummyCallbacks = new DummyCameraClient();
String clientPackageName = getContext().getPackageName();
BinderHolder holder = new BinderHolder();
CameraBinderDecorator.newInstance(mUtils.getCameraService())
.connect(dummyCallbacks, cameraId, clientPackageName,
CameraBinderTestUtils.USE_CALLING_UID, holder);
ICamera cameraUser = ICamera.Stub.asInterface(holder.getBinder());
assertNotNull(String.format("Camera %s was null", cameraId), cameraUser);
Log.v(TAG, String.format("Camera %s connected", cameraId));
cameraUser.disconnect();
}
| public void | testConnectDevice()
for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) {
ICameraDeviceCallbacks dummyCallbacks = new DummyCameraDeviceCallbacks();
String clientPackageName = getContext().getPackageName();
BinderHolder holder = new BinderHolder();
CameraBinderDecorator.newInstance(mUtils.getCameraService())
.connectDevice(dummyCallbacks, cameraId,
clientPackageName, CameraBinderTestUtils.USE_CALLING_UID, holder);
ICameraDeviceUser cameraUser = ICameraDeviceUser.Stub.asInterface(holder.getBinder());
assertNotNull(String.format("Camera %s was null", cameraId), cameraUser);
Log.v(TAG, String.format("Camera %s connected", cameraId));
cameraUser.disconnect();
}
| public void | testConnectLegacy()
final int CAMERA_HAL_API_VERSION_1_0 = 0x100;
for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) {
ICamera cameraUser = null;
ICameraClient dummyCallbacks = new DummyCameraClient();
String clientPackageName = getContext().getPackageName();
BinderHolder holder = new BinderHolder();
try {
CameraBinderDecorator.newInstance(mUtils.getCameraService())
.connectLegacy(dummyCallbacks, cameraId, CAMERA_HAL_API_VERSION_1_0,
clientPackageName,
CameraBinderTestUtils.USE_CALLING_UID, holder);
cameraUser = ICamera.Stub.asInterface(holder.getBinder());
assertNotNull(String.format("Camera %s was null", cameraId), cameraUser);
Log.v(TAG, String.format("Camera %s connected as HAL1 legacy device", cameraId));
} catch (RuntimeException e) {
// Not all camera device support openLegacy.
Log.i(TAG, "Unable to open camera as HAL1 legacy camera device " + e);
} finally {
if (cameraUser != null) {
cameraUser.disconnect();
}
}
}
| public void | testConnectPro()
for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) {
IProCameraCallbacks dummyCallbacks = new DummyProCameraCallbacks();
String clientPackageName = getContext().getPackageName();
BinderHolder holder = new BinderHolder();
CameraBinderDecorator.newInstance(mUtils.getCameraService())
.connectPro(dummyCallbacks, cameraId,
clientPackageName, CameraBinderTestUtils.USE_CALLING_UID, holder);
IProCameraUser cameraUser = IProCameraUser.Stub.asInterface(holder.getBinder());
assertNotNull(String.format("Camera %s was null", cameraId), cameraUser);
Log.v(TAG, String.format("Camera %s connected", cameraId));
cameraUser.disconnect();
}
| public void | testGetLegacyParameters()
for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) {
String[] parameters = new String[1];
assertEquals("Camera service returned parameters for camera " + cameraId,
CameraBinderTestUtils.NO_ERROR,
mUtils.getCameraService().getLegacyParameters(cameraId, /*out*/parameters));
assertNotNull(parameters[0]);
assertTrue("Parameters should have at least one character in it",
parameters[0].length() > 0);
int end = parameters[0].length();
if (end > MAX_PARAMETERS_LENGTH) {
end = MAX_PARAMETERS_LENGTH;
}
Log.v(TAG, "Camera " + cameraId + " parameters: " + parameters[0].substring(0, end));
}
| public void | testNumberOfCameras()
int numCameras = mUtils.getCameraService().getNumberOfCameras();
assertTrue("At least this many cameras: " + mUtils.getGuessedNumCameras(),
numCameras >= mUtils.getGuessedNumCameras());
Log.v(TAG, "Number of cameras " + numCameras);
| public void | testSupportsCamera1Api()The camera1 api is supported on *all* devices regardless of HAL version
for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) {
int res = mUtils.getCameraService().supportsCameraApi(cameraId, API_VERSION_1);
assertEquals(
"Camera service returned bad value when queried if it supports camera1 api: "
+ res + " for camera ID " + cameraId, CameraBinderTestUtils.NO_ERROR, res);
}
| public void | testSupportsCamera2Api()The camera2 api is only supported on HAL3.2+ devices
for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) {
int res = mUtils.getCameraService().supportsCameraApi(cameraId, API_VERSION_2);
if (res != CameraBinderTestUtils.NO_ERROR && res != CameraBinderTestUtils.EOPNOTSUPP) {
fail("Camera service returned bad value when queried if it supports camera2 api: "
+ res + " for camera ID " + cameraId);
}
boolean supports = res == CameraBinderTestUtils.NO_ERROR;
Log.v(TAG, "Camera " + cameraId + " supports api2: " + supports);
}
|
|