Skip to content

Commit a68d262

Browse files
committed
login: Switch to SettingsProvider for "Alt Sign in"
* This was using PreferenceManager which we aren't using after 3651: Refactor settings access to use a SettingsProvider | https://review.calyxos.org/c/CalyxOS/platform_external_microg_GmsCore/+/3651 * This is still the known working approach for now so let's switch it over. Change-Id: I76939af2a39eaf16c20d05e8c10ef0cc213611ae
1 parent 8fe1881 commit a68d262

File tree

6 files changed

+46
-13
lines changed

6 files changed

+46
-13
lines changed

play-services-basement/src/main/kotlin/org/microg/gms/settings/SettingsContract.kt

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

26+
const val BRAND_SPOOF = "brandSpoof"
27+
2628
val PROJECTION = arrayOf(
2729
ENABLED,
2830
ANDROID_ID,
@@ -31,6 +33,7 @@ object SettingsContract {
3133
SECURITY_TOKEN,
3234
VERSION_INFO,
3335
DEVICE_DATA_VERSION_INFO,
36+
BRAND_SPOOF,
3437
)
3538
const val PREFERENCES_NAME = "checkin"
3639
const val INITIAL_DIGEST = "1-929a0dca0eee55513280171a8585da7dcd3700f8"

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

+11-10
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
import static android.view.View.VISIBLE;
7474
import static android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT;
7575
import static org.microg.gms.auth.AuthPrefs.isAuthVisible;
76+
import static org.microg.gms.checkin.CheckinPrefs.isSpoofingEnabled;
77+
import static org.microg.gms.checkin.CheckinPrefs.setSpoofingEnabled;
7678
import static org.microg.gms.common.Constants.GMS_PACKAGE_NAME;
7779
import static org.microg.gms.common.Constants.GMS_VERSION_CODE;
7880

@@ -162,13 +164,14 @@ protected void onSpoofButtonClicked() {
162164
super.onSpoofButtonClicked();
163165
state++;
164166
if (state == 1) {
165-
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(SpoofButtonPreference, true).apply();
166-
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(LoginButtonPreference, true)) {
167-
LastCheckinInfo.ClearCheckinInfo(this);
168-
CheckinClient.brandSpoof = true;
169-
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(LoginButtonPreference, true).apply();
167+
if (!isSpoofingEnabled(this)) {
168+
LastCheckinInfo.clear(this);
169+
setSpoofingEnabled(this, true);
170170
}
171171
init();
172+
} else if (state == -1) {
173+
setResult(RESULT_CANCELED);
174+
finish();
172175
}
173176
}
174177

@@ -177,11 +180,9 @@ protected void onNextButtonClicked() {
177180
super.onNextButtonClicked();
178181
state++;
179182
if (state == 1) {
180-
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(LoginButtonPreference, true).apply();
181-
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(SpoofButtonPreference, true)) {
182-
LastCheckinInfo.ClearCheckinInfo(this);
183-
CheckinClient.brandSpoof = false;
184-
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(SpoofButtonPreference, true).apply();
183+
if (isSpoofingEnabled(this)) {
184+
LastCheckinInfo.clear(this);
185+
setSpoofingEnabled(this, false);
185186
}
186187
init();
187188
} else if (state == -1) {

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public class CheckinClient {
4646
private static final List<String> TODO_LIST_STRING = new ArrayList<>(); // TODO
4747
private static final List<CheckinRequest.Checkin.Statistic> TODO_LIST_CHECKIN = new ArrayList<>(); // TODO
4848
private static final String SERVICE_URL = "https://android.clients.google.com/checkin";
49-
public static boolean brandSpoof = false;
5049

5150
public static CheckinResponse request(CheckinRequest request) throws IOException {
5251
HttpURLConnection connection = (HttpURLConnection) new URL(SERVICE_URL).openConnection();
@@ -80,7 +79,7 @@ public static CheckinResponse request(CheckinRequest request) throws IOException
8079
public static CheckinRequest makeRequest(Build build, DeviceConfiguration deviceConfiguration,
8180
DeviceIdentifier deviceIdent, PhoneInfo phoneInfo,
8281
LastCheckinInfo checkinInfo, Locale locale,
83-
List<Account> accounts) {
82+
List<Account> accounts, Boolean brandSpoof) {
8483
CheckinRequest.Builder builder = new CheckinRequest.Builder()
8584
.accountCookie(new ArrayList<>())
8685
.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
@@ -33,6 +33,8 @@
3333
import java.util.ArrayList;
3434
import java.util.List;
3535

36+
import static org.microg.gms.checkin.CheckinPrefs.isSpoofingEnabled;
37+
3638
public class CheckinManager {
3739
private static final long MIN_CHECKIN_INTERVAL = 3 * 60 * 60 * 1000; // 3 hours
3840

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

+16
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.gms.settings.SettingsContract
99
import org.microg.gms.settings.SettingsContract.CheckIn
10+
import org.microg.gms.settings.SettingsContract.setSettings
1011

1112
object CheckinPrefs {
1213

@@ -18,4 +19,19 @@ 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+
2137
}

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

+11
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class SettingsProvider : ContentProvider() {
8888
CheckIn.SECURITY_TOKEN -> checkInPrefs.getLong(key, 0)
8989
CheckIn.VERSION_INFO -> checkInPrefs.getString(key, "") ?: ""
9090
CheckIn.DEVICE_DATA_VERSION_INFO -> checkInPrefs.getString(key, "") ?: ""
91+
CheckIn.BRAND_SPOOF -> getSettingsBoolean(key, false)
9192
else -> throw IllegalArgumentException()
9293
}
9394
}
@@ -107,6 +108,10 @@ class SettingsProvider : ContentProvider() {
107108
// special case: not saved in checkInPrefs
108109
updateCheckInEnabled(value as Boolean)
109110
}
111+
if (key == CheckIn.BRAND_SPOOF) {
112+
// special case: not saved in checkInPrefs
113+
updateSpoofingEnabled(value as Boolean)
114+
}
110115
when (key) {
111116
CheckIn.ANDROID_ID -> editor.putLong(key, value as Long)
112117
CheckIn.DIGEST -> editor.putString(key, value as String?)
@@ -125,6 +130,12 @@ class SettingsProvider : ContentProvider() {
125130
.apply()
126131
}
127132

133+
private fun updateSpoofingEnabled(enabled: Boolean) {
134+
preferences.edit()
135+
.putBoolean(CheckIn.BRAND_SPOOF, enabled)
136+
.apply()
137+
}
138+
128139
private fun queryGcm(p: Array<out String>): Cursor = MatrixCursor(p).addRow(p) { key ->
129140
when (key) {
130141
Gcm.ENABLE_GCM -> getSettingsBoolean(key, false)

0 commit comments

Comments
 (0)