Load Weaver HAL if needed in destroyWeaverSlot()

Now that mWeaver is not initialized at boot time, but rather only by
isWeaverAvailable(), we need to make sure that isWeaverAvailable() is
called before dereferencing mWeaver.  This was done in all cases except
for destroyWeaverSlot(), which is reachable with null mWeaver if a user
is removed before any user is unlocked.  Fix this.

This fixes commit 61bd5961f6 ("Do not initialize the weaver service at
boot") (http://ag/21164366).

Bug: 252760591
Test: Set a PIN on user 0.  Add secondary user.  Reboot.  Remove
      secondary user using 'pm remove-user'.  system_server crashes
      before this change, but not after it.
Change-Id: I05019af328c56739724a67f9af776664e2cef438
This commit is contained in:
Eric Biggers
2023-02-24 05:11:08 +00:00
parent bc34045c05
commit 8f5189dd60

View File

@@ -780,6 +780,10 @@ class SyntheticPasswordManager {
int slot = loadWeaverSlot(protectorId, userId);
destroyState(WEAVER_SLOT_NAME, protectorId, userId);
if (slot != INVALID_WEAVER_SLOT) {
if (!isWeaverAvailable()) {
Slog.e(TAG, "Cannot erase Weaver slot because Weaver is unavailable");
return;
}
Set<Integer> usedSlots = getUsedWeaverSlots();
if (!usedSlots.contains(slot)) {
Slog.i(TAG, "Destroy weaver slot " + slot + " for user " + userId);