From c542a6dfb54bb0e57efe10aa4c575a42ce929e35 Mon Sep 17 00:00:00 2001 From: Cedric Bruckner Date: Thu, 24 Oct 2019 10:08:09 +0200 Subject: [PATCH] Added new method entry to know if the lib can handle the autostart --- .../autostarter/AutoStartPermissionHelper.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/autostarter/src/main/java/com/judemanutd/autostarter/AutoStartPermissionHelper.kt b/autostarter/src/main/java/com/judemanutd/autostarter/AutoStartPermissionHelper.kt index aaf1c4e..594a6d4 100644 --- a/autostarter/src/main/java/com/judemanutd/autostarter/AutoStartPermissionHelper.kt +++ b/autostarter/src/main/java/com/judemanutd/autostarter/AutoStartPermissionHelper.kt @@ -72,6 +72,8 @@ class AutoStartPermissionHelper private constructor() { private val PACKAGE_NOKIA_MAIN = "com.evenwell.powersaving.g3" private val PACKAGE_NOKIA_COMPONENT = "com.evenwell.powersaving.g3.exception.PowerSaverExceptionActivity" + private val PACKAGES_TO_CHECK_FOR_PERMISSION = listOf(PACKAGE_ASUS_MAIN, PACKAGE_XIAOMI_MAIN, PACKAGE_LETV_MAIN, PACKAGE_HONOR_MAIN, PACKAGE_OPPO_MAIN, PACKAGE_OPPO_FALLBACK, PACKAGE_VIVO_MAIN, PACKAGE_VIVO_FALLBACK, PACKAGE_NOKIA_MAIN, PACKAGE_HUAWEI_MAIN) + fun getAutoStartPermission(context: Context) { val build_info = Build.BRAND.toLowerCase() @@ -97,6 +99,19 @@ class AutoStartPermissionHelper private constructor() { } + fun isAutoStartPermissionAvailable(context: Context): Boolean { + + val packages: List + val pm = context.packageManager + packages = pm.getInstalledApplications(0) + for (packageInfo in packages) { + if (PACKAGES_TO_CHECK_FOR_PERMISSION.contains(packageInfo.packageName)) { + return true + } + } + return false + } + private fun autoStartXiaomi(context: Context) { if (isPackageExists(context, PACKAGE_XIAOMI_MAIN)) { try {