diff --git a/app/src/main/java/de/redno/disabledlauncher/ActionReceiverActivity.kt b/app/src/main/java/de/redno/disabledlauncher/ActionReceiverActivity.kt index 39f038c..c139ae7 100644 --- a/app/src/main/java/de/redno/disabledlauncher/ActionReceiverActivity.kt +++ b/app/src/main/java/de/redno/disabledlauncher/ActionReceiverActivity.kt @@ -16,13 +16,18 @@ class ActionReceiverActivity : ComponentActivity() { "${packageName}.action.OPEN_APP" -> { val packageNameToOpen = intent.getStringExtra("package_name") if (packageNameToOpen != null && packageNameToOpen.matches(Regex("^\\w+\\.[\\w.]*\\w+$"))) { - try { - AppService.openAppLogic(this, AppService.getDetailsForPackage(this, packageNameToOpen)) - setResult(RESULT_OK, Intent()) - } catch (e: DisabledLauncherException) { - e.getLocalizedMessage(this)?.let { - error(it, e !is RedirectedToGooglePlayException) + val app = AppService.getDetailsForPackage(this, packageNameToOpen) + if (app.isInstalled) { + try { + AppService.openAppLogic(this, app) + setResult(RESULT_OK, Intent()) + } catch (e: DisabledLauncherException) { + e.getLocalizedMessage(this)?.let { + error(it, e !is RedirectedToGooglePlayException) + } } + } else { + error(getString(R.string.app_not_found), true) } } else { error(getString(R.string.intent_extras_incorrect)) diff --git a/app/src/main/java/de/redno/disabledlauncher/service/AdbService.kt b/app/src/main/java/de/redno/disabledlauncher/service/AdbService.kt index 968a044..48e689e 100644 --- a/app/src/main/java/de/redno/disabledlauncher/service/AdbService.kt +++ b/app/src/main/java/de/redno/disabledlauncher/service/AdbService.kt @@ -1,7 +1,7 @@ package de.redno.disabledlauncher.service +import android.content.Context import android.content.pm.PackageManager -import android.content.res.Resources import androidx.compose.material.* import androidx.compose.runtime.* import de.redno.disabledlauncher.R @@ -33,11 +33,11 @@ object AdbService { } @Throws(DisabledLauncherException::class) - fun executeAdbCommand(command: String) { + fun executeAdbCommand(context: Context, command: String) { checkShizukuPermission() if (Shizuku.newProcess(arrayOf("sh", "-c", command), null, null).waitFor() != 0) { - throw DisabledLauncherException(Resources.getSystem().getString(R.string.process_failure)) + throw DisabledLauncherException(context.getString(R.string.process_failure)) } } } diff --git a/app/src/main/java/de/redno/disabledlauncher/service/AppService.kt b/app/src/main/java/de/redno/disabledlauncher/service/AppService.kt index 7b74da6..bee55cb 100644 --- a/app/src/main/java/de/redno/disabledlauncher/service/AppService.kt +++ b/app/src/main/java/de/redno/disabledlauncher/service/AppService.kt @@ -49,19 +49,20 @@ object AppService { } return App( - name = context.getString(R.string.app_not_found), + name = context.getString(R.string.unknown_app), packageName = packageName, icon = context.getDrawable(R.drawable.ic_launcher_background)!! .toBitmap(), // TODO: add proper app icons (+ for static shortcut, etc.) isEnabled = false, - isInstalled = false + isInstalled = false, + overlyingListType = overlyingListType ) } @Throws(DisabledLauncherException::class) fun enableApp(context: Context, app: App, showToast: Boolean = false) { try { - AdbService.executeAdbCommand("pm enable ${app.packageName}") + AdbService.executeAdbCommand(context, "pm enable ${app.packageName}") if (showToast) { AndroidUtil.asyncToastMakeText( @@ -104,7 +105,7 @@ object AppService { @Throws(DisabledLauncherException::class) fun disableApp(context: Context, app: App, showToast: Boolean = true) { - AdbService.executeAdbCommand("pm disable-user --user 0 ${app.packageName}") + AdbService.executeAdbCommand(context, "pm disable-user --user 0 ${app.packageName}") if (showToast) { AndroidUtil.asyncToastMakeText( diff --git a/app/src/main/java/de/redno/disabledlauncher/ui/components/Common.kt b/app/src/main/java/de/redno/disabledlauncher/ui/components/Common.kt index fb7c86a..60dc759 100644 --- a/app/src/main/java/de/redno/disabledlauncher/ui/components/Common.kt +++ b/app/src/main/java/de/redno/disabledlauncher/ui/components/Common.kt @@ -335,6 +335,7 @@ fun AppList( LazyColumn { // TODO: prevent being called on every search text change (; is this still applicable?) items(items = appList + .distinctBy { it.packageName + it.overlyingListType } // ensuring unique key in the list .filter { val searchTerms = text.trim().lowercase().split(" ") val searchReference = "${it.name.trim().lowercase()} ${it.packageName.trim().lowercase()}" @@ -349,7 +350,7 @@ fun AppList( } } .sortedBy { !it.isInstalled }, - key = App::packageName + key = { "${it.packageName}_${it.overlyingListType}" } ) { app -> AppEntry( app = app, diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index b094fd5..6332c86 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -13,6 +13,7 @@ Auswahl bestätigen Suche löschen App nicht gefunden + Unbekannte App Nichts zu deaktivieren %s deaktiviert %s aktiviert diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0c3101f..1207a54 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -13,6 +13,7 @@ Confirm selected apps Clear search App not found + Unknown app Nothing to disable Disabled %s Enabled %s