From 33c126473045c90019bf313d14afae9ac19ab590 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Wed, 25 Dec 2024 14:14:11 +0400 Subject: [PATCH] fix(GmsCore support): Do not show battery optimization error on Android Automotive devices (Google built-in) --- .../app/revanced/extension/shared/GmsCoreSupport.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/extensions/shared/library/src/main/java/app/revanced/extension/shared/GmsCoreSupport.java b/extensions/shared/library/src/main/java/app/revanced/extension/shared/GmsCoreSupport.java index d7bd715905..83a3ca130f 100644 --- a/extensions/shared/library/src/main/java/app/revanced/extension/shared/GmsCoreSupport.java +++ b/extensions/shared/library/src/main/java/app/revanced/extension/shared/GmsCoreSupport.java @@ -106,7 +106,11 @@ public static void checkGmsCore(Activity context) { } // Check if GmsCore is whitelisted from battery optimizations. - if (batteryOptimizationsEnabled(context)) { + if (isAndroidAutomotive(context)) { + // Ignore Android Automotive devices (Google built-in), + // as there is no way to disable battery optimizations. + Logger.printDebug(() -> "Device is Android Automotive"); + } else if (batteryOptimizationsEnabled(context)) { Logger.printInfo(() -> "GmsCore is not whitelisted from battery optimizations"); showBatteryOptimizationDialog(context, @@ -147,6 +151,10 @@ private static boolean batteryOptimizationsEnabled(Context context) { return !powerManager.isIgnoringBatteryOptimizations(GMS_CORE_PACKAGE_NAME); } + private static boolean isAndroidAutomotive(Context context) { + return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE); + } + private static String getGmsCoreDownload() { final var vendorGroupId = getGmsCoreVendorGroupId(); //noinspection SwitchStatementWithTooFewBranches