Don't crash on opening ejecting USB.

This crash occurs because, even if you finish an Activity during
onCreate, the other lifecycle methods occur. In this case,
onActivityCreated assumes that onCreate ran properly.

By exiting early from onActivityCreated, we can ensure the activity
is finished properly.

Change-Id: Ia354341bf82d295c7dd042668fb11d588ddfebc0
Fixes: 37334861
Test: Instrumentation test
This commit is contained in:
Daniel Nishi
2017-04-14 17:06:42 -07:00
parent 526185c89b
commit edafa44c7e
2 changed files with 59 additions and 1 deletions

View File

@@ -98,7 +98,9 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
mVolume = mStorageManager.findVolumeByUuid(fsUuid);
} else {
final String volId = getArguments().getString(VolumeInfo.EXTRA_VOLUME_ID);
mVolume = mStorageManager.findVolumeById(volId);
if (volId != null) {
mVolume = mStorageManager.findVolumeById(volId);
}
}
if (!isVolumeValid()) {
@@ -129,6 +131,12 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// If the volume isn't valid, we are not scaffolded to set up a view.
if (!isVolumeValid()) {
return;
}
final Resources resources = getResources();
final int padding = resources.getDimensionPixelSize(
R.dimen.unmount_button_padding);