1 /* <lambda>null2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.statusbar.policy 18 19 import android.app.NotificationManager 20 import com.android.systemui.CoreStartable 21 import com.android.systemui.dagger.qualifiers.Application 22 import com.android.systemui.dagger.qualifiers.Background 23 import com.android.systemui.modes.shared.ModesUi 24 import javax.inject.Inject 25 import kotlin.coroutines.CoroutineContext 26 import kotlinx.coroutines.CoroutineScope 27 import com.android.app.tracing.coroutines.launchTraced as launch 28 import kotlinx.coroutines.withContext 29 30 /** 31 * Cleanup task that deletes the obsolete "Gaming" AutomaticZenRule that was created by SystemUI in 32 * the faraway past, and still exists on some devices through upgrades or B&R. 33 */ 34 // TODO: b/372874878 - Remove this thing once it has run long enough 35 class ZenModesCleanupStartable 36 @Inject 37 constructor( 38 @Application private val applicationCoroutineScope: CoroutineScope, 39 @Background private val bgContext: CoroutineContext, 40 val notificationManager: NotificationManager, 41 ) : CoreStartable { 42 43 override fun start() { 44 if (!ModesUi.isEnabled) { 45 return 46 } 47 applicationCoroutineScope.launch { deleteObsoleteGamingMode() } 48 } 49 50 private suspend fun deleteObsoleteGamingMode() { 51 withContext(bgContext) { 52 val allRules = notificationManager.automaticZenRules 53 val gamingModeEntry = 54 allRules.entries.firstOrNull { entry -> 55 entry.value.packageName == "com.android.systemui" && 56 entry.value.conditionId?.toString() == 57 "android-app://com.android.systemui/game-mode-dnd-controller" 58 } 59 if (gamingModeEntry != null) { 60 notificationManager.removeAutomaticZenRule(gamingModeEntry.key) 61 } 62 } 63 } 64 } 65