summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Fengjiang Li <fengjial@google.com> 2024-06-14 14:45:05 -0700
committer Fengjiang Li <fengjial@google.com> 2024-06-15 15:04:18 -0700
commit9f6265008df6e7d70c624d55c9f5cac4f90af2ab (patch)
tree0727427ecc5440a36263cbc189a13b519b88acf0
parenta0e55bf92dfff4c08570e564ddf5c21b13fa2c9c (diff)
[Launcher Jank] Avoid SmartspaceView making binder call from main thread
Test: manual Flag: NONE performance change Bug: 333772683 Change-Id: I58b7014122b1b127ed3ee499306a0c20e040f7d4
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/smartspace/CommunalSmartspaceControllerTest.kt3
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/smartspace/DreamSmartspaceControllerTest.kt3
-rw-r--r--packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceDataPlugin.java4
-rw-r--r--packages/SystemUI/src/com/android/systemui/smartspace/dagger/SmartspaceViewComponent.kt19
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt2
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceControllerTest.kt17
6 files changed, 40 insertions, 8 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/smartspace/CommunalSmartspaceControllerTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/smartspace/CommunalSmartspaceControllerTest.kt
index ad4b98bdb3ee..eac86e55763a 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/smartspace/CommunalSmartspaceControllerTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/smartspace/CommunalSmartspaceControllerTest.kt
@@ -20,6 +20,7 @@ import android.app.smartspace.SmartspaceSession
import android.app.smartspace.SmartspaceTarget
import android.content.Context
import android.graphics.drawable.Drawable
+import android.os.Handler
import android.testing.TestableLooper
import android.view.View
import android.widget.FrameLayout
@@ -86,6 +87,8 @@ class CommunalSmartspaceControllerTest : SysuiTestCase() {
override fun setUiSurface(uiSurface: String) {}
+ override fun setBgHandler(bgHandler: Handler?) {}
+
override fun setDozeAmount(amount: Float) {}
override fun setIntentStarter(intentStarter: BcSmartspaceDataPlugin.IntentStarter?) {}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/smartspace/DreamSmartspaceControllerTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/smartspace/DreamSmartspaceControllerTest.kt
index 3a386311223f..e774aed2045b 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/smartspace/DreamSmartspaceControllerTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/smartspace/DreamSmartspaceControllerTest.kt
@@ -20,6 +20,7 @@ import android.app.smartspace.SmartspaceSession
import android.app.smartspace.SmartspaceTarget
import android.content.Context
import android.graphics.drawable.Drawable
+import android.os.Handler
import android.testing.TestableLooper
import android.view.View
import android.view.ViewGroup
@@ -119,6 +120,8 @@ class DreamSmartspaceControllerTest : SysuiTestCase() {
override fun setUiSurface(uiSurface: String) {}
+ override fun setBgHandler(bgHandler: Handler?) {}
+
override fun setDozeAmount(amount: Float) {}
override fun setIntentStarter(intentStarter: BcSmartspaceDataPlugin.IntentStarter?) {}
diff --git a/packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceDataPlugin.java b/packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceDataPlugin.java
index 9ad4012cfd07..074277c55c88 100644
--- a/packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceDataPlugin.java
+++ b/packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceDataPlugin.java
@@ -24,6 +24,7 @@ import android.app.smartspace.uitemplatedata.TapAction;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.drawable.Drawable;
+import android.os.Handler;
import android.os.Parcelable;
import android.util.Log;
import android.view.View;
@@ -123,6 +124,9 @@ public interface BcSmartspaceDataPlugin extends Plugin {
*/
void setUiSurface(String uiSurface);
+ /** Set background handler to make binder calls. */
+ void setBgHandler(Handler bgHandler);
+
/**
* Range [0.0 - 1.0] when transitioning from Lockscreen to/from AOD
*/
diff --git a/packages/SystemUI/src/com/android/systemui/smartspace/dagger/SmartspaceViewComponent.kt b/packages/SystemUI/src/com/android/systemui/smartspace/dagger/SmartspaceViewComponent.kt
index 6d951bf4d83b..abffd3c53908 100644
--- a/packages/SystemUI/src/com/android/systemui/smartspace/dagger/SmartspaceViewComponent.kt
+++ b/packages/SystemUI/src/com/android/systemui/smartspace/dagger/SmartspaceViewComponent.kt
@@ -18,8 +18,10 @@ package com.android.systemui.smartspace.dagger
import android.app.ActivityOptions
import android.app.PendingIntent
import android.content.Intent
+import android.os.Handler
import android.view.View
import android.view.ViewGroup
+import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.plugins.BcSmartspaceDataPlugin
import com.android.systemui.plugins.BcSmartspaceDataPlugin.UI_SURFACE_DREAM
@@ -51,19 +53,20 @@ interface SmartspaceViewComponent {
@Provides
fun providesSmartspaceView(
- activityStarter: ActivityStarter,
- falsingManager: FalsingManager,
- parent: ViewGroup,
- @Named(PLUGIN) plugin: BcSmartspaceDataPlugin,
- viewWithCustomLayout: View?,
- onAttachListener: View.OnAttachStateChangeListener
- ):
- BcSmartspaceDataPlugin.SmartspaceView {
+ activityStarter: ActivityStarter,
+ falsingManager: FalsingManager,
+ parent: ViewGroup,
+ @Named(PLUGIN) plugin: BcSmartspaceDataPlugin,
+ viewWithCustomLayout: View?,
+ onAttachListener: View.OnAttachStateChangeListener,
+ @Background bgHandler: Handler,
+ ): BcSmartspaceDataPlugin.SmartspaceView {
val ssView = viewWithCustomLayout
as? BcSmartspaceDataPlugin.SmartspaceView
?: plugin.getView(parent)
// Currently, this is only used to provide SmartspaceView on Dream surface.
ssView.setUiSurface(UI_SURFACE_DREAM)
+ ssView.setBgHandler(bgHandler)
ssView.registerDataProvider(plugin)
ssView.setIntentStarter(object : BcSmartspaceDataPlugin.IntentStarter {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt
index ee2c9cc9acde..af8a89d82fe7 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt
@@ -109,6 +109,7 @@ constructor(
@Main private val uiExecutor: Executor,
@Background private val bgExecutor: Executor,
@Main private val handler: Handler,
+ @Background private val bgHandler: Handler,
@Named(DATE_SMARTSPACE_DATA_PLUGIN)
optionalDatePlugin: Optional<BcSmartspaceDataPlugin>,
@Named(WEATHER_SMARTSPACE_DATA_PLUGIN)
@@ -412,6 +413,7 @@ constructor(
val ssView = plugin.getView(parent)
configPlugin?.let { ssView.registerConfigProvider(it) }
+ ssView.setBgHandler(bgHandler)
ssView.setUiSurface(BcSmartspaceDataPlugin.UI_SURFACE_LOCK_SCREEN_AOD)
ssView.setTimeChangedDelegate(SmartspaceTimeChangedDelegate(keyguardUpdateMonitor))
ssView.registerDataProvider(plugin)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceControllerTest.kt
index 066ca1c17d30..b944d7248173 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceControllerTest.kt
@@ -136,6 +136,9 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
private lateinit var handler: Handler
@Mock
+ private lateinit var bgHandler: Handler
+
+ @Mock
private lateinit var datePlugin: BcSmartspaceDataPlugin
@Mock
@@ -265,6 +268,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
executor,
bgExecutor,
handler,
+ bgHandler,
Optional.of(datePlugin),
Optional.of(weatherPlugin),
Optional.of(plugin),
@@ -762,6 +766,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
// THEN the existing session is reused and views are registered
verify(smartspaceManager, never()).createSmartspaceSession(any())
verify(smartspaceView2).setUiSurface(BcSmartspaceDataPlugin.UI_SURFACE_LOCK_SCREEN_AOD)
+ verify(smartspaceView2).setBgHandler(bgHandler)
verify(smartspaceView2).setTimeChangedDelegate(any())
verify(smartspaceView2).registerDataProvider(plugin)
verify(smartspaceView2).registerConfigProvider(configPlugin)
@@ -838,6 +843,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
verify(dateSmartspaceView).setUiSurface(
BcSmartspaceDataPlugin.UI_SURFACE_LOCK_SCREEN_AOD)
verify(dateSmartspaceView).setTimeChangedDelegate(any())
+ verify(dateSmartspaceView).setBgHandler(bgHandler)
verify(dateSmartspaceView).registerDataProvider(datePlugin)
verify(dateSmartspaceView).setPrimaryTextColor(anyInt())
@@ -851,6 +857,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
verify(weatherSmartspaceView).setUiSurface(
BcSmartspaceDataPlugin.UI_SURFACE_LOCK_SCREEN_AOD)
verify(weatherSmartspaceView).setTimeChangedDelegate(any())
+ verify(weatherSmartspaceView).setBgHandler(bgHandler)
verify(weatherSmartspaceView).registerDataProvider(weatherPlugin)
verify(weatherSmartspaceView).setPrimaryTextColor(anyInt())
@@ -863,6 +870,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
verify(smartspaceView).setUiSurface(BcSmartspaceDataPlugin.UI_SURFACE_LOCK_SCREEN_AOD)
verify(smartspaceView).setTimeChangedDelegate(any())
+ verify(smartspaceView).setBgHandler(bgHandler)
verify(smartspaceView).registerDataProvider(plugin)
verify(smartspaceView).registerConfigProvider(configPlugin)
verify(smartspaceSession)
@@ -988,6 +996,9 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
override fun setUiSurface(uiSurface: String) {
}
+ override fun setBgHandler(bgHandler: Handler?) {
+ }
+
override fun setTimeChangedDelegate(
delegate: BcSmartspaceDataPlugin.TimeChangedDelegate?
) {}
@@ -1020,6 +1031,9 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
override fun setUiSurface(uiSurface: String) {
}
+ override fun setBgHandler(bgHandler: Handler?) {
+ }
+
override fun setTimeChangedDelegate(
delegate: BcSmartspaceDataPlugin.TimeChangedDelegate?
) {}
@@ -1048,6 +1062,9 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
override fun setUiSurface(uiSurface: String) {
}
+ override fun setBgHandler(bgHandler: Handler?) {
+ }
+
override fun setTimeChangedDelegate(
delegate: BcSmartspaceDataPlugin.TimeChangedDelegate?
) {}