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

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

Iteration on multi-user Storage UI.

Now that DefaultContainerService has visibility of external storage
for all users, we can measure internal storage in a single pass.
Internal storage measurement now iterates across all known users,
counting both apps and emulated storage usage.

Create MeasurementDetails object with documentation about what is
counted under various device configurations.  Generalize to measure
each Environment.DIRECTORY separately, so it can be combined as
needed.  General cleanup of how measurements are passed to UI.

Bug: 7003520
Change-Id: Ib89c185296a0c9debdc20beeaa98584d803a84e8
parent fc76a78c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_JAVA_LIBRARIES := bouncycastle telephony-common
LOCAL_STATIC_JAVA_LIBRARIES := guava android-support-v4
LOCAL_STATIC_JAVA_LIBRARIES := guava android-support-v4 jsr305

LOCAL_MODULE_TAGS := optional

+2 −1
Original line number Diff line number Diff line
@@ -1863,6 +1863,8 @@
    <string name="sd_memory" product="default">SD card</string>
    <!-- SD card & phone storage settings title. The amount of free space for some storage partition.  For example, this is listed under both the "Internal phone storage" section and the "SD card" section. -->
    <string name="memory_available">Available</string>
    <!-- SD card & phone storage settings title. The amount of free space for some storage partition when the volume is read-only. [CHAR LIMIT=64] -->
    <string name="memory_available_read_only">Available (read-only)</string>
    <!-- SD card & phone storage settings screen heading.  The total amount of storage space for some storage partition.  For example, this is listed under both the "Internal phone storage" section and the "SD card" section -->
    <string name="memory_size">Total space</string>
    <!-- SD card & phone storage settings summary. Displayed when the total memory usage is being calculated. Will be replaced with a number like "12.3 GB" when finished calucating. [CHAR LIMIT=30] -->
@@ -1916,7 +1918,6 @@
    <!-- SD card & phone storage settings item summary that will result in the phone connected to PC and MTP/PTP enabled.   [CHAR LIMIT=80] -->
    <string name="mtp_ptp_mode_summary">MTP or PTP function is active</string>

    <string name="read_only">\u0020(Read-only)</string>
    <!-- SD card eject confirmation dialog title   [CHAR LIMIT=25] -->
    <string name="dlg_confirm_unmount_title" product="nosdcard">Unmount USB storage?</string>
    <!-- SD card eject confirmation dialog title   -->
+13 −18
Original line number Diff line number Diff line
@@ -66,9 +66,9 @@ public class Memory extends SettingsPreferenceFragment {
    private static String sClickedMountPoint;

    // Access using getMountService()
    private IMountService mMountService = null;
    private StorageManager mStorageManager = null;
    private UsbManager mUsbManager = null;
    private IMountService mMountService;
    private StorageManager mStorageManager;
    private UsbManager mUsbManager;

    private ArrayList<StorageVolumePreferenceCategory> mCategories = Lists.newArrayList();

@@ -76,33 +76,28 @@ public class Memory extends SettingsPreferenceFragment {
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        final Context context = getActivity();

        mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);

        if (mStorageManager == null) {
            mStorageManager = (StorageManager) getSystemService(Context.STORAGE_SERVICE);
        mStorageManager = StorageManager.from(context);
        mStorageManager.registerListener(mStorageListener);
        }

        addPreferencesFromResource(R.xml.device_info_memory);

        if (!Environment.isExternalStorageEmulated()) {
            // External storage is separate from internal storage; need to
            // show internal storage as a separate item.
            addCategoryForVolume(null);
        }
        addCategory(StorageVolumePreferenceCategory.buildForInternal(context));

        final StorageVolume[] storageVolumes = mStorageManager.getVolumeList();
        for (StorageVolume volume : storageVolumes) {
            addCategoryForVolume(volume);
            if (!volume.isEmulated()) {
                addCategory(StorageVolumePreferenceCategory.buildForPhysical(context, volume));
            }
        }

        setHasOptionsMenu(true);
    }

    private void addCategoryForVolume(StorageVolume volume) {
        // TODO: Cluster multi-user emulated volumes into single category
        final StorageVolumePreferenceCategory category = new StorageVolumePreferenceCategory(
                getActivity(), volume);
    private void addCategory(StorageVolumePreferenceCategory category) {
        mCategories.add(category);
        getPreferenceScreen().addPreference(category);
        category.init();
+1 −2
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.storage.StorageVolume;
import android.text.format.Formatter;
import android.util.Log;
@@ -195,7 +194,7 @@ public class MiscFilesHandler extends ListActivity {
            final StorageVolume storageVolume = activity.getIntent().getParcelableExtra(
                    StorageVolume.EXTRA_STORAGE_VOLUME);
            StorageMeasurement mMeasurement = StorageMeasurement.getInstance(
                    activity, storageVolume, UserHandle.CURRENT);
                    activity, storageVolume);
            if (mMeasurement == null) return;
            mData = (ArrayList<StorageMeasurement.FileInfo>) mMeasurement.mFileInfoForMisc;
            if (mData != null) {
+13 −13
Original line number Diff line number Diff line
@@ -21,34 +21,38 @@ import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.os.UserHandle;
import android.preference.Preference;

import com.android.settings.R;

public class StorageItemPreference extends Preference {
    public final int color;
    public final int userHandle;

    private int mColor = Color.MAGENTA;

    public StorageItemPreference(Context context, String key, int titleRes, int colorRes) {
        this(context, key, context.getText(titleRes), colorRes);
    public StorageItemPreference(Context context, int titleRes, int colorRes) {
        this(context, context.getText(titleRes), colorRes, UserHandle.USER_NULL);
    }

    public StorageItemPreference(Context context, String key, CharSequence title, int colorRes) {
    public StorageItemPreference(
            Context context, CharSequence title, int colorRes, int userHandle) {
        super(context);
        //setLayoutResource(R.layout.app_percentage_item);

        if (colorRes != 0) {
            mColor = context.getResources().getColor(colorRes);
            this.color = context.getResources().getColor(colorRes);

            final Resources res = context.getResources();
            final int width = res.getDimensionPixelSize(R.dimen.device_memory_usage_button_width);
            final int height = res.getDimensionPixelSize(R.dimen.device_memory_usage_button_height);
            setIcon(createRectShape(width, height, mColor));
            setIcon(createRectShape(width, height, this.color));
        } else {
            this.color = Color.MAGENTA;
        }

        setKey(key);
        setTitle(title);
        setSummary(R.string.memory_calculating_size);

        this.userHandle = userHandle;
    }

    private static ShapeDrawable createRectShape(int width, int height, int color) {
@@ -58,8 +62,4 @@ public class StorageItemPreference extends Preference {
        shape.getPaint().setColor(color);
        return shape;
    }

    public int getColor() {
        return mColor;
    }
}
Loading