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

Commit 9f7aa446 authored by Dominggoes Isakh's avatar Dominggoes Isakh Committed by Michael Bestas
Browse files

PrivateStorageInfo: Exclude primary physical volume total space

BUGBASH-355

Change-Id: If811545e352d7e499630e11e7583d643e1510431
parent c0f1177c
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.os.storage.VolumeInfo;
import android.util.Log;

import java.io.File;
import java.util.List;
import java.util.Objects;

/**
@@ -36,6 +37,15 @@ public class PrivateStorageInfo {
        this.totalBytes = totalBytes;
    }

    public static long getPrimaryPhysicalTotalSpace(List<VolumeInfo> volumes) {
        for (VolumeInfo vol : volumes) {
            if (vol.isPrimaryPhysical()) {
                return vol.getPath().getTotalSpace();
            }
        }
        return 0;
    }

    public static PrivateStorageInfo getPrivateStorageInfo(StorageVolumeProvider sm) {
        long totalInternalStorage = sm.getPrimaryStorageSize();
        long privateFreeBytes = 0;
@@ -48,6 +58,8 @@ public class PrivateStorageInfo {
            privateTotalBytes += getTotalSize(info, totalInternalStorage);
            privateFreeBytes += path.getFreeSpace();
        }

        privateTotalBytes -= getPrimaryPhysicalTotalSpace(sm.getVolumes());
        return new PrivateStorageInfo(privateFreeBytes, privateTotalBytes);
    }