Include user identifier in external storage paths.
When building external storage paths, always include user in path to enable cross-user paths and aid debugging. Mostly changes so Storage doesn't crash; will take another UI iteration pass soon. Bug: 7131382 Change-Id: If7ec807f12a36eb8ed02a0fb94e8a0b3a6694f16
This commit is contained in:
@@ -100,6 +100,7 @@ public class Memory extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addCategoryForVolume(StorageVolume volume) {
|
private void addCategoryForVolume(StorageVolume volume) {
|
||||||
|
// TODO: Cluster multi-user emulated volumes into single category
|
||||||
final StorageVolumePreferenceCategory category = new StorageVolumePreferenceCategory(
|
final StorageVolumePreferenceCategory category = new StorageVolumePreferenceCategory(
|
||||||
getActivity(), volume);
|
getActivity(), volume);
|
||||||
mCategories.add(category);
|
mCategories.add(category);
|
||||||
@@ -108,9 +109,10 @@ public class Memory extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMassStorageEnabled() {
|
private boolean isMassStorageEnabled() {
|
||||||
// mass storage is enabled if primary volume supports it
|
// Mass storage is enabled if primary volume supports it
|
||||||
final StorageVolume[] storageVolumes = mStorageManager.getVolumeList();
|
final StorageVolume[] volumes = mStorageManager.getVolumeList();
|
||||||
return (storageVolumes.length > 0 && storageVolumes[0].allowMassStorage());
|
final StorageVolume primary = StorageManager.getPrimaryVolume(volumes);
|
||||||
|
return primary != null && primary.allowMassStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -26,6 +26,7 @@ import android.content.pm.PackageManager;
|
|||||||
import android.content.pm.PackageStats;
|
import android.content.pm.PackageStats;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.os.Environment.UserEnvironment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
@@ -103,6 +104,7 @@ public class StorageMeasurement {
|
|||||||
|
|
||||||
private final StorageVolume mStorageVolume;
|
private final StorageVolume mStorageVolume;
|
||||||
private final UserHandle mUser;
|
private final UserHandle mUser;
|
||||||
|
private final UserEnvironment mUserEnv;
|
||||||
private final boolean mIsPrimary;
|
private final boolean mIsPrimary;
|
||||||
private final boolean mIsInternal;
|
private final boolean mIsInternal;
|
||||||
|
|
||||||
@@ -118,6 +120,7 @@ public class StorageMeasurement {
|
|||||||
private StorageMeasurement(Context context, StorageVolume volume, UserHandle user) {
|
private StorageMeasurement(Context context, StorageVolume volume, UserHandle user) {
|
||||||
mStorageVolume = volume;
|
mStorageVolume = volume;
|
||||||
mUser = Preconditions.checkNotNull(user);
|
mUser = Preconditions.checkNotNull(user);
|
||||||
|
mUserEnv = new UserEnvironment(mUser.getIdentifier());
|
||||||
mIsInternal = volume == null;
|
mIsInternal = volume == null;
|
||||||
mIsPrimary = volume != null ? volume.isPrimary() : false;
|
mIsPrimary = volume != null ? volume.isPrimary() : false;
|
||||||
|
|
||||||
@@ -389,7 +392,7 @@ public class StorageMeasurement {
|
|||||||
final long[] stats = imcs.getFileSystemStats(path);
|
final long[] stats = imcs.getFileSystemStats(path);
|
||||||
mTotalSize = stats[0];
|
mTotalSize = stats[0];
|
||||||
mAvailSize = stats[1];
|
mAvailSize = stats[1];
|
||||||
} catch (RemoteException e) {
|
} catch (Exception e) {
|
||||||
Log.w(TAG, "Problem in container service", e);
|
Log.w(TAG, "Problem in container service", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,7 +453,7 @@ public class StorageMeasurement {
|
|||||||
|
|
||||||
// Downloads (primary volume only)
|
// Downloads (primary volume only)
|
||||||
if (mIsPrimary) {
|
if (mIsPrimary) {
|
||||||
final String downloadsPath = Environment.getExternalStoragePublicDirectory(
|
final String downloadsPath = mUserEnv.getExternalStoragePublicDirectory(
|
||||||
Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
|
Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
|
||||||
mDownloadsSize = getDirectorySize(imcs, downloadsPath);
|
mDownloadsSize = getDirectorySize(imcs, downloadsPath);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -27,6 +27,7 @@ import android.content.res.Resources;
|
|||||||
import android.hardware.usb.UsbManager;
|
import android.hardware.usb.UsbManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.os.Environment.UserEnvironment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
@@ -50,17 +51,21 @@ import java.util.Set;
|
|||||||
public class StorageVolumePreferenceCategory extends PreferenceCategory
|
public class StorageVolumePreferenceCategory extends PreferenceCategory
|
||||||
implements MeasurementReceiver {
|
implements MeasurementReceiver {
|
||||||
private static final String KEY_TOTAL_SIZE = "total_size";
|
private static final String KEY_TOTAL_SIZE = "total_size";
|
||||||
|
private static final String KEY_AVAILABLE = "available";
|
||||||
|
|
||||||
private static final String KEY_APPLICATIONS = "applications";
|
private static final String KEY_APPLICATIONS = "applications";
|
||||||
private static final String KEY_DCIM = "dcim"; // Pictures and Videos
|
private static final String KEY_DCIM = "dcim"; // Pictures and Videos
|
||||||
private static final String KEY_MUSIC = "music";
|
private static final String KEY_MUSIC = "music";
|
||||||
private static final String KEY_DOWNLOADS = "downloads";
|
private static final String KEY_DOWNLOADS = "downloads";
|
||||||
private static final String KEY_MISC = "misc";
|
private static final String KEY_MISC = "misc";
|
||||||
private static final String KEY_AVAILABLE = "available";
|
|
||||||
private static final String KEY_USER_PREFIX = "user";
|
private static final String KEY_USER_PREFIX = "user";
|
||||||
|
|
||||||
private static final int ORDER_USAGE_BAR = -2;
|
private static final int ORDER_USAGE_BAR = -2;
|
||||||
private static final int ORDER_STORAGE_LOW = -1;
|
private static final int ORDER_STORAGE_LOW = -1;
|
||||||
|
|
||||||
|
private Preference mItemTotal;
|
||||||
|
private Preference mItemAvailable;
|
||||||
|
|
||||||
private UsageBarPreference mUsageBarPreference;
|
private UsageBarPreference mUsageBarPreference;
|
||||||
private Preference mMountTogglePreference;
|
private Preference mMountTogglePreference;
|
||||||
private Preference mFormatPreference;
|
private Preference mFormatPreference;
|
||||||
@@ -75,6 +80,9 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory
|
|||||||
private final StorageManager mStorageManager;
|
private final StorageManager mStorageManager;
|
||||||
private final UserManager mUserManager;
|
private final UserManager mUserManager;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
private static final UserEnvironment sOwnerEnv = new UserEnvironment(UserHandle.USER_OWNER);
|
||||||
|
|
||||||
/** Measurement for local user. */
|
/** Measurement for local user. */
|
||||||
private StorageMeasurement mLocalMeasure;
|
private StorageMeasurement mLocalMeasure;
|
||||||
/** All used measurements, including other users. */
|
/** All used measurements, including other users. */
|
||||||
@@ -98,7 +106,7 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory
|
|||||||
mDirPaths = new String[length];
|
mDirPaths = new String[length];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
final String name = directories[i];
|
final String name = directories[i];
|
||||||
final String path = Environment.getExternalStoragePublicDirectory(name).
|
final String path = sOwnerEnv.getExternalStoragePublicDirectory(name).
|
||||||
getAbsolutePath();
|
getAbsolutePath();
|
||||||
mDirPaths[i] = path;
|
mDirPaths[i] = path;
|
||||||
sPathsExcludedForMisc.add(path);
|
sPathsExcludedForMisc.add(path);
|
||||||
@@ -116,10 +124,10 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
// Downloads
|
// Downloads
|
||||||
sPathsExcludedForMisc.add(Environment.getExternalStoragePublicDirectory(
|
sPathsExcludedForMisc.add(sOwnerEnv.getExternalStoragePublicDirectory(
|
||||||
Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
|
Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
|
||||||
// Apps
|
// Apps
|
||||||
sPathsExcludedForMisc.add(Environment.getExternalStorageDirectory().getAbsolutePath() +
|
sPathsExcludedForMisc.add(sOwnerEnv.getExternalStorageDirectory().getAbsolutePath() +
|
||||||
"/Android");
|
"/Android");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,8 +204,11 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory
|
|||||||
if (!mIsPrimary) mAllowFormat = false;
|
if (!mIsPrimary) mAllowFormat = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addStorageItem(String key, int titleRes, int colorRes) {
|
private StorageItemPreference addStorageItem(String key, int titleRes, int colorRes) {
|
||||||
addPreference(new StorageItemPreference(getContext(), key, titleRes, colorRes));
|
final StorageItemPreference pref = new StorageItemPreference(
|
||||||
|
getContext(), key, titleRes, colorRes);
|
||||||
|
addPreference(pref);
|
||||||
|
return pref;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String buildUserKey(UserHandle user) {
|
private static String buildUserKey(UserHandle user) {
|
||||||
@@ -221,8 +232,9 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory
|
|||||||
mUsageBarPreference.setOrder(ORDER_USAGE_BAR);
|
mUsageBarPreference.setOrder(ORDER_USAGE_BAR);
|
||||||
addPreference(mUsageBarPreference);
|
addPreference(mUsageBarPreference);
|
||||||
|
|
||||||
addStorageItem(KEY_TOTAL_SIZE, R.string.memory_size, 0);
|
mItemTotal = addStorageItem(KEY_TOTAL_SIZE, R.string.memory_size, 0);
|
||||||
addStorageItem(KEY_AVAILABLE, R.string.memory_available, R.color.memory_avail);
|
mItemAvailable = addStorageItem(
|
||||||
|
KEY_AVAILABLE, R.string.memory_available, R.color.memory_avail);
|
||||||
|
|
||||||
if (measureUsers) {
|
if (measureUsers) {
|
||||||
addPreference(new PreferenceHeader(context, currentUser.name));
|
addPreference(new PreferenceHeader(context, currentUser.name));
|
||||||
@@ -309,8 +321,9 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Environment.MEDIA_MOUNTED.equals(state)) {
|
if (Environment.MEDIA_MOUNTED.equals(state)) {
|
||||||
final Preference pref = findPreference(KEY_AVAILABLE);
|
// TODO: create better i18n strings here; we might end up appending
|
||||||
pref.setSummary(pref.getSummary() + readOnly);
|
// multiple times
|
||||||
|
mItemAvailable.setSummary(mItemAvailable.getSummary() + readOnly);
|
||||||
|
|
||||||
mMountTogglePreference.setEnabled(true);
|
mMountTogglePreference.setEnabled(true);
|
||||||
mMountTogglePreference.setTitle(mResources.getString(R.string.sd_eject));
|
mMountTogglePreference.setTitle(mResources.getString(R.string.sd_eject));
|
||||||
@@ -328,8 +341,8 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory
|
|||||||
}
|
}
|
||||||
|
|
||||||
removePreference(mUsageBarPreference);
|
removePreference(mUsageBarPreference);
|
||||||
removePreference(findPreference(KEY_TOTAL_SIZE));
|
removePreference(mItemTotal);
|
||||||
removePreference(findPreference(KEY_AVAILABLE));
|
removePreference(mItemAvailable);
|
||||||
if (mFormatPreference != null) {
|
if (mFormatPreference != null) {
|
||||||
removePreference(mFormatPreference);
|
removePreference(mFormatPreference);
|
||||||
}
|
}
|
||||||
@@ -354,8 +367,8 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateApproximate(long totalSize, long availSize) {
|
public void updateApproximate(long totalSize, long availSize) {
|
||||||
findPreference(KEY_TOTAL_SIZE).setSummary(formatSize(totalSize));
|
mItemTotal.setSummary(formatSize(totalSize));
|
||||||
findPreference(KEY_AVAILABLE).setSummary(formatSize(availSize));
|
mItemAvailable.setSummary(formatSize(availSize));
|
||||||
|
|
||||||
final long usedSize = totalSize - availSize;
|
final long usedSize = totalSize - availSize;
|
||||||
|
|
||||||
@@ -374,7 +387,7 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory
|
|||||||
mShowingApprox = false;
|
mShowingApprox = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
findPreference(KEY_TOTAL_SIZE).setSummary(formatSize(totalSize));
|
mItemTotal.setSummary(formatSize(totalSize));
|
||||||
|
|
||||||
if (mLocalMeasure.isExternalSDCard()) {
|
if (mLocalMeasure.isExternalSDCard()) {
|
||||||
// TODO FIXME: external SD card will not report any size. Show used space in bar graph
|
// TODO FIXME: external SD card will not report any size. Show used space in bar graph
|
||||||
@@ -399,7 +412,7 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory
|
|||||||
// Block size is taken into account. That can be extra space from folders. TODO Investigate
|
// Block size is taken into account. That can be extra space from folders. TODO Investigate
|
||||||
updatePreference(miscSize, totalSize, KEY_MISC);
|
updatePreference(miscSize, totalSize, KEY_MISC);
|
||||||
|
|
||||||
updatePreference(availSize, totalSize, KEY_AVAILABLE, false);
|
mItemAvailable.setSummary(formatSize(availSize));
|
||||||
|
|
||||||
mUsageBarPreference.commit();
|
mUsageBarPreference.commit();
|
||||||
}
|
}
|
||||||
@@ -419,19 +432,13 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updatePreference(long size, long totalSize, String category) {
|
private void updatePreference(long size, long totalSize, String category) {
|
||||||
updatePreference(size, totalSize, category, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updatePreference(long size, long totalSize, String category, boolean addBar) {
|
|
||||||
final StorageItemPreference pref = (StorageItemPreference) findPreference(category);
|
final StorageItemPreference pref = (StorageItemPreference) findPreference(category);
|
||||||
|
|
||||||
if (pref != null) {
|
if (pref != null) {
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
pref.setSummary(formatSize(size));
|
pref.setSummary(formatSize(size));
|
||||||
if (addBar) {
|
|
||||||
final int order = pref.getOrder();
|
final int order = pref.getOrder();
|
||||||
mUsageBarPreference.addEntry(order, size / (float) totalSize, pref.getColor());
|
mUsageBarPreference.addEntry(order, size / (float) totalSize, pref.getColor());
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
removePreference(pref);
|
removePreference(pref);
|
||||||
}
|
}
|
||||||
@@ -550,7 +557,6 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return list of other users, excluding the current user.
|
* Return list of other users, excluding the current user.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user