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

This commit is contained in:
inotia00 2024-12-31 21:51:39 +09:00
parent b105fc1f62
commit 41aaeafbe9

View File

@ -120,7 +120,11 @@ public class GmsCoreSupport {
} }
// Check if GmsCore is whitelisted from battery optimizations. // Check if GmsCore is whitelisted from battery optimizations.
if (batteryOptimizationsEnabled(mActivity)) { if (isAndroidAutomotive(mActivity)) {
// 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(mActivity)) {
Logger.printInfo(() -> "GmsCore is not whitelisted from battery optimizations"); Logger.printInfo(() -> "GmsCore is not whitelisted from battery optimizations");
showBatteryOptimizationDialog(mActivity, showBatteryOptimizationDialog(mActivity,
"gms_core_dialog_not_whitelisted_using_battery_optimizations_message", "gms_core_dialog_not_whitelisted_using_battery_optimizations_message",
@ -220,6 +224,10 @@ public class GmsCoreSupport {
return packageName; return packageName;
} }
private static boolean isAndroidAutomotive(Context context) {
return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
}
private static String getGmsCoreDownload() { private static String getGmsCoreDownload() {
final String vendorGroupId = getGmsCoreVendorGroupId(); final String vendorGroupId = getGmsCoreVendorGroupId();
return switch (vendorGroupId) { return switch (vendorGroupId) {