mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-10-30 06:34:13 +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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user