From c86b9ab7c583b8796e0a9ef893c92a7b2d7cbfce Mon Sep 17 00:00:00 2001 From: Oizaro <75915943+Oizaro@users.noreply.github.com> Date: Tue, 6 Jul 2021 15:07:39 +0200 Subject: [PATCH] Remove getDefaultSharedPreferences calls --- .../microg/gms/auth/login/LoginActivity.java | 20 ++++++++-------- .../org/microg/gms/checkin/CheckinClient.java | 5 ++-- .../microg/gms/checkin/CheckinManager.java | 5 +++- .../org/microg/gms/checkin/CheckinPrefs.kt | 23 +++++++++++++++++++ .../org/microg/gms/ui/SettingsFragment.kt | 6 ++--- .../microg/mgms/settings/SettingsContract.kt | 6 +++++ .../microg/mgms/settings/SettingsProvider.kt | 22 ++++++++++++++++++ .../src/main/res/values-cs/strings.xml | 2 +- .../src/main/res/values-es/strings.xml | 2 +- .../src/main/res/values-in/strings.xml | 2 +- .../src/main/res/values-it/strings.xml | 2 +- .../src/main/res/values-ru/strings.xml | 2 +- .../src/main/res/values/strings.xml | 2 +- .../src/main/res/xml/preferences_start.xml | 4 ++-- 14 files changed, 78 insertions(+), 25 deletions(-) diff --git a/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java b/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java index 5f82f96541..61224887a9 100644 --- a/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java +++ b/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java @@ -75,6 +75,9 @@ import static android.view.View.VISIBLE; import static android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT; import static org.microg.gms.auth.AuthPrefs.isAuthVisible; +import static org.microg.gms.checkin.CheckinPrefs.hideLauncherIcon; +import static org.microg.gms.checkin.CheckinPrefs.isSpoofingEnabled; +import static org.microg.gms.checkin.CheckinPrefs.setSpoofingEnabled; import static org.microg.gms.common.Constants.GMS_PACKAGE_NAME; import static org.microg.gms.common.Constants.GMS_VERSION_CODE; @@ -163,16 +166,17 @@ protected void onHuaweiButtonClicked() { state++; if (state == 1) { if (SDK_INT >= Build.VERSION_CODES.M) { - PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean("pref_hide_launcher_icon", false).apply(); + hideLauncherIcon(this, false); UtilsKt.hideIcon(this, false); } - PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(HuaweiButtonPreference, true).apply(); - if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(LoginButtonPreference, true)) { + if (!isSpoofingEnabled(this)) { LastCheckinInfo.clear(this); - CheckinClient.brandSpoof = true; - PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(LoginButtonPreference, true).apply(); + setSpoofingEnabled(this, true); } init(); + } else if (state == -1) { + setResult(RESULT_CANCELED); + finish(); } } @@ -181,11 +185,9 @@ protected void onNextButtonClicked() { super.onNextButtonClicked(); state++; if (state == 1) { - PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(LoginButtonPreference, true).apply(); - if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(HuaweiButtonPreference, true)) { + if (isSpoofingEnabled(this)) { LastCheckinInfo.clear(this); - CheckinClient.brandSpoof = false; - PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(HuaweiButtonPreference, true).apply(); + setSpoofingEnabled(this, false); } init(); } else if (state == -1) { diff --git a/play-services-core/src/main/java/org/microg/gms/checkin/CheckinClient.java b/play-services-core/src/main/java/org/microg/gms/checkin/CheckinClient.java index 5527ac48b7..2793663a4a 100755 --- a/play-services-core/src/main/java/org/microg/gms/checkin/CheckinClient.java +++ b/play-services-core/src/main/java/org/microg/gms/checkin/CheckinClient.java @@ -45,8 +45,7 @@ public class CheckinClient { private static final List TODO_LIST_STRING = new ArrayList<>(); // TODO private static final List TODO_LIST_CHECKIN = new ArrayList(); // TODO private static final String SERVICE_URL = "https://android.clients.google.com/checkin"; - public static boolean brandSpoof = false; - + public static CheckinResponse request(CheckinRequest request) throws IOException { HttpURLConnection connection = (HttpURLConnection) new URL(SERVICE_URL).openConnection(); connection.setRequestMethod("POST"); @@ -79,7 +78,7 @@ public static CheckinResponse request(CheckinRequest request) throws IOException public static CheckinRequest makeRequest(Build build, DeviceConfiguration deviceConfiguration, DeviceIdentifier deviceIdent, PhoneInfo phoneInfo, LastCheckinInfo checkinInfo, Locale locale, - List accounts) { + List accounts, Boolean brandSpoof) { CheckinRequest.Builder builder = new CheckinRequest.Builder() .accountCookie(new ArrayList<>()) .androidId(checkinInfo.getAndroidId()) diff --git a/play-services-core/src/main/java/org/microg/gms/checkin/CheckinManager.java b/play-services-core/src/main/java/org/microg/gms/checkin/CheckinManager.java index 018d96559a..9bed5db080 100755 --- a/play-services-core/src/main/java/org/microg/gms/checkin/CheckinManager.java +++ b/play-services-core/src/main/java/org/microg/gms/checkin/CheckinManager.java @@ -32,6 +32,8 @@ import java.util.ArrayList; import java.util.List; +import static org.microg.gms.checkin.CheckinPrefs.isSpoofingEnabled; + public class CheckinManager { private static final String TAG = "GmsCheckinManager"; private static final long MIN_CHECKIN_INTERVAL = 3 * 60 * 60 * 1000; // 3 hours @@ -58,7 +60,8 @@ public static synchronized LastCheckinInfo checkin(Context context, boolean forc } CheckinRequest request = CheckinClient.makeRequest(Utils.getBuild(context), new DeviceConfiguration(context), Utils.getDeviceIdentifier(context), - Utils.getPhoneInfo(context), info, Utils.getLocale(context), accounts); + Utils.getPhoneInfo(context), info, Utils.getLocale(context), accounts, + isSpoofingEnabled(context)); return handleResponse(context, CheckinClient.request(request)); } diff --git a/play-services-core/src/main/kotlin/org/microg/gms/checkin/CheckinPrefs.kt b/play-services-core/src/main/kotlin/org/microg/gms/checkin/CheckinPrefs.kt index 5623765387..ece388d9ff 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/checkin/CheckinPrefs.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/checkin/CheckinPrefs.kt @@ -7,6 +7,7 @@ package org.microg.gms.checkin import android.content.Context import org.microg.mgms.settings.SettingsContract import org.microg.mgms.settings.SettingsContract.CheckIn +import org.microg.mgms.settings.SettingsContract.setSettings object CheckinPrefs { @@ -18,4 +19,26 @@ object CheckinPrefs { } } + @JvmStatic + fun isSpoofingEnabled(context: Context): Boolean { + val projection = arrayOf(CheckIn.BRAND_SPOOF) + return SettingsContract.getSettings(context, CheckIn.CONTENT_URI, projection) { c -> + c.getInt(0) != 0 + } + } + + @JvmStatic + fun setSpoofingEnabled(context: Context, enabled: Boolean) { + setSettings(context, CheckIn.CONTENT_URI) { + put(CheckIn.BRAND_SPOOF, enabled) + } + } + + @JvmStatic + fun hideLauncherIcon(context: Context, enabled: Boolean) { + setSettings(context, CheckIn.CONTENT_URI) { + put(CheckIn.HIDE_LAUNCHER_ICON, enabled) + } + } + } diff --git a/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt index 884bc1d781..92b0d0edfc 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt @@ -9,7 +9,6 @@ import android.content.ComponentName import android.content.pm.PackageManager import android.content.Intent import android.os.Bundle -import android.util.Log import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import androidx.preference.Preference @@ -23,6 +22,7 @@ import org.microg.gms.gcm.McsConstants.ACTION_RECONNECT import org.microg.gms.gcm.McsService import org.microg.gms.gcm.TriggerReceiver import org.microg.gms.gcm.getGcmServiceInfo +import org.microg.mgms.settings.SettingsContract import org.microg.tools.ui.ResourceSettingsFragment class SettingsFragment : ResourceSettingsFragment() { @@ -57,7 +57,7 @@ class SettingsFragment : ResourceSettingsFragment() { true } - findPreference(PREF_CAST_HIDE_LAUNCHER_ICON)?.apply { + findPreference(SettingsContract.CheckIn.HIDE_LAUNCHER_ICON)?.apply { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { setOnPreferenceChangeListener { _, newValue -> requireActivity().hideIcon(newValue as Boolean) @@ -101,8 +101,6 @@ class SettingsFragment : ResourceSettingsFragment() { const val PREF_GCM = "pref_gcm" const val PREF_CHECKIN = "pref_checkin" const val PREF_CAST_DOUBLE_FIX_ENABLED = "pref_cast_double_fix_enabled" - const val PREF_CAST_HIDE_LAUNCHER_ICON = "pref_hide_launcher_icon" - const val BRAND_SPOOF_FIX_ENABLED = "brand_spoof_fix_enabled" } init { diff --git a/play-services-core/src/main/kotlin/org/microg/mgms/settings/SettingsContract.kt b/play-services-core/src/main/kotlin/org/microg/mgms/settings/SettingsContract.kt index b736f569b7..aa200de446 100644 --- a/play-services-core/src/main/kotlin/org/microg/mgms/settings/SettingsContract.kt +++ b/play-services-core/src/main/kotlin/org/microg/mgms/settings/SettingsContract.kt @@ -23,6 +23,10 @@ object SettingsContract { const val VERSION_INFO = "versionInfo" const val DEVICE_DATA_VERSION_INFO = "deviceDataVersionInfo" + const val BRAND_SPOOF = "brandSpoof" + + const val HIDE_LAUNCHER_ICON = "hideLauncherIcon" + val PROJECTION = arrayOf( ENABLED, ANDROID_ID, @@ -31,6 +35,8 @@ object SettingsContract { SECURITY_TOKEN, VERSION_INFO, DEVICE_DATA_VERSION_INFO, + BRAND_SPOOF, + HIDE_LAUNCHER_ICON, ) const val PREFERENCES_NAME = "checkin" const val INITIAL_DIGEST = "1-929a0dca0eee55513280171a8585da7dcd3700f8" diff --git a/play-services-core/src/main/kotlin/org/microg/mgms/settings/SettingsProvider.kt b/play-services-core/src/main/kotlin/org/microg/mgms/settings/SettingsProvider.kt index caf5ada63a..d191fc6e1e 100644 --- a/play-services-core/src/main/kotlin/org/microg/mgms/settings/SettingsProvider.kt +++ b/play-services-core/src/main/kotlin/org/microg/mgms/settings/SettingsProvider.kt @@ -85,6 +85,8 @@ class SettingsProvider : ContentProvider() { CheckIn.SECURITY_TOKEN -> checkInPrefs.getLong(key, 0) CheckIn.VERSION_INFO -> checkInPrefs.getString(key, "") ?: "" CheckIn.DEVICE_DATA_VERSION_INFO -> checkInPrefs.getString(key, "") ?: "" + CheckIn.BRAND_SPOOF -> getSettingsBoolean(key, false) + CheckIn.HIDE_LAUNCHER_ICON -> getSettingsBoolean(key, false) else -> throw IllegalArgumentException() } } @@ -104,6 +106,14 @@ class SettingsProvider : ContentProvider() { // special case: not saved in checkInPrefs updateCheckInEnabled(value as Boolean) } + if (key == CheckIn.BRAND_SPOOF) { + // special case: not saved in checkInPrefs + updateSpoofingEnabled(value as Boolean) + } + if (key == CheckIn.HIDE_LAUNCHER_ICON) { + // special case: not saved in checkInPrefs + updateHideLauncherIcon(value as Boolean) + } when (key) { CheckIn.ANDROID_ID -> editor.putLong(key, value as Long) CheckIn.DIGEST -> editor.putString(key, value as String?) @@ -122,6 +132,18 @@ class SettingsProvider : ContentProvider() { .apply() } + private fun updateSpoofingEnabled(enabled: Boolean) { + preferences.edit() + .putBoolean(CheckIn.BRAND_SPOOF, enabled) + .apply() + } + + private fun updateHideLauncherIcon(enabled: Boolean) { + preferences.edit() + .putBoolean(CheckIn.HIDE_LAUNCHER_ICON, enabled) + .apply() + } + private fun queryGcm(p: Array): Cursor = MatrixCursor(p).addRow(p) { key -> when (key) { Gcm.ENABLE_GCM -> getSettingsBoolean(key, true) diff --git a/play-services-core/src/main/res/values-cs/strings.xml b/play-services-core/src/main/res/values-cs/strings.xml index c5221edf8d..43a9ee9eff 100644 --- a/play-services-core/src/main/res/values-cs/strings.xml +++ b/play-services-core/src/main/res/values-cs/strings.xml @@ -102,7 +102,7 @@ Tato akce může trvat několik minut." O aplikaci Vanced microG Opravit duplicity ve Vysílání - Skrýt ikonu ze spouštěče + Skrýt ikonu ze spouštěče Huawei diff --git a/play-services-core/src/main/res/values-es/strings.xml b/play-services-core/src/main/res/values-es/strings.xml index 924113405b..cf50650eee 100644 --- a/play-services-core/src/main/res/values-es/strings.xml +++ b/play-services-core/src/main/res/values-es/strings.xml @@ -102,7 +102,7 @@ Esto puede tardar unos minutos." Acerca de Vanced microG Solucion para Cast duplicado - Ocultar microG del lanzador + Ocultar microG del lanzador Huawei diff --git a/play-services-core/src/main/res/values-in/strings.xml b/play-services-core/src/main/res/values-in/strings.xml index 6827eb66b4..d3163eb45b 100644 --- a/play-services-core/src/main/res/values-in/strings.xml +++ b/play-services-core/src/main/res/values-in/strings.xml @@ -102,7 +102,7 @@ Ini bisa berlangsung beberapa menit." Tentang Vanced microG Perbaikan Cast terduplikasi - Sembunyikan microG dari peluncur + Sembunyikan microG dari peluncur Registrasi perangkat Registrasi perangkat anda ke layanan Google dan buat pengenal perangkat unik. Vanced microG strips mengenal bits selain dari akun Google anda dari data registrasi. diff --git a/play-services-core/src/main/res/values-it/strings.xml b/play-services-core/src/main/res/values-it/strings.xml index adacbe3a6c..faaf7b72df 100755 --- a/play-services-core/src/main/res/values-it/strings.xml +++ b/play-services-core/src/main/res/values-it/strings.xml @@ -102,7 +102,7 @@ Questo potrà richiedere un paio di minuti" Informazioni su Vanced microG Correzione cast duplicato - Nascondi microG dal launcher + Nascondi microG dal launcher Registra dispositivo Registra il tuo dispositivo sui servizi Google e crea un identificatore univoco del dispositivo. Verranno rimossi dai Servizi Vanced microG alcuni bit utili per identificare i dati di registrazione, oltre al nome dell\'account Google. diff --git a/play-services-core/src/main/res/values-ru/strings.xml b/play-services-core/src/main/res/values-ru/strings.xml index f5a78cc0b5..93be73433c 100644 --- a/play-services-core/src/main/res/values-ru/strings.xml +++ b/play-services-core/src/main/res/values-ru/strings.xml @@ -102,7 +102,7 @@ О Vanced microG Исправление двух кнопок трансляции - скрыть микрог из лаунчера + скрыть микрог из лаунчера Huawei diff --git a/play-services-core/src/main/res/values/strings.xml b/play-services-core/src/main/res/values/strings.xml index 35dfabdbd7..030ec7bd80 100755 --- a/play-services-core/src/main/res/values/strings.xml +++ b/play-services-core/src/main/res/values/strings.xml @@ -102,7 +102,7 @@ This can take a couple of minutes." About Vanced microG Cast duplication fix - Hide icon from launcher + Hide icon from launcher Huawei diff --git a/play-services-core/src/main/res/xml/preferences_start.xml b/play-services-core/src/main/res/xml/preferences_start.xml index 7ea2cfa342..1e796d7bdf 100755 --- a/play-services-core/src/main/res/xml/preferences_start.xml +++ b/play-services-core/src/main/res/xml/preferences_start.xml @@ -49,8 +49,8 @@ android:summary="@string/pref_cast_double_fix_summary" android:defaultValue="false"/>