Avoid a few crashes around unmounting.

Also refresh UI when metadata changes.

Bug: 19993667
Change-Id: Ib0ea9be68a3db5c71d15fae6809f31df43fd9af0
This commit is contained in:
Jeff Sharkey
2015-04-14 23:16:59 -07:00
parent 4366b565e1
commit 7bc9235aaa
3 changed files with 29 additions and 13 deletions

View File

@@ -433,6 +433,14 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
refresh(); refresh();
} }
} }
@Override
public void onVolumeMetadataChanged(VolumeInfo vol) {
if (Objects.equals(mVolume.getId(), vol.getId())) {
mVolume = vol;
refresh();
}
}
}; };
/** /**

View File

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

View File

@@ -122,6 +122,18 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
screen.addPreference(mGraph); screen.addPreference(mGraph);
screen.addPreference(mTotal); screen.addPreference(mTotal);
screen.addPreference(mAvailable); screen.addPreference(mAvailable);
final File file = mVolume.getPath();
mTotalSize = file.getTotalSpace();
mAvailSize = file.getFreeSpace();
mTotal.setSummary(Formatter.formatFileSize(context, mTotalSize));
mAvailable.setSummary(Formatter.formatFileSize(context, mAvailSize));
mGraph.clear();
mGraph.addEntry(0, (mTotalSize - mAvailSize) / (float) mTotalSize,
android.graphics.Color.GRAY);
mGraph.commit();
} }
if (mVolume.getState() == VolumeInfo.STATE_UNMOUNTED) { if (mVolume.getState() == VolumeInfo.STATE_UNMOUNTED) {
@@ -134,18 +146,6 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
if (mDisk.isAdoptable()) { if (mDisk.isAdoptable()) {
screen.addPreference(mFormatInternal); screen.addPreference(mFormatInternal);
} }
final File file = mVolume.getPath();
mTotalSize = file.getTotalSpace();
mAvailSize = file.getFreeSpace();
mTotal.setSummary(Formatter.formatFileSize(context, mTotalSize));
mAvailable.setSummary(Formatter.formatFileSize(context, mAvailSize));
mGraph.clear();
mGraph.addEntry(0, (mTotalSize - mAvailSize) / (float) mTotalSize,
android.graphics.Color.GRAY);
mGraph.commit();
} }
private UsageBarPreference buildGraph() { private UsageBarPreference buildGraph() {
@@ -215,5 +215,13 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
refresh(); refresh();
} }
} }
@Override
public void onVolumeMetadataChanged(VolumeInfo vol) {
if (Objects.equals(mVolume.getId(), vol.getId())) {
mVolume = vol;
refresh();
}
}
}; };
} }