Keep host window lookup separate from the service-owned window field
This commit is contained in:
1 parent
18cb661c91
commit
d6c178a39b
3 files changed
+7
-7
No files matched your search
@@ -30,7 +30,7 @@ class NotificationChannel(val id: String, val name: String, val importance: Int)
|
||||
|
||||
/** Host OS boundaries: отказы канала, разрешений и публикации независимы. */
|
||||
class NotificationManager {
|
||||
companion object { const val IMPORTANCE_HIGH = 4 }
|
||||
companion object { const val IMPORTANCE_HIGH = 4; const val IMPORTANCE_LOW = 2 }
|
||||
var failures = emptySet<String>()
|
||||
var notificationsEnabled = true
|
||||
var fullScreenAllowed = true
|
||||
|
||||
@@ -28,7 +28,7 @@ open class Context {
|
||||
var powerManager: PowerManager? = PowerManager()
|
||||
var failPowerService = false
|
||||
val resources = HostResources()
|
||||
var windowManager: android.view.WindowManager? = android.view.WindowManager()
|
||||
var windowService: android.view.WindowManager? = android.view.WindowManager()
|
||||
val serviceStarts = mutableListOf<Intent>()
|
||||
val serviceStops = mutableListOf<Intent>()
|
||||
var failServiceStart = false
|
||||
@@ -81,7 +81,7 @@ open class Context {
|
||||
VIBRATOR_SERVICE -> vibrator
|
||||
POWER_SERVICE -> { check(!failPowerService) { "power service lookup unavailable" }; powerManager }
|
||||
WIFI_SERVICE -> { check(!failWifiService) { "Wi-Fi service unavailable" }; wifiManager }
|
||||
WINDOW_SERVICE -> windowManager
|
||||
WINDOW_SERVICE -> windowService
|
||||
else -> error("Unknown service: $name")
|
||||
}
|
||||
fun <T> getSystemService(type: Class<T>): T? {
|
||||
|
||||
+4
-4
@@ -34,7 +34,7 @@ class RadioOverlayLifecycleTest {
|
||||
private val dispatcher = StandardTestDispatcher()
|
||||
private val services = mutableListOf<RadioOverlayService>()
|
||||
private var previousEngine: Any? = null
|
||||
private val wm get() = requireNotNull(context.windowManager)
|
||||
private val wm get() = requireNotNull(context.windowService)
|
||||
private val view get() = wm.windows.keys.single()
|
||||
private val main get() = Looper.getMainLooper()
|
||||
|
||||
@@ -79,7 +79,7 @@ class RadioOverlayLifecycleTest {
|
||||
|
||||
private fun drain() { io.submit {}.get(5, TimeUnit.SECONDS) }
|
||||
private fun create(): RadioOverlayService = RadioOverlayService().also {
|
||||
services.add(it); it.notificationManager = context.notificationManager; it.windowManager = wm
|
||||
services.add(it); it.notificationManager = context.notificationManager; it.windowService = wm
|
||||
it.permissionGranted = context.permissionGranted
|
||||
it.onCreate(); dispatcher.scheduler.runCurrent()
|
||||
}
|
||||
@@ -99,12 +99,12 @@ class RadioOverlayLifecycleTest {
|
||||
|
||||
@Test fun startupChannelAndForegroundFailuresAreLoggedAndRequestStop() {
|
||||
for (failure in listOf("channel", "foreground", "foreground after", "window")) {
|
||||
val service = RadioOverlayService().also { services.add(it); it.notificationManager = context.notificationManager; it.windowManager = wm }
|
||||
val service = RadioOverlayService().also { services.add(it); it.notificationManager = context.notificationManager; it.windowService = wm }
|
||||
when (failure) {
|
||||
"channel" -> requireNotNull(context.notificationManager).failures = setOf("channel")
|
||||
"foreground" -> service.failForeground = true
|
||||
"foreground after" -> service.failForegroundAfter = true
|
||||
"window" -> service.windowManager = null
|
||||
"window" -> service.windowService = null
|
||||
}
|
||||
service.onCreate(); assertTrue(service.stops > 0); diagnostic("service setup failed")
|
||||
requireNotNull(context.notificationManager).failures = emptySet(); service.onDestroy()
|
||||
|
||||
Reference in new issue
Block a user