Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions wa/framework/workload.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import os
import time

from distutils.version import LooseVersion

from devlib.utils.android import ApkInfo

from wa.framework.plugin import TargetedPlugin, Parameter
Expand Down Expand Up @@ -172,10 +174,15 @@ class ApkWorkload(Workload):

# May be optionally overwritten by subclasses
# Times are in seconds
# activity_name: This is the initial activity of the app. This will be used
# to launch the app during the setup. Many applications do
# not need to specify a launch activity.
loading_time = 10
package_names = []
activity_name = None
view = None
clear_data_on_reset = True
max_apk_version = None

# Set this to True to mark that this workload requires the target apk to be run
# for initialisation purposes before the main run is performed.
Expand Down Expand Up @@ -252,14 +259,16 @@ def __init__(self, target, **kwargs):
self.apk = PackageHandler(self,
package_name=self.package_name,
variant=self.variant,
activity_name=self.activity_name,
strict=self.strict,
version=self.version,
force_install=self.force_install,
install_timeout=self.install_timeout,
uninstall=self.uninstall,
exact_abi=self.exact_abi,
prefer_host_package=self.prefer_host_package,
clear_data_on_reset=self.clear_data_on_reset)
clear_data_on_reset=self.clear_data_on_reset,
max_apk_version=self.max_apk_version)

@once_per_instance
def initialize(self, context):
Expand Down Expand Up @@ -637,27 +646,32 @@ def package(self):

@property
def activity(self):
if self.activity_name is not None:
return self.activity_name
if self.apk_info is None:
return None
return self.apk_info.activity

def __init__(self, owner, install_timeout=300, version=None, variant=None,
package_name=None, strict=False, force_install=False, uninstall=False,
exact_abi=False, prefer_host_package=True, clear_data_on_reset=True):
package_name=None, activity_name=False, strict=False, force_install=False,
uninstall=False, exact_abi=False, prefer_host_package=True, clear_data_on_reset=True,
max_apk_version=None):
self.logger = logging.getLogger('apk')
self.owner = owner
self.target = self.owner.target
self.install_timeout = install_timeout
self.version = version
self.variant = variant
self.package_name = package_name
self.activity_name = activity_name
self.strict = strict
self.force_install = force_install
self.uninstall = uninstall
self.exact_abi = exact_abi
self.prefer_host_package = prefer_host_package
self.clear_data_on_reset = clear_data_on_reset
self.supported_abi = self.target.supported_abi
self.max_apk_version = max_apk_version
self.apk_file = None
self.apk_info = None
self.apk_version = None
Expand All @@ -670,6 +684,8 @@ def initialize(self, context):
def setup(self, context):
context.update_metadata('app_version', self.apk_info.version_name)
self.initialize_package(context)
if self.prefer_host_package:
self.check_apk_version()
self.start_activity()
self.target.execute('am kill-all') # kill all *background* activities
self.target.clear_logcat()
Expand Down Expand Up @@ -787,18 +803,20 @@ def initialize_package(self, context):
self.install_apk(context)
else:
self.reset(context)
if self.apk_info.permissions:
self.logger.debug('Granting runtime permissions')
for permission in self.apk_info.permissions:
self.target.grant_package_permission(self.apk_info.package, permission)
self.apk_version = host_version

def check_apk_version(self):
if self.max_apk_version is not None:
if LooseVersion(self.apk_version) > LooseVersion(self.max_apk_version):
msg = "APK version not supported. Maximum version supported: {}".format(self.max_apk_version)
raise WorkloadError(msg)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the correct place to be doing this check as this would cause the workload to fail unnecessarily late in the execution and will not deal with multiple versions of the apk being available correctly. Both in the case of there being multiple apks available on the host system, which could result in an incorrect apk being selected during initialization only to fail here in setup and in the event of a pre-installed version on the target when prefer_host_package is False.

I would suggest instead that the maximum version is passed as an extra parameter during the initialization of the ApkFile object and used when matching for an apk on the host system in resolve_package_from_host and the installed version on the target will also need to be checked in resolve_package_from_target with the appropriate error message added to the resolve_package method of workload.

def start_activity(self):
if not self.apk_info.activity:
if not self.activity:
cmd = 'am start -W {}'.format(self.apk_info.package)
else:
cmd = 'am start -W -n {}/{}'.format(self.apk_info.package,
self.apk_info.activity)
self.activity)
output = self.target.execute(cmd)
if 'Error:' in output:
# this will dismiss any error dialogs
Expand Down
44 changes: 44 additions & 0 deletions wa/workloads/facebook/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2013-2015 ARM Limited
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message references the wrong issue, it should be #704

#
# 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.
#


import os
import sys

from wa import ApkUiautoWorkload


class Facebook(ApkUiautoWorkload):

name = 'facebook'
description = """
Uses com.facebook.patana apk for facebook workload.
This workload does the following activities in facebook
Login to facebook account.
Send a message.
Check latest notification.
Search particular user account and visit his/her facebook account.
Find friends.
Update the facebook status
.. note:: This workload starts disableUpdate workload as a part of setup to
disable online updates, which helps to tackle problem of uncertain
behavier during facebook workload run.]
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This workload require an internet connection so the workload attribute requires_network should be set to True to allow the workload to fail quicker if no network is detected.

package_names = ['com.facebook.katana']
activity_name = '.LoginActivity'
max_apk_version = '3.4'
Binary file not shown.
35 changes: 35 additions & 0 deletions wa/workloads/facebook/uiauto/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apply plugin: 'com.android.application'

def packageName = "com.arm.wa.uiauto.facebook"

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "${packageName}"
minSdkVersion 18
targetSdkVersion 25
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = file("$project.buildDir/apk/${packageName}.apk")
}
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support.test:runner:0.5'
compile 'com.android.support.test:rules:0.5'
compile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
compile(name: 'uiauto', ext:'aar')
}

repositories {
flatDir {
dirs 'libs'
}
}
13 changes: 13 additions & 0 deletions wa/workloads/facebook/uiauto/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.arm.wa.uiauto.facebook"
android:versionCode="1"
android:versionName="1.0">


<instrumentation
android:name="android.support.test.runner.AndroidJUnitRunner"
android:targetPackage="${applicationId}"/>

</manifest>

Loading