summaryrefslogtreecommitdiff
path: root/media/java/android/mtp/MtpDatabase.java
diff options
context:
space:
mode:
authorJerry Zhang <zhangjerry@google.com>2017-08-22 17:42:54 -0700
committerJerry Zhang <zhangjerry@google.com>2017-08-23 11:10:51 -0700
commit5f0139d2e8bc8b5819e2c5ef4440f766a4af8813 (patch)
treee8f4577c028875f6ed03b722cbe5b4948a7cab03 /media/java/android/mtp/MtpDatabase.java
parente537a8313987bd10208281c4fa5c6834b4fd1d15 (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-xmedia/java/android/mtp/MtpDatabase.java8
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;
}
}