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

Commit a83bf196 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Use best volume description for MTP.

Otherwise we end up showing adopted storage devices as "Unknown."

Bug: 20275423
Change-Id: Ib42474fd5b3284b1e8eca7de8a4cfbb71a34a107
parent 5af1835d
Loading
Loading
Loading
Loading
+15 −10
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.annotation.Nullable;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.mtp.MtpStorage;
import android.net.Uri;
import android.os.Environment;
import android.os.Parcel;
@@ -300,6 +299,8 @@ public class VolumeInfo implements Parcelable {
    }

    public StorageVolume buildStorageVolume(Context context, int userId) {
        final StorageManager storage = context.getSystemService(StorageManager.class);

        final boolean removable;
        final boolean emulated;
        final boolean allowMassStorage = false;
@@ -310,14 +311,7 @@ public class VolumeInfo implements Parcelable {
            userPath = new File("/dev/null");
        }

        String description = getDescription();
        if (description == null) {
            description = getFsUuid();
        }
        if (description == null) {
            description = context.getString(android.R.string.unknownName);
        }

        String description = null;
        long mtpReserveSize = 0;
        long maxFileSize = 0;
        int mtpStorageId = StorageVolume.STORAGE_ID_INVALID;
@@ -325,11 +319,16 @@ public class VolumeInfo implements Parcelable {
        if (type == TYPE_EMULATED) {
            emulated = true;

            final VolumeInfo privateVol = storage.findPrivateForEmulated(this);
            if (privateVol != null) {
                description = storage.getBestVolumeDescription(privateVol);
            }

            if (isPrimary()) {
                mtpStorageId = StorageVolume.STORAGE_ID_PRIMARY;
            }

            mtpReserveSize = StorageManager.from(context).getStorageLowBytes(userPath);
            mtpReserveSize = storage.getStorageLowBytes(userPath);

            if (ID_EMULATED_INTERNAL.equals(id)) {
                removable = false;
@@ -341,6 +340,8 @@ public class VolumeInfo implements Parcelable {
            emulated = false;
            removable = true;

            description = storage.getBestVolumeDescription(this);

            if (isPrimary()) {
                mtpStorageId = StorageVolume.STORAGE_ID_PRIMARY;
            } else {
@@ -357,6 +358,10 @@ public class VolumeInfo implements Parcelable {
            throw new IllegalStateException("Unexpected volume type " + type);
        }

        if (description == null) {
            description = context.getString(android.R.string.unknownName);
        }

        return new StorageVolume(id, mtpStorageId, userPath, description, isPrimary(), removable,
                emulated, mtpReserveSize, allowMassStorage, maxFileSize, new UserHandle(userId),
                fsUuid, envState);