mirror of
https://github.com/topjohnwu/Magisk.git
synced 2026-01-15 22:33:05 -08:00
Multiple minor changes
This commit is contained in:
@@ -2,10 +2,6 @@ package com.topjohnwu.magisk.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.net.Uri
|
||||
import android.os.Environment
|
||||
@@ -18,7 +14,6 @@ import com.topjohnwu.magisk.model.update.UpdateCheckService
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import com.topjohnwu.superuser.internal.UiThreadHandler
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
object Utils {
|
||||
@@ -33,40 +28,17 @@ object Utils {
|
||||
UiThreadHandler.run { Toast.makeText(get(), resId, duration).show() }
|
||||
}
|
||||
|
||||
fun getPrefsInt(prefs: SharedPreferences, key: String, def: Int = 0): Int {
|
||||
return prefs.getString(key, def.toString())!!.toInt()
|
||||
}
|
||||
|
||||
fun dpInPx(dp: Int): Int {
|
||||
val scale = get<Resources>().displayMetrics.density
|
||||
return (dp * scale + 0.5).toInt()
|
||||
}
|
||||
|
||||
fun fmt(fmt: String, vararg args: Any): String {
|
||||
return String.format(Locale.US, fmt, *args)
|
||||
}
|
||||
|
||||
fun getAppLabel(info: ApplicationInfo, pm: PackageManager): String {
|
||||
try {
|
||||
if (info.labelRes > 0) {
|
||||
val res = pm.getResourcesForApplication(info)
|
||||
val config = Configuration()
|
||||
config.setLocale(currentLocale)
|
||||
res.updateConfiguration(config, res.displayMetrics)
|
||||
return res.getString(info.labelRes)
|
||||
}
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
|
||||
return info.loadLabel(pm).toString()
|
||||
}
|
||||
|
||||
fun showSuperUser(): Boolean {
|
||||
return Shell.rootAccess() && (Const.USER_ID == 0
|
||||
|| Config.suMultiuserMode != Config.Value.MULTIUSER_MODE_OWNER_MANAGED)
|
||||
}
|
||||
|
||||
fun scheduleUpdateCheck() {
|
||||
fun scheduleUpdateCheck(context: Context) {
|
||||
if (Config.checkUpdate) {
|
||||
val constraints = Constraints.Builder()
|
||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||
@@ -76,11 +48,12 @@ object Utils {
|
||||
.Builder(ClassMap[UpdateCheckService::class.java], 12, TimeUnit.HOURS)
|
||||
.setConstraints(constraints)
|
||||
.build()
|
||||
WorkManager.getInstance().enqueueUniquePeriodicWork(
|
||||
WorkManager.getInstance(context).enqueueUniquePeriodicWork(
|
||||
Const.ID.CHECK_MAGISK_UPDATE_WORKER_ID,
|
||||
ExistingPeriodicWorkPolicy.REPLACE, request)
|
||||
} else {
|
||||
WorkManager.getInstance().cancelUniqueWork(Const.ID.CHECK_MAGISK_UPDATE_WORKER_ID)
|
||||
WorkManager.getInstance(context)
|
||||
.cancelUniqueWork(Const.ID.CHECK_MAGISK_UPDATE_WORKER_ID)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user