From 29c75abfe17c603cf075075beda32eb5d163d6c0 Mon Sep 17 00:00:00 2001 From: Ram Periathiruvadi Date: Tue, 25 Feb 2020 10:12:44 -0800 Subject: [PATCH] Resolve trust agents on USER_STARTED in addition to USER_ADDED. ACTION_USER_ADDED is a broadcast that is sent once when the user is created. TrustManagerService resolves the enabled trust agents for an user only when the user is created. However, if there is a reboot or power loss before the broadcast is received, the trust agents are never resolved for that user. This change also registers for ACTION_USER_STARTED, so the service checks for enabled trust agents on every boot. If the trust agents have been already resolved and initialized for that users, there is already a Secure Settings key (TRUST_AGENTS_INITIALIZED) that is turned on, so we wouldn't be doing this more than once per user. Bug: 150145767 Test: TrustManagerService resolves trust agents only once - either on USER_ADDED or USER_STARTED. Change-Id: I83c2dd02d4b476f8b85af1aa4d9d0c77095207ce --- .../java/com/android/server/trust/TrustManagerService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/trust/TrustManagerService.java b/services/core/java/com/android/server/trust/TrustManagerService.java index 7408dd40b5cad..ef54d0477615f 100644 --- a/services/core/java/com/android/server/trust/TrustManagerService.java +++ b/services/core/java/com/android/server/trust/TrustManagerService.java @@ -1389,7 +1389,8 @@ public class TrustManagerService extends SystemService { if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals(action)) { refreshAgentList(getSendingUserId()); updateDevicePolicyFeatures(); - } else if (Intent.ACTION_USER_ADDED.equals(action)) { + } else if (Intent.ACTION_USER_ADDED.equals(action) || Intent.ACTION_USER_STARTED.equals( + action)) { int userId = getUserId(intent); if (userId > 0) { maybeEnableFactoryTrustAgents(mLockPatternUtils, userId); @@ -1430,6 +1431,7 @@ public class TrustManagerService extends SystemService { filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); filter.addAction(Intent.ACTION_USER_ADDED); filter.addAction(Intent.ACTION_USER_REMOVED); + filter.addAction(Intent.ACTION_USER_STARTED); context.registerReceiverAsUser(this, UserHandle.ALL, filter,