Skip to content

Commit

Permalink
fix(root): Fixed crash when attempting to open battery optimization s…
Browse files Browse the repository at this point in the history
…ettings page but it isn't implemented by the manufacturer
  • Loading branch information
timschneeb committed May 23, 2023
1 parent d35b653 commit f493a86
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import me.timschneeberger.rootlessjamesdsp.databinding.DialogTextinputBinding
import me.timschneeberger.rootlessjamesdsp.utils.Constants
import me.timschneeberger.rootlessjamesdsp.utils.extensions.CompatExtensions.getApplicationInfoCompat
import me.timschneeberger.rootlessjamesdsp.utils.extensions.CompatExtensions.getPackageInfoCompat
import me.timschneeberger.rootlessjamesdsp.utils.extensions.ContextExtensions.toast
import timber.log.Timber
import java.io.File
import kotlin.math.roundToInt
Expand Down Expand Up @@ -145,15 +146,20 @@ object ContextExtensions {
@SuppressLint("BatteryLife")
fun Context.requestIgnoreBatteryOptimizations() {
if (!BuildConfig.ROOTLESS && !getSystemService<PowerManager>()!!.isIgnoringBatteryOptimizations(packageName)) {
startActivity(Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
Uri.parse("package:$packageName")))
try {
startActivity(Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
Uri.parse("package:$packageName")))
}
catch(ex: ActivityNotFoundException) {
toast(getString(R.string.no_activity_found))
}
}
}

// Very simple & naive app cloner checks; please don't use multiple instances at once
private val PKGNAME_REFS = setOf("bWUudGltc2NobmVlYmVyZ2VyLnJvb3RsZXNzamFtZXNkc3A=",
"bWUudGltc2NobmVlYmVyZ2VyLnJvb3RsZXNzamFtZXNkc3AuZGVidWc=",
"amFtZXMuZHNw", "amFtZXMuZHNwLmRlYnVn")
"bWUudGltc2NobmVlYmVyZ2VyLnJvb3RsZXNzamFtZXNkc3AuZGVidWc=",
"amFtZXMuZHNw", "amFtZXMuZHNwLmRlYnVn")
private val APPNAME_REFS = setOf("Um9vdGxlc3NKYW1lc0RTUA==", "SmFtZXNEU1A=")
fun Context.check(): Int {
val appName = getAppName()
Expand Down Expand Up @@ -238,7 +244,7 @@ object ContextExtensions {
suffix: String?,
callback: ((String?) -> Unit)
) {
showInputAlert(layoutInflater, getString(title), getString(hint), value, isNumberInput, suffix, callback)
showInputAlert(layoutInflater, getString(title), getString(hint), value, isNumberInput, suffix, callback)
}

fun Context.showInputAlert(
Expand Down

0 comments on commit f493a86

Please sign in to comment.