Set max auto heartbeat interval to 15min 1e96dd137e
This commit is contained in:
parent
1b4ff54e59
commit
08f46a1a49
5 changed files with 62 additions and 16 deletions
|
|
@ -30,9 +30,6 @@ import java.io.File
|
|||
*/
|
||||
@SuppressLint("DiscouragedPrivateApi")
|
||||
class SettingsProvider : ContentProvider() {
|
||||
companion object {
|
||||
const val INTERVAL = 1 * 60 * 1000 // 1 minute
|
||||
}
|
||||
|
||||
private val preferences: SharedPreferences by lazy {
|
||||
PreferenceManager.getDefaultSharedPreferences(context)
|
||||
|
|
@ -167,9 +164,15 @@ class SettingsProvider : ContentProvider() {
|
|||
Gcm.NETWORK_ROAMING -> Integer.parseInt(preferences.getString(key, "0") ?: "0")
|
||||
Gcm.NETWORK_OTHER -> Integer.parseInt(preferences.getString(key, "0") ?: "0")
|
||||
|
||||
<<<<<<< HEAD
|
||||
Gcm.LEARNT_MOBILE -> preferences.getInt(key, INTERVAL)
|
||||
Gcm.LEARNT_WIFI -> preferences.getInt(key, INTERVAL)
|
||||
Gcm.LEARNT_OTHER -> preferences.getInt(key, INTERVAL)
|
||||
=======
|
||||
Gcm.LEARNT_MOBILE -> preferences.getInt(key, 300000)
|
||||
Gcm.LEARNT_WIFI -> preferences.getInt(key, 300000)
|
||||
Gcm.LEARNT_OTHER -> preferences.getInt(key, 300000)
|
||||
>>>>>>> b0b92c8c (Set max auto heartbeat interval to 15min https://github.com/microg/GmsCore/commit/1e96dd137eae86bbf3be3ca72a6345fa837ad8ff)
|
||||
|
||||
else -> throw IllegalArgumentException("Unknown key: $key")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -286,8 +286,8 @@ public class McsService extends Service implements Handler.Callback {
|
|||
|
||||
public synchronized static long getCurrentDelay() {
|
||||
long delay = currentDelay == 0 ? 5000 : currentDelay;
|
||||
if (currentDelay < SettingsProvider.INTERVAL) currentDelay += 10000;
|
||||
if (currentDelay >= SettingsProvider.INTERVAL && currentDelay < 600000) currentDelay += SettingsProvider.INTERVAL;
|
||||
if (currentDelay < 60000) currentDelay += 10000;
|
||||
if (currentDelay >= 60000 && currentDelay < 600000) currentDelay += 60000;
|
||||
return delay;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ import org.microg.gms.gcm.TriggerReceiver.FORCE_TRY_RECONNECT
|
|||
import org.microg.mgms.settings.SettingsContract
|
||||
import org.microg.mgms.settings.SettingsContract.Gcm
|
||||
import org.microg.mgms.settings.SettingsContract.setSettings
|
||||
import org.microg.mgms.settings.SettingsProvider
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
data class GcmPrefs(
|
||||
val isGcmLogEnabled: Boolean,
|
||||
|
|
@ -37,6 +38,9 @@ data class GcmPrefs(
|
|||
const val PREF_NETWORK_ROAMING = Gcm.NETWORK_ROAMING
|
||||
const val PREF_NETWORK_OTHER = Gcm.NETWORK_OTHER
|
||||
|
||||
private const val MIN_INTERVAL = 5 * 60 * 1000 // 5 minutes
|
||||
private const val MAX_INTERVAL = 15 * 60 * 1000 // 15 minutes
|
||||
|
||||
@JvmStatic
|
||||
fun get(context: Context): GcmPrefs? {
|
||||
return Gcm.getContentUri(context)?.let {
|
||||
|
|
@ -93,6 +97,7 @@ data class GcmPrefs(
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun getNetworkPrefForInfo(info: NetworkInfo?): String {
|
||||
if (info == null) return PREF_NETWORK_OTHER
|
||||
return if (info.isRoaming) PREF_NETWORK_ROAMING else when (info.type) {
|
||||
|
|
@ -102,25 +107,27 @@ data class GcmPrefs(
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun getHeartbeatMsFor(info: NetworkInfo?): Int {
|
||||
return getHeartbeatMsFor(getNetworkPrefForInfo(info))
|
||||
}
|
||||
|
||||
fun getHeartbeatMsFor(pref: String): Int {
|
||||
return if (PREF_NETWORK_ROAMING == pref) {
|
||||
if (networkRoaming != 0) networkRoaming * SettingsProvider.INTERVAL else learntMobileInterval
|
||||
if (networkRoaming != 0) networkRoaming * 60000 else learntMobileInterval
|
||||
} else if (PREF_NETWORK_MOBILE == pref) {
|
||||
if (networkMobile != 0) networkMobile * SettingsProvider.INTERVAL else learntMobileInterval
|
||||
if (networkMobile != 0) networkMobile * 60000 else learntMobileInterval
|
||||
} else if (PREF_NETWORK_WIFI == pref) {
|
||||
if (networkWifi != 0) networkWifi * SettingsProvider.INTERVAL else learntWifiInterval
|
||||
if (networkWifi != 0) networkWifi * 60000 else learntWifiInterval
|
||||
} else {
|
||||
if (networkOther != 0) networkOther * SettingsProvider.INTERVAL else learntOtherInterval
|
||||
if (networkOther != 0) networkOther * 60000 else learntOtherInterval
|
||||
}
|
||||
}
|
||||
|
||||
fun learnTimeout(context: Context, pref: String) {
|
||||
Log.d("GmsGcmPrefs", "learnTimeout: $pref")
|
||||
when (pref) {
|
||||
<<<<<<< HEAD
|
||||
PREF_NETWORK_MOBILE, PREF_NETWORK_ROAMING -> Gcm.getContentUri(context)?.let {
|
||||
setSettings(context, it) {
|
||||
val newInterval = (learntMobileInterval * 0.95).toInt()
|
||||
|
|
@ -138,6 +145,19 @@ data class GcmPrefs(
|
|||
val newInterval = (learntMobileInterval * 0.95).toInt()
|
||||
put(Gcm.LEARNT_OTHER, newInterval)
|
||||
}
|
||||
=======
|
||||
PREF_NETWORK_MOBILE, PREF_NETWORK_ROAMING -> setSettings(context, Gcm.getContentUri(context)) {
|
||||
val newInterval = (learntMobileInterval * 0.95).toInt()
|
||||
put(Gcm.LEARNT_MOBILE, max(MIN_INTERVAL, min(newInterval, MAX_INTERVAL)))
|
||||
}
|
||||
PREF_NETWORK_WIFI -> setSettings(context, Gcm.getContentUri(context)) {
|
||||
val newInterval = (learntWifiInterval * 0.95).toInt()
|
||||
put(Gcm.LEARNT_WIFI, max(MIN_INTERVAL, min(newInterval, MAX_INTERVAL)))
|
||||
}
|
||||
else -> setSettings(context, Gcm.getContentUri(context)) {
|
||||
val newInterval = (learntOtherInterval * 0.95).toInt()
|
||||
put(Gcm.LEARNT_OTHER, max(MIN_INTERVAL, min(newInterval, MAX_INTERVAL)))
|
||||
>>>>>>> b0b92c8c (Set max auto heartbeat interval to 15min https://github.com/microg/GmsCore/commit/1e96dd137eae86bbf3be3ca72a6345fa837ad8ff)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -147,34 +167,53 @@ data class GcmPrefs(
|
|||
when (pref) {
|
||||
PREF_NETWORK_MOBILE, PREF_NETWORK_ROAMING -> {
|
||||
if (time > learntMobileInterval / 4 * 3) {
|
||||
<<<<<<< HEAD
|
||||
Gcm.getContentUri(context)?.let {
|
||||
setSettings(context, it) {
|
||||
put(Gcm.LEARNT_MOBILE, SettingsProvider.INTERVAL)
|
||||
}
|
||||
=======
|
||||
val newInterval = (learntMobileInterval * 1.02).toInt()
|
||||
setSettings(context, Gcm.getContentUri(context)) {
|
||||
put(Gcm.LEARNT_MOBILE, max(MIN_INTERVAL, min(newInterval, MAX_INTERVAL)))
|
||||
>>>>>>> b0b92c8c (Set max auto heartbeat interval to 15min https://github.com/microg/GmsCore/commit/1e96dd137eae86bbf3be3ca72a6345fa837ad8ff)
|
||||
}
|
||||
}
|
||||
}
|
||||
PREF_NETWORK_WIFI -> {
|
||||
if (time > learntWifiInterval / 4 * 3) {
|
||||
<<<<<<< HEAD
|
||||
Gcm.getContentUri(context)?.let {
|
||||
setSettings(context, it) {
|
||||
put(Gcm.LEARNT_WIFI, SettingsProvider.INTERVAL)
|
||||
}
|
||||
=======
|
||||
val newInterval = (learntWifiInterval * 1.02).toInt()
|
||||
setSettings(context, Gcm.getContentUri(context)) {
|
||||
put(Gcm.LEARNT_WIFI, max(MIN_INTERVAL, min(newInterval, MAX_INTERVAL)))
|
||||
>>>>>>> b0b92c8c (Set max auto heartbeat interval to 15min https://github.com/microg/GmsCore/commit/1e96dd137eae86bbf3be3ca72a6345fa837ad8ff)
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
if (time > learntOtherInterval / 4 * 3) {
|
||||
<<<<<<< HEAD
|
||||
Gcm.getContentUri(context)?.let {
|
||||
setSettings(context, it) {
|
||||
put(Gcm.LEARNT_OTHER, SettingsProvider.INTERVAL)
|
||||
}
|
||||
=======
|
||||
val newInterval = (learntOtherInterval * 1.02).toInt()
|
||||
setSettings(context, Gcm.getContentUri(context)) {
|
||||
put(Gcm.LEARNT_OTHER, max(MIN_INTERVAL, min(newInterval, MAX_INTERVAL)))
|
||||
>>>>>>> b0b92c8c (Set max auto heartbeat interval to 15min https://github.com/microg/GmsCore/commit/1e96dd137eae86bbf3be3ca72a6345fa837ad8ff)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun isEnabledFor(info: NetworkInfo?): Boolean {
|
||||
return isEnabled && info != null && getHeartbeatMsFor(info) >= 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class PushNotificationAdvancedFragment : PreferenceFragmentCompat() {
|
|||
val appContext = requireContext().applicationContext
|
||||
lifecycleScope.launchWhenResumed {
|
||||
(newValue as? String)?.toIntOrNull()?.let {
|
||||
setGcmServiceConfiguration(requireContext(), getGcmServiceInfo(appContext).configuration.copy(mobile = it))
|
||||
setGcmServiceConfiguration(appContext, getGcmServiceInfo(appContext).configuration.copy(mobile = it))
|
||||
}
|
||||
updateContent()
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ class PushNotificationAdvancedFragment : PreferenceFragmentCompat() {
|
|||
val appContext = requireContext().applicationContext
|
||||
lifecycleScope.launchWhenResumed {
|
||||
(newValue as? String)?.toIntOrNull()?.let {
|
||||
setGcmServiceConfiguration(appContext, getGcmServiceInfo(requireContext()).configuration.copy(wifi = it))
|
||||
setGcmServiceConfiguration(appContext, getGcmServiceInfo(appContext).configuration.copy(wifi = it))
|
||||
}
|
||||
updateContent()
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ class PushNotificationAdvancedFragment : PreferenceFragmentCompat() {
|
|||
val appContext = requireContext().applicationContext
|
||||
lifecycleScope.launchWhenResumed {
|
||||
(newValue as? String)?.toIntOrNull()?.let {
|
||||
setGcmServiceConfiguration(appContext, getGcmServiceInfo(requireContext()).configuration.copy(roaming = it))
|
||||
setGcmServiceConfiguration(appContext, getGcmServiceInfo(appContext).configuration.copy(roaming = it))
|
||||
}
|
||||
updateContent()
|
||||
}
|
||||
|
|
@ -67,7 +67,7 @@ class PushNotificationAdvancedFragment : PreferenceFragmentCompat() {
|
|||
val appContext = requireContext().applicationContext
|
||||
lifecycleScope.launchWhenResumed {
|
||||
(newValue as? String)?.toIntOrNull()?.let {
|
||||
setGcmServiceConfiguration(appContext, getGcmServiceInfo(requireContext()).configuration.copy(other = it))
|
||||
setGcmServiceConfiguration(appContext, getGcmServiceInfo(appContext).configuration.copy(other = it))
|
||||
}
|
||||
updateContent()
|
||||
}
|
||||
|
|
@ -98,13 +98,13 @@ class PushNotificationAdvancedFragment : PreferenceFragmentCompat() {
|
|||
private fun getSummaryString(value: Int, learnt: Int): String = when (value) {
|
||||
-1 -> getString(R.string.service_status_disabled_short)
|
||||
0 -> getString(R.string.service_status_enabled_short) + " / " + getString(R.string.gcm_status_pref_default) + ": " + getHeartbeatString(learnt)
|
||||
else -> getString(R.string.service_status_enabled_short) + " / " + getString(R.string.gcm_status_pref_manual) + ": " + getHeartbeatString(value * SettingsProvider.INTERVAL)
|
||||
else -> getString(R.string.service_status_enabled_short) + " / " + getString(R.string.gcm_status_pref_manual) + ": " + getHeartbeatString(value * 60000)
|
||||
}
|
||||
|
||||
private fun getHeartbeatString(heartbeatMs: Int): String {
|
||||
return if (heartbeatMs < 120000) {
|
||||
(heartbeatMs / 1000).toString() + " " + getString(R.string.gcm_status_pref_sec)
|
||||
} else (heartbeatMs / SettingsProvider.INTERVAL).toString() + " " + getString(R.string.gcm_status_pref_min)
|
||||
} else (heartbeatMs / 60000).toString() + " " + getString(R.string.gcm_status_pref_min)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
<ListPreference
|
||||
android:defaultValue="0"
|
||||
android:persistent="false"
|
||||
android:entries="@array/gcm_network_config_names"
|
||||
android:entryValues="@array/gcm_network_config_values"
|
||||
android:key="gcm_network_mobile"
|
||||
|
|
@ -31,6 +32,7 @@
|
|||
|
||||
<ListPreference
|
||||
android:defaultValue="0"
|
||||
android:persistent="false"
|
||||
android:entries="@array/gcm_network_config_names"
|
||||
android:entryValues="@array/gcm_network_config_values"
|
||||
android:key="gcm_network_wifi"
|
||||
|
|
@ -39,6 +41,7 @@
|
|||
|
||||
<ListPreference
|
||||
android:defaultValue="0"
|
||||
android:persistent="false"
|
||||
android:entries="@array/gcm_network_config_names"
|
||||
android:entryValues="@array/gcm_network_config_values"
|
||||
android:key="gcm_network_roaming"
|
||||
|
|
@ -47,6 +50,7 @@
|
|||
|
||||
<ListPreference
|
||||
android:defaultValue="0"
|
||||
android:persistent="false"
|
||||
android:entries="@array/gcm_network_config_names"
|
||||
android:entryValues="@array/gcm_network_config_values"
|
||||
android:key="gcm_network_other"
|
||||
|
|
|
|||
Loading…
Reference in a new issue