From e98b653b3e53f398c26f86becaa6297bb359d471 Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Thu, 11 May 2017 13:47:36 +0100 Subject: [PATCH] AndroidDevice: Add `refresh_device_files` method Adds a method to determine the appropriate method of triggering a media refresh of a given list of file based on the devices android version and root status. If a device is running android marshmallow and below or has root, trigger a refresh of the files containing folder otherwise trigger a refresh of each individual file. --- wlauto/common/android/device.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/wlauto/common/android/device.py b/wlauto/common/android/device.py index 0687c01b..452dd1f8 100644 --- a/wlauto/common/android/device.py +++ b/wlauto/common/android/device.py @@ -30,7 +30,7 @@ from wlauto.common.resources import Executable from wlauto.core.resource import NO_ONE from wlauto.common.linux.device import BaseLinuxDevice, PsEntry from wlauto.exceptions import DeviceError, WorkerThreadError, TimeoutError, DeviceNotRespondingError -from wlauto.utils.misc import convert_new_lines, ABI_MAP +from wlauto.utils.misc import convert_new_lines, ABI_MAP, commonprefix from wlauto.utils.types import boolean, regex from wlauto.utils.android import (adb_shell, adb_background_shell, adb_list_devices, adb_command, AndroidProperties, ANDROID_VERSION_MAP) @@ -716,6 +716,19 @@ class AndroidDevice(BaseLinuxDevice): # pylint: disable=W0223 except KeyError: return None + def refresh_device_files(self, file_list): + """ + Depending on the devices android version and root status, determine the + appropriate method of forcing a re-index of the mediaserver cache for a given + list of files. + """ + if self.device.is_rooted or self.device.get_sdk_version() < 24: # MM and below + common_path = commonprefix(file_list, sep=self.device.path.sep) + self.broadcast_media_mounted(common_path, self.device.is_rooted) + else: + for f in file_list: + self.broadcast_media_scan_file(f) + def broadcast_media_scan_file(self, filepath): """ Force a re-index of the mediaserver cache for the specified file.