diff --git a/build.gradle b/build.gradle index ee659d3de2baeb7542224bc7aac9fb5897b62f39..785ae44a042222efd8a6119920f3976c2e00ed75 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.6.10' + ext.kotlin_version = '1.6.20' repositories { mavenCentral() google() diff --git a/gradle.properties b/gradle.properties index 972becf0d6f5dca077449178dcb68ae25022f88b..5d34c3a431147fdededa057f053ebaa83cce0ebf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ GROUP=org.briarproject POM_ARTIFACT_ID=dont-kill-me-lib -VERSION_NAME=0.1 +VERSION_NAME=0.2 POM_NAME=Do not kill me library POM_DESCRIPTION=An Android library helping to keep a foreground service with wake-locks running. No other use-cases considered. diff --git a/lib/src/main/java/org/briarproject/android/dontkillmelib/HuaweiUtils.kt b/lib/src/main/java/org/briarproject/android/dontkillmelib/HuaweiUtils.kt index 1f891679efcd5f8517594ea2291598a88c3664b0..979f4f852e58f262016f038171a2d667cdaeb259 100644 --- a/lib/src/main/java/org/briarproject/android/dontkillmelib/HuaweiUtils.kt +++ b/lib/src/main/java/org/briarproject/android/dontkillmelib/HuaweiUtils.kt @@ -8,6 +8,8 @@ import android.os.Build.VERSION.SDK_INT public object HuaweiUtils { private const val PACKAGE_NAME_HUAWEI = "com.huawei.systemmanager" + private const val CLASS_NAME_APP_LIST = + "$PACKAGE_NAME_HUAWEI.startupmgr.ui.StartupNormalAppListActivity" private const val CLASS_NAME_POWER_MANAGER = "$PACKAGE_NAME_HUAWEI.power.ui.HwPowerManagerActivity" private const val CLASS_NAME_PROTECTED_APPS = @@ -22,8 +24,10 @@ public object HuaweiUtils { // "App launch" was introduced in EMUI 8 (Android 8.0) if (SDK_INT < 26) return false val pm = context.packageManager - val resolveInfos = pm.queryIntentActivities(huaweiProtectedAppsIntent, MATCH_DEFAULT_ONLY) - return resolveInfos.isNotEmpty() + for (i in huaweiAppLaunchIntents) { + if (pm.queryIntentActivities(i, MATCH_DEFAULT_ONLY).isNotEmpty()) return true + } + return false } /** @@ -39,11 +43,27 @@ public object HuaweiUtils { return resolveInfos.isNotEmpty() } + @JvmStatic + public val huaweiAppListIntent: Intent = Intent().apply { + setClassName(PACKAGE_NAME_HUAWEI, CLASS_NAME_APP_LIST) + } + @JvmStatic public val huaweiPowerManagerIntent: Intent = Intent().apply { setClassName(PACKAGE_NAME_HUAWEI, CLASS_NAME_POWER_MANAGER) } + /** + * First tries [huaweiAppListIntent] and then falls back to [huaweiPowerManagerIntent]. + */ + @JvmStatic + public val huaweiAppLaunchIntents: List<Intent> = listOf( + // First try to open StartupNormalAppListActivity + huaweiAppListIntent, + // Fall back to HwPowerManagerActivity + huaweiPowerManagerIntent, + ) + @JvmStatic public val huaweiProtectedAppsIntent: Intent = Intent().apply { setClassName(PACKAGE_NAME_HUAWEI, CLASS_NAME_PROTECTED_APPS) diff --git a/lib/src/main/res/values/strings.xml b/lib/src/main/res/values/strings.xml index 62db8f4213222ede75df0509a85ffa591be85a3c..ce4fe3f42cecdb47feedd26566da9cd15ba504e9 100644 --- a/lib/src/main/res/values/strings.xml +++ b/lib/src/main/res/values/strings.xml @@ -12,6 +12,7 @@ <string name="dnkm_huawei_app_launch_text">Please tap the button below, open the \"App launch\" screen and make sure this app is set to \"Manage manually\".</string> <string name="dnkm_huawei_app_launch_button">Open Battery Settings</string> <string name="dnkm_huawei_app_launch_help">If this app is not set to \"Manage manually\" in the \"App launch\" screen, it will not be able to run in the background.</string> + <string name="dnkm_huawei_app_launch_error_toast">Could not open battery settings</string> <string name="dnkm_xiaomi_text">To run in the background, this app needs to be locked to the recent apps list.</string> <string name="dnkm_xiaomi_button">Lock to recent apps</string> @@ -21,4 +22,6 @@ <string name="dnkm_got_it">Got it</string> <string name="dnkm_help">Help</string> + + <string name="dnkm_warning_dozed">%s was unable to run in the background</string> </resources>