From a2afbe07fd24b60ade03fd7ca9885db8bae467fe Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sun, 13 Sep 2020 02:10:44 +0200 Subject: [PATCH] Only apply preferences when they actually changed --- .../src/main/java/org/microg/gms/checkin/CheckinPrefs.java | 2 ++ .../src/main/java/org/microg/gms/gcm/GcmPrefs.java | 2 ++ .../gms/nearby/exposurenotification/ExposurePreferences.kt | 2 ++ 3 files changed, 6 insertions(+) diff --git a/play-services-core/src/main/java/org/microg/gms/checkin/CheckinPrefs.java b/play-services-core/src/main/java/org/microg/gms/checkin/CheckinPrefs.java index 348f4244..f4f5b76d 100644 --- a/play-services-core/src/main/java/org/microg/gms/checkin/CheckinPrefs.java +++ b/play-services-core/src/main/java/org/microg/gms/checkin/CheckinPrefs.java @@ -67,7 +67,9 @@ public class CheckinPrefs implements SharedPreferences.OnSharedPreferenceChangeL } public static void setEnabled(Context context, boolean newStatus) { + boolean changed = CheckinPrefs.get(context).isEnabled() != newStatus; PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(PREF_ENABLE_CHECKIN, newStatus).commit(); + if (!changed) return; if (newStatus) { context.sendOrderedBroadcast(new Intent(context, TriggerReceiver.class), null); } diff --git a/play-services-core/src/main/java/org/microg/gms/gcm/GcmPrefs.java b/play-services-core/src/main/java/org/microg/gms/gcm/GcmPrefs.java index 568efd1f..852f85ea 100644 --- a/play-services-core/src/main/java/org/microg/gms/gcm/GcmPrefs.java +++ b/play-services-core/src/main/java/org/microg/gms/gcm/GcmPrefs.java @@ -218,7 +218,9 @@ public class GcmPrefs implements SharedPreferences.OnSharedPreferenceChangeListe } public static void setEnabled(Context context, boolean newStatus) { + boolean changed = GcmPrefs.get(context).isEnabled() != newStatus; PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(GcmPrefs.PREF_ENABLE_GCM, newStatus).commit(); + if (!changed) return; if (!newStatus) { McsService.stop(context); } else { diff --git a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposurePreferences.kt b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposurePreferences.kt index 511e3b02..9b840f73 100644 --- a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposurePreferences.kt +++ b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposurePreferences.kt @@ -25,7 +25,9 @@ class ExposurePreferences(private val context: Context) { var enabled get() = preferences.getBoolean(PREF_SCANNER_ENABLED, false) set(newStatus) { + val changed = enabled != newStatus preferences.edit().putBoolean(PREF_SCANNER_ENABLED, newStatus).commit() + if (!changed) return if (newStatus) { context.sendOrderedBroadcast(Intent(context, ServiceTrigger::class.java), null) } else {