Skip to content

Commit 39b3729

Browse files
committed
DeviceRegistrationFragment: Allow viewing device registration data shared with remote
Change-Id: I93666445d14505c0a4289d63caa8054440ef1eef Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
1 parent de40837 commit 39b3729

File tree

6 files changed

+67
-3
lines changed

6 files changed

+67
-3
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ buildscript {
1515
ext.biometricVersion = '1.1.0'
1616
ext.coreVersion = '1.12.0'
1717
ext.fragmentVersion = '1.6.2'
18+
ext.gsonVersion = '2.10.1'
1819
ext.lifecycleVersion = '2.7.0'
1920
ext.loaderVersion = '1.1.0'
2021
ext.materialVersion = '1.11.0'

play-services-core/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ dependencies {
7979
implementation "androidx.preference:preference-ktx:$preferenceVersion"
8080
implementation "androidx.webkit:webkit:$webkitVersion"
8181

82+
// Gson
83+
implementation "com.google.code.gson:gson:$gsonVersion"
84+
8285
// Material Components
8386
implementation "com.google.android.material:material:$materialVersion"
8487

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

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
import android.accounts.AccountManager;
2121
import android.content.ContentResolver;
2222
import android.content.Context;
23+
import android.content.SharedPreferences;
24+
25+
import androidx.annotation.Nullable;
26+
27+
import com.google.gson.Gson;
28+
import com.google.gson.GsonBuilder;
2329

2430
import org.microg.gms.auth.AuthConstants;
2531
import org.microg.gms.auth.AuthRequest;
@@ -33,6 +39,10 @@
3339
import java.util.List;
3440

3541
public class CheckinManager {
42+
43+
private static final String LAST_CHECK_IN_DATA = "LAST_CHECK_IN_DATA";
44+
private static final String CHECK_IN_PREF = "check_in";
45+
3646
private static final long MIN_CHECKIN_INTERVAL = 3 * 60 * 60 * 1000; // 3 hours
3747

3848
@SuppressWarnings("MissingPermission")
@@ -42,7 +52,20 @@ public static synchronized LastCheckinInfo checkin(Context context, boolean forc
4252
return null;
4353
if (!CheckinPreferences.isEnabled(context))
4454
return null;
45-
List<CheckinClient.Account> accounts = new ArrayList<CheckinClient.Account>();
55+
CheckinRequest checkinRequest = getCheckinRequest(context, info);
56+
saveLastCheckInRequest(context, checkinRequest);
57+
return handleResponse(context, CheckinClient.request(checkinRequest));
58+
}
59+
60+
@Nullable
61+
public static String getLastRawCheckInRequest(Context context) {
62+
String rawCheckInRequest = getCheckInSharedPreferences(context)
63+
.getString(LAST_CHECK_IN_DATA, "");
64+
return !rawCheckInRequest.isEmpty() ? rawCheckInRequest : null;
65+
}
66+
67+
private static CheckinRequest getCheckinRequest(Context context, LastCheckinInfo info) throws IOException {
68+
List<CheckinClient.Account> accounts = new ArrayList<>();
4669
AccountManager accountManager = AccountManager.get(context);
4770
String accountType = AuthConstants.DEFAULT_ACCOUNT_TYPE;
4871
for (Account account : accountManager.getAccountsByType(accountType)) {
@@ -55,10 +78,9 @@ public static synchronized LastCheckinInfo checkin(Context context, boolean forc
5578
accounts.add(new CheckinClient.Account(account.name, token));
5679
}
5780
}
58-
CheckinRequest request = CheckinClient.makeRequest(context,
81+
return CheckinClient.makeRequest(context,
5982
new DeviceConfiguration(context), Utils.getDeviceIdentifier(context),
6083
Utils.getPhoneInfo(context), info, Utils.getLocale(context), accounts);
61-
return handleResponse(context, CheckinClient.request(request));
6284
}
6385

6486
private static LastCheckinInfo handleResponse(Context context, CheckinResponse response) {
@@ -72,4 +94,20 @@ private static LastCheckinInfo handleResponse(Context context, CheckinResponse r
7294

7395
return info;
7496
}
97+
98+
private static void saveLastCheckInRequest(Context context, CheckinRequest checkinRequest) {
99+
getCheckInSharedPreferences(context).edit()
100+
.putString(LAST_CHECK_IN_DATA, getGsonInstance().toJson(checkinRequest))
101+
.apply();
102+
}
103+
104+
private static SharedPreferences getCheckInSharedPreferences(Context context) {
105+
return context.getSharedPreferences(CHECK_IN_PREF, Context.MODE_PRIVATE);
106+
}
107+
108+
private static Gson getGsonInstance() {
109+
return new GsonBuilder()
110+
.setPrettyPrinting()
111+
.create();
112+
}
75113
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import androidx.preference.Preference
1919
import androidx.preference.PreferenceCategory
2020
import androidx.preference.PreferenceFragmentCompat
2121
import com.google.android.gms.R
22+
import com.google.android.material.dialog.MaterialAlertDialogBuilder
23+
import org.microg.gms.checkin.CheckinManager
2224
import org.microg.gms.checkin.CheckinPreferences
2325
import org.microg.gms.checkin.getCheckinServiceInfo
2426
import org.microg.gms.profile.ProfileManager
@@ -94,6 +96,17 @@ class DeviceRegistrationFragment : PreferenceFragmentCompat() {
9496
CheckinPreferences.setEnabled(requireContext(), newStatus)
9597
true
9698
}
99+
100+
findPreference<Preference>("pref_device_registration_data")?.setOnPreferenceClickListener {
101+
val rawCheckInRequest = CheckinManager.getLastRawCheckInRequest(context)
102+
MaterialAlertDialogBuilder(it.context)
103+
.setTitle(R.string.pref_device_registration_data_title)
104+
.setMessage(rawCheckInRequest ?: getString(R.string.data_na))
105+
.setPositiveButton(android.R.string.ok) { dialog, _ -> dialog.dismiss() }
106+
.create()
107+
.show()
108+
true
109+
}
97110
}
98111

99112
private fun configureProfilePreference() {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ This can take a couple of minutes."</string>
116116
<string name="self_check_resolution_battery_optimizations">Touch here to disable battery optimizations. Not doing this may result in misbehaving applications.</string>
117117

118118
<!-- Settings strings -->
119+
<string name="data_na">No data available right now</string>
119120

120121
<string name="prefcat_about">About</string>
121122
<string name="prefcat_components">Components</string>
@@ -146,6 +147,9 @@ This can take a couple of minutes."</string>
146147
<string name="pref_checkin_enable_summary">Registers your device to Google services and creates a unique device identifier. microG strips identifying bits other than your Google account name from registration data.</string>
147148
<string name="pref_device_registration_android_id">Android ID</string>
148149

150+
<string name="pref_device_registration_data_title">Device registration data</string>
151+
<string name="pref_device_registration_data_summary">Check data shared with Google servers for device registration</string>
152+
149153
<string name="checkin_not_registered">Not registered</string>
150154
<string name="checkin_last_registration">Last registration: <xliff:g example="Yesterday, 02:20 PM">%1$s</xliff:g></string>
151155
<string name="checkin_enable_switch">Register device</string>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
android:title="@string/pref_device_registration_android_id"
5151
tools:summary="1953a59d1c1b7e4b"
5252
app:iconSpaceReserved="false" />
53+
<Preference
54+
android:key="pref_device_registration_data"
55+
android:summary="@string/pref_device_registration_data_summary"
56+
android:title="@string/pref_device_registration_data_title"
57+
app:iconSpaceReserved="false" />
5358
</PreferenceCategory>
5459
<PreferenceCategory android:layout="@layout/preference_category_no_label">
5560
<org.microg.gms.ui.FooterPreference

0 commit comments

Comments
 (0)