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.car.carlaunchercommon.shortcuts
18 
19 import android.content.Context
20 import android.content.Intent
21 import android.net.Uri
22 import android.os.UserHandle
23 import android.provider.Settings
24 import com.android.car.carlaunchercommon.R
25 import com.android.car.hidden.apis.HiddenApiAccess.startActivityAsUser
26 import com.android.car.ui.shortcutspopup.CarUiShortcutsPopup
27 
28 class AppInfoShortcutItem constructor(
29     private val context: Context,
30     private val packageName: String,
31     private val userHandle: UserHandle
32 ) : CarUiShortcutsPopup.ShortcutItem {
33     private companion object {
34         private const val PACKAGE_URI_PREFIX = "package:"
35     }
36 
datanull37     override fun data(): CarUiShortcutsPopup.ItemData {
38         return CarUiShortcutsPopup.ItemData(
39             R.drawable.ic_app_info,
40             context.resources.getString(R.string.app_info_shortcut_label)
41         )
42     }
43 
onClicknull44     override fun onClick(): Boolean {
45         val packageURI = Uri.parse(PACKAGE_URI_PREFIX + packageName)
46         val intent = Intent(
47             Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
48             packageURI
49         )
50         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
51         startActivityAsUser(context, intent, userHandle)
52         return true
53     }
54 
isEnablednull55     override fun isEnabled(): Boolean {
56         return true
57     }
58 }
59