0
0
Fork 0
mirror of https://github.com/YTVanced/VancedMicroG synced 2024-11-27 21:53:00 +00:00

Add default preferences for Huawei devices

This commit is contained in:
Oizaro 2020-09-15 00:19:43 +02:00
parent 7b9fb6d04b
commit 4376d011ad
3 changed files with 24 additions and 8 deletions

View file

@ -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() {

View file

@ -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() {

View file

@ -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;
}
}