From 9ac468fc359a1b548455c35f9b85919968b2d5b6 Mon Sep 17 00:00:00 2001 From: Zhen Zhang Date: Thu, 29 Apr 2021 15:50:25 -0700 Subject: [PATCH] Clear calling identity before calling into AMS Clear calling identity before calling into AMS in unhibernatePackageForUser() to make sure we are calling as system user and avoid security exception Bug: 186701008 Test: built and flashed to wembley device, then run adb shell cmd app_hibernation set-state PACKAGE_NAME false. No exceptions found. Test: atest AppHibernationServiceTest Change-Id: Icf0c72b85f4c611c84129a6fb9425f4344b4681b --- .../android/server/apphibernation/AppHibernationService.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/apphibernation/AppHibernationService.java b/services/core/java/com/android/server/apphibernation/AppHibernationService.java index 52388ff2877c5..9396241c3f982 100644 --- a/services/core/java/com/android/server/apphibernation/AppHibernationService.java +++ b/services/core/java/com/android/server/apphibernation/AppHibernationService.java @@ -393,6 +393,7 @@ public final class AppHibernationService extends SystemService { Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "unhibernatePackage"); pkgState.hibernated = false; pkgState.lastUnhibernatedMs = System.currentTimeMillis(); + final long caller = Binder.clearCallingIdentity(); // Deliver LOCKED_BOOT_COMPLETE AND BOOT_COMPLETE broadcast so app can re-register // their alarms/jobs/etc. try { @@ -435,8 +436,10 @@ public final class AppHibernationService extends SystemService { userId); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); + } finally { + Binder.restoreCallingIdentity(caller); + Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); } - Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); } /**