Add support for user profiles to the Storage Settings.
This adds new preferences for each profile (such as the work
profile) and defines a new view for viewing the storage
breakdown for the individual profile. The functionality closely
mimics the presentation on the main view, but without the system-wide
breakdown and without any additional users/profiles.
Bug: 34715777
Test: Settings Robotests
Change-Id: I19d449b648c6566331fd02e45c2e45f8c74ea7e7
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 124c441..350ab9c 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -65,6 +65,7 @@
import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.StorageManager;
+import android.os.storage.VolumeInfo;
import android.preference.PreferenceFrameLayout;
import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.Contacts;
@@ -1258,4 +1259,21 @@
(user.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID
&& user.profileGroupId == profile.profileGroupId);
}
+
+ /**
+ * Tries to initalize a volume with the given bundle. If it is a valid, private, and readable
+ * {@link VolumeInfo}, it is returned. If it is not valid, null is returned.
+ */
+ @Nullable
+ public static VolumeInfo maybeInitializeVolume(StorageManager sm, Bundle bundle) {
+ final String volumeId = bundle.getString(VolumeInfo.EXTRA_VOLUME_ID,
+ VolumeInfo.ID_PRIVATE_INTERNAL);
+ VolumeInfo volume = sm.findVolumeById(volumeId);
+ return isVolumeValid(volume) ? volume : null;
+ }
+
+ private static boolean isVolumeValid(VolumeInfo volume) {
+ return (volume != null) && (volume.getType() == VolumeInfo.TYPE_PRIVATE)
+ && volume.isMountedReadable();
+ }
}