From 4376d011ad112c970666bb2e9319292fd21cb650 Mon Sep 17 00:00:00 2001 From: Oizaro <45825534+Oizaro@users.noreply.github.com> Date: Tue, 15 Sep 2020 00:19:43 +0200 Subject: [PATCH] Add default preferences for Huawei devices --- .../java/org/microg/gms/checkin/CheckinPrefs.java | 9 +++++---- .../src/main/java/org/microg/gms/gcm/GcmPrefs.java | 9 +++++---- .../main/java/org/microg/gms/gcm/McsConstants.java | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 8 deletions(-) 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 81e0db1c..c3993be7 100755 --- 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 @@ -13,6 +13,7 @@ import androidx.preference.PreferenceManager; import android.util.Log; import org.microg.gms.common.PackageUtils; +import org.microg.gms.gcm.McsConstants; import java.io.File; @@ -43,7 +44,7 @@ public class CheckinPrefs implements SharedPreferences.OnSharedPreferenceChangeL systemDefaultPreferences = (SharedPreferences) Context.class.getDeclaredMethod("getSharedPreferences", File.class, int.class).invoke(context, new File("/system/etc/microg.xml"), Context.MODE_PRIVATE); } catch (Exception ignored) { } - update(); + update(context); } } @@ -54,13 +55,13 @@ public class CheckinPrefs implements SharedPreferences.OnSharedPreferenceChangeL return preferences.getBoolean(key, def); } - private void update() { - checkinEnabled = getSettingsBoolean(PREF_ENABLE_CHECKIN, true); + private void update(Context context) { + checkinEnabled = getSettingsBoolean(PREF_ENABLE_CHECKIN, McsConstants.gmsExists(context)); } @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - update(); + update(null); } public boolean isEnabled() { 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 6bea3c8f..71ca319d 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 @@ -19,6 +19,7 @@ package org.microg.gms.gcm; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.util.Log; @@ -88,7 +89,7 @@ public class GcmPrefs implements SharedPreferences.OnSharedPreferenceChangeListe systemDefaultPreferences = (SharedPreferences) Context.class.getDeclaredMethod("getSharedPreferences", File.class, int.class).invoke(context, new File("/system/etc/microg.xml"), Context.MODE_PRIVATE); } catch (Exception ignored) { } - update(); + update(context); } } @@ -99,8 +100,8 @@ public class GcmPrefs implements SharedPreferences.OnSharedPreferenceChangeListe return preferences.getBoolean(key, def); } - public void update() { - gcmEnabled = getSettingsBoolean(PREF_ENABLE_GCM, true); + public void update(Context context) { + gcmEnabled = getSettingsBoolean(PREF_ENABLE_GCM, McsConstants.gmsExists(context)); gcmLogEnabled = getSettingsBoolean(PREF_FULL_LOG, true); confirmNewApps = getSettingsBoolean(PREF_CONFIRM_NEW_APPS, false); @@ -207,7 +208,7 @@ public class GcmPrefs implements SharedPreferences.OnSharedPreferenceChangeListe @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - update(); + update(null); } public boolean isEnabled() { diff --git a/play-services-core/src/main/java/org/microg/gms/gcm/McsConstants.java b/play-services-core/src/main/java/org/microg/gms/gcm/McsConstants.java index 0b3108dd..325cd373 100644 --- a/play-services-core/src/main/java/org/microg/gms/gcm/McsConstants.java +++ b/play-services-core/src/main/java/org/microg/gms/gcm/McsConstants.java @@ -16,6 +16,9 @@ package org.microg.gms.gcm; +import android.content.Context; +import android.content.pm.PackageManager; + public final class McsConstants { public static final int MCS_HEARTBEAT_PING_TAG = 0; public static final int MCS_HEARTBEAT_ACK_TAG = 1; @@ -44,4 +47,15 @@ public final class McsConstants { public static String ACTION_SEND = "org.microg.gms.gcm.mcs.SEND"; public static String ACTION_ACK = "org.microg.gms.gcm.mcs.ACK"; public static String EXTRA_REASON = "org.microg.gms.gcm.mcs.REASON"; + + public static boolean gmsExists(Context context) { + try { + if (context != null && + context.getPackageManager().getApplicationInfo("com.google.android.gms", 0).enabled) { + return true; + } + } catch (PackageManager.NameNotFoundException e) {} + + return false; + } }