summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Anton Potapov <apotapov@google.com> 2023-05-12 14:56:53 +0100
committer Anton Potapov <apotapov@google.com> 2023-05-17 13:10:03 +0000
commit80db4505cddf1ef92d250745d6f9dc580f07c26c (patch)
tree42fd3d5bfbf8c082329ba9262ffa6ead5a4b3993
parent53c901a01cba683e7a7cbe1c76c97f2f87eec22d (diff)
Add system ui background handlers dispatch and delivery logging thresholds
Those thresholds would help us to further investigate bugs like this one. Looper#showSlowLog prints Slog.w when the threshold is met. This risk free change will help us investigate issues when something got stuck in the background thread. I've also removed misleading `run` from `UserTrackerImpl` because those are kotlin run to change context, which doesn't change execution thread. Bug: 281851220 Test: manual Change-Id: I127ec03e15f76295484e34b0ff0f3e7ad9ac9b88
-rw-r--r--packages/SystemUI/src/com/android/systemui/settings/UserTrackerImpl.kt12
-rw-r--r--packages/SystemUI/src/com/android/systemui/util/concurrency/SysUIConcurrencyModule.java22
2 files changed, 24 insertions, 10 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/settings/UserTrackerImpl.kt b/packages/SystemUI/src/com/android/systemui/settings/UserTrackerImpl.kt
index fbf134db15f1..5fb3c01bbc1d 100644
--- a/packages/SystemUI/src/com/android/systemui/settings/UserTrackerImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/settings/UserTrackerImpl.kt
@@ -166,21 +166,19 @@ open class UserTrackerImpl internal constructor(
}
override fun onUserSwitching(newUserId: Int, reply: IRemoteCallback?) {
- backgroundHandler.run {
- handleUserSwitching(newUserId)
- reply?.sendResult(null)
- }
+ handleUserSwitching(newUserId)
+ reply?.sendResult(null)
}
override fun onUserSwitchComplete(newUserId: Int) {
- backgroundHandler.run {
- handleUserSwitchComplete(newUserId)
- }
+ handleUserSwitchComplete(newUserId)
}
}, TAG)
}
+ @WorkerThread
protected open fun handleBeforeUserSwitching(newUserId: Int) {
+ Assert.isNotMainThread()
setUserIdInternal(newUserId)
}
diff --git a/packages/SystemUI/src/com/android/systemui/util/concurrency/SysUIConcurrencyModule.java b/packages/SystemUI/src/com/android/systemui/util/concurrency/SysUIConcurrencyModule.java
index c72853ef37be..7b652c11e9ec 100644
--- a/packages/SystemUI/src/com/android/systemui/util/concurrency/SysUIConcurrencyModule.java
+++ b/packages/SystemUI/src/com/android/systemui/util/concurrency/SysUIConcurrencyModule.java
@@ -29,18 +29,28 @@ import com.android.systemui.dagger.qualifiers.BroadcastRunning;
import com.android.systemui.dagger.qualifiers.LongRunning;
import com.android.systemui.dagger.qualifiers.Main;
+import dagger.Module;
+import dagger.Provides;
+
import java.util.concurrent.Executor;
import javax.inject.Named;
-import dagger.Module;
-import dagger.Provides;
-
/**
* Dagger Module for classes found within the concurrent package.
*/
@Module
public abstract class SysUIConcurrencyModule {
+
+ // Slow BG executor can potentially affect UI if UI is waiting for an updated state from this
+ // thread
+ private static final Long BG_SLOW_DISPATCH_THRESHOLD = 1000L;
+ private static final Long BG_SLOW_DELIVERY_THRESHOLD = 1000L;
+ private static final Long LONG_SLOW_DISPATCH_THRESHOLD = 2500L;
+ private static final Long LONG_SLOW_DELIVERY_THRESHOLD = 2500L;
+ private static final Long BROADCAST_SLOW_DISPATCH_THRESHOLD = 1000L;
+ private static final Long BROADCAST_SLOW_DELIVERY_THRESHOLD = 1000L;
+
/** Background Looper */
@Provides
@SysUISingleton
@@ -49,6 +59,8 @@ public abstract class SysUIConcurrencyModule {
HandlerThread thread = new HandlerThread("SysUiBg",
Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
+ thread.getLooper().setSlowLogThresholdMs(BG_SLOW_DISPATCH_THRESHOLD,
+ BG_SLOW_DELIVERY_THRESHOLD);
return thread.getLooper();
}
@@ -60,6 +72,8 @@ public abstract class SysUIConcurrencyModule {
HandlerThread thread = new HandlerThread("BroadcastRunning",
Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
+ thread.getLooper().setSlowLogThresholdMs(BROADCAST_SLOW_DISPATCH_THRESHOLD,
+ BROADCAST_SLOW_DELIVERY_THRESHOLD);
return thread.getLooper();
}
@@ -71,6 +85,8 @@ public abstract class SysUIConcurrencyModule {
HandlerThread thread = new HandlerThread("SysUiLng",
Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
+ thread.getLooper().setSlowLogThresholdMs(LONG_SLOW_DISPATCH_THRESHOLD,
+ LONG_SLOW_DELIVERY_THRESHOLD);
return thread.getLooper();
}