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:
parent
7b9fb6d04b
commit
4376d011ad
3 changed files with 24 additions and 8 deletions
|
@ -13,6 +13,7 @@ import androidx.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.microg.gms.common.PackageUtils;
|
import org.microg.gms.common.PackageUtils;
|
||||||
|
import org.microg.gms.gcm.McsConstants;
|
||||||
|
|
||||||
import java.io.File;
|
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);
|
systemDefaultPreferences = (SharedPreferences) Context.class.getDeclaredMethod("getSharedPreferences", File.class, int.class).invoke(context, new File("/system/etc/microg.xml"), Context.MODE_PRIVATE);
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
update();
|
update(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,13 +55,13 @@ public class CheckinPrefs implements SharedPreferences.OnSharedPreferenceChangeL
|
||||||
return preferences.getBoolean(key, def);
|
return preferences.getBoolean(key, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update() {
|
private void update(Context context) {
|
||||||
checkinEnabled = getSettingsBoolean(PREF_ENABLE_CHECKIN, true);
|
checkinEnabled = getSettingsBoolean(PREF_ENABLE_CHECKIN, McsConstants.gmsExists(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
update();
|
update(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.microg.gms.gcm;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.util.Log;
|
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);
|
systemDefaultPreferences = (SharedPreferences) Context.class.getDeclaredMethod("getSharedPreferences", File.class, int.class).invoke(context, new File("/system/etc/microg.xml"), Context.MODE_PRIVATE);
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
update();
|
update(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,8 +100,8 @@ public class GcmPrefs implements SharedPreferences.OnSharedPreferenceChangeListe
|
||||||
return preferences.getBoolean(key, def);
|
return preferences.getBoolean(key, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update(Context context) {
|
||||||
gcmEnabled = getSettingsBoolean(PREF_ENABLE_GCM, true);
|
gcmEnabled = getSettingsBoolean(PREF_ENABLE_GCM, McsConstants.gmsExists(context));
|
||||||
gcmLogEnabled = getSettingsBoolean(PREF_FULL_LOG, true);
|
gcmLogEnabled = getSettingsBoolean(PREF_FULL_LOG, true);
|
||||||
confirmNewApps = getSettingsBoolean(PREF_CONFIRM_NEW_APPS, false);
|
confirmNewApps = getSettingsBoolean(PREF_CONFIRM_NEW_APPS, false);
|
||||||
|
|
||||||
|
@ -207,7 +208,7 @@ public class GcmPrefs implements SharedPreferences.OnSharedPreferenceChangeListe
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
update();
|
update(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
|
|
|
@ -16,6 +16,9 @@
|
||||||
|
|
||||||
package org.microg.gms.gcm;
|
package org.microg.gms.gcm;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
|
||||||
public final class McsConstants {
|
public final class McsConstants {
|
||||||
public static final int MCS_HEARTBEAT_PING_TAG = 0;
|
public static final int MCS_HEARTBEAT_PING_TAG = 0;
|
||||||
public static final int MCS_HEARTBEAT_ACK_TAG = 1;
|
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_SEND = "org.microg.gms.gcm.mcs.SEND";
|
||||||
public static String ACTION_ACK = "org.microg.gms.gcm.mcs.ACK";
|
public static String ACTION_ACK = "org.microg.gms.gcm.mcs.ACK";
|
||||||
public static String EXTRA_REASON = "org.microg.gms.gcm.mcs.REASON";
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue