Merge "Optimize DeviceFoldStateProvider#onHingeAngle" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
78108c1096
@@ -15,21 +15,51 @@
|
|||||||
package com.android.systemui.unfold.system
|
package com.android.systemui.unfold.system
|
||||||
|
|
||||||
import android.app.ActivityManager
|
import android.app.ActivityManager
|
||||||
|
import android.app.ActivityManager.RunningTaskInfo
|
||||||
import android.app.WindowConfiguration
|
import android.app.WindowConfiguration
|
||||||
|
import android.os.Trace
|
||||||
|
import com.android.systemui.shared.system.TaskStackChangeListener
|
||||||
|
import com.android.systemui.shared.system.TaskStackChangeListeners
|
||||||
import com.android.systemui.unfold.util.CurrentActivityTypeProvider
|
import com.android.systemui.unfold.util.CurrentActivityTypeProvider
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class ActivityManagerActivityTypeProvider @Inject constructor(
|
class ActivityManagerActivityTypeProvider
|
||||||
private val activityManager: ActivityManager
|
@Inject
|
||||||
) : CurrentActivityTypeProvider {
|
constructor(private val activityManager: ActivityManager) : CurrentActivityTypeProvider {
|
||||||
|
|
||||||
override val isHomeActivity: Boolean?
|
override val isHomeActivity: Boolean?
|
||||||
get() {
|
get() = _isHomeActivity
|
||||||
val activityType = activityManager.getRunningTasks(/* maxNum= */ 1)
|
|
||||||
?.getOrNull(0)?.topActivityType ?: return null
|
|
||||||
|
|
||||||
return activityType == WindowConfiguration.ACTIVITY_TYPE_HOME
|
private var _isHomeActivity: Boolean? = null
|
||||||
|
|
||||||
|
|
||||||
|
override fun init() {
|
||||||
|
_isHomeActivity = activityManager.isOnHomeActivity()
|
||||||
|
TaskStackChangeListeners.getInstance().registerTaskStackListener(taskStackChangeListener)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun uninit() {
|
||||||
|
TaskStackChangeListeners.getInstance().unregisterTaskStackListener(taskStackChangeListener)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val taskStackChangeListener =
|
||||||
|
object : TaskStackChangeListener {
|
||||||
|
override fun onTaskMovedToFront(taskInfo: RunningTaskInfo) {
|
||||||
|
_isHomeActivity = taskInfo.isHomeActivity()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun RunningTaskInfo.isHomeActivity(): Boolean =
|
||||||
|
topActivityType == WindowConfiguration.ACTIVITY_TYPE_HOME
|
||||||
|
|
||||||
|
private fun ActivityManager.isOnHomeActivity(): Boolean? {
|
||||||
|
try {
|
||||||
|
Trace.beginSection("isOnHomeActivity")
|
||||||
|
return getRunningTasks(/* maxNum= */ 1)?.firstOrNull()?.isHomeActivity()
|
||||||
|
} finally {
|
||||||
|
Trace.endSection()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ constructor(
|
|||||||
screenStatusProvider.addCallback(screenListener)
|
screenStatusProvider.addCallback(screenListener)
|
||||||
hingeAngleProvider.addCallback(hingeAngleListener)
|
hingeAngleProvider.addCallback(hingeAngleListener)
|
||||||
rotationChangeProvider.addCallback(rotationListener)
|
rotationChangeProvider.addCallback(rotationListener)
|
||||||
|
activityTypeProvider.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun stop() {
|
override fun stop() {
|
||||||
@@ -87,6 +88,7 @@ constructor(
|
|||||||
hingeAngleProvider.removeCallback(hingeAngleListener)
|
hingeAngleProvider.removeCallback(hingeAngleListener)
|
||||||
hingeAngleProvider.stop()
|
hingeAngleProvider.stop()
|
||||||
rotationChangeProvider.removeCallback(rotationListener)
|
rotationChangeProvider.removeCallback(rotationListener)
|
||||||
|
activityTypeProvider.uninit()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addCallback(listener: FoldUpdatesListener) {
|
override fun addCallback(listener: FoldUpdatesListener) {
|
||||||
@@ -115,19 +117,17 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val isClosing = angle < lastHingeAngle
|
val isClosing = angle < lastHingeAngle
|
||||||
val closingThreshold = getClosingThreshold()
|
|
||||||
val closingThresholdMet = closingThreshold == null || angle < closingThreshold
|
|
||||||
val isFullyOpened = FULLY_OPEN_DEGREES - angle < FULLY_OPEN_THRESHOLD_DEGREES
|
val isFullyOpened = FULLY_OPEN_DEGREES - angle < FULLY_OPEN_THRESHOLD_DEGREES
|
||||||
val closingEventDispatched = lastFoldUpdate == FOLD_UPDATE_START_CLOSING
|
val closingEventDispatched = lastFoldUpdate == FOLD_UPDATE_START_CLOSING
|
||||||
val screenAvailableEventSent = isUnfoldHandled
|
val screenAvailableEventSent = isUnfoldHandled
|
||||||
|
|
||||||
if (isClosing // hinge angle should be decreasing since last update
|
if (isClosing // hinge angle should be decreasing since last update
|
||||||
&& closingThresholdMet // hinge angle is below certain threshold
|
|
||||||
&& !closingEventDispatched // we haven't sent closing event already
|
&& !closingEventDispatched // we haven't sent closing event already
|
||||||
&& !isFullyOpened // do not send closing event if we are in fully opened hinge
|
&& !isFullyOpened // do not send closing event if we are in fully opened hinge
|
||||||
// angle range as closing threshold could overlap this range
|
// angle range as closing threshold could overlap this range
|
||||||
&& screenAvailableEventSent // do not send closing event if we are still in
|
&& screenAvailableEventSent // do not send closing event if we are still in
|
||||||
// the process of turning on the inner display
|
// the process of turning on the inner display
|
||||||
|
&& isClosingThresholdMet(angle) // hinge angle is below certain threshold.
|
||||||
) {
|
) {
|
||||||
notifyFoldUpdate(FOLD_UPDATE_START_CLOSING)
|
notifyFoldUpdate(FOLD_UPDATE_START_CLOSING)
|
||||||
}
|
}
|
||||||
@@ -146,6 +146,11 @@ constructor(
|
|||||||
outputListeners.forEach { it.onHingeAngleUpdate(angle) }
|
outputListeners.forEach { it.onHingeAngleUpdate(angle) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isClosingThresholdMet(currentAngle: Float) : Boolean {
|
||||||
|
val closingThreshold = getClosingThreshold()
|
||||||
|
return closingThreshold == null || currentAngle < closingThreshold
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fold animation should be started only after the threshold returned here.
|
* Fold animation should be started only after the threshold returned here.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ package com.android.systemui.unfold.util
|
|||||||
|
|
||||||
interface CurrentActivityTypeProvider {
|
interface CurrentActivityTypeProvider {
|
||||||
val isHomeActivity: Boolean?
|
val isHomeActivity: Boolean?
|
||||||
|
|
||||||
|
/** Starts listening for task updates. */
|
||||||
|
fun init() {}
|
||||||
|
/** Stop listening for task updates. */
|
||||||
|
fun uninit() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class EmptyCurrentActivityTypeProvider(override val isHomeActivity: Boolean? = null) :
|
class EmptyCurrentActivityTypeProvider(override val isHomeActivity: Boolean? = null) :
|
||||||
|
|||||||
Reference in New Issue
Block a user