fix(GmsCore support): Do not show battery optimization error on Android Automotive devices (Google built-in) (#4218)

This commit is contained in:
LisoUseInAIKyrios 2024-12-27 10:22:50 +04:00 committed by GitHub
parent cff1153d24
commit d6e389cc43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -106,7 +106,11 @@ public class GmsCoreSupport {
}
// 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 @@ public class GmsCoreSupport {
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