Catch exceptions from prepareUserStorage() in loadPrivatePackagesInner()

There is a race condition where loadPrivatePackagesInner() can run after
the volume has already been unmounted, and even reformatted as a public
volume.  This race can be triggered by AdoptableHostTest in CTS.

Until the volume state change handling logic is fixed, it is necessary
to ignore the RuntimeException that sm.prepareUserStorage() can throw
after commit 9d2bb776ed (https://r.android.com/1959519).

Bug: 253711749
Bug: 253868095
Change-Id: I9985eb5e410a5a5ff41935c806370826c6e4117d
This commit is contained in:
Eric Biggers
2022-10-31 23:19:02 +00:00
parent 2681cb2d92
commit 415ed9afd6

View File

@@ -197,8 +197,11 @@ public final class StorageEventHelper extends StorageEventListener {
appDataHelper.reconcileAppsDataLI(volumeUuid, user.id, flags,
true /* migrateAppData */);
}
} catch (IllegalStateException e) {
// Device was probably ejected, and we'll process that event momentarily
} catch (RuntimeException e) {
// The volume was probably already unmounted. We'll probably process the unmount
// event momentarily. TODO(b/256909937): ignoring errors from prepareUserStorage()
// is very dangerous. Instead, we should fix the race condition that allows this
// code to run on an unmounted volume in the first place.
Slog.w(TAG, "Failed to prepare storage: " + e);
}
}