From d25e351c41bd43d6b755e50a09637f38bff5b063 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Fri, 28 May 2021 11:40:08 -0300 Subject: [PATCH] Re-connected in SettingsFragment if we are erroneously disconnected --- .../org/microg/gms/ui/SettingsFragment.kt | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) 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 681b1f4c..769e4cba 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 @@ -5,6 +5,7 @@ package org.microg.gms.ui +import android.content.Intent import android.content.Context import android.os.Bundle import androidx.lifecycle.lifecycleScope @@ -13,6 +14,8 @@ import androidx.preference.Preference import com.google.android.gms.R import org.microg.gms.checkin.getCheckinServiceInfo import org.microg.gms.gcm.GcmDatabase +import org.microg.gms.gcm.McsConstants.ACTION_RECONNECT +import org.microg.gms.gcm.TriggerReceiver import org.microg.gms.gcm.getGcmServiceInfo import org.microg.gms.safetynet.getSafetyNetServiceInfo import org.microg.nlp.client.UnifiedLocationClient @@ -58,24 +61,29 @@ class SettingsFragment : ResourceSettingsFragment() { } private suspend fun updateDetails(context: Context) { - if (getGcmServiceInfo(requireContext()).configuration.enabled) { + val gcmServiceInfo = getGcmServiceInfo(context) + if (gcmServiceInfo.configuration.enabled) { val database = GcmDatabase(context) val regCount = database.registrationList.size + // check if we are connected as we should be and re-connect if not + if (!gcmServiceInfo.connected) { + context.sendBroadcast(Intent(ACTION_RECONNECT, null, context, TriggerReceiver::class.java)) + } database.close() findPreference(PREF_GCM)!!.summary = getString(R.string.service_status_enabled_short) + " - " + resources.getQuantityString(R.plurals.gcm_registered_apps_counter, regCount, regCount) } else { findPreference(PREF_GCM)!!.setSummary(R.string.service_status_disabled_short) } - findPreference(PREF_CHECKIN)!!.setSummary(if (getCheckinServiceInfo(requireContext()).configuration.enabled) R.string.service_status_enabled_short else R.string.service_status_disabled_short) - findPreference(PREF_SNET)!!.setSummary(if (getSafetyNetServiceInfo(requireContext()).configuration.enabled) R.string.service_status_enabled_short else R.string.service_status_disabled_short) + findPreference(PREF_CHECKIN)!!.setSummary(if (getCheckinServiceInfo(context).configuration.enabled) R.string.service_status_enabled_short else R.string.service_status_disabled_short) + findPreference(PREF_SNET)!!.setSummary(if (getSafetyNetServiceInfo(context).configuration.enabled) R.string.service_status_enabled_short else R.string.service_status_disabled_short) - val backendCount = UnifiedLocationClient[context].getLocationBackends().size + UnifiedLocationClient[requireContext()].getGeocoderBackends().size + val backendCount = UnifiedLocationClient[context].getLocationBackends().size + UnifiedLocationClient[context].getGeocoderBackends().size findPreference(PREF_UNIFIEDNLP)!!.summary = resources.getQuantityString(R.plurals.pref_unifiednlp_summary, backendCount, backendCount); findPreference(PREF_EXPOSURE)?.isVisible = NearbyPreferencesIntegration.isAvailable - findPreference(PREF_EXPOSURE)?.icon = NearbyPreferencesIntegration.getIcon(requireContext()) - findPreference(PREF_EXPOSURE)?.summary = NearbyPreferencesIntegration.getExposurePreferenceSummary(requireContext()) + findPreference(PREF_EXPOSURE)?.icon = NearbyPreferencesIntegration.getIcon(context) + findPreference(PREF_EXPOSURE)?.summary = NearbyPreferencesIntegration.getExposurePreferenceSummary(context) } companion object {