mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-02-20 11:58:55 +00:00
cameracapture & camerarecord: Updated workloads to work with Android M+
The stock camera app as of Android M has changed. This commit updates the ui automation to work with this new app. As part of this change it was required to bump the API level of the ui automation to 18. Also made the teardown of the capture workload close the app like the record workload.
This commit is contained in:
parent
46cd26e774
commit
5a1c8c7a7e
@ -111,7 +111,6 @@ def list_of_numbers(value):
|
||||
"""
|
||||
Value must be iterable. All elements will be converted to numbers (either ``ints`` or
|
||||
``float``\ s depending on the elements).
|
||||
|
||||
"""
|
||||
if not isiterable(value):
|
||||
raise ValueError(value)
|
||||
@ -300,3 +299,32 @@ class arguments(list):
|
||||
def __str__(self):
|
||||
return ' '.join(self)
|
||||
|
||||
|
||||
class range_dict(dict):
|
||||
"""
|
||||
This dict allows you to specify mappings with a range.
|
||||
|
||||
If a key is not in the dict it will search downward until
|
||||
the next key and return its value. E.g:
|
||||
|
||||
If:
|
||||
a[5] = "Hello"
|
||||
a[10] = "There"
|
||||
|
||||
Then:
|
||||
a[2] == None
|
||||
a[7] == "Hello"
|
||||
a[999] == "There"
|
||||
|
||||
"""
|
||||
def __getitem__(self, i):
|
||||
key = int(i)
|
||||
while key not in self and key > 0:
|
||||
key -= 1
|
||||
if key <= 0:
|
||||
raise KeyError(i)
|
||||
return dict.__getitem__(self, key)
|
||||
|
||||
def __setitem__(self, i, v):
|
||||
i = int(i)
|
||||
super(range_dict, self).__setitem__(i, v)
|
||||
|
@ -16,6 +16,7 @@
|
||||
# pylint: disable=E1101
|
||||
|
||||
from wlauto import UiAutomatorWorkload, Parameter
|
||||
from wlauto.utils.types import range_dict
|
||||
|
||||
|
||||
class Cameracapture(UiAutomatorWorkload):
|
||||
@ -28,6 +29,10 @@ class Cameracapture(UiAutomatorWorkload):
|
||||
package = 'com.google.android.gallery3d'
|
||||
activity = 'com.android.camera.CameraActivity'
|
||||
|
||||
api_packages = range_dict()
|
||||
api_packages[1] = 'com.google.android.gallery3d'
|
||||
api_packages[23] = 'com.google.android.GoogleCamera'
|
||||
|
||||
parameters = [
|
||||
Parameter('no_of_captures', kind=int, default=5,
|
||||
description='Number of photos to be taken.'),
|
||||
@ -40,12 +45,18 @@ class Cameracapture(UiAutomatorWorkload):
|
||||
self.uiauto_params['no_of_captures'] = self.no_of_captures
|
||||
self.uiauto_params['time_between_captures'] = self.time_between_captures
|
||||
|
||||
def initialize(self, context):
|
||||
api = self.device.get_sdk_version()
|
||||
self.uiauto_params['api_level'] = api
|
||||
self.package = self.api_packages[api]
|
||||
version = self.device.get_installed_package_version(self.package)
|
||||
version = version.replace(' ', '_')
|
||||
self.uiauto_params['version'] = version
|
||||
|
||||
def setup(self, context):
|
||||
super(Cameracapture, self).setup(context)
|
||||
self.device.execute('am start -n {}/{}'.format(self.package, self.activity))
|
||||
|
||||
def update_result(self, context):
|
||||
pass
|
||||
|
||||
def teardown(self, context):
|
||||
self.device.execute('am force-stop {}'.format(self.package))
|
||||
super(Cameracapture, self).teardown(context)
|
||||
|
Binary file not shown.
@ -11,4 +11,4 @@
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
# Project target.
|
||||
target=android-17
|
||||
target=android-18
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
package com.arm.wlauto.uiauto.cameracapture;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
@ -32,37 +34,98 @@ import com.arm.wlauto.uiauto.BaseUiAutomation;
|
||||
public class UiAutomation extends BaseUiAutomation {
|
||||
|
||||
public static String TAG = "cameracapture";
|
||||
int timeDurationBetweenEachCapture = 0;
|
||||
int sleepTime = 2;
|
||||
int iterations = 0;
|
||||
int api = 0;
|
||||
Integer[] version = {0,0,0};
|
||||
|
||||
public void runUiAutomation() throws Exception {
|
||||
int timeDurationBetweenEachCapture = 0;
|
||||
int sleepTime = 2;
|
||||
Bundle parameters = getParams();
|
||||
String noOfCaptures = "";
|
||||
int iterations = 0;
|
||||
Bundle parameters = getParams();
|
||||
if (parameters.size() > 0) {
|
||||
iterations = Integer.parseInt(parameters
|
||||
.getString("no_of_captures"));
|
||||
timeDurationBetweenEachCapture = Integer.parseInt(parameters
|
||||
.getString("time_between_captures"));
|
||||
api = Integer.parseInt(parameters.getString("api_level"));
|
||||
String versionString = parameters.getString("version");
|
||||
version = splitVersion(versionString);
|
||||
}
|
||||
|
||||
// Pre Android M UI
|
||||
if(api < 23)
|
||||
takePhotosAosp();
|
||||
else
|
||||
{
|
||||
if(compareVersions(version, new Integer[]{3,2,0}) >= 0)
|
||||
takePhotosGoogleV3_2();
|
||||
else
|
||||
takePhotosGoogle();
|
||||
}
|
||||
}
|
||||
|
||||
if (parameters.size() > 0) {
|
||||
iterations = Integer.parseInt(parameters
|
||||
.getString("no_of_captures"));
|
||||
timeDurationBetweenEachCapture = Integer.parseInt(parameters
|
||||
.getString("time_between_captures"));
|
||||
}
|
||||
// switch to camera capture mode
|
||||
UiObject clickModes = new UiObject(new UiSelector().descriptionMatches("Camera, video or panorama selector"));
|
||||
clickModes.click();
|
||||
sleep(sleepTime);
|
||||
private void takePhotosAosp() throws Exception
|
||||
{
|
||||
// switch to camera capture mode
|
||||
UiObject clickModes = new UiObject(new UiSelector().descriptionMatches("Camera, video or panorama selector"));
|
||||
clickModes.click();
|
||||
sleep(sleepTime);
|
||||
|
||||
UiObject changeModeToCapture = new UiObject(new UiSelector().descriptionMatches("Switch to photo"));
|
||||
UiObject changeModeToCapture = new UiObject(new UiSelector().descriptionMatches("Switch to photo"));
|
||||
|
||||
changeModeToCapture.click();
|
||||
sleep(sleepTime);
|
||||
changeModeToCapture.click();
|
||||
sleep(sleepTime);
|
||||
|
||||
// click to capture photos
|
||||
UiObject clickCaptureButton = new UiObject(new UiSelector().descriptionMatches("Shutter button"));
|
||||
// click to capture photos
|
||||
UiObject clickCaptureButton = new UiObject(new UiSelector().descriptionMatches("Shutter button"));
|
||||
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
clickCaptureButton.longClick();
|
||||
sleep(timeDurationBetweenEachCapture);
|
||||
}
|
||||
getUiDevice().pressBack();
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
clickCaptureButton.longClick();
|
||||
sleep(timeDurationBetweenEachCapture);
|
||||
}
|
||||
getUiDevice().pressBack();
|
||||
}
|
||||
|
||||
private void takePhotosGoogleV3_2() throws Exception
|
||||
{
|
||||
// clear tutorial if needed
|
||||
UiObject tutorialText = new UiObject(new UiSelector().resourceId("com.android.camera2:id/photoVideoSwipeTutorialText"));
|
||||
if (tutorialText.waitForExists(TimeUnit.SECONDS.toMillis(5))) {
|
||||
tutorialText.swipeLeft(5);
|
||||
sleep(sleepTime);
|
||||
tutorialText.swipeRight(5);
|
||||
}
|
||||
|
||||
// ensure we are in photo mode
|
||||
UiObject viewFinder = new UiObject(new UiSelector().resourceId("com.android.camera2:id/viewfinder_frame"));
|
||||
viewFinder.swipeRight(5);
|
||||
|
||||
// click to capture photos
|
||||
UiObject clickCaptureButton = new UiObject(new UiSelector().resourceId("com.android.camera2:id/photo_video_button"));
|
||||
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
clickCaptureButton.longClick();
|
||||
sleep(timeDurationBetweenEachCapture);
|
||||
}
|
||||
}
|
||||
|
||||
private void takePhotosGoogle() throws Exception
|
||||
{
|
||||
// open mode select menu
|
||||
UiObject swipeScreen = new UiObject(new UiSelector().resourceId("com.android.camera2:id/mode_options_overlay"));
|
||||
swipeScreen.swipeRight(5);
|
||||
|
||||
// switch to video mode
|
||||
UiObject changeModeToCapture = new UiObject(new UiSelector().descriptionMatches("Switch to Camera Mode"));
|
||||
changeModeToCapture.click();
|
||||
sleep(sleepTime);
|
||||
|
||||
// click to capture photos
|
||||
UiObject clickCaptureButton = new UiObject(new UiSelector().descriptionMatches("Shutter"));
|
||||
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
clickCaptureButton.longClick();
|
||||
sleep(timeDurationBetweenEachCapture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
#
|
||||
|
||||
from wlauto import UiAutomatorWorkload, Parameter
|
||||
from wlauto.utils.types import range_dict
|
||||
|
||||
|
||||
class Camerarecord(UiAutomatorWorkload):
|
||||
@ -28,6 +29,10 @@ class Camerarecord(UiAutomatorWorkload):
|
||||
activity = 'com.android.camera.CameraActivity'
|
||||
run_timeout = 0
|
||||
|
||||
api_packages = range_dict()
|
||||
api_packages[1] = 'com.google.android.gallery3d'
|
||||
api_packages[23] = 'com.google.android.GoogleCamera'
|
||||
|
||||
parameters = [
|
||||
Parameter('recording_time', kind=int, default=60,
|
||||
description='The video recording time in seconds.'),
|
||||
@ -36,8 +41,17 @@ class Camerarecord(UiAutomatorWorkload):
|
||||
def __init__(self, device, **kwargs):
|
||||
super(Camerarecord, self).__init__(device)
|
||||
self.uiauto_params['recording_time'] = self.recording_time # pylint: disable=E1101
|
||||
self.uiauto_params['version'] = "button"
|
||||
self.run_timeout = 3 * self.uiauto_params['recording_time']
|
||||
|
||||
def initialize(self, context):
|
||||
api = self.device.get_sdk_version()
|
||||
self.uiauto_params['api_level'] = api
|
||||
self.package = self.api_packages[api]
|
||||
version = self.device.get_installed_package_version(self.package)
|
||||
version = version.replace(' ', '_')
|
||||
self.uiauto_params['version'] = version
|
||||
|
||||
def setup(self, context):
|
||||
super(Camerarecord, self).setup(context)
|
||||
self.device.execute('am start -n {}/{}'.format(self.package, self.activity))
|
||||
|
Binary file not shown.
@ -11,4 +11,4 @@
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
# Project target.
|
||||
target=android-17
|
||||
target=android-18
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
package com.arm.wlauto.uiauto.camerarecord;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
@ -32,18 +34,36 @@ import com.arm.wlauto.uiauto.BaseUiAutomation;
|
||||
public class UiAutomation extends BaseUiAutomation {
|
||||
|
||||
public static String TAG = "camerarecord";
|
||||
int timeToRecord = 0;
|
||||
int timeout = 4;
|
||||
int sleepTime = 2;
|
||||
int recordingTime = 0;
|
||||
int api = 0;
|
||||
Integer[] version = {0,0,0};
|
||||
|
||||
public void runUiAutomation() throws Exception {
|
||||
Bundle parameters = getParams();
|
||||
int timeToRecord = 0;
|
||||
int timeout = 4;
|
||||
int sleepTime = 2;
|
||||
int recordingTime = 0;
|
||||
if (parameters.size() > 0) {
|
||||
recordingTime = Integer.parseInt(parameters
|
||||
.getString("recording_time"));
|
||||
api = Integer.parseInt(parameters.getString("api_level"));
|
||||
String versionString = parameters.getString("version");
|
||||
version = splitVersion(versionString);
|
||||
}
|
||||
|
||||
//Pre Android M UI
|
||||
if (api < 23)
|
||||
recordVideoAosp();
|
||||
else
|
||||
{
|
||||
if(compareVersions(version, new Integer[]{3,2,0}) >= 0)
|
||||
recordVideoGoogleV3_2();
|
||||
else
|
||||
recordVideoGoogle();
|
||||
}
|
||||
}
|
||||
|
||||
void recordVideoAosp() throws Exception {
|
||||
// switch to camera capture mode
|
||||
UiObject clickModes = new UiObject(new UiSelector().descriptionMatches("Camera, video or panorama selector"));
|
||||
clickModes.click();
|
||||
@ -62,4 +82,44 @@ public class UiAutomation extends BaseUiAutomation {
|
||||
getUiDevice().pressBack();
|
||||
}
|
||||
|
||||
void recordVideoGoogleV3_2() throws Exception {
|
||||
// clear tutorial if needed
|
||||
UiObject tutorialText = new UiObject(new UiSelector().resourceId("com.android.camera2:id/photoVideoSwipeTutorialText"));
|
||||
if (tutorialText.waitForExists(TimeUnit.SECONDS.toMillis(5))) {
|
||||
tutorialText.swipeLeft(5);
|
||||
sleep(sleepTime);
|
||||
tutorialText.swipeRight(5);
|
||||
}
|
||||
|
||||
// ensure we are in video mode
|
||||
UiObject viewFinder = new UiObject(new UiSelector().resourceId("com.android.camera2:id/viewfinder_frame"));
|
||||
viewFinder.swipeLeft(5);
|
||||
|
||||
// click to capture photos
|
||||
UiObject clickCaptureButton = new UiObject(new UiSelector().resourceId("com.android.camera2:id/photo_video_button"));
|
||||
clickCaptureButton.longClick();
|
||||
sleep(recordingTime);
|
||||
|
||||
// stop video recording
|
||||
clickCaptureButton.longClick();
|
||||
}
|
||||
|
||||
void recordVideoGoogle() throws Exception {
|
||||
// Open mode select menu
|
||||
UiObject swipeScreen = new UiObject(new UiSelector().resourceId("com.android.camera2:id/mode_options_overlay"));
|
||||
swipeScreen.swipeRight(5);
|
||||
|
||||
// Switch to video mode
|
||||
UiObject changeModeToCapture = new UiObject(new UiSelector().descriptionMatches("Switch to Video Camera"));
|
||||
changeModeToCapture.click();
|
||||
sleep(sleepTime);
|
||||
|
||||
UiObject clickRecordingButton = new UiObject(new UiSelector().descriptionMatches("Shutter"));
|
||||
clickRecordingButton.longClick();
|
||||
sleep(recordingTime);
|
||||
|
||||
// Stop video recording
|
||||
clickRecordingButton.longClick();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user