From d3dcf5106ef77ae910c0cdf069a572c7a77faca9 Mon Sep 17 00:00:00 2001 From: Kevin Han Date: Thu, 13 May 2021 16:44:24 -0700 Subject: [PATCH] Log instead of throw exception when pkg not found Throwing an exception for the package being missing in app hibernation service crashes the system, so we replace it with a log to keep builds with hibernation stable. Bug: 188059563 Test: builds Change-Id: I9cf461ab01369ff790f3fa196c3f8e5e1a33b0e3 --- .../apphibernation/AppHibernationService.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/apphibernation/AppHibernationService.java b/services/core/java/com/android/server/apphibernation/AppHibernationService.java index 05c443109a4a8..535fb679ab4dc 100644 --- a/services/core/java/com/android/server/apphibernation/AppHibernationService.java +++ b/services/core/java/com/android/server/apphibernation/AppHibernationService.java @@ -220,9 +220,9 @@ public final class AppHibernationService extends SystemService { final Map packageStates = mUserStates.get(userId); final UserLevelState pkgState = packageStates.get(packageName); if (pkgState == null) { - throw new IllegalArgumentException( - String.format("Package %s is not installed for user %s", - packageName, userId)); + Slog.e(TAG, String.format("Package %s is not installed for user %s", + packageName, userId)); + return false; } return pkgState.hibernated; } @@ -275,9 +275,9 @@ public final class AppHibernationService extends SystemService { final Map packageStates = mUserStates.get(userId); final UserLevelState pkgState = packageStates.get(packageName); if (pkgState == null) { - throw new IllegalArgumentException( - String.format("Package %s is not installed for user %s", - packageName, userId)); + Slog.e(TAG, String.format("Package %s is not installed for user %s", + packageName, userId)); + return; } if (pkgState.hibernated == isHibernating) { @@ -320,8 +320,8 @@ public final class AppHibernationService extends SystemService { synchronized (mLock) { GlobalLevelState state = mGlobalHibernationStates.get(packageName); if (state == null) { - throw new IllegalArgumentException( - String.format("Package %s is not installed for any user", packageName)); + Slog.e(TAG, String.format("Package %s is not installed for any user", packageName)); + return; } if (state.hibernated != isHibernating) { if (isHibernating) {