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

Commit 01788562 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

MTP: Fix copying files to root of storage using parent handle = 0



Change-Id: Ie732c5778e9424512b2ddecd87779f8c55668deb
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent 3e13c1b7
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ public class MtpDatabase {
    private final IContentProvider mMediaProvider;
    private final String mVolumeName;
    private final Uri mObjectsUri;
    private final String mMediaStoragePath;

    // true if the database has been modified in the current MTP session
    private boolean mDatabaseModified;
@@ -84,12 +85,13 @@ public class MtpDatabase {
        System.loadLibrary("media_jni");
    }

    public MtpDatabase(Context context, String volumeName) {
    public MtpDatabase(Context context, String volumeName, String storagePath) {
        native_setup();

        mContext = context;
        mMediaProvider = context.getContentResolver().acquireProvider("media");
        mVolumeName = volumeName;
        mMediaStoragePath = storagePath;
        mObjectsUri = Files.getMtpObjectsUri(volumeName);
        mMediaScanner = new MediaScanner(context);
        openDevicePropertiesDatabase(context);
@@ -701,6 +703,13 @@ public class MtpDatabase {

    private int getObjectFilePath(int handle, char[] outFilePath, long[] outFileLength) {
        Log.d(TAG, "getObjectFilePath: " + handle);
        if (handle == 0) {
            // special case root directory
            mMediaStoragePath.getChars(0, mMediaStoragePath.length(), outFilePath, 0);
            outFilePath[mMediaStoragePath.length()] = 0;
            outFileLength[0] = 0;
            return MtpConstants.RESPONSE_OK;
        }
        Cursor c = null;
        try {
            c = mMediaProvider.query(mObjectsUri, PATH_SIZE_PROJECTION,