Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5f0139d2 authored by Jerry Zhang's avatar Jerry Zhang
Browse files

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
parent e537a831
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -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;
        }
    }