1 /* <lambda>null2 * 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.settings.spa.app.appinfo 18 19 import android.content.Intent 20 import android.content.pm.ApplicationInfo 21 import androidx.compose.material.icons.Icons 22 import androidx.compose.material.icons.outlined.FileDownload 23 import com.android.settings.R 24 import com.android.settings.applications.AppStoreUtil 25 import com.android.settingslib.spa.widget.button.ActionButton 26 import com.android.settingslib.spaprivileged.model.app.userHandle 27 28 class AppInstallButton(private val packageInfoPresenter: PackageInfoPresenter) { 29 private val context = packageInfoPresenter.context 30 31 fun getActionButton(app: ApplicationInfo): ActionButton? { 32 if (!app.isInstantApp) return null 33 34 return AppStoreUtil.getAppStoreLink(packageInfoPresenter.userContext, app.packageName) 35 ?.let { intent -> installButton(intent, app) } 36 } 37 38 private fun installButton(intent: Intent, app: ApplicationInfo) = ActionButton( 39 text = context.getString(R.string.install_text), 40 imageVector = Icons.Outlined.FileDownload, 41 ) { 42 context.startActivityAsUser(intent, app.userHandle) 43 } 44 } 45