1 /*
2  * Copyright (C) 2023 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.communal.widgets
18 
19 import android.content.Context
20 import android.content.Intent
21 import com.android.systemui.communal.widgets.EditWidgetsActivity.Companion.EXTRA_OPEN_WIDGET_PICKER_ON_START
22 import com.android.systemui.communal.widgets.EditWidgetsActivity.Companion.EXTRA_PRESELECTED_KEY
23 import com.android.systemui.dagger.qualifiers.Application
24 import com.android.systemui.plugins.ActivityStarter
25 import javax.inject.Inject
26 
27 interface EditWidgetsActivityStarter {
startActivitynull28     fun startActivity(
29         preselectedKey: String? = null,
30         shouldOpenWidgetPickerOnStart: Boolean = false,
31     )
32 }
33 
34 class EditWidgetsActivityStarterImpl
35 @Inject
36 constructor(
37     @Application private val applicationContext: Context,
38     private val activityStarter: ActivityStarter,
39 ) : EditWidgetsActivityStarter {
40 
41     override fun startActivity(preselectedKey: String?, shouldOpenWidgetPickerOnStart: Boolean) {
42         activityStarter.startActivityDismissingKeyguard(
43             Intent(applicationContext, EditWidgetsActivity::class.java)
44                 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
45                 .apply {
46                     preselectedKey?.let { putExtra(EXTRA_PRESELECTED_KEY, preselectedKey) }
47                     putExtra(EXTRA_OPEN_WIDGET_PICKER_ON_START, shouldOpenWidgetPickerOnStart)
48                 },
49             /* onlyProvisioned = */ true,
50             /* dismissShade = */ true,
51         )
52     }
53 }
54