1#!/usr/bin/env vpython3 2# 3# Copyright 2018 The Chromium Authors 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6 7"""Manually applies a shared preference JSON file. 8 9If needed during automation, use the --shared-prefs-file in test_runner.py 10instead. 11""" 12 13import argparse 14import sys 15 16# pylint: disable=ungrouped-imports 17from pylib.constants import host_paths 18if host_paths.DEVIL_PATH not in sys.path: 19 sys.path.append(host_paths.DEVIL_PATH) 20 21from devil.android import device_utils 22from devil.android.sdk import shared_prefs 23from pylib.utils import shared_preference_utils 24 25 26def main(): 27 parser = argparse.ArgumentParser( 28 description='Manually apply shared preference JSON files.') 29 parser.add_argument('filepaths', nargs='*', 30 help='Any number of paths to shared preference JSON ' 31 'files to apply.') 32 args = parser.parse_args() 33 34 all_devices = device_utils.DeviceUtils.HealthyDevices() 35 if not all_devices: 36 raise RuntimeError('No healthy devices attached') 37 38 for filepath in args.filepaths: 39 all_settings = shared_preference_utils.ExtractSettingsFromJson(filepath) 40 for setting in all_settings: 41 for device in all_devices: 42 shared_pref = shared_prefs.SharedPrefs( 43 device, setting['package'], setting['filename'], 44 use_encrypted_path=setting.get('supports_encrypted_path', False)) 45 shared_preference_utils.ApplySharedPreferenceSetting( 46 shared_pref, setting) 47 48 49if __name__ == '__main__': 50 main() 51