Re-connected in SettingsFragment if we are erroneously disconnected

This commit is contained in:
Torsten Grote 2021-05-28 11:40:08 -03:00 committed by Marvin W
parent 9067f66f0c
commit d25e351c41

View File

@ -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<Preference>(PREF_GCM)!!.summary = getString(R.string.service_status_enabled_short) + " - " + resources.getQuantityString(R.plurals.gcm_registered_apps_counter, regCount, regCount)
} else {
findPreference<Preference>(PREF_GCM)!!.setSummary(R.string.service_status_disabled_short)
}
findPreference<Preference>(PREF_CHECKIN)!!.setSummary(if (getCheckinServiceInfo(requireContext()).configuration.enabled) R.string.service_status_enabled_short else R.string.service_status_disabled_short)
findPreference<Preference>(PREF_SNET)!!.setSummary(if (getSafetyNetServiceInfo(requireContext()).configuration.enabled) R.string.service_status_enabled_short else R.string.service_status_disabled_short)
findPreference<Preference>(PREF_CHECKIN)!!.setSummary(if (getCheckinServiceInfo(context).configuration.enabled) R.string.service_status_enabled_short else R.string.service_status_disabled_short)
findPreference<Preference>(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<Preference>(PREF_UNIFIEDNLP)!!.summary = resources.getQuantityString(R.plurals.pref_unifiednlp_summary, backendCount, backendCount);
findPreference<Preference>(PREF_EXPOSURE)?.isVisible = NearbyPreferencesIntegration.isAvailable
findPreference<Preference>(PREF_EXPOSURE)?.icon = NearbyPreferencesIntegration.getIcon(requireContext())
findPreference<Preference>(PREF_EXPOSURE)?.summary = NearbyPreferencesIntegration.getExposurePreferenceSummary(requireContext())
findPreference<Preference>(PREF_EXPOSURE)?.icon = NearbyPreferencesIntegration.getIcon(context)
findPreference<Preference>(PREF_EXPOSURE)?.summary = NearbyPreferencesIntegration.getExposurePreferenceSummary(context)
}
companion object {