1 /* 2 * 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.notification.interruption 18 19 import android.content.BroadcastReceiver 20 import android.content.Context 21 import android.content.Intent 22 import android.content.IntentFilter 23 import android.util.Log 24 import com.android.internal.logging.UiEventLogger 25 import com.android.systemui.broadcast.BroadcastDispatcher 26 import com.android.systemui.dagger.SysUISingleton 27 import com.android.systemui.statusbar.notification.interruption.AvalancheSuppressor.AvalancheEvent 28 import javax.inject.Inject 29 30 // Class to track avalanche trigger event time. 31 @SysUISingleton 32 class AvalancheProvider 33 @Inject 34 constructor( 35 private val broadcastDispatcher: BroadcastDispatcher, 36 private val uiEventLogger: UiEventLogger, 37 ) { 38 val TAG = "AvalancheProvider" 39 val timeoutMs = 120000 40 var startTime: Long = 0L 41 42 private val avalancheTriggerIntents = 43 mutableSetOf( 44 Intent.ACTION_AIRPLANE_MODE_CHANGED, 45 Intent.ACTION_BOOT_COMPLETED, 46 Intent.ACTION_MANAGED_PROFILE_AVAILABLE, 47 Intent.ACTION_USER_SWITCHED 48 ) 49 50 private val broadcastReceiver: BroadcastReceiver = 51 object : BroadcastReceiver() { onReceivenull52 override fun onReceive(context: Context, intent: Intent) { 53 if (intent.action in avalancheTriggerIntents) { 54 55 // Ignore when airplane mode turned on 56 if ( 57 intent.action == Intent.ACTION_AIRPLANE_MODE_CHANGED && 58 intent.getBooleanExtra(/* name= */ "state", /* defaultValue */ false) 59 ) { 60 Log.d(TAG, "broadcastReceiver: ignore airplane mode on") 61 return 62 } 63 Log.d(TAG, "broadcastReceiver received intent.action=" + intent.action) 64 uiEventLogger.log(AvalancheEvent.AVALANCHE_SUPPRESSOR_RECEIVED_TRIGGERING_EVENT) 65 startTime = System.currentTimeMillis() 66 } 67 } 68 } 69 registernull70 fun register() { 71 val intentFilter = IntentFilter() 72 for (intent in avalancheTriggerIntents) { 73 intentFilter.addAction(intent) 74 } 75 broadcastDispatcher.registerReceiver(broadcastReceiver, intentFilter) 76 } 77 } 78