diff options
author | Timothy Knight <tknight@google.com> | 2014-07-28 00:23:28 -0700 |
---|---|---|
committer | Timothy Knight <tknight@google.com> | 2014-07-28 00:31:34 -0700 |
commit | f0d20a944b20378a366da6295ba9d1bbbf337473 (patch) | |
tree | 1a29c2cd91f12ba9be36899cf3784b6e61e687f9 /apps | |
parent | 4490e575163270e0ac877916d0a30a5f8f124549 (diff) | |
download | pdk-f0d20a944b20378a366da6295ba9d1bbbf337473.tar.gz |
CameraITS: Added support for multiple cameras.
Scripts can run on the front camera by just appending "camera=1" to the
script command line when executing it. By default, camera=0 is still
used, which is the rear camera.
Change-Id: Ib95fdfc25720957f2801c78692bbb9ee841c5beb
Diffstat (limited to 'apps')
-rw-r--r-- | apps/CameraITS/README | 7 | ||||
-rw-r--r-- | apps/CameraITS/pymodules/its/device.py | 7 | ||||
-rw-r--r-- | apps/CameraITS/service/src/com/android/camera2/its/ItsService.java | 28 |
3 files changed, 31 insertions, 11 deletions
diff --git a/apps/CameraITS/README b/apps/CameraITS/README index c530dc7..0003a36 100644 --- a/apps/CameraITS/README +++ b/apps/CameraITS/README @@ -206,6 +206,13 @@ Each test assumes some sort of target or scene. There are multiple scene<N> folders under the tests directory, and each contains a README file which describes the scene for the scripts in that folder. +By default, camera device id=0 is opened when the script connects to the unit, +however this can be specified by adding a "camera=1" or similar argument to +the script command line. On a typical device, camera=0 is the main (rear) +camera, and camera=1 is the front-facing camera. + + python tests/scene1/test_linearity.py camera=1 + The tools/run_scene_tests.sh script can be executed from inside one of the tests/scene<N> folders, and it will simply run each test script in that folder in turn, reporting whether it passed or failed. The scene should be setup as diff --git a/apps/CameraITS/pymodules/its/device.py b/apps/CameraITS/pymodules/its/device.py index aef493a..b675e48 100644 --- a/apps/CameraITS/pymodules/its/device.py +++ b/apps/CameraITS/pymodules/its/device.py @@ -75,11 +75,16 @@ class ItsSession(object): def __init__(self): reboot_device_on_argv() + # Get the camera ID to open as an argument. + camera_id = 0 + for s in sys.argv[1:]: + if s[:7] == "camera=" and len(s) > 7: + camera_id = int(s[7:]) # TODO: Figure out why "--user 0" is needed, and fix the problem _run('%s logcat -c' % (self.ADB)) _run('%s shell am force-stop --user 0 %s' % (self.ADB, self.PACKAGE)) _run(('%s shell am startservice --user 0 -t text/plain ' - '-a %s') % (self.ADB, self.INTENT_START)) + '-a %s -d "%d"') % (self.ADB, self.INTENT_START, camera_id)) self._wait_until_socket_ready() _run('%s forward tcp:%d tcp:%d' % (self.ADB,self.PORT,self.PORT)) self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) diff --git a/apps/CameraITS/service/src/com/android/camera2/its/ItsService.java b/apps/CameraITS/service/src/com/android/camera2/its/ItsService.java index d812675..8716c1d 100644 --- a/apps/CameraITS/service/src/com/android/camera2/its/ItsService.java +++ b/apps/CameraITS/service/src/com/android/camera2/its/ItsService.java @@ -174,6 +174,10 @@ public class ItsService extends Service implements SensorEventListener { @Override public void onCreate() { + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { try { // Get handle to camera manager. mCameraManager = (CameraManager) this.getSystemService(Context.CAMERA_SERVICE); @@ -194,15 +198,23 @@ public class ItsService extends Service implements SensorEventListener { throw new ItsException("Failed to get device ID list", e); } + // Args are a string, which is just the camera ID to open. + int cameraId = 0; + String args = intent.getDataString(); + if (args != null) { + Log.i(TAG, String.format("Received intent args: %s", args)); + cameraId = Integer.parseInt(args); + } + Log.i(TAG, String.format("Opening camera %d", cameraId)); + mCameraThread = new HandlerThread("ItsCameraThread"); try { mCameraThread.start(); Handler cameraHandler = new Handler(mCameraThread.getLooper()); - - // TODO: Add support for specifying which device to open. - mCamera = mBlockingCameraManager.openCamera(devices[0], mCameraListener, - cameraHandler); - mCameraCharacteristics = mCameraManager.getCameraCharacteristics(devices[0]); + mCamera = mBlockingCameraManager.openCamera(devices[cameraId], + mCameraListener, cameraHandler); + mCameraCharacteristics = mCameraManager.getCameraCharacteristics( + devices[cameraId]); } catch (CameraAccessException e) { throw new ItsException("Failed to open camera", e); } catch (BlockingOpenException e) { @@ -241,6 +253,7 @@ public class ItsService extends Service implements SensorEventListener { } catch (ItsException e) { Log.e(TAG, "Service failed to start: ", e); } + return START_STICKY; } @Override @@ -267,11 +280,6 @@ public class ItsService extends Service implements SensorEventListener { } } - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - return START_STICKY; - } - class SocketWriteRunnable implements Runnable { // Use a separate thread to service a queue of objects to be written to the socket, |