Skip to content

Commit

Permalink
Don't crash if we are not allowed to open the system details for an app
Browse files Browse the repository at this point in the history
realme narzo 30A (RMX3171) @ Android 11
```
java.lang.SecurityException: Not allowed to start activity Intent { act=android.settings.APPLICATION_DETAILS_SETTINGS dat=package:com.coloros.sauhelper flg=0x10000000 }
``
  • Loading branch information
d4rken committed May 12, 2023
1 parent d1c490a commit 34271f2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import eu.darken.sdmse.R
import eu.darken.sdmse.appcleaner.core.AppJunk
import eu.darken.sdmse.appcleaner.ui.details.appjunk.AppJunkElementsAdapter
import eu.darken.sdmse.common.coil.loadAppIcon
import eu.darken.sdmse.common.debug.logging.Logging.Priority.WARN
import eu.darken.sdmse.common.debug.logging.log
import eu.darken.sdmse.common.lists.binding
import eu.darken.sdmse.common.pkgs.getSettingsIntent
import eu.darken.sdmse.databinding.AppcleanerAppjunkElementHeaderBinding
Expand All @@ -31,7 +33,11 @@ class AppJunkElementHeaderVH(parent: ViewGroup) :
loadAppIcon(junk.pkg)
setOnLongClickListener {
val intent = junk.pkg.getSettingsIntent(context)
context.startActivity(intent)
try {
context.startActivity(intent)
} catch (e: Exception) {
log(WARN) { "Settings intent failed for ${junk.pkg}: $e" }
}
true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.view.ViewGroup
import eu.darken.sdmse.R
import eu.darken.sdmse.appcleaner.core.AppJunk
import eu.darken.sdmse.common.coil.loadAppIcon
import eu.darken.sdmse.common.debug.logging.Logging.Priority.WARN
import eu.darken.sdmse.common.debug.logging.log
import eu.darken.sdmse.common.lists.binding
import eu.darken.sdmse.common.pkgs.getSettingsIntent
import eu.darken.sdmse.databinding.AppcleanerListItemBinding
Expand All @@ -27,7 +29,11 @@ class AppCleanerListRowVH(parent: ViewGroup) :
loadAppIcon(junk.pkg)
setOnLongClickListener {
val intent = junk.pkg.getSettingsIntent(context)
context.startActivity(intent)
try {
context.startActivity(intent)
} catch (e: Exception) {
log(WARN) { "Settings intent failed for ${junk.pkg}: $e" }
}
true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ import eu.darken.sdmse.appcontrol.core.createSystemSettingsIntent
import eu.darken.sdmse.appcontrol.core.toggle.AppControlToggleTask
import eu.darken.sdmse.appcontrol.core.uninstall.UninstallException
import eu.darken.sdmse.appcontrol.core.uninstall.UninstallTask
import eu.darken.sdmse.appcontrol.ui.list.actions.items.*
import eu.darken.sdmse.appcontrol.ui.list.actions.items.AppStoreActionVH
import eu.darken.sdmse.appcontrol.ui.list.actions.items.ExcludeActionVH
import eu.darken.sdmse.appcontrol.ui.list.actions.items.LaunchActionVH
import eu.darken.sdmse.appcontrol.ui.list.actions.items.SystemSettingsActionVH
import eu.darken.sdmse.appcontrol.ui.list.actions.items.ToggleActionVH
import eu.darken.sdmse.appcontrol.ui.list.actions.items.UninstallActionVH
import eu.darken.sdmse.common.SingleLiveEvent
import eu.darken.sdmse.common.coroutine.DispatcherProvider
import eu.darken.sdmse.common.debug.logging.Logging.Priority.ERROR
import eu.darken.sdmse.common.debug.logging.asLog
import eu.darken.sdmse.common.debug.logging.log
import eu.darken.sdmse.common.debug.logging.logTag
import eu.darken.sdmse.common.navigation.navArgs
Expand All @@ -29,7 +36,12 @@ import eu.darken.sdmse.exclusion.core.currentExclusions
import eu.darken.sdmse.exclusion.core.types.Exclusion
import eu.darken.sdmse.exclusion.core.types.PackageExclusion
import eu.darken.sdmse.main.core.taskmanager.TaskManager
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.take
import javax.inject.Inject


Expand Down Expand Up @@ -88,7 +100,12 @@ class AppActionDialogVM @Inject constructor(
appInfo = appInfo,
onSettings = {
val intent = it.createSystemSettingsIntent(context)
context.startActivity(intent)
try {
context.startActivity(intent)
} catch (e: Exception) {
log(TAG, ERROR) { "Launching system settings intent failed: ${e.asLog()}" }
errorEvents.postValue(e)
}
}
)

Expand Down

0 comments on commit 34271f2

Please sign in to comment.