Skip to content
This repository was archived by the owner on Apr 6, 2024. It is now read-only.

Commit 020b789

Browse files
authored
Merge pull request #155 from Oizaro/master
Remove getDefaultSharedPreferences calls
2 parents 4c9230d + c86b9ab commit 020b789

File tree

14 files changed

+78
-25
lines changed

14 files changed

+78
-25
lines changed

play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
import static android.view.View.VISIBLE;
7676
import static android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT;
7777
import static org.microg.gms.auth.AuthPrefs.isAuthVisible;
78+
import static org.microg.gms.checkin.CheckinPrefs.hideLauncherIcon;
79+
import static org.microg.gms.checkin.CheckinPrefs.isSpoofingEnabled;
80+
import static org.microg.gms.checkin.CheckinPrefs.setSpoofingEnabled;
7881
import static org.microg.gms.common.Constants.GMS_PACKAGE_NAME;
7982
import static org.microg.gms.common.Constants.GMS_VERSION_CODE;
8083

@@ -163,16 +166,17 @@ protected void onHuaweiButtonClicked() {
163166
state++;
164167
if (state == 1) {
165168
if (SDK_INT >= Build.VERSION_CODES.M) {
166-
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean("pref_hide_launcher_icon", false).apply();
169+
hideLauncherIcon(this, false);
167170
UtilsKt.hideIcon(this, false);
168171
}
169-
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(HuaweiButtonPreference, true).apply();
170-
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(LoginButtonPreference, true)) {
172+
if (!isSpoofingEnabled(this)) {
171173
LastCheckinInfo.clear(this);
172-
CheckinClient.brandSpoof = true;
173-
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(LoginButtonPreference, true).apply();
174+
setSpoofingEnabled(this, true);
174175
}
175176
init();
177+
} else if (state == -1) {
178+
setResult(RESULT_CANCELED);
179+
finish();
176180
}
177181
}
178182

@@ -181,11 +185,9 @@ protected void onNextButtonClicked() {
181185
super.onNextButtonClicked();
182186
state++;
183187
if (state == 1) {
184-
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(LoginButtonPreference, true).apply();
185-
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(HuaweiButtonPreference, true)) {
188+
if (isSpoofingEnabled(this)) {
186189
LastCheckinInfo.clear(this);
187-
CheckinClient.brandSpoof = false;
188-
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(HuaweiButtonPreference, true).apply();
190+
setSpoofingEnabled(this, false);
189191
}
190192
init();
191193
} else if (state == -1) {

play-services-core/src/main/java/org/microg/gms/checkin/CheckinClient.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public class CheckinClient {
4545
private static final List<String> TODO_LIST_STRING = new ArrayList<>(); // TODO
4646
private static final List<CheckinRequest.Checkin.Statistic> TODO_LIST_CHECKIN = new ArrayList<CheckinRequest.Checkin.Statistic>(); // TODO
4747
private static final String SERVICE_URL = "https://android.clients.google.com/checkin";
48-
public static boolean brandSpoof = false;
49-
48+
5049
public static CheckinResponse request(CheckinRequest request) throws IOException {
5150
HttpURLConnection connection = (HttpURLConnection) new URL(SERVICE_URL).openConnection();
5251
connection.setRequestMethod("POST");
@@ -79,7 +78,7 @@ public static CheckinResponse request(CheckinRequest request) throws IOException
7978
public static CheckinRequest makeRequest(Build build, DeviceConfiguration deviceConfiguration,
8079
DeviceIdentifier deviceIdent, PhoneInfo phoneInfo,
8180
LastCheckinInfo checkinInfo, Locale locale,
82-
List<Account> accounts) {
81+
List<Account> accounts, Boolean brandSpoof) {
8382
CheckinRequest.Builder builder = new CheckinRequest.Builder()
8483
.accountCookie(new ArrayList<>())
8584
.androidId(checkinInfo.getAndroidId())

play-services-core/src/main/java/org/microg/gms/checkin/CheckinManager.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.util.ArrayList;
3333
import java.util.List;
3434

35+
import static org.microg.gms.checkin.CheckinPrefs.isSpoofingEnabled;
36+
3537
public class CheckinManager {
3638
private static final String TAG = "GmsCheckinManager";
3739
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
5860
}
5961
CheckinRequest request = CheckinClient.makeRequest(Utils.getBuild(context),
6062
new DeviceConfiguration(context), Utils.getDeviceIdentifier(context),
61-
Utils.getPhoneInfo(context), info, Utils.getLocale(context), accounts);
63+
Utils.getPhoneInfo(context), info, Utils.getLocale(context), accounts,
64+
isSpoofingEnabled(context));
6265
return handleResponse(context, CheckinClient.request(request));
6366
}
6467

play-services-core/src/main/kotlin/org/microg/gms/checkin/CheckinPrefs.kt

+23
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package org.microg.gms.checkin
77
import android.content.Context
88
import org.microg.mgms.settings.SettingsContract
99
import org.microg.mgms.settings.SettingsContract.CheckIn
10+
import org.microg.mgms.settings.SettingsContract.setSettings
1011

1112
object CheckinPrefs {
1213

@@ -18,4 +19,26 @@ object CheckinPrefs {
1819
}
1920
}
2021

22+
@JvmStatic
23+
fun isSpoofingEnabled(context: Context): Boolean {
24+
val projection = arrayOf(CheckIn.BRAND_SPOOF)
25+
return SettingsContract.getSettings(context, CheckIn.CONTENT_URI, projection) { c ->
26+
c.getInt(0) != 0
27+
}
28+
}
29+
30+
@JvmStatic
31+
fun setSpoofingEnabled(context: Context, enabled: Boolean) {
32+
setSettings(context, CheckIn.CONTENT_URI) {
33+
put(CheckIn.BRAND_SPOOF, enabled)
34+
}
35+
}
36+
37+
@JvmStatic
38+
fun hideLauncherIcon(context: Context, enabled: Boolean) {
39+
setSettings(context, CheckIn.CONTENT_URI) {
40+
put(CheckIn.HIDE_LAUNCHER_ICON, enabled)
41+
}
42+
}
43+
2144
}

play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import android.content.ComponentName
99
import android.content.pm.PackageManager
1010
import android.content.Intent
1111
import android.os.Bundle
12-
import android.util.Log
1312
import androidx.lifecycle.lifecycleScope
1413
import androidx.navigation.fragment.findNavController
1514
import androidx.preference.Preference
@@ -23,6 +22,7 @@ import org.microg.gms.gcm.McsConstants.ACTION_RECONNECT
2322
import org.microg.gms.gcm.McsService
2423
import org.microg.gms.gcm.TriggerReceiver
2524
import org.microg.gms.gcm.getGcmServiceInfo
25+
import org.microg.mgms.settings.SettingsContract
2626
import org.microg.tools.ui.ResourceSettingsFragment
2727

2828
class SettingsFragment : ResourceSettingsFragment() {
@@ -57,7 +57,7 @@ class SettingsFragment : ResourceSettingsFragment() {
5757
true
5858
}
5959

60-
findPreference<SwitchPreferenceCompat>(PREF_CAST_HIDE_LAUNCHER_ICON)?.apply {
60+
findPreference<SwitchPreferenceCompat>(SettingsContract.CheckIn.HIDE_LAUNCHER_ICON)?.apply {
6161
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
6262
setOnPreferenceChangeListener { _, newValue ->
6363
requireActivity().hideIcon(newValue as Boolean)
@@ -101,8 +101,6 @@ class SettingsFragment : ResourceSettingsFragment() {
101101
const val PREF_GCM = "pref_gcm"
102102
const val PREF_CHECKIN = "pref_checkin"
103103
const val PREF_CAST_DOUBLE_FIX_ENABLED = "pref_cast_double_fix_enabled"
104-
const val PREF_CAST_HIDE_LAUNCHER_ICON = "pref_hide_launcher_icon"
105-
const val BRAND_SPOOF_FIX_ENABLED = "brand_spoof_fix_enabled"
106104
}
107105

108106
init {

play-services-core/src/main/kotlin/org/microg/mgms/settings/SettingsContract.kt

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ object SettingsContract {
2323
const val VERSION_INFO = "versionInfo"
2424
const val DEVICE_DATA_VERSION_INFO = "deviceDataVersionInfo"
2525

26+
const val BRAND_SPOOF = "brandSpoof"
27+
28+
const val HIDE_LAUNCHER_ICON = "hideLauncherIcon"
29+
2630
val PROJECTION = arrayOf(
2731
ENABLED,
2832
ANDROID_ID,
@@ -31,6 +35,8 @@ object SettingsContract {
3135
SECURITY_TOKEN,
3236
VERSION_INFO,
3337
DEVICE_DATA_VERSION_INFO,
38+
BRAND_SPOOF,
39+
HIDE_LAUNCHER_ICON,
3440
)
3541
const val PREFERENCES_NAME = "checkin"
3642
const val INITIAL_DIGEST = "1-929a0dca0eee55513280171a8585da7dcd3700f8"

play-services-core/src/main/kotlin/org/microg/mgms/settings/SettingsProvider.kt

+22
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class SettingsProvider : ContentProvider() {
8585
CheckIn.SECURITY_TOKEN -> checkInPrefs.getLong(key, 0)
8686
CheckIn.VERSION_INFO -> checkInPrefs.getString(key, "") ?: ""
8787
CheckIn.DEVICE_DATA_VERSION_INFO -> checkInPrefs.getString(key, "") ?: ""
88+
CheckIn.BRAND_SPOOF -> getSettingsBoolean(key, false)
89+
CheckIn.HIDE_LAUNCHER_ICON -> getSettingsBoolean(key, false)
8890
else -> throw IllegalArgumentException()
8991
}
9092
}
@@ -104,6 +106,14 @@ class SettingsProvider : ContentProvider() {
104106
// special case: not saved in checkInPrefs
105107
updateCheckInEnabled(value as Boolean)
106108
}
109+
if (key == CheckIn.BRAND_SPOOF) {
110+
// special case: not saved in checkInPrefs
111+
updateSpoofingEnabled(value as Boolean)
112+
}
113+
if (key == CheckIn.HIDE_LAUNCHER_ICON) {
114+
// special case: not saved in checkInPrefs
115+
updateHideLauncherIcon(value as Boolean)
116+
}
107117
when (key) {
108118
CheckIn.ANDROID_ID -> editor.putLong(key, value as Long)
109119
CheckIn.DIGEST -> editor.putString(key, value as String?)
@@ -122,6 +132,18 @@ class SettingsProvider : ContentProvider() {
122132
.apply()
123133
}
124134

135+
private fun updateSpoofingEnabled(enabled: Boolean) {
136+
preferences.edit()
137+
.putBoolean(CheckIn.BRAND_SPOOF, enabled)
138+
.apply()
139+
}
140+
141+
private fun updateHideLauncherIcon(enabled: Boolean) {
142+
preferences.edit()
143+
.putBoolean(CheckIn.HIDE_LAUNCHER_ICON, enabled)
144+
.apply()
145+
}
146+
125147
private fun queryGcm(p: Array<out String>): Cursor = MatrixCursor(p).addRow(p) { key ->
126148
when (key) {
127149
Gcm.ENABLE_GCM -> getSettingsBoolean(key, true)

play-services-core/src/main/res/values-cs/strings.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Tato akce může trvat několik minut."</string>
102102

103103
<string name="pref_about_title">O aplikaci Vanced microG</string>
104104
<string name="pref_cast_double_fix">Opravit duplicity ve Vysílání</string>
105-
<string name="pref_hide_launcher_icon">Skrýt ikonu ze spouštěče</string>
105+
<string name="hideLauncherIcon">Skrýt ikonu ze spouštěče</string>
106106

107107
<string name="brand_spoof_button">Huawei</string>
108108

play-services-core/src/main/res/values-es/strings.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Esto puede tardar unos minutos."</string>
102102

103103
<string name="pref_about_title">Acerca de Vanced microG</string>
104104
<string name="pref_cast_double_fix">Solucion para Cast duplicado</string>
105-
<string name="pref_hide_launcher_icon">Ocultar microG del lanzador</string>
105+
<string name="hideLauncherIcon">Ocultar microG del lanzador</string>
106106

107107
<string name="brand_spoof_button">Huawei</string>
108108

play-services-core/src/main/res/values-in/strings.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Ini bisa berlangsung beberapa menit."</string>
102102

103103
<string name="pref_about_title">Tentang Vanced microG</string>
104104
<string name="pref_cast_double_fix">Perbaikan Cast terduplikasi</string>
105-
<string name="pref_hide_launcher_icon">Sembunyikan microG dari peluncur</string>
105+
<string name="hideLauncherIcon">Sembunyikan microG dari peluncur</string>
106106

107107
<string name="pref_switcher_title">Registrasi perangkat</string>
108108
<string name="pref_checkin_enable_summary">Registrasi perangkat anda ke layanan Google dan buat pengenal perangkat unik. Vanced microG strips mengenal bits selain dari akun Google anda dari data registrasi.</string>

play-services-core/src/main/res/values-it/strings.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Questo potrà richiedere un paio di minuti"</string>
102102

103103
<string name="pref_about_title">Informazioni su Vanced microG</string>
104104
<string name="pref_cast_double_fix">Correzione cast duplicato</string>
105-
<string name="pref_hide_launcher_icon">Nascondi microG dal launcher</string>
105+
<string name="hideLauncherIcon">Nascondi microG dal launcher</string>
106106

107107
<string name="pref_switcher_title">Registra dispositivo</string>
108108
<string name="pref_checkin_enable_summary">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.</string>

play-services-core/src/main/res/values-ru/strings.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102

103103
<string name="pref_about_title">О Vanced microG</string>
104104
<string name="pref_cast_double_fix">Исправление двух кнопок трансляции</string>
105-
<string name="pref_hide_launcher_icon">скрыть микрог из лаунчера</string>
105+
<string name="hideLauncherIcon">скрыть микрог из лаунчера</string>
106106

107107
<string name="brand_spoof_button">Huawei</string>
108108

play-services-core/src/main/res/values/strings.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ This can take a couple of minutes."</string>
102102

103103
<string name="pref_about_title">About Vanced microG</string>
104104
<string name="pref_cast_double_fix">Cast duplication fix</string>
105-
<string name="pref_hide_launcher_icon">Hide icon from launcher</string>
105+
<string name="hideLauncherIcon">Hide icon from launcher</string>
106106

107107
<string name="brand_spoof_button">Huawei</string>
108108

play-services-core/src/main/res/xml/preferences_start.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
android:summary="@string/pref_cast_double_fix_summary"
5050
android:defaultValue="false"/>
5151
<SwitchPreferenceCompat
52-
android:key="pref_hide_launcher_icon"
53-
android:title="@string/pref_hide_launcher_icon"
52+
android:key="hideLauncherIcon"
53+
android:title="@string/hideLauncherIcon"
5454
android:icon="@drawable/ic_baseline_hide_source_24"
5555
android:defaultValue="true"/>
5656
</PreferenceCategory>

0 commit comments

Comments
 (0)