From 152db1f9dcaffdb1db1f035614ede9ee7c3c774b Mon Sep 17 00:00:00 2001 From: Songchun Fan Date: Tue, 13 Jun 2023 14:14:00 -0700 Subject: [PATCH] [pm] fix crash caused by race condition onUidGone GentleUpdateHelper monitors uids when they are no longer running and informs installers when an installation can be proceeded. A race race condition can happen when HotwordDetectionService stops running, and its isolated uid's owner uid has also been recently removed, which causes an uncaught exception in pm's code, causing system server crash. BUG: 286903116 Test: builds Change-Id: I05662d2268d6e94132fb62e75908525dccba9ecb --- .../java/com/android/server/pm/ComputerEngine.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/pm/ComputerEngine.java b/services/core/java/com/android/server/pm/ComputerEngine.java index abfc1d7ff2d2f..78f1fa60b69fd 100644 --- a/services/core/java/com/android/server/pm/ComputerEngine.java +++ b/services/core/java/com/android/server/pm/ComputerEngine.java @@ -4311,7 +4311,12 @@ public class ComputerEngine implements Computer { if (Process.isIsolatedUid(uid) && mPermissionManager.getHotwordDetectionServiceProvider() != null && uid == mPermissionManager.getHotwordDetectionServiceProvider().getUid()) { - uid = getIsolatedOwner(uid); + try { + uid = getIsolatedOwner(uid); + } catch (IllegalStateException e) { + // If the owner uid doesn't exist, just use the current uid + Slog.wtf(TAG, "Expected isolated uid " + uid + " to have an owner", e); + } } final int callingUserId = UserHandle.getUserId(callingUid); final int appId = UserHandle.getAppId(uid); @@ -4352,7 +4357,12 @@ public class ComputerEngine implements Computer { if (Process.isIsolatedUid(uid) && mPermissionManager.getHotwordDetectionServiceProvider() != null && uid == mPermissionManager.getHotwordDetectionServiceProvider().getUid()) { - uid = getIsolatedOwner(uid); + try { + uid = getIsolatedOwner(uid); + } catch (IllegalStateException e) { + // If the owner uid doesn't exist, just use the current uid + Slog.wtf(TAG, "Expected isolated uid " + uid + " to have an owner", e); + } } final int appId = UserHandle.getAppId(uid); final Object obj = mSettings.getSettingBase(appId);