From c0a896642d58edc7882954d9db15176642bcae82 Mon Sep 17 00:00:00 2001
From: Sergei Trofimov <sergei.trofimov@arm.com>
Date: Tue, 21 Nov 2017 13:25:45 +0000
Subject: [PATCH] target: fix broadcast_media_mounted for Android O

In an effort to reduce thrashing, "implicit" broadcasts are no longer
allowed in Android O. See:

https://issuetracker.google.com/issues/36496703#comment7

This impacts MEDIA_MOUNTED broadcasts. To get around this issue,
explicitly specify the component the broadcast is targeted at.
---
 devlib/target.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/devlib/target.py b/devlib/target.py
index 9e7ad0d..48f7b1b 100644
--- a/devlib/target.py
+++ b/devlib/target.py
@@ -1238,8 +1238,9 @@ class AndroidTarget(Target):
         """
         Force a re-index of the mediaserver cache for the specified directory.
         """
-        command = 'am broadcast -a  android.intent.action.MEDIA_MOUNTED -d file://'
-        self.execute(command + dirpath, as_root=as_root)
+        command = 'am broadcast -a  android.intent.action.MEDIA_MOUNTED -d file://{} '\
+                  '-n com.android.providers.media/.MediaScannerReceiver'
+        self.execute(command.format(dirpath), as_root=as_root)
 
     def install_executable(self, filepath, with_name=None):
         self._ensure_executables_directory_is_writable()