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.wm.shell.bubbles.shortcut
18 
19 import android.app.Activity
20 import android.content.ComponentName
21 import android.content.Context
22 import android.content.Intent
23 import android.os.Bundle
24 import com.android.wm.shell.Flags
25 import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_BUBBLES
26 import com.android.wm.shell.util.KtProtoLog
27 
28 /** Activity that sends a broadcast to open bubbles */
29 class ShowBubblesActivity : Activity() {
30 
onCreatenull31     override fun onCreate(savedInstanceState: Bundle?) {
32         super.onCreate(savedInstanceState)
33         if (Flags.enableRetrievableBubbles()) {
34             val intent =
35                 Intent().apply {
36                     action = BubbleShortcutHelper.ACTION_SHOW_BUBBLES
37                     // Set the package as the receiver is not exported
38                     `package` = packageName
39                 }
40             KtProtoLog.v(WM_SHELL_BUBBLES, "Sending broadcast to show bubbles")
41             sendBroadcast(intent)
42         }
43         finish()
44     }
45 
46     companion object {
47         /** Create intent to launch this activity */
createIntentnull48         fun createIntent(context: Context): Intent {
49             return Intent(context, ShowBubblesActivity::class.java).apply {
50                 action = BubbleShortcutHelper.ACTION_SHOW_BUBBLES
51             }
52         }
53 
54         /** Create component for this activity */
createComponentnull55         fun createComponent(context: Context): ComponentName {
56             return ComponentName(context, ShowBubblesActivity::class.java)
57         }
58     }
59 }
60