diff options
author | Jerry Zhang <zhangjerry@google.com> | 2017-08-22 17:42:54 -0700 |
---|---|---|
committer | Jerry Zhang <zhangjerry@google.com> | 2017-08-23 11:10:51 -0700 |
commit | 5f0139d2e8bc8b5819e2c5ef4440f766a4af8813 (patch) | |
tree | e8f4577c028875f6ed03b722cbe5b4948a7cab03 /media/java/android/mtp/MtpDatabase.java | |
parent | e537a8313987bd10208281c4fa5c6834b4fd1d15 (diff) |
Add additional context to MtpDatabase
MtpService has been changed to a singleton service
running in user 0, so the original context will
be that of user 0. Accesses to MediaProvider and
MediaScanner should use the new passed in user context
in order to access user data, while the broadcast
receiver for battery data will use the original context.
Bug: 64822515
Test: Use Mtp and switch users.
Change-Id: Ic181258337944db7dc6f6097c967cb104df938d3
Diffstat (limited to 'media/java/android/mtp/MtpDatabase.java')
-rwxr-xr-x | media/java/android/mtp/MtpDatabase.java | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/media/java/android/mtp/MtpDatabase.java b/media/java/android/mtp/MtpDatabase.java index 9847d705adcf..80fd5c03b929 100755 --- a/media/java/android/mtp/MtpDatabase.java +++ b/media/java/android/mtp/MtpDatabase.java @@ -52,6 +52,7 @@ import java.util.concurrent.atomic.AtomicBoolean; public class MtpDatabase implements AutoCloseable { private static final String TAG = "MtpDatabase"; + private final Context mUserContext; private final Context mContext; private final String mPackageName; private final ContentProviderClient mMediaProvider; @@ -159,13 +160,14 @@ public class MtpDatabase implements AutoCloseable { } }; - public MtpDatabase(Context context, String volumeName, String storagePath, + public MtpDatabase(Context context, Context userContext, String volumeName, String storagePath, String[] subDirectories) { native_setup(); mContext = context; + mUserContext = userContext; mPackageName = context.getPackageName(); - mMediaProvider = context.getContentResolver() + mMediaProvider = userContext.getContentResolver() .acquireContentProviderClient(MediaStore.AUTHORITY); mVolumeName = volumeName; mMediaStoragePath = storagePath; @@ -1114,7 +1116,7 @@ public class MtpDatabase implements AutoCloseable { private void sessionEnded() { if (mDatabaseModified) { - mContext.sendBroadcast(new Intent(MediaStore.ACTION_MTP_SESSION_END)); + mUserContext.sendBroadcast(new Intent(MediaStore.ACTION_MTP_SESSION_END)); mDatabaseModified = false; } } |