Merge "Add flag gate to show only indicator dot" into sc-dev

This commit is contained in:
Nate Myren
2021-05-06 02:11:45 +00:00
committed by Android (Google) Code Review
3 changed files with 22 additions and 10 deletions

View File

@@ -31,6 +31,8 @@ interface StatusEvent {
val priority: Int val priority: Int
// Whether or not to force the status bar open and show a dot // Whether or not to force the status bar open and show a dot
val forceVisible: Boolean val forceVisible: Boolean
// Whether or not to show an animation for this event
val showAnimation: Boolean
val viewCreator: (context: Context) -> View val viewCreator: (context: Context) -> View
// Update this event with values from another event. // Update this event with values from another event.
@@ -47,6 +49,7 @@ interface StatusEvent {
class BatteryEvent : StatusEvent { class BatteryEvent : StatusEvent {
override val priority = 50 override val priority = 50
override val forceVisible = false override val forceVisible = false
override val showAnimation = true
override val viewCreator: (context: Context) -> View = { context -> override val viewCreator: (context: Context) -> View = { context ->
val iv = ImageView(context) val iv = ImageView(context)
@@ -59,7 +62,7 @@ class BatteryEvent : StatusEvent {
return javaClass.simpleName return javaClass.simpleName
} }
} }
class PrivacyEvent : StatusEvent { class PrivacyEvent(override val showAnimation: Boolean = true) : StatusEvent {
override val priority = 100 override val priority = 100
override val forceVisible = true override val forceVisible = true
var privacyItems: List<PrivacyItem> = listOf() var privacyItems: List<PrivacyItem> = listOf()

View File

@@ -16,11 +16,13 @@
package com.android.systemui.statusbar.events package com.android.systemui.statusbar.events
import android.os.SystemClock import android.provider.DeviceConfig
import android.provider.DeviceConfig.NAMESPACE_PRIVACY
import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.privacy.PrivacyItem import com.android.systemui.privacy.PrivacyItem
import com.android.systemui.privacy.PrivacyItemController import com.android.systemui.privacy.PrivacyItemController
import com.android.systemui.statusbar.policy.BatteryController import com.android.systemui.statusbar.policy.BatteryController
import com.android.systemui.util.time.SystemClock
import javax.inject.Inject import javax.inject.Inject
/** /**
@@ -29,6 +31,7 @@ import javax.inject.Inject
*/ */
@SysUISingleton @SysUISingleton
class SystemEventCoordinator @Inject constructor( class SystemEventCoordinator @Inject constructor(
private val systemClock: SystemClock,
private val batteryController: BatteryController, private val batteryController: BatteryController,
private val privacyController: PrivacyItemController private val privacyController: PrivacyItemController
) { ) {
@@ -61,9 +64,9 @@ class SystemEventCoordinator @Inject constructor(
} }
fun notifyPrivacyItemsChanged(showAnimation: Boolean = true) { fun notifyPrivacyItemsChanged(showAnimation: Boolean = true) {
val event = PrivacyEvent() val event = PrivacyEvent(showAnimation)
event.privacyItems = privacyStateListener.currentPrivacyItems event.privacyItems = privacyStateListener.currentPrivacyItems
scheduler.onStatusEvent(event, showAnimation) scheduler.onStatusEvent(event)
} }
private val batteryStateListener = object : BatteryController.BatteryStateChangeCallback { private val batteryStateListener = object : BatteryController.BatteryStateChangeCallback {
@@ -92,14 +95,14 @@ class SystemEventCoordinator @Inject constructor(
private val privacyStateListener = object : PrivacyItemController.Callback { private val privacyStateListener = object : PrivacyItemController.Callback {
var currentPrivacyItems = listOf<PrivacyItem>() var currentPrivacyItems = listOf<PrivacyItem>()
var previousPrivacyItems = listOf<PrivacyItem>() var previousPrivacyItems = listOf<PrivacyItem>()
var timeLastEmpty = SystemClock.elapsedRealtime() var timeLastEmpty = systemClock.elapsedRealtime()
override fun onPrivacyItemsChanged(privacyItems: List<PrivacyItem>) { override fun onPrivacyItemsChanged(privacyItems: List<PrivacyItem>) {
if (uniqueItemsMatch(privacyItems, currentPrivacyItems)) { if (uniqueItemsMatch(privacyItems, currentPrivacyItems)) {
return return
} else if (privacyItems.isEmpty()) { } else if (privacyItems.isEmpty()) {
previousPrivacyItems = currentPrivacyItems previousPrivacyItems = currentPrivacyItems
timeLastEmpty = SystemClock.elapsedRealtime() timeLastEmpty = systemClock.elapsedRealtime()
} }
currentPrivacyItems = privacyItems currentPrivacyItems = privacyItems
@@ -110,8 +113,9 @@ class SystemEventCoordinator @Inject constructor(
if (currentPrivacyItems.isEmpty()) { if (currentPrivacyItems.isEmpty()) {
notifyPrivacyItemsEmpty() notifyPrivacyItemsEmpty()
} else { } else {
val showAnimation = !uniqueItemsMatch(currentPrivacyItems, previousPrivacyItems) || val showAnimation = isChipAnimationEnabled() &&
SystemClock.elapsedRealtime() - timeLastEmpty >= DEBOUNCE_TIME (!uniqueItemsMatch(currentPrivacyItems, previousPrivacyItems) ||
systemClock.elapsedRealtime() - timeLastEmpty >= DEBOUNCE_TIME)
notifyPrivacyItemsChanged(showAnimation) notifyPrivacyItemsChanged(showAnimation)
} }
} }
@@ -121,8 +125,13 @@ class SystemEventCoordinator @Inject constructor(
return one.map { it.application.uid to it.privacyType.permGroupName }.toSet() == return one.map { it.application.uid to it.privacyType.permGroupName }.toSet() ==
two.map { it.application.uid to it.privacyType.permGroupName }.toSet() two.map { it.application.uid to it.privacyType.permGroupName }.toSet()
} }
private fun isChipAnimationEnabled(): Boolean {
return DeviceConfig.getBoolean(NAMESPACE_PRIVACY, CHIP_ANIMATION_ENABLED, true)
}
} }
} }
private const val DEBOUNCE_TIME = 3000L private const val DEBOUNCE_TIME = 3000L
private const val CHIP_ANIMATION_ENABLED = "privacy_chip_animation_enabled"
private const val TAG = "SystemEventCoordinator" private const val TAG = "SystemEventCoordinator"

View File

@@ -90,7 +90,7 @@ class SystemStatusAnimationScheduler @Inject constructor(
coordinator.attachScheduler(this) coordinator.attachScheduler(this)
} }
fun onStatusEvent(event: StatusEvent, showAnimation: Boolean = true) { fun onStatusEvent(event: StatusEvent) {
// Ignore any updates until the system is up and running // Ignore any updates until the system is up and running
if (isTooEarly() || !isImmersiveIndicatorEnabled()) { if (isTooEarly() || !isImmersiveIndicatorEnabled()) {
return return
@@ -103,7 +103,7 @@ class SystemStatusAnimationScheduler @Inject constructor(
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "scheduling event $event") Log.d(TAG, "scheduling event $event")
} }
if (showAnimation) { if (event.showAnimation) {
scheduleEvent(event) scheduleEvent(event)
} else if (event.forceVisible) { } else if (event.forceVisible) {
hasPersistentDot = true hasPersistentDot = true