From df38221d30f3363b5ad8edfb76a1e63af2f9922b Mon Sep 17 00:00:00 2001 From: Matthew Sedam Date: Wed, 17 May 2023 18:33:48 +0000 Subject: [PATCH] Properly handle HSUM no-user in the ContextHubService When the system is in Headless System User Mode (HSUM), the system runs the UI as user 0. User 0 cannot have a credential and the device is automatically unlocked. Any user can change the microphone setting. Bug: 278961972 Test: Run the MicDisableSettingsTest (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:8ff589c9120113b2b61c27accd319cd04cef5980) Merged-In: I1d24b1cfe2222868670e4b8569229f1ed0ad378b Change-Id: I1d24b1cfe2222868670e4b8569229f1ed0ad378b --- .../location/contexthub/ContextHubService.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubService.java b/services/core/java/com/android/server/location/contexthub/ContextHubService.java index 5f783742bd266..93c66a19c89d1 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubService.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubService.java @@ -52,6 +52,7 @@ import android.os.ResultReceiver; import android.os.ShellCallback; import android.os.SystemClock; import android.os.UserHandle; +import android.os.UserManager; import android.provider.Settings; import android.util.Log; import android.util.Pair; @@ -169,6 +170,8 @@ public class ContextHubService extends IContextHubService.Stub { private SensorPrivacyManagerInternal mSensorPrivacyManagerInternal; + private UserManager mUserManager = null; + private final Map mLastRestartTimestampMap = new HashMap<>(); /** @@ -491,6 +494,14 @@ public class ContextHubService extends IContextHubService.Stub { return; } + if (mUserManager == null) { + mUserManager = mContext.getSystemService(UserManager.class); + if (mUserManager == null) { + Log.e(TAG, "Unable to get the UserManager service"); + return; + } + } + sendMicrophoneDisableSettingUpdateForCurrentUser(); if (mSensorPrivacyManagerInternal == null) { Log.e(TAG, "Unable to add a sensor privacy listener for all users"); @@ -499,8 +510,9 @@ public class ContextHubService extends IContextHubService.Stub { mSensorPrivacyManagerInternal.addSensorPrivacyListenerForAllUsers( SensorPrivacyManager.Sensors.MICROPHONE, (userId, enabled) -> { - if (userId == getCurrentUserId()) { - Log.d(TAG, "User: " + userId + "mic privacy: " + enabled); + // If we are in HSUM mode, any user can change the microphone setting + if (mUserManager.isHeadlessSystemUserMode() || userId == getCurrentUserId()) { + Log.d(TAG, "User: " + userId + " mic privacy: " + enabled); sendMicrophoneDisableSettingUpdate(enabled); } });