Reland "Move some VR Telemetry setup into shared state"

This is a reland of 550f26061a53fd69ada8fafc13170dff06e5e544
Original change's description:
> Move some VR Telemetry setup into shared state
> 
> Moves the VrCore installation and setup out of run_benchmark
> and into the shared state class used by VR benchmarks. Has some
> ugly temporary hacks to make presubmit happy that will be removed
> in a follow-up CL that moves the remaining of setup code out of
> run_benchmark, allowing us to remove the file completely.
> 
> This CL relies on the following Catapult CL being submitted
> beforehand: https://codereview.chromium.org/2995713002/
> 
> Bug: 726906
> Change-Id: Ib5969b1657aa11b9b640ea4f7420ff746991f0c1
> Reviewed-on: https://chromium-review.googlesource.com/608984
> Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
> Reviewed-by: Ned Nguyen <nednguyen@google.com>
> Reviewed-by: John Budorick <jbudorick@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#494603}

Bug: 726906
Change-Id: I2ec5475b0e04023fb50ff8cc3d17bd77a8a07f37
Reviewed-on: https://chromium-review.googlesource.com/617820
Reviewed-by: Ned Nguyen <nednguyen@google.com>
Reviewed-by: Achuith Bhandarkar <achuith@chromium.org>
Reviewed-by: John Budorick <jbudorick@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#495196}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: e95bb966ef5e097fab7a2897e474908ad25712e7
This commit is contained in:
bsheedy 2017-08-17 16:48:54 +00:00 коммит произвёл Commit Bot
Родитель 14d6078a7c
Коммит 8db5262e8d
2 изменённых файлов: 31 добавлений и 31 удалений

Просмотреть файл

@ -17,6 +17,7 @@ from devil.android import crash_handler
from devil.android import device_errors
from devil.android import device_temp_file
from devil.android import flag_changer
from devil.android.sdk import shared_prefs
from devil.android.tools import system_app
from devil.utils import reraiser_thread
from incremental_install import installer
@ -211,8 +212,11 @@ class LocalDeviceInstrumentationTestRun(
@trace_event.traced
def edit_shared_prefs():
shared_preference_utils.ApplySharedPreferenceSettings(
dev, self._test_instance.edit_shared_prefs)
for setting in self._test_instance.edit_shared_prefs:
shared_pref = shared_prefs.SharedPrefs(dev, setting['package'],
setting['filename'])
shared_preference_utils.ApplySharedPreferenceSetting(
shared_pref, setting)
@instrumentation_tracing.no_tracing
def push_test_data():

Просмотреть файл

@ -7,8 +7,6 @@
import json
import logging
from devil.android.sdk import shared_prefs
def ExtractSettingsFromJson(filepath):
"""Extracts the settings data from the given JSON file.
@ -35,12 +33,12 @@ def ExtractSettingsFromJson(filepath):
return unicode_to_str(json.load(prefs_file))
def ApplySharedPreferenceSettings(device, settings):
def ApplySharedPreferenceSetting(shared_pref, setting):
"""Applies the given app settings to the given device.
Modifies an installed app's settings by modifying its shared preference
settings file. Provided settings data must be a list of settings dictionaries,
where dictionaries are in the following format:
settings file. Provided settings data must be a settings dictionary,
which are in the following format:
{
"package": "com.example.package",
"filename": "AppSettingsFile.xml",
@ -61,28 +59,26 @@ def ApplySharedPreferenceSettings(device, settings):
this function are in //chrome/android/shared_preference_files/test/.
Args:
device: The devil DeviceUtils object for the device the settings will be
applied to.
settings: A list of settings dictionaries to apply.
shared_pref: The devil SharedPrefs object for the device the settings will
be applied to.
setting: A settings dictionary to apply.
"""
for pref in settings:
prefs = shared_prefs.SharedPrefs(device, pref['package'], pref['filename'])
prefs.Load()
for key in pref.get('remove', []):
try:
prefs.Remove(key)
except KeyError:
logging.warning("Attempted to remove non-existent key %s", key)
for key, value in pref.get('set', {}).iteritems():
if isinstance(value, bool):
prefs.SetBoolean(key, value)
elif isinstance(value, basestring):
prefs.SetString(key, value)
elif isinstance(value, long) or isinstance(value, int):
prefs.SetLong(key, value)
elif isinstance(value, list):
prefs.SetStringSet(key, value)
else:
raise ValueError("Given invalid value type %s for key %s" % (
str(type(value)), key))
prefs.Commit()
shared_pref.Load()
for key in setting.get('remove', []):
try:
shared_pref.Remove(key)
except KeyError:
logging.warning("Attempted to remove non-existent key %s", key)
for key, value in setting.get('set', {}).iteritems():
if isinstance(value, bool):
shared_pref.SetBoolean(key, value)
elif isinstance(value, basestring):
shared_pref.SetString(key, value)
elif isinstance(value, long) or isinstance(value, int):
shared_pref.SetLong(key, value)
elif isinstance(value, list):
shared_pref.SetStringSet(key, value)
else:
raise ValueError("Given invalid value type %s for key %s" % (
str(type(value)), key))
shared_pref.Commit()