Pass a bg handler when registering broadcast receiver
This should hopefully ensure that we're avoiding doing binder calls on
the main thread.
I made it nullable because we don't have a great way to fake a handler
in SettingsLib, unless we want to add a dependency on
SystemUITestUtils...
Bug: 348810424
Test: ZenModeRepositoryTest
Flag: com.android.settingslib.flags.volume_panel_broadcast_fix
Change-Id: I6aa1e45efa08dcd7e3352db3b383d317d1a56b90
diff --git a/packages/SettingsLib/src/com/android/settingslib/notification/data/repository/ZenModeRepository.kt b/packages/SettingsLib/src/com/android/settingslib/notification/data/repository/ZenModeRepository.kt
index 58541418..273a63d 100644
--- a/packages/SettingsLib/src/com/android/settingslib/notification/data/repository/ZenModeRepository.kt
+++ b/packages/SettingsLib/src/com/android/settingslib/notification/data/repository/ZenModeRepository.kt
@@ -21,6 +21,7 @@
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
+import android.os.Handler
import com.android.settingslib.flags.Flags
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
@@ -50,6 +51,9 @@
private val notificationManager: NotificationManager,
val scope: CoroutineScope,
val backgroundCoroutineContext: CoroutineContext,
+ // This is nullable just to simplify testing, since SettingsLib doesn't have a good way
+ // to create a fake handler.
+ val backgroundHandler: Handler?,
) : ZenModeRepository {
private val notificationBroadcasts =
@@ -69,7 +73,14 @@
if (Flags.volumePanelBroadcastFix() && android.app.Flags.modesApi())
addAction(
NotificationManager.ACTION_CONSOLIDATED_NOTIFICATION_POLICY_CHANGED)
- })
+ },
+ /* broadcastPermission = */ null,
+ /* scheduler = */ if (Flags.volumePanelBroadcastFix()) {
+ backgroundHandler
+ } else {
+ null
+ },
+ )
awaitClose { context.unregisterReceiver(receiver) }
}
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/data/repository/ZenModeRepositoryTest.kt b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/data/repository/ZenModeRepositoryTest.kt
index 5294ce3..096c25d 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/data/repository/ZenModeRepositoryTest.kt
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/data/repository/ZenModeRepositoryTest.kt
@@ -69,6 +69,7 @@
notificationManager,
testScope.backgroundScope,
testScope.testScheduler,
+ backgroundHandler = null,
)
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java
index fec7cf0..b63ee4c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java
@@ -18,6 +18,7 @@
import android.app.NotificationManager;
import android.content.Context;
+import android.os.Handler;
import android.service.notification.NotificationListenerService;
import com.android.internal.jank.InteractionJankMonitor;
@@ -283,9 +284,11 @@
Context context,
NotificationManager notificationManager,
@Application CoroutineScope coroutineScope,
- @Background CoroutineContext coroutineContext) {
+ @Background CoroutineContext coroutineContext,
+ @Background Handler handler
+ ) {
return new ZenModeRepositoryImpl(context, notificationManager,
- coroutineScope, coroutineContext);
+ coroutineScope, coroutineContext, handler);
}
@Provides