Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeviceRegistartionFragment: Allow viewing device registartion data #2275

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ buildscript {
ext.biometricVersion = '1.1.0'
ext.coreVersion = '1.12.0'
ext.fragmentVersion = '1.6.2'
ext.gsonVersion = '2.10.1'
ext.lifecycleVersion = '2.7.0'
ext.loaderVersion = '1.1.0'
ext.materialVersion = '1.11.0'
Expand Down
3 changes: 3 additions & 0 deletions play-services-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ dependencies {
implementation "androidx.preference:preference-ktx:$preferenceVersion"
implementation "androidx.webkit:webkit:$webkitVersion"

// Gson
implementation "com.google.code.gson:gson:$gsonVersion"

// Material Components
implementation "com.google.android.material:material:$materialVersion"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public static synchronized LastCheckinInfo checkin(Context context, boolean forc
return null;
if (!CheckinPreferences.isEnabled(context))
return null;
List<CheckinClient.Account> accounts = new ArrayList<CheckinClient.Account>();
return handleResponse(context, CheckinClient.request(getCheckinRequest(context, info)));
}

public static CheckinRequest getCheckinRequest(Context context, LastCheckinInfo info) throws IOException {
List<CheckinClient.Account> accounts = new ArrayList<>();
AccountManager accountManager = AccountManager.get(context);
String accountType = AuthConstants.DEFAULT_ACCOUNT_TYPE;
for (Account account : accountManager.getAccountsByType(accountType)) {
Expand All @@ -55,10 +59,9 @@ public static synchronized LastCheckinInfo checkin(Context context, boolean forc
accounts.add(new CheckinClient.Account(account.name, token));
}
}
CheckinRequest request = CheckinClient.makeRequest(context,
return CheckinClient.makeRequest(context,
new DeviceConfiguration(context), Utils.getDeviceIdentifier(context),
Utils.getPhoneInfo(context), info, Utils.getLocale(context), accounts);
return handleResponse(context, CheckinClient.request(request));
}

private static LastCheckinInfo handleResponse(Context context, CheckinResponse response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat
import com.google.android.gms.R
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.gson.GsonBuilder
import org.microg.gms.checkin.CheckinManager
import org.microg.gms.checkin.CheckinPreferences
import org.microg.gms.checkin.LastCheckinInfo
import org.microg.gms.checkin.getCheckinServiceInfo
import org.microg.gms.profile.ProfileManager
import org.microg.gms.profile.ProfileManager.PROFILE_AUTO
Expand Down Expand Up @@ -94,6 +98,24 @@ class DeviceRegistrationFragment : PreferenceFragmentCompat() {
CheckinPreferences.setEnabled(requireContext(), newStatus)
true
}

findPreference<Preference>("pref_device_registration_data")?.setOnPreferenceClickListener {
val checkInRequest = CheckinManager.getCheckinRequest(
it.context,
LastCheckinInfo.read(it.context)
)
val gson = GsonBuilder()
.setPrettyPrinting()
.create()

MaterialAlertDialogBuilder(it.context)
.setTitle(R.string.pref_device_registration_data_title)
.setMessage(gson.toJson(checkInRequest))
.setPositiveButton(android.R.string.ok) { dialog, _ -> dialog.dismiss() }
.create()
.show()
true
}
}

private fun configureProfilePreference() {
Expand Down
3 changes: 3 additions & 0 deletions play-services-core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ This can take a couple of minutes."</string>
<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>
<string name="pref_device_registration_android_id">Android ID</string>

<string name="pref_device_registration_data_title">Device registration data</string>
<string name="pref_device_registration_data_summary">Check data shared with Google servers for device registration</string>

<string name="checkin_not_registered">Not registered</string>
<string name="checkin_last_registration">Last registration: <xliff:g example="Yesterday, 02:20 PM">%1$s</xliff:g></string>
<string name="checkin_enable_switch">Register device</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
android:title="@string/pref_device_registration_android_id"
tools:summary="1953a59d1c1b7e4b"
app:iconSpaceReserved="false" />
<Preference
android:key="pref_device_registration_data"
android:summary="@string/pref_device_registration_data_summary"
android:title="@string/pref_device_registration_data_title"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory android:layout="@layout/preference_category_no_label">
<org.microg.gms.ui.FooterPreference
Expand Down