Fix cross-profile app actions

- Launch app info using the correct profile
- Hide uninstall for non-personal profiles
This commit is contained in:
MM20 2022-04-16 18:03:26 +02:00
parent fc320251f6
commit d8b6175e6e
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389

View File

@ -1,11 +1,13 @@
package de.mm20.launcher2.ui.launcher.search.apps package de.mm20.launcher2.ui.launcher.search.apps
import android.app.PendingIntent import android.app.PendingIntent
import android.content.ComponentName
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.* import android.content.pm.*
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.net.Uri import android.net.Uri
import android.os.Process
import android.provider.Settings import android.provider.Settings
import android.service.notification.StatusBarNotification import android.service.notification.StatusBarNotification
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
@ -40,23 +42,39 @@ class AppItemVM(
} }
fun openAppInfo(context: Context) { fun openAppInfo(context: Context) {
context.tryStartActivity( val launcherApps = context.getSystemService<LauncherApps>()!!
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
data = Uri.parse("package:${app.`package`}") if (app is LauncherApp) {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) launcherApps.startAppDetailsActivity(
} ComponentName(app.`package`, app.activity),
) app.getUser(),
null,
null
)
} else {
context.tryStartActivity(
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
data = Uri.parse("package:${app.`package`}")
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
)
}
} }
suspend fun shareApkFile(context: Context) { suspend fun shareApkFile(context: Context) {
val launcherApps = context.getSystemService<LauncherApps>()!!
val fileCopy = java.io.File( val fileCopy = java.io.File(
context.cacheDir, context.cacheDir,
"${app.`package`}-${app.version}.apk" "${app.`package`}-${app.version}.apk"
) )
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
try { try {
val info = context.packageManager val user = (app as? LauncherApp)?.getUser()
.getApplicationInfo(app.`package`, 0) val info = if (user != null) {
launcherApps.getApplicationInfo(app.`package`, 0, user)
} else {
context.packageManager.getApplicationInfo(app.`package`, 0)
}
val file = java.io.File(info.publicSourceDir) val file = java.io.File(info.publicSourceDir)
try { try {
@ -89,7 +107,7 @@ class AppItemVM(
context.startActivity(Intent.createChooser(shareIntent, null)) context.startActivity(Intent.createChooser(shareIntent, null))
} }
val canUninstall = app.flags and ApplicationInfo.FLAG_SYSTEM == 0 val canUninstall = app.flags and ApplicationInfo.FLAG_SYSTEM == 0 && (app as LauncherApp).getUser() == Process.myUserHandle()
fun uninstall(context: Context) { fun uninstall(context: Context) {
val intent = Intent(Intent.ACTION_DELETE) val intent = Intent(Intent.ACTION_DELETE)