Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
voruti committed Jul 14, 2023
1 parent 5659315 commit 85d2e82
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()}"
Expand All @@ -349,7 +350,7 @@ fun AppList(
}
}
.sortedBy { !it.isInstalled },
key = App::packageName
key = { "${it.packageName}_${it.overlyingListType}" }
) { app ->
AppEntry(
app = app,
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<string name="confirm_selected_apps">Auswahl bestätigen</string>
<string name="clear_search">Suche löschen</string>
<string name="app_not_found">App nicht gefunden</string>
<string name="unknown_app">Unbekannte App</string>
<string name="nothing_to_disable">Nichts zu deaktivieren</string>
<string name="disabled_app">%s deaktiviert</string>
<string name="enabled_app">%s aktiviert</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<string name="confirm_selected_apps">Confirm selected apps</string>
<string name="clear_search">Clear search</string>
<string name="app_not_found">App not found</string>
<string name="unknown_app">Unknown app</string>
<string name="nothing_to_disable">Nothing to disable</string>
<string name="disabled_app">Disabled %s</string>
<string name="enabled_app">Enabled %s</string>
Expand Down

0 comments on commit 85d2e82

Please sign in to comment.