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

Commit 4452e751 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Dumps total size of primary storage."

parents a5c859c0 281389ac
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
import android.util.Slog;
import android.util.SparseArray;

@@ -929,22 +930,29 @@ public class StorageManager {
    }

    /** {@hide} */
    public long getPrimaryStorageSize() {
    public static Pair<String, Long> getPrimaryStoragePathAndSize() {
        for (String path : INTERNAL_STORAGE_SIZE_PATHS) {
            final long numberBlocks = readLong(path);
            if (numberBlocks > 0) {
                return numberBlocks * INTERNAL_STORAGE_SECTOR_SIZE;
                return new Pair<>(path, Long.valueOf(numberBlocks * INTERNAL_STORAGE_SECTOR_SIZE));
            }
        }
        return 0;
        return null;
    }


    /** {@hide} */
    public long getPrimaryStorageSize() {
        final Pair<String, Long> pair = getPrimaryStoragePathAndSize();
        return pair == null ? 0 : pair.second.longValue();
    }

    private long readLong(String path) {
    private static long readLong(String path) {
        try (final FileInputStream fis = new FileInputStream(path);
                final BufferedReader reader = new BufferedReader(new InputStreamReader(fis));) {
            return Long.parseLong(reader.readLine());
        } catch (Exception e) {
            Slog.w(TAG, "Could not read " + path, e);
            Slog.w(TAG, "readLong(): could not read " + path + ": " + e);
            return 0;
        }
    }
+14 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.content.pm.ProviderInfo;
import android.content.pm.UserInfo;
import android.content.res.Configuration;
import android.content.res.ObbInfo;
import android.net.TrafficStats;
import android.net.Uri;
import android.os.Binder;
import android.os.DropBoxManager;
@@ -86,6 +87,7 @@ import android.text.format.DateUtils;
import android.util.ArrayMap;
import android.util.AtomicFile;
import android.util.Log;
import android.util.Pair;
import android.util.Slog;
import android.util.TimeUtils;
import android.util.Xml;
@@ -3738,6 +3740,18 @@ class MountService extends IMountService.Stub

            pw.println();
            pw.println("Primary storage UUID: " + mPrimaryStorageUuid);
            final Pair<String, Long> pair = StorageManager.getPrimaryStoragePathAndSize();
            if (pair == null) {
                pw.println("Internal storage total size: N/A");
            } else {
                pw.print("Internal storage (");
                pw.print(pair.first);
                pw.print(") total size: ");
                pw.print(pair.second);
                pw.print(" (");
                pw.print((float) pair.second / TrafficStats.GB_IN_BYTES);
                pw.println(" GB)");
            }
            pw.println("Force adoptable: " + mForceAdoptable);
            pw.println();
            pw.println("Local unlocked users: " + Arrays.toString(mLocalUnlockedUsers));