Loading packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataFilter.kt +24 −3 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.systemui.media.controls.pipeline import android.content.Context import android.content.pm.UserInfo import android.os.SystemProperties import android.util.Log import com.android.internal.annotations.KeepForWeakReference Loading Loading @@ -88,7 +89,11 @@ constructor( private val userTrackerCallback = object : UserTracker.Callback { override fun onUserChanged(newUser: Int, userContext: Context) { handleUserSwitched(newUser) handleUserSwitched() } override fun onProfilesChanged(profiles: List<UserInfo>) { handleProfileChanged() } } Loading @@ -109,7 +114,10 @@ constructor( } allEntries.put(key, data) if (!lockscreenUserManager.isCurrentProfile(data.userId)) { if ( !lockscreenUserManager.isCurrentProfile(data.userId) || !lockscreenUserManager.isProfileAvailable(data.userId) ) { return } Loading Loading @@ -231,7 +239,20 @@ constructor( } @VisibleForTesting internal fun handleUserSwitched(id: Int) { internal fun handleProfileChanged() { // TODO(b/317221348) re-add media removed when profile is available. allEntries.forEach { (key, data) -> if (!lockscreenUserManager.isProfileAvailable(data.userId)) { // Only remove media when the profile is unavailable. if (DEBUG) Log.d(TAG, "Removing $key after profile change") userEntries.remove(key, data) listeners.forEach { listener -> listener.onMediaDataRemoved(key) } } } } @VisibleForTesting internal fun handleUserSwitched() { // If the user changes, remove all current MediaData objects and inform listeners val listenersCopy = listeners val keyCopy = userEntries.keys.toMutableList() Loading packages/SystemUI/src/com/android/systemui/settings/UserTrackerImpl.kt +9 −1 Original line number Diff line number Diff line Loading @@ -135,6 +135,10 @@ open class UserTrackerImpl internal constructor( val filter = IntentFilter().apply { addAction(Intent.ACTION_LOCALE_CHANGED) addAction(Intent.ACTION_USER_INFO_CHANGED) addAction(Intent.ACTION_PROFILE_ADDED) addAction(Intent.ACTION_PROFILE_REMOVED) addAction(Intent.ACTION_PROFILE_AVAILABLE) addAction(Intent.ACTION_PROFILE_UNAVAILABLE) // These get called when a managed profile goes in or out of quiet mode. addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE) addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE) Loading @@ -157,7 +161,11 @@ open class UserTrackerImpl internal constructor( Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE, Intent.ACTION_MANAGED_PROFILE_ADDED, Intent.ACTION_MANAGED_PROFILE_REMOVED, Intent.ACTION_MANAGED_PROFILE_UNLOCKED -> { Intent.ACTION_MANAGED_PROFILE_UNLOCKED, Intent.ACTION_PROFILE_ADDED, Intent.ACTION_PROFILE_REMOVED, Intent.ACTION_PROFILE_AVAILABLE, Intent.ACTION_PROFILE_UNAVAILABLE -> { handleProfilesChanged() } } Loading packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManager.java +7 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,13 @@ public interface NotificationLockscreenUserManager { boolean isCurrentProfile(int userId); /** * * @param userId user Id * @return true if user profile is running. */ boolean isProfileAvailable(int userId); /** Adds a listener to be notified when the current user changes. */ void addUserChangedListener(UserChangedListener listener); Loading packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java +7 −0 Original line number Diff line number Diff line Loading @@ -461,6 +461,13 @@ public class NotificationLockscreenUserManagerImpl implements } } @SuppressLint("AndroidFrameworkRequiresPermission") public boolean isProfileAvailable(int userId) { synchronized (mLock) { return mUserManager.isUserRunning(userId); } } private void setShowLockscreenNotifications(boolean show) { mShowLockscreenNotifications = show; } Loading packages/SystemUI/tests/src/com/android/systemui/media/controls/pipeline/MediaDataFilterTest.kt +29 −1 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ private const val KEY = "TEST_KEY" private const val KEY_ALT = "TEST_KEY_2" private const val USER_MAIN = 0 private const val USER_GUEST = 10 private const val PRIVATE_PROFILE = 12 private const val PACKAGE = "PKG" private val INSTANCE_ID = InstanceId.fakeInstanceId(123)!! private const val APP_UID = 99 Loading Loading @@ -82,6 +83,7 @@ class MediaDataFilterTest : SysuiTestCase() { private lateinit var mediaDataFilter: MediaDataFilter private lateinit var dataMain: MediaData private lateinit var dataGuest: MediaData private lateinit var dataPrivateProfile: MediaData private val clock = FakeSystemClock() @Before Loading Loading @@ -115,6 +117,7 @@ class MediaDataFilterTest : SysuiTestCase() { appUid = APP_UID ) dataGuest = dataMain.copy(userId = USER_GUEST) dataPrivateProfile = dataMain.copy(userId = PRIVATE_PROFILE) whenever(smartspaceData.targetId).thenReturn(SMARTSPACE_KEY) whenever(smartspaceData.isActive).thenReturn(true) Loading @@ -130,8 +133,19 @@ class MediaDataFilterTest : SysuiTestCase() { private fun setUser(id: Int) { whenever(lockscreenUserManager.isCurrentProfile(anyInt())).thenReturn(false) whenever(lockscreenUserManager.isProfileAvailable(anyInt())).thenReturn(false) whenever(lockscreenUserManager.isCurrentProfile(eq(id))).thenReturn(true) mediaDataFilter.handleUserSwitched(id) whenever(lockscreenUserManager.isProfileAvailable(eq(id))).thenReturn(true) whenever(lockscreenUserManager.isProfileAvailable(eq(PRIVATE_PROFILE))).thenReturn(true) mediaDataFilter.handleUserSwitched() } private fun setPrivateProfileUnavailable() { whenever(lockscreenUserManager.isCurrentProfile(anyInt())).thenReturn(false) whenever(lockscreenUserManager.isCurrentProfile(eq(USER_MAIN))).thenReturn(true) whenever(lockscreenUserManager.isCurrentProfile(eq(PRIVATE_PROFILE))).thenReturn(true) whenever(lockscreenUserManager.isProfileAvailable(eq(PRIVATE_PROFILE))).thenReturn(false) mediaDataFilter.handleProfileChanged() } @Test Loading Loading @@ -205,6 +219,20 @@ class MediaDataFilterTest : SysuiTestCase() { .onMediaDataLoaded(eq(KEY), any(), eq(dataMain), anyBoolean(), anyInt(), anyBoolean()) } @Test fun testOnProfileChanged_profileUnavailable_loadControls() { // GIVEN that we had some media for both profiles mediaDataFilter.onMediaDataLoaded(KEY, null, dataMain) mediaDataFilter.onMediaDataLoaded(KEY_ALT, null, dataPrivateProfile) reset(listener) // and we change profile status setPrivateProfileUnavailable() // THEN we should add the private profile media verify(listener).onMediaDataRemoved(eq(KEY_ALT)) } @Test fun hasAnyMedia_noMediaSet_returnsFalse() { assertThat(mediaDataFilter.hasAnyMedia()).isFalse() Loading Loading
packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataFilter.kt +24 −3 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.systemui.media.controls.pipeline import android.content.Context import android.content.pm.UserInfo import android.os.SystemProperties import android.util.Log import com.android.internal.annotations.KeepForWeakReference Loading Loading @@ -88,7 +89,11 @@ constructor( private val userTrackerCallback = object : UserTracker.Callback { override fun onUserChanged(newUser: Int, userContext: Context) { handleUserSwitched(newUser) handleUserSwitched() } override fun onProfilesChanged(profiles: List<UserInfo>) { handleProfileChanged() } } Loading @@ -109,7 +114,10 @@ constructor( } allEntries.put(key, data) if (!lockscreenUserManager.isCurrentProfile(data.userId)) { if ( !lockscreenUserManager.isCurrentProfile(data.userId) || !lockscreenUserManager.isProfileAvailable(data.userId) ) { return } Loading Loading @@ -231,7 +239,20 @@ constructor( } @VisibleForTesting internal fun handleUserSwitched(id: Int) { internal fun handleProfileChanged() { // TODO(b/317221348) re-add media removed when profile is available. allEntries.forEach { (key, data) -> if (!lockscreenUserManager.isProfileAvailable(data.userId)) { // Only remove media when the profile is unavailable. if (DEBUG) Log.d(TAG, "Removing $key after profile change") userEntries.remove(key, data) listeners.forEach { listener -> listener.onMediaDataRemoved(key) } } } } @VisibleForTesting internal fun handleUserSwitched() { // If the user changes, remove all current MediaData objects and inform listeners val listenersCopy = listeners val keyCopy = userEntries.keys.toMutableList() Loading
packages/SystemUI/src/com/android/systemui/settings/UserTrackerImpl.kt +9 −1 Original line number Diff line number Diff line Loading @@ -135,6 +135,10 @@ open class UserTrackerImpl internal constructor( val filter = IntentFilter().apply { addAction(Intent.ACTION_LOCALE_CHANGED) addAction(Intent.ACTION_USER_INFO_CHANGED) addAction(Intent.ACTION_PROFILE_ADDED) addAction(Intent.ACTION_PROFILE_REMOVED) addAction(Intent.ACTION_PROFILE_AVAILABLE) addAction(Intent.ACTION_PROFILE_UNAVAILABLE) // These get called when a managed profile goes in or out of quiet mode. addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE) addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE) Loading @@ -157,7 +161,11 @@ open class UserTrackerImpl internal constructor( Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE, Intent.ACTION_MANAGED_PROFILE_ADDED, Intent.ACTION_MANAGED_PROFILE_REMOVED, Intent.ACTION_MANAGED_PROFILE_UNLOCKED -> { Intent.ACTION_MANAGED_PROFILE_UNLOCKED, Intent.ACTION_PROFILE_ADDED, Intent.ACTION_PROFILE_REMOVED, Intent.ACTION_PROFILE_AVAILABLE, Intent.ACTION_PROFILE_UNAVAILABLE -> { handleProfilesChanged() } } Loading
packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManager.java +7 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,13 @@ public interface NotificationLockscreenUserManager { boolean isCurrentProfile(int userId); /** * * @param userId user Id * @return true if user profile is running. */ boolean isProfileAvailable(int userId); /** Adds a listener to be notified when the current user changes. */ void addUserChangedListener(UserChangedListener listener); Loading
packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java +7 −0 Original line number Diff line number Diff line Loading @@ -461,6 +461,13 @@ public class NotificationLockscreenUserManagerImpl implements } } @SuppressLint("AndroidFrameworkRequiresPermission") public boolean isProfileAvailable(int userId) { synchronized (mLock) { return mUserManager.isUserRunning(userId); } } private void setShowLockscreenNotifications(boolean show) { mShowLockscreenNotifications = show; } Loading
packages/SystemUI/tests/src/com/android/systemui/media/controls/pipeline/MediaDataFilterTest.kt +29 −1 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ private const val KEY = "TEST_KEY" private const val KEY_ALT = "TEST_KEY_2" private const val USER_MAIN = 0 private const val USER_GUEST = 10 private const val PRIVATE_PROFILE = 12 private const val PACKAGE = "PKG" private val INSTANCE_ID = InstanceId.fakeInstanceId(123)!! private const val APP_UID = 99 Loading Loading @@ -82,6 +83,7 @@ class MediaDataFilterTest : SysuiTestCase() { private lateinit var mediaDataFilter: MediaDataFilter private lateinit var dataMain: MediaData private lateinit var dataGuest: MediaData private lateinit var dataPrivateProfile: MediaData private val clock = FakeSystemClock() @Before Loading Loading @@ -115,6 +117,7 @@ class MediaDataFilterTest : SysuiTestCase() { appUid = APP_UID ) dataGuest = dataMain.copy(userId = USER_GUEST) dataPrivateProfile = dataMain.copy(userId = PRIVATE_PROFILE) whenever(smartspaceData.targetId).thenReturn(SMARTSPACE_KEY) whenever(smartspaceData.isActive).thenReturn(true) Loading @@ -130,8 +133,19 @@ class MediaDataFilterTest : SysuiTestCase() { private fun setUser(id: Int) { whenever(lockscreenUserManager.isCurrentProfile(anyInt())).thenReturn(false) whenever(lockscreenUserManager.isProfileAvailable(anyInt())).thenReturn(false) whenever(lockscreenUserManager.isCurrentProfile(eq(id))).thenReturn(true) mediaDataFilter.handleUserSwitched(id) whenever(lockscreenUserManager.isProfileAvailable(eq(id))).thenReturn(true) whenever(lockscreenUserManager.isProfileAvailable(eq(PRIVATE_PROFILE))).thenReturn(true) mediaDataFilter.handleUserSwitched() } private fun setPrivateProfileUnavailable() { whenever(lockscreenUserManager.isCurrentProfile(anyInt())).thenReturn(false) whenever(lockscreenUserManager.isCurrentProfile(eq(USER_MAIN))).thenReturn(true) whenever(lockscreenUserManager.isCurrentProfile(eq(PRIVATE_PROFILE))).thenReturn(true) whenever(lockscreenUserManager.isProfileAvailable(eq(PRIVATE_PROFILE))).thenReturn(false) mediaDataFilter.handleProfileChanged() } @Test Loading Loading @@ -205,6 +219,20 @@ class MediaDataFilterTest : SysuiTestCase() { .onMediaDataLoaded(eq(KEY), any(), eq(dataMain), anyBoolean(), anyInt(), anyBoolean()) } @Test fun testOnProfileChanged_profileUnavailable_loadControls() { // GIVEN that we had some media for both profiles mediaDataFilter.onMediaDataLoaded(KEY, null, dataMain) mediaDataFilter.onMediaDataLoaded(KEY_ALT, null, dataPrivateProfile) reset(listener) // and we change profile status setPrivateProfileUnavailable() // THEN we should add the private profile media verify(listener).onMediaDataRemoved(eq(KEY_ALT)) } @Test fun hasAnyMedia_noMediaSet_returnsFalse() { assertThat(mediaDataFilter.hasAnyMedia()).isFalse() Loading