1 /*
2  * Copyright (C) 2022 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.volume
18 
19 import android.content.BroadcastReceiver
20 import android.content.Context
21 import android.content.Intent
22 import android.provider.Settings
23 import android.text.TextUtils
24 import android.util.Log
25 import javax.inject.Inject
26 
27 private const val TAG = "VolumePanelDialogReceiver"
28 private const val LAUNCH_ACTION = "com.android.systemui.action.LAUNCH_VOLUME_PANEL_DIALOG"
29 private const val DISMISS_ACTION = "com.android.systemui.action.DISMISS_VOLUME_PANEL_DIALOG"
30 
31 /**
32  * BroadcastReceiver for handling volume panel dialog intent
33  */
34 class VolumePanelDialogReceiver @Inject constructor(
35     private val volumePanelFactory: VolumePanelFactory
36 ) : BroadcastReceiver() {
37     override fun onReceive(context: Context, intent: Intent) {
38         Log.d(TAG, "onReceive intent" + intent.action)
39         if (TextUtils.equals(LAUNCH_ACTION, intent.action) ||
40                 TextUtils.equals(Settings.Panel.ACTION_VOLUME, intent.action)) {
41             volumePanelFactory.create(true, null)
42         } else if (TextUtils.equals(DISMISS_ACTION, intent.action)) {
43             volumePanelFactory.dismiss()
44         }
45     }
46 }
47