Gracefully handle null volumes after forgetting.

If a user tells a device to forget a storage volume and then
goes back to the PrivateVolumeForget activity from their Recents, it
attempts to re-initialize itself with a volume that it forgot.

And this makes Settings crash.

By gracefully killing the activity when we try to open
PrivateVolumeForget for a forgotten volume, we avoid this crash.

Change-Id: Ib4e881c10f0c872ce6b268b16a573960230ef99b
Fixes: 34856304
Test: Settings unit test
This commit is contained in:
Daniel Nishi
2017-04-18 14:57:54 -07:00
parent 526185c89b
commit 6b37d6341f
2 changed files with 62 additions and 0 deletions

View File

@@ -53,8 +53,18 @@ public class PrivateVolumeForget extends SettingsPreferenceFragment {
Bundle savedInstanceState) {
final StorageManager storage = getActivity().getSystemService(StorageManager.class);
final String fsUuid = getArguments().getString(VolumeRecord.EXTRA_FS_UUID);
// Passing null will crash the StorageManager, so let's early exit.
if (fsUuid == null) {
getActivity().finish();
return null;
}
mRecord = storage.findRecordByUuid(fsUuid);
if (mRecord == null) {
getActivity().finish();
return null;
}
final View view = inflater.inflate(R.layout.storage_internal_forget, container, false);
final TextView body = (TextView) view.findViewById(R.id.body);
final Button confirm = (Button) view.findViewById(R.id.confirm);