summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/deviceinfo
diff options
context:
space:
mode:
authorDaniel Nishi <dhnishi@google.com>2018-03-28 15:31:17 -0700
committerDaniel Nishi <dhnishi@google.com>2018-03-28 15:31:17 -0700
commit3c6627d894c7d6fdcc229a594c5f8f857a6aba0c (patch)
tree5926d08411886d8446a4d392470b20fa18562e86 /src/com/android/settings/deviceinfo
parent00a2dcb8f9f9636a98c38e24edecb6934d1f59d2 (diff)
downloadpackages_apps_Settings-3c6627d894c7d6fdcc229a594c5f8f857a6aba0c.tar.gz
packages_apps_Settings-3c6627d894c7d6fdcc229a594c5f8f857a6aba0c.tar.bz2
packages_apps_Settings-3c6627d894c7d6fdcc229a594c5f8f857a6aba0c.zip
Better public volumes handling on secondary users.
Public volumes are only mounted for a single user at a time, so only show notifications and launch Intents for the relevant user. Test: RunSettingsRobotest Bug: 73642796 Change-Id: Ic386ec03598ab8968b75320be7844b6ac7f1387b
Diffstat (limited to 'src/com/android/settings/deviceinfo')
-rw-r--r--src/com/android/settings/deviceinfo/StorageSettings.java127
1 files changed, 70 insertions, 57 deletions
diff --git a/src/com/android/settings/deviceinfo/StorageSettings.java b/src/com/android/settings/deviceinfo/StorageSettings.java
index aaa75e343f..cf9d34b3bc 100644
--- a/src/com/android/settings/deviceinfo/StorageSettings.java
+++ b/src/com/android/settings/deviceinfo/StorageSettings.java
@@ -36,6 +36,7 @@ import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.os.storage.VolumeRecord;
import android.support.annotation.NonNull;
+import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import android.text.TextUtils;
@@ -71,10 +72,11 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
private static final String TAG_VOLUME_UNMOUNTED = "volume_unmounted";
private static final String TAG_DISK_INIT = "disk_init";
+ private static final int METRICS_CATEGORY = MetricsEvent.DEVICEINFO_STORAGE;
static final int COLOR_PUBLIC = Color.parseColor("#ff9e9e9e");
- static final int[] COLOR_PRIVATE = new int[] {
+ static final int[] COLOR_PRIVATE = new int[]{
Color.parseColor("#ff26a69a"),
Color.parseColor("#ffab47bc"),
Color.parseColor("#fff2a600"),
@@ -94,7 +96,7 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
@Override
public int getMetricsCategory() {
- return MetricsEvent.DEVICEINFO_STORAGE;
+ return METRICS_CATEGORY;
}
@Override
@@ -139,7 +141,7 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
};
private static boolean isInteresting(VolumeInfo vol) {
- switch(vol.getType()) {
+ switch (vol.getType()) {
case VolumeInfo.TYPE_PRIVATE:
case VolumeInfo.TYPE_PUBLIC:
return true;
@@ -301,20 +303,7 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
return true;
} else if (vol.getType() == VolumeInfo.TYPE_PUBLIC) {
- if (vol.isMountedReadable()) {
- startActivity(vol.buildBrowseIntent());
- return true;
- } else {
- final Bundle args = new Bundle();
- args.putString(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
- new SubSettingLauncher(getContext())
- .setDestination(PublicVolumeSettings.class.getCanonicalName())
- .setTitle(-1)
- .setSourceMetricsCategory(getMetricsCategory())
- .setArguments(args)
- .launch();
- return true;
- }
+ return handlePublicVolumeClick(getContext(), vol);
}
} else if (key.startsWith("disk:")) {
@@ -328,7 +317,7 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
args.putString(VolumeRecord.EXTRA_FS_UUID, key);
new SubSettingLauncher(getContext())
.setDestination(PrivateVolumeForget.class.getCanonicalName())
- .setTitle(R.string.storage_menu_forget)
+ .setTitle(R.string.storage_menu_forget)
.setSourceMetricsCategory(getMetricsCategory())
.setArguments(args)
.launch();
@@ -338,6 +327,25 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
return false;
}
+ @VisibleForTesting
+ static boolean handlePublicVolumeClick(Context context, VolumeInfo vol) {
+ final Intent intent = vol.buildBrowseIntent();
+ if (vol.isMountedReadable() && intent != null) {
+ context.startActivity(intent);
+ return true;
+ } else {
+ final Bundle args = new Bundle();
+ args.putString(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
+ new SubSettingLauncher(context)
+ .setDestination(PublicVolumeSettings.class.getCanonicalName())
+ .setTitle(-1)
+ .setSourceMetricsCategory(METRICS_CATEGORY)
+ .setArguments(args)
+ .launch();
+ return true;
+ }
+ }
+
public static class MountTask extends AsyncTask<Void, Void, Exception> {
private final Context mContext;
private final StorageManager mStorageManager;
@@ -440,40 +448,45 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
builder.setPositiveButton(R.string.storage_menu_mount,
new DialogInterface.OnClickListener() {
- /**
- * Check if an {@link RestrictedLockUtils#sendShowAdminSupportDetailsIntent admin
- * details intent} should be shown for the restriction and show it.
- *
- * @param restriction The restriction to check
- * @return {@code true} iff a intent was shown.
- */
- private boolean wasAdminSupportIntentShown(@NonNull String restriction) {
- EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(
- getActivity(), restriction, UserHandle.myUserId());
- boolean hasBaseUserRestriction = RestrictedLockUtils.hasBaseUserRestriction(
- getActivity(), restriction, UserHandle.myUserId());
- if (admin != null && !hasBaseUserRestriction) {
- RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getActivity(), admin);
- return true;
- }
-
- return false;
- }
+ /**
+ * Check if an {@link
+ * RestrictedLockUtils#sendShowAdminSupportDetailsIntent admin
+ * details intent} should be shown for the restriction and show it.
+ *
+ * @param restriction The restriction to check
+ * @return {@code true} iff a intent was shown.
+ */
+ private boolean wasAdminSupportIntentShown(@NonNull String restriction) {
+ EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(
+ getActivity(), restriction, UserHandle.myUserId());
+ boolean hasBaseUserRestriction =
+ RestrictedLockUtils.hasBaseUserRestriction(
+ getActivity(), restriction, UserHandle.myUserId());
+ if (admin != null && !hasBaseUserRestriction) {
+ RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getActivity(),
+ admin);
+ return true;
+ }
+
+ return false;
+ }
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (wasAdminSupportIntentShown(UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA)) {
- return;
- }
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (wasAdminSupportIntentShown(
+ UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA)) {
+ return;
+ }
- if (vol.disk != null && vol.disk.isUsb() &&
- wasAdminSupportIntentShown(UserManager.DISALLOW_USB_FILE_TRANSFER)) {
- return;
- }
+ if (vol.disk != null && vol.disk.isUsb() &&
+ wasAdminSupportIntentShown(
+ UserManager.DISALLOW_USB_FILE_TRANSFER)) {
+ return;
+ }
- new MountTask(context, vol).execute();
- }
- });
+ new MountTask(context, vol).execute();
+ }
+ });
builder.setNegativeButton(R.string.cancel, null);
return builder.create();
@@ -511,13 +524,13 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
builder.setPositiveButton(R.string.storage_menu_set_up,
new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- final Intent intent = new Intent(context, StorageWizardInit.class);
- intent.putExtra(DiskInfo.EXTRA_DISK_ID, diskId);
- startActivity(intent);
- }
- });
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ final Intent intent = new Intent(context, StorageWizardInit.class);
+ intent.putExtra(DiskInfo.EXTRA_DISK_ID, diskId);
+ startActivity(intent);
+ }
+ });
builder.setNegativeButton(R.string.cancel, null);
return builder.create();
@@ -586,7 +599,7 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
for (VolumeInfo vol : vols) {
if (isInteresting(vol)) {
data.title = storage.getBestVolumeDescription(vol);
- data.key = "storage_settings_volume_" +vol.id;
+ data.key = "storage_settings_volume_" + vol.id;
data.screenTitle = context.getString(R.string.storage_settings);
result.add(data);
}