Merge "Smartspace - Listen for SHOW_NOTIFICATIONS setting" into tm-dev am: 39630cfbb0
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18052137 Change-Id: I0ef8e75fc6444519c026fbe86f3caa1bf7f6d921 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -28,7 +28,8 @@ import android.database.ContentObserver
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.UserHandle
|
import android.os.UserHandle
|
||||||
import android.provider.Settings
|
import android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS
|
||||||
|
import android.provider.Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@@ -85,6 +86,7 @@ class LockscreenSmartspaceController @Inject constructor(
|
|||||||
// Smartspace can be used on multiple displays, such as when the user casts their screen
|
// Smartspace can be used on multiple displays, such as when the user casts their screen
|
||||||
private var smartspaceViews = mutableSetOf<SmartspaceView>()
|
private var smartspaceViews = mutableSetOf<SmartspaceView>()
|
||||||
|
|
||||||
|
private var showNotifications = false
|
||||||
private var showSensitiveContentForCurrentUser = false
|
private var showSensitiveContentForCurrentUser = false
|
||||||
private var showSensitiveContentForManagedUser = false
|
private var showSensitiveContentForManagedUser = false
|
||||||
private var managedUserHandle: UserHandle? = null
|
private var managedUserHandle: UserHandle? = null
|
||||||
@@ -233,7 +235,13 @@ class LockscreenSmartspaceController @Inject constructor(
|
|||||||
deviceProvisionedController.removeCallback(deviceProvisionedListener)
|
deviceProvisionedController.removeCallback(deviceProvisionedListener)
|
||||||
userTracker.addCallback(userTrackerCallback, uiExecutor)
|
userTracker.addCallback(userTrackerCallback, uiExecutor)
|
||||||
contentResolver.registerContentObserver(
|
contentResolver.registerContentObserver(
|
||||||
secureSettings.getUriFor(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS),
|
secureSettings.getUriFor(LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS),
|
||||||
|
true,
|
||||||
|
settingsObserver,
|
||||||
|
UserHandle.USER_ALL
|
||||||
|
)
|
||||||
|
contentResolver.registerContentObserver(
|
||||||
|
secureSettings.getUriFor(LOCK_SCREEN_SHOW_NOTIFICATIONS),
|
||||||
true,
|
true,
|
||||||
settingsObserver,
|
settingsObserver,
|
||||||
UserHandle.USER_ALL
|
UserHandle.USER_ALL
|
||||||
@@ -286,6 +294,9 @@ class LockscreenSmartspaceController @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun filterSmartspaceTarget(t: SmartspaceTarget): Boolean {
|
private fun filterSmartspaceTarget(t: SmartspaceTarget): Boolean {
|
||||||
|
if (!showNotifications) {
|
||||||
|
return t.getFeatureType() == SmartspaceTarget.FEATURE_WEATHER
|
||||||
|
}
|
||||||
return when (t.userHandle) {
|
return when (t.userHandle) {
|
||||||
userTracker.userHandle -> {
|
userTracker.userHandle -> {
|
||||||
!t.isSensitive || showSensitiveContentForCurrentUser
|
!t.isSensitive || showSensitiveContentForCurrentUser
|
||||||
@@ -310,16 +321,26 @@ class LockscreenSmartspaceController @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun reloadSmartspace() {
|
private fun reloadSmartspace() {
|
||||||
val setting = Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS
|
showNotifications = secureSettings.getIntForUser(
|
||||||
|
LOCK_SCREEN_SHOW_NOTIFICATIONS,
|
||||||
|
0,
|
||||||
|
userTracker.userId
|
||||||
|
) == 1
|
||||||
|
|
||||||
showSensitiveContentForCurrentUser =
|
showSensitiveContentForCurrentUser = secureSettings.getIntForUser(
|
||||||
secureSettings.getIntForUser(setting, 0, userTracker.userId) == 1
|
LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
|
||||||
|
0,
|
||||||
|
userTracker.userId
|
||||||
|
) == 1
|
||||||
|
|
||||||
managedUserHandle = getWorkProfileUser()
|
managedUserHandle = getWorkProfileUser()
|
||||||
val managedId = managedUserHandle?.identifier
|
val managedId = managedUserHandle?.identifier
|
||||||
if (managedId != null) {
|
if (managedId != null) {
|
||||||
showSensitiveContentForManagedUser =
|
showSensitiveContentForManagedUser = secureSettings.getIntForUser(
|
||||||
secureSettings.getIntForUser(setting, 0, managedId) == 1
|
LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
|
||||||
|
0,
|
||||||
|
managedId
|
||||||
|
) == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
session?.requestSmartspaceUpdate()
|
session?.requestSmartspaceUpdate()
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
|
|||||||
private val execution = FakeExecution()
|
private val execution = FakeExecution()
|
||||||
private val fakeParent = FrameLayout(context)
|
private val fakeParent = FrameLayout(context)
|
||||||
private val fakePrivateLockscreenSettingUri = Uri.Builder().appendPath("test").build()
|
private val fakePrivateLockscreenSettingUri = Uri.Builder().appendPath("test").build()
|
||||||
|
private val fakeNotifOnLockscreenSettingUri = Uri.Builder().appendPath("notif").build()
|
||||||
|
|
||||||
private val userHandlePrimary: UserHandle = UserHandle(0)
|
private val userHandlePrimary: UserHandle = UserHandle(0)
|
||||||
private val userHandleManaged: UserHandle = UserHandle(2)
|
private val userHandleManaged: UserHandle = UserHandle(2)
|
||||||
@@ -149,6 +150,8 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
|
|||||||
|
|
||||||
`when`(secureSettings.getUriFor(PRIVATE_LOCKSCREEN_SETTING))
|
`when`(secureSettings.getUriFor(PRIVATE_LOCKSCREEN_SETTING))
|
||||||
.thenReturn(fakePrivateLockscreenSettingUri)
|
.thenReturn(fakePrivateLockscreenSettingUri)
|
||||||
|
`when`(secureSettings.getUriFor(NOTIF_ON_LOCKSCREEN_SETTING))
|
||||||
|
.thenReturn(fakeNotifOnLockscreenSettingUri)
|
||||||
`when`(smartspaceManager.createSmartspaceSession(any())).thenReturn(smartspaceSession)
|
`when`(smartspaceManager.createSmartspaceSession(any())).thenReturn(smartspaceSession)
|
||||||
`when`(plugin.getView(any())).thenReturn(createSmartspaceView(), createSmartspaceView())
|
`when`(plugin.getView(any())).thenReturn(createSmartspaceView(), createSmartspaceView())
|
||||||
`when`(userTracker.userProfiles).thenReturn(userList)
|
`when`(userTracker.userProfiles).thenReturn(userList)
|
||||||
@@ -160,6 +163,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
|
|||||||
setAllowPrivateNotifications(userHandlePrimary, true)
|
setAllowPrivateNotifications(userHandlePrimary, true)
|
||||||
setAllowPrivateNotifications(userHandleManaged, true)
|
setAllowPrivateNotifications(userHandleManaged, true)
|
||||||
setAllowPrivateNotifications(userHandleSecondary, true)
|
setAllowPrivateNotifications(userHandleSecondary, true)
|
||||||
|
setShowNotifications(userHandlePrimary, true)
|
||||||
|
|
||||||
controller = LockscreenSmartspaceController(
|
controller = LockscreenSmartspaceController(
|
||||||
context,
|
context,
|
||||||
@@ -340,6 +344,26 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
|
|||||||
verify(plugin).onTargetsAvailable(eq(targets))
|
verify(plugin).onTargetsAvailable(eq(targets))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testAllTargetsAreFilteredExceptWeatherWhenNotificationsAreDisabled() {
|
||||||
|
// GIVEN the active user doesn't allow any notifications on lockscreen
|
||||||
|
setShowNotifications(userHandlePrimary, false)
|
||||||
|
connectSession()
|
||||||
|
|
||||||
|
// WHEN we receive a list of targets
|
||||||
|
val targets = listOf(
|
||||||
|
makeTarget(1, userHandlePrimary, isSensitive = true),
|
||||||
|
makeTarget(2, userHandlePrimary),
|
||||||
|
makeTarget(3, userHandleManaged),
|
||||||
|
makeTarget(4, userHandlePrimary, featureType = SmartspaceTarget.FEATURE_WEATHER)
|
||||||
|
)
|
||||||
|
|
||||||
|
sessionListener.onTargetsAvailable(targets)
|
||||||
|
|
||||||
|
// THEN all non-sensitive content is still shown
|
||||||
|
verify(plugin).onTargetsAvailable(eq(listOf(targets[3])))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testSensitiveTargetsAreFilteredOutForAppropriateUsers() {
|
fun testSensitiveTargetsAreFilteredOutForAppropriateUsers() {
|
||||||
// GIVEN the active and managed users don't allow sensitive lockscreen content
|
// GIVEN the active and managed users don't allow sensitive lockscreen content
|
||||||
@@ -391,6 +415,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
|
|||||||
fun testRecognizeSwitchToSecondaryUser() {
|
fun testRecognizeSwitchToSecondaryUser() {
|
||||||
// GIVEN an inactive secondary user that doesn't allow sensitive content
|
// GIVEN an inactive secondary user that doesn't allow sensitive content
|
||||||
setAllowPrivateNotifications(userHandleSecondary, false)
|
setAllowPrivateNotifications(userHandleSecondary, false)
|
||||||
|
setShowNotifications(userHandleSecondary, true)
|
||||||
connectSession()
|
connectSession()
|
||||||
|
|
||||||
// WHEN the secondary user becomes the active user
|
// WHEN the secondary user becomes the active user
|
||||||
@@ -518,13 +543,15 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
|
|||||||
fun makeTarget(
|
fun makeTarget(
|
||||||
id: Int,
|
id: Int,
|
||||||
userHandle: UserHandle,
|
userHandle: UserHandle,
|
||||||
isSensitive: Boolean = false
|
isSensitive: Boolean = false,
|
||||||
|
featureType: Int = 0
|
||||||
): SmartspaceTarget {
|
): SmartspaceTarget {
|
||||||
return SmartspaceTarget.Builder(
|
return SmartspaceTarget.Builder(
|
||||||
"target$id",
|
"target$id",
|
||||||
ComponentName("testpackage", "testclass$id"),
|
ComponentName("testpackage", "testclass$id"),
|
||||||
userHandle)
|
userHandle)
|
||||||
.setSensitive(isSensitive)
|
.setSensitive(isSensitive)
|
||||||
|
.setFeatureType(featureType)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,6 +563,14 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
|
|||||||
).thenReturn(if (value) 1 else 0)
|
).thenReturn(if (value) 1 else 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setShowNotifications(user: UserHandle, value: Boolean) {
|
||||||
|
`when`(secureSettings.getIntForUser(
|
||||||
|
eq(NOTIF_ON_LOCKSCREEN_SETTING),
|
||||||
|
anyInt(),
|
||||||
|
eq(user.identifier))
|
||||||
|
).thenReturn(if (value) 1 else 0)
|
||||||
|
}
|
||||||
|
|
||||||
private fun createSmartspaceView(): SmartspaceView {
|
private fun createSmartspaceView(): SmartspaceView {
|
||||||
return spy(object : View(context), SmartspaceView {
|
return spy(object : View(context), SmartspaceView {
|
||||||
override fun registerDataProvider(plugin: BcSmartspaceDataPlugin?) {
|
override fun registerDataProvider(plugin: BcSmartspaceDataPlugin?) {
|
||||||
@@ -574,3 +609,5 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
|
|||||||
|
|
||||||
private const val PRIVATE_LOCKSCREEN_SETTING =
|
private const val PRIVATE_LOCKSCREEN_SETTING =
|
||||||
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS
|
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS
|
||||||
|
private const val NOTIF_ON_LOCKSCREEN_SETTING =
|
||||||
|
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS
|
||||||
|
|||||||
Reference in New Issue
Block a user