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
diff --git a/media/java/android/mtp/MtpDatabase.java b/media/java/android/mtp/MtpDatabase.java
index 9847d705..80fd5c0 100755
--- a/media/java/android/mtp/MtpDatabase.java
+++ b/media/java/android/mtp/MtpDatabase.java
@@ -52,6 +52,7 @@
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 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 @@
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;
}
}