diff options
author | Igor Murashkin <iam@google.com> | 2013-05-31 16:43:48 -0700 |
---|---|---|
committer | Igor Murashkin <iam@google.com> | 2013-06-11 11:36:38 -0700 |
commit | 4491d684f47fcf1e05652f910587a930be8a4135 (patch) | |
tree | 9692bbe442682bf876bad7f2554ddfcc13ae1851 /media/tests | |
parent | 4f057ffa2a9bed82d97c1889dc95d6b2bed8ff8d (diff) | |
download | frameworks_base-4491d684f47fcf1e05652f910587a930be8a4135.zip frameworks_base-4491d684f47fcf1e05652f910587a930be8a4135.tar.gz frameworks_base-4491d684f47fcf1e05652f910587a930be8a4135.tar.bz2 |
camera: Add Java binder proxies for some existing binder interfaces
Note that anything not in the AIDL interfaces, will NOT be magically
compatible if you just add it there. It probably requires a change in
frameworks/av/camera as well.
Bug: 9213377
Change-Id: I91d3efb755ed2e3ace139f83573f86efdccccd06
Diffstat (limited to 'media/tests')
5 files changed, 291 insertions, 2 deletions
diff --git a/media/tests/MediaFrameworkTest/AndroidManifest.xml b/media/tests/MediaFrameworkTest/AndroidManifest.xml index b698705..91ee2c6 100644 --- a/media/tests/MediaFrameworkTest/AndroidManifest.xml +++ b/media/tests/MediaFrameworkTest/AndroidManifest.xml @@ -71,4 +71,9 @@ android:label="Media Power tests InstrumentationRunner"> </instrumentation> + <instrumentation android:name=".MediaFrameworkIntegrationTestRunner" + android:targetPackage="com.android.mediaframeworktest" + android:label="MediaFramework integration tests InstrumentationRunner"> + </instrumentation> + </manifest> diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkIntegrationTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkIntegrationTestRunner.java new file mode 100644 index 0000000..88c5b0c --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkIntegrationTestRunner.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest; + +import android.os.Bundle; +import android.test.InstrumentationTestRunner; +import android.test.InstrumentationTestSuite; + +import com.android.mediaframeworktest.integration.CameraBinderTest; + +import junit.framework.TestSuite; + +/** + * Instrumentation Test Runner for all media framework integration tests. + * + * Running all tests: + * + * adb shell am instrument -w com.android.mediaframeworktest/.MediaFrameworkIntegrationTestRunner + */ + +public class MediaFrameworkIntegrationTestRunner extends InstrumentationTestRunner { + + + @Override + public TestSuite getAllTests() { + TestSuite suite = new InstrumentationTestSuite(this); + suite.addTestSuite(CameraBinderTest.class); + return suite; + } + + @Override + public ClassLoader getLoader() { + return MediaFrameworkIntegrationTestRunner.class.getClassLoader(); + } + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + } +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java index 92ac9eb..cbb6642 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java @@ -50,7 +50,7 @@ import android.test.InstrumentationTestSuite; * Running all tests: * * adb shell am instrument \ - * -w com.android.smstests.MediaPlayerInstrumentationTestRunner + * -w com.android.mediaframeworktest/.MediaFrameworkTestRunner */ public class MediaFrameworkTestRunner extends InstrumentationTestRunner { diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CameraTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CameraTest.java index 2f864d7..7f23ba5 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CameraTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CameraTest.java @@ -36,7 +36,12 @@ import java.io.*; /** * Junit / Instrumentation test case for the camera api - + * + * To run only tests in this class: + * + * adb shell am instrument \ + * -e class com.android.mediaframeworktest.functional.CameraTest \ + * -w com.android.mediaframeworktest/.MediaFrameworkTestRunner */ public class CameraTest extends ActivityInstrumentationTestCase<MediaFrameworkTest> { private String TAG = "CameraTest"; diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java new file mode 100644 index 0000000..ba2859b --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java @@ -0,0 +1,225 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.integration; + +import android.content.Context; +import android.content.pm.FeatureInfo; +import android.content.pm.PackageManager; +import android.hardware.CameraInfo; +import android.hardware.ICamera; +import android.hardware.ICameraClient; +import android.hardware.ICameraService; +import android.hardware.ICameraServiceListener; +import android.hardware.IProCameraCallbacks; +import android.hardware.IProCameraUser; +import android.os.Binder; +import android.os.IBinder; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; +import android.util.Log; + +/** + * 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 + */ +public class CameraBinderTest extends AndroidTestCase { + private static String TAG = "CameraBinderTest"; + + private static final String CAMERA_SERVICE_BINDER_NAME = "media.camera"; + private static final int NO_ERROR = 0; + private static final int ALREADY_EXISTS = -17; + private static final int BAD_VALUE = -22; + + private static final int USE_CALLING_UID = -1; + + private ICameraService mCameraService; + private int mGuessedNumCameras = 0; + + public CameraBinderTest() { + } + + private final static boolean isFeatureAvailable(Context context, String feature) { + final PackageManager packageManager = context.getPackageManager(); + final FeatureInfo[] featuresList = packageManager.getSystemAvailableFeatures(); + for (FeatureInfo f : featuresList) { + if (f.name != null && f.name.equals(feature)) { + return true; + } + } + + return false; + } + + // Guess the lower bound for how many cameras there are + private void guessNumCameras() { + + /** + * Why do we need this? This way we have no dependency on getNumCameras + * actually working. On most systems there are only 0, 1, or 2 cameras, + * and this covers that 'usual case'. On other systems there might be 3+ + * cameras, but this will at least check the first 2. + */ + mGuessedNumCameras = 0; + + // Front facing camera + if (isFeatureAvailable(getContext(), PackageManager.FEATURE_CAMERA_FRONT)) { + mGuessedNumCameras++; + } + + // Back facing camera + if (isFeatureAvailable(getContext(), PackageManager.FEATURE_CAMERA)) { + mGuessedNumCameras++; + } + + // Any facing camera + if (mGuessedNumCameras == 0 + && isFeatureAvailable(getContext(), PackageManager.FEATURE_CAMERA_ANY)) { + mGuessedNumCameras++; + } + + Log.v(TAG, "Guessing there are at least " + mGuessedNumCameras + " cameras"); + } + + protected void setUp() throws Exception { + super.setUp(); + + guessNumCameras(); + + IBinder cameraServiceBinder = ServiceManager.getService(CAMERA_SERVICE_BINDER_NAME); + assertNotNull("Camera service IBinder should not be null", cameraServiceBinder); + + mCameraService = ICameraService.Stub.asInterface(cameraServiceBinder); + assertNotNull("Camera service should not be null", mCameraService); + } + + @SmallTest + public void testNumberOfCameras() throws Exception { + int numCameras = mCameraService.getNumberOfCameras(); + assertTrue("At least this many cameras: " + mGuessedNumCameras, + numCameras >= mGuessedNumCameras); + Log.v(TAG, "Number of cameras " + numCameras); + } + + @SmallTest + public void testCameraInfo() throws Exception { + for (int cameraId = 0; cameraId < mGuessedNumCameras; ++cameraId) { + + CameraInfo info = new CameraInfo(); + info.info.facing = -1; + info.info.orientation = -1; + + assertTrue("Camera service returned info for camera " + cameraId, + mCameraService.getCameraInfo(cameraId, info) == 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); + } + } + + static abstract class DummyBase extends Binder implements android.os.IInterface { + @Override + public IBinder asBinder() { + return this; + } + } + + static class DummyCameraClient extends DummyBase implements ICameraClient { + } + + @SmallTest + public void testConnect() throws Exception { + for (int cameraId = 0; cameraId < mGuessedNumCameras; ++cameraId) { + + ICameraClient dummyCallbacks = new DummyCameraClient(); + + String clientPackageName = getContext().getPackageName(); + + ICamera cameraUser = mCameraService.connect(dummyCallbacks, cameraId, clientPackageName, + USE_CALLING_UID); + assertNotNull(String.format("Camera %s was null", cameraId), cameraUser); + + Log.v(TAG, String.format("Camera %s connected", cameraId)); + + cameraUser.disconnect(); + } + } + + static class DummyProCameraCallbacks extends DummyBase implements IProCameraCallbacks { + } + + @SmallTest + public void testConnectPro() throws Exception { + for (int cameraId = 0; cameraId < mGuessedNumCameras; ++cameraId) { + + IProCameraCallbacks dummyCallbacks = new DummyProCameraCallbacks(); + + String clientPackageName = getContext().getPackageName(); + + IProCameraUser cameraUser = mCameraService.connectPro(dummyCallbacks, cameraId, + clientPackageName, USE_CALLING_UID); + assertNotNull(String.format("Camera %s was null", cameraId), cameraUser); + + Log.v(TAG, String.format("Camera %s connected", cameraId)); + + cameraUser.disconnect(); + } + } + + static class DummyCameraServiceListener extends DummyBase implements ICameraServiceListener { + @Override + public void onStatusChanged(int status, int cameraId) + throws RemoteException { + Log.v(TAG, String.format("Camera %d has status changed to 0x%x", cameraId, status)); + } + } + + /** + * adb shell am instrument \ + * -e class 'com.android.mediaframeworktest.integration.CameraBinderTest#testAddRemoveListeners' \ + * -w com.android.mediaframeworktest/.MediaFrameworkIntegrationTestRunner + */ + @SmallTest + public void testAddRemoveListeners() throws Exception { + for (int cameraId = 0; cameraId < mGuessedNumCameras; ++cameraId) { + + ICameraServiceListener listener = new DummyCameraServiceListener(); + + assertTrue("Listener was removed before added", + mCameraService.removeListener(listener) == BAD_VALUE); + + assertTrue("Listener was not added", mCameraService.addListener(listener) == NO_ERROR); + assertTrue("Listener was wrongly added again", + mCameraService.addListener(listener) == ALREADY_EXISTS); + + assertTrue("Listener was not removed", + mCameraService.removeListener(listener) == NO_ERROR); + assertTrue("Listener was wrongly removed again", + mCameraService.removeListener(listener) == BAD_VALUE); + } + } +} |