Storage accessors; persist nickname, flags.

Move to using new public accessors on DiskInfo and VolumeInfo.

Persist nickname changes, and remember when user has initialized a
public volume.  Also skip the migration part of storage wizard until
it's implemented.

Bug: 19993667
Change-Id: I642fb43afb95380fddd48a1dad438e87b06454da
This commit is contained in:
Jeff Sharkey
2015-04-14 21:42:46 -07:00
parent 2949a4ab4d
commit 4366b565e1
15 changed files with 83 additions and 63 deletions

View File

@@ -48,7 +48,7 @@ public class PrivateVolumeFormatConfirm extends InstrumentedFragment {
final StorageManager storage = getActivity().getSystemService(StorageManager.class);
final String volumeId = getArguments().getString(VolumeInfo.EXTRA_VOLUME_ID);
mVolume = storage.findVolumeById(volumeId);
mDisk = storage.findDiskById(mVolume.diskId);
mDisk = storage.findDiskById(mVolume.getDiskId());
final View view = inflater.inflate(R.layout.storage_internal_format, container, false);
final TextView body = (TextView) view.findViewById(R.id.body);
@@ -65,7 +65,7 @@ public class PrivateVolumeFormatConfirm extends InstrumentedFragment {
@Override
public void onClick(View v) {
final Intent intent = new Intent(getActivity(), StorageWizardFormatProgress.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.id);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
intent.putExtra(StorageWizardFormatProgress.EXTRA_FORMAT_PUBLIC, true);
startActivity(intent);
getActivity().finish();

View File

@@ -121,13 +121,13 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
mVolume = mStorageManager.findVolumeById(mVolumeId);
Preconditions.checkNotNull(mVolume);
Preconditions.checkState(mVolume.type == VolumeInfo.TYPE_PRIVATE);
Preconditions.checkState(mVolume.getType() == VolumeInfo.TYPE_PRIVATE);
addPreferencesFromResource(R.xml.device_info_storage_volume);
// Find the emulated shared storage layered above this private volume
mSharedVolume = mStorageManager.findVolumeById(
mVolume.id.replace("private", "emulated"));
mVolume.getId().replace("private", "emulated"));
mMeasure = new StorageMeasurement(context, mVolume, mSharedVolume);
mMeasure.setReceiver(mReceiver);
@@ -168,7 +168,7 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
screen.removeAll();
if (mVolume.state != VolumeInfo.STATE_MOUNTED) {
if (mVolume.getState() != VolumeInfo.STATE_MOUNTED) {
return;
}
@@ -202,7 +202,7 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
}
}
final File file = new File(mVolume.path);
final File file = mVolume.getPath();
mTotalSize = file.getTotalSpace();
mAvailSize = file.getFreeSpace();
@@ -272,15 +272,15 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
// Actions live in menu for non-internal private volumes; they're shown
// as preference items for public volumes.
if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(mVolume.id)) {
if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(mVolume.getId())) {
rename.setVisible(false);
mount.setVisible(false);
unmount.setVisible(false);
format.setVisible(false);
} else {
rename.setVisible(mVolume.type == VolumeInfo.TYPE_PRIVATE);
mount.setVisible(mVolume.state == VolumeInfo.STATE_UNMOUNTED);
unmount.setVisible(mVolume.state == VolumeInfo.STATE_MOUNTED);
rename.setVisible(mVolume.getType() == VolumeInfo.TYPE_PRIVATE);
mount.setVisible(mVolume.getState() == VolumeInfo.STATE_UNMOUNTED);
unmount.setVisible(mVolume.getState() == VolumeInfo.STATE_MOUNTED);
format.setVisible(true);
}
@@ -300,12 +300,12 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
new MountTask(context, mVolume).execute();
return true;
case R.id.storage_unmount:
args.putString(VolumeInfo.EXTRA_VOLUME_ID, mVolume.id);
args.putString(VolumeInfo.EXTRA_VOLUME_ID, mVolume.getId());
startFragment(this, PrivateVolumeUnmountConfirm.class.getCanonicalName(),
R.string.storage_menu_unmount, 0, args);
return true;
case R.id.storage_format:
args.putString(VolumeInfo.EXTRA_VOLUME_ID, mVolume.id);
args.putString(VolumeInfo.EXTRA_VOLUME_ID, mVolume.getId());
startFragment(this, PrivateVolumeFormatConfirm.class.getCanonicalName(),
R.string.storage_menu_format, 0, args);
return true;
@@ -428,7 +428,7 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
private final StorageEventListener mStorageListener = new StorageEventListener() {
@Override
public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState) {
if (Objects.equals(mVolume.id, vol.id)) {
if (Objects.equals(mVolume.getId(), vol.getId())) {
mVolume = vol;
refresh();
}
@@ -462,8 +462,8 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
final View view = dialogInflater.inflate(R.layout.dialog_edittext, null, false);
final EditText nickname = (EditText) view.findViewById(R.id.edittext);
if (!TextUtils.isEmpty(vol.nickname)) {
nickname.setText(vol.nickname);
if (!TextUtils.isEmpty(vol.getNickname())) {
nickname.setText(vol.getNickname());
} else {
nickname.setText(storageManager.getBestVolumeDescription(vol));
}
@@ -475,7 +475,8 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO: persist the edited nickname!
// TODO: move to background thread
storageManager.setVolumeNickname(volId, nickname.getText().toString());
}
});
builder.setNegativeButton(R.string.cancel, null);

View File

@@ -48,7 +48,7 @@ public class PrivateVolumeUnmountConfirm extends InstrumentedFragment {
final StorageManager storage = getActivity().getSystemService(StorageManager.class);
final String volumeId = getArguments().getString(VolumeInfo.EXTRA_VOLUME_ID);
mVolume = storage.findVolumeById(volumeId);
mDisk = storage.findDiskById(mVolume.id);
mDisk = storage.findDiskById(mVolume.getId());
final View view = inflater.inflate(R.layout.storage_internal_unmount, container, false);
final TextView body = (TextView) view.findViewById(R.id.body);

View File

@@ -91,12 +91,12 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
}
Preconditions.checkNotNull(mVolume);
Preconditions.checkState(mVolume.type == VolumeInfo.TYPE_PUBLIC);
Preconditions.checkState(mVolume.getType() == VolumeInfo.TYPE_PUBLIC);
mDisk = mStorageManager.findDiskById(mVolume.diskId);
mDisk = mStorageManager.findDiskById(mVolume.getDiskId());
Preconditions.checkNotNull(mDisk);
mVolumeId = mVolume.id;
mVolumeId = mVolume.getId();
addPreferencesFromResource(R.xml.device_info_storage_volume);
@@ -118,24 +118,24 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
screen.removeAll();
if (mVolume.state == VolumeInfo.STATE_MOUNTED) {
if (mVolume.getState() == VolumeInfo.STATE_MOUNTED) {
screen.addPreference(mGraph);
screen.addPreference(mTotal);
screen.addPreference(mAvailable);
}
if (mVolume.state == VolumeInfo.STATE_UNMOUNTED) {
if (mVolume.getState() == VolumeInfo.STATE_UNMOUNTED) {
screen.addPreference(mMount);
}
if (mVolume.state == VolumeInfo.STATE_MOUNTED) {
if (mVolume.getState() == VolumeInfo.STATE_MOUNTED) {
screen.addPreference(mUnmount);
}
screen.addPreference(mFormat);
if ((mDisk.flags & DiskInfo.FLAG_ADOPTABLE) != 0) {
if (mDisk.isAdoptable()) {
screen.addPreference(mFormatInternal);
}
final File file = new File(mVolume.path);
final File file = mVolume.getPath();
mTotalSize = file.getTotalSpace();
mAvailSize = file.getFreeSpace();
@@ -200,7 +200,7 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
new FormatTask(context, mVolume).execute();
} else if (pref == mFormatInternal) {
final Intent intent = new Intent(context, StorageWizardFormatConfirm.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.id);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
startActivity(intent);
}
@@ -210,7 +210,7 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
private final StorageEventListener mStorageListener = new StorageEventListener() {
@Override
public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState) {
if (Objects.equals(mVolume.id, vol.id)) {
if (Objects.equals(mVolume.getId(), vol.getId())) {
mVolume = vol;
refresh();
}

View File

@@ -345,7 +345,7 @@ public class StorageMeasurement {
final Message finished = mMeasurementHandler.obtainMessage(MeasurementHandler.MSG_COMPLETED,
details);
if (mSharedVolume != null && mSharedVolume.state == VolumeInfo.STATE_MOUNTED) {
if (mSharedVolume != null && mSharedVolume.getState() == VolumeInfo.STATE_MOUNTED) {
final File basePath = mSharedVolume.getPathForUser(currentUser);
// Measure media types for emulated storage, or for primary physical
@@ -359,7 +359,7 @@ public class StorageMeasurement {
// Measure misc files not counted under media
details.miscSize = measureMisc(imcs, basePath);
if (mSharedVolume.type == VolumeInfo.TYPE_EMULATED) {
if (mSharedVolume.getType() == VolumeInfo.TYPE_EMULATED) {
// Measure total emulated storage of all users; internal apps data
// will be spliced in later
for (UserInfo user : users) {
@@ -371,14 +371,14 @@ public class StorageMeasurement {
}
// Measure all apps hosted on this volume for all users
if (mVolume.type == VolumeInfo.TYPE_PRIVATE) {
if (mVolume.getType() == VolumeInfo.TYPE_PRIVATE) {
final List<ApplicationInfo> apps = packageManager.getInstalledApplications(
PackageManager.GET_UNINSTALLED_PACKAGES
| PackageManager.GET_DISABLED_COMPONENTS);
final List<ApplicationInfo> volumeApps = new ArrayList<>();
for (ApplicationInfo app : apps) {
if (Objects.equals(app.volumeUuid, mVolume.fsUuid)) {
if (Objects.equals(app.volumeUuid, mVolume.getFsUuid())) {
volumeApps.add(app);
}
}

View File

@@ -94,10 +94,12 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
private static final Comparator<VolumeInfo> sVolumeComparator = new Comparator<VolumeInfo>() {
@Override
public int compare(VolumeInfo lhs, VolumeInfo rhs) {
if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(lhs.id)) {
if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(lhs.getId())) {
return -1;
} else if (lhs.getDescription() == null) {
return 1;
} else if (rhs.getDescription() == null) {
return -1;
} else {
return lhs.getDescription().compareTo(rhs.getDescription());
}
@@ -114,7 +116,13 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
};
private static boolean isInteresting(VolumeInfo vol) {
return vol.type == VolumeInfo.TYPE_PRIVATE || vol.type == VolumeInfo.TYPE_PUBLIC;
switch(vol.getType()) {
case VolumeInfo.TYPE_PRIVATE:
case VolumeInfo.TYPE_PUBLIC:
return true;
default:
return false;
}
}
private void refresh() {
@@ -128,9 +136,9 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
Collections.sort(volumes, sVolumeComparator);
for (VolumeInfo vol : volumes) {
if (vol.type == VolumeInfo.TYPE_PRIVATE) {
if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
mInternalCategory.addPreference(new StorageVolumePreference(context, vol));
} else if (vol.type == VolumeInfo.TYPE_PUBLIC) {
} else if (vol.getType() == VolumeInfo.TYPE_PUBLIC) {
mExternalCategory.addPreference(new StorageVolumePreference(context, vol));
}
}
@@ -186,15 +194,15 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
if (vol == null) {
return false;
} else if (vol.type == VolumeInfo.TYPE_PRIVATE) {
} else if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
final Bundle args = new Bundle();
args.putString(VolumeInfo.EXTRA_VOLUME_ID, volId);
startFragment(this, PrivateVolumeSettings.class.getCanonicalName(),
-1, 0, args);
return true;
} else if (vol.type == VolumeInfo.TYPE_PUBLIC) {
if (vol.state == VolumeInfo.STATE_MOUNTED) {
} else if (vol.getType() == VolumeInfo.TYPE_PUBLIC) {
if (vol.getState() == VolumeInfo.STATE_MOUNTED) {
startActivity(vol.buildBrowseIntent());
return true;
} else {
@@ -218,7 +226,7 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
public MountTask(Context context, VolumeInfo volume) {
mContext = context.getApplicationContext();
mStorageManager = mContext.getSystemService(StorageManager.class);
mVolumeId = volume.id;
mVolumeId = volume.getId();
mDescription = mStorageManager.getBestVolumeDescription(volume);
}
@@ -254,7 +262,7 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
public UnmountTask(Context context, VolumeInfo volume) {
mContext = context.getApplicationContext();
mStorageManager = mContext.getSystemService(StorageManager.class);
mVolumeId = volume.id;
mVolumeId = volume.getId();
mDescription = mStorageManager.getBestVolumeDescription(volume);
}
@@ -290,7 +298,7 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
public FormatTask(Context context, VolumeInfo volume) {
mContext = context.getApplicationContext();
mStorageManager = mContext.getSystemService(StorageManager.class);
mVolumeId = volume.id;
mVolumeId = volume.getId();
mDescription = mStorageManager.getBestVolumeDescription(volume);
}

View File

@@ -44,13 +44,13 @@ public class StorageVolumePreference extends Preference {
mStorageManager = context.getSystemService(StorageManager.class);
mVolume = volume;
setKey(volume.id);
setKey(volume.getId());
setTitle(mStorageManager.getBestVolumeDescription(volume));
switch (volume.state) {
switch (volume.getState()) {
case VolumeInfo.STATE_MOUNTED:
// TODO: move statfs() to background thread
final File path = new File(volume.path);
final File path = volume.getPath();
final String free = Formatter.formatFileSize(context, path.getFreeSpace());
final String total = Formatter.formatFileSize(context, path.getTotalSpace());
setSummary(context.getString(R.string.storage_volume_summary, free, total));
@@ -58,13 +58,14 @@ public class StorageVolumePreference extends Preference {
}
// TODO: better icons
if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(volume.id)) {
if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(volume.getId())) {
setIcon(context.getDrawable(R.drawable.ic_settings_storage));
} else {
setIcon(context.getDrawable(R.drawable.ic_sim_sd));
}
if (volume.type == VolumeInfo.TYPE_PUBLIC && volume.state == VolumeInfo.STATE_MOUNTED) {
if (volume.getType() == VolumeInfo.TYPE_PUBLIC
&& volume.getState() == VolumeInfo.STATE_MOUNTED) {
setWidgetLayoutResource(R.layout.preference_storage_action);
}
}

View File

@@ -57,7 +57,7 @@ public abstract class StorageWizardBase extends Activity implements NavigationBa
if (!TextUtils.isEmpty(diskId)) {
mDisk = mStorage.findDiskById(diskId);
} else {
mDisk = mStorage.findDiskById(mVolume.diskId);
mDisk = mStorage.findDiskById(mVolume.getDiskId());
}
setTheme(R.style.SuwThemeMaterial_Light);

View File

@@ -42,7 +42,7 @@ public class StorageWizardFormatConfirm extends StorageWizardBase {
@Override
public void onNavigateNext() {
final Intent intent = new Intent(this, StorageWizardFormatProgress.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.id);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
startActivity(intent);
finishAffinity();
}

View File

@@ -59,9 +59,9 @@ public class StorageWizardFormatProgress extends StorageWizardBase {
protected Exception doInBackground(Void... params) {
try {
if (mFormatPublic) {
mStorage.partitionPublic(mDisk.id);
mStorage.partitionPublic(mDisk.getId());
} else {
mStorage.partitionPrivate(mDisk.id);
mStorage.partitionPrivate(mDisk.getId());
}
return null;
} catch (Exception e) {
@@ -74,8 +74,12 @@ public class StorageWizardFormatProgress extends StorageWizardBase {
final Context context = StorageWizardFormatProgress.this;
if (e == null) {
if (!mFormatPublic) {
final Intent intent = new Intent(context, StorageWizardMigrate.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.id);
// TODO: bring back migration once implemented
// final Intent intent = new Intent(context, StorageWizardMigrate.class);
// intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
// startActivity(intent);
final Intent intent = new Intent(context, StorageWizardReady.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
startActivity(intent);
}
finishAffinity();

View File

@@ -72,12 +72,15 @@ public class StorageWizardInit extends StorageWizardBase {
@Override
public void onNavigateNext() {
if (mRadioExternal.isChecked()) {
// Remember that user made decision
mStorage.setVolumeInited(mVolume.getId(), true);
final Intent intent = new Intent(this, StorageWizardReady.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.id);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
startActivity(intent);
} else if (mRadioInternal.isChecked()) {
final Intent intent = new Intent(this, StorageWizardFormatConfirm.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.id);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
startActivity(intent);
}
}

View File

@@ -71,11 +71,11 @@ public class StorageWizardMigrate extends StorageWizardBase {
public void onNavigateNext() {
if (mRadioNow.isChecked()) {
final Intent intent = new Intent(this, StorageWizardMigrateConfirm.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.id);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
startActivity(intent);
} else if (mRadioLater.isChecked()) {
final Intent intent = new Intent(this, StorageWizardReady.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.id);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
startActivity(intent);
}
}

View File

@@ -46,7 +46,7 @@ public class StorageWizardMigrateConfirm extends StorageWizardBase {
@Override
public void onNavigateNext() {
final Intent intent = new Intent(this, StorageWizardMigrateProgress.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.id);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
startActivity(intent);
finishAffinity();
}

View File

@@ -62,7 +62,7 @@ public class StorageWizardMigrateProgress extends StorageWizardBase {
final Context context = StorageWizardMigrateProgress.this;
if (e == null) {
final Intent intent = new Intent(context, StorageWizardReady.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.id);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
startActivity(intent);
finishAffinity();

View File

@@ -22,6 +22,9 @@ import android.os.storage.VolumeInfo;
import com.android.internal.util.Preconditions;
import com.android.settings.R;
import java.util.List;
import java.util.Objects;
public class StorageWizardReady extends StorageWizardBase {
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -34,15 +37,15 @@ public class StorageWizardReady extends StorageWizardBase {
// TODO: handle mixed partition cases instead of just guessing based on
// first volume type we encounter
for (String volId : mDisk.volumeIds) {
final VolumeInfo vol = mStorage.findVolumeById(volId);
if (vol == null) continue;
final List<VolumeInfo> vols = mStorage.getVolumes();
for (VolumeInfo vol : vols) {
if (!Objects.equals(mDisk.getId(), vol.getDiskId())) continue;
if (vol.type == VolumeInfo.TYPE_PUBLIC) {
if (vol.getType() == VolumeInfo.TYPE_PUBLIC) {
setBodyText(R.string.storage_wizard_ready_external_body,
mDisk.getDescription());
break;
} else if (vol.type == VolumeInfo.TYPE_PRIVATE) {
} else if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
setBodyText(R.string.storage_wizard_ready_internal_body,
mDisk.getDescription());
break;