preserve most recent maxInterval rather than counting on getting it

from relay.
This commit is contained in:
Eric House 2013-08-30 23:18:28 -07:00
parent d9bfc01e35
commit 7b9f6adf6d
2 changed files with 25 additions and 5 deletions

View file

@ -76,6 +76,7 @@
<string name="key_default_group">key_default_group</string>
<string name="key_group_posns">key_group_posns</string>
<string name="key_last_packet">key_last_packet</string>
<string name="key_udp_interval">key_udp_interval</string>
<string name="key_notagain_sync">key_notagain_sync</string>
<string name="key_notagain_chat">key_notagain_chat</string>

View file

@ -90,7 +90,7 @@ public class RelayService extends XWService
new LinkedBlockingQueue<DatagramPacket>();
private Handler m_handler;
private Runnable m_onInactivity;
private short m_maxIntervalSeconds = 5; // give time to get real value
private int m_maxIntervalSeconds = 0;
private long m_lastGamePacketReceived;
// These must match the enum XWPDevProto in xwrelay.h
@ -306,7 +306,7 @@ public class RelayService extends XWService
m_lastGamePacketReceived );
if ( shouldMaintainConnection() ) {
long interval_millis = m_maxIntervalSeconds * 1000;
long interval_millis = getMaxIntervalSeconds() * 1000;
RelayReceiver.RestartTimer( this, interval_millis );
}
stopThreads();
@ -543,9 +543,10 @@ public class RelayService extends XWService
break;
case XWPDEV_REGRSP:
str = getVLIString( dis );
m_maxIntervalSeconds = dis.readShort();
short maxIntervalSeconds = dis.readShort();
DbgUtils.logf( "got relayid %s, maxInterval %d", str,
m_maxIntervalSeconds );
maxIntervalSeconds );
setMaxIntervalSeconds( maxIntervalSeconds );
XWPrefs.setRelayDevID( this, str );
break;
case XWPDEV_HAVEMSGS:
@ -984,7 +985,7 @@ public class RelayService extends XWService
// UDP socket's no good as a return address after several
// minutes of inactivity, so do something after that time.
m_handler.postDelayed( m_onInactivity,
m_maxIntervalSeconds * 1000 );
getMaxIntervalSeconds() * 1000 );
}
private void startThreads()
@ -1057,6 +1058,24 @@ public class RelayService extends XWService
os.writeBytes( str );
}
private void setMaxIntervalSeconds( int maxIntervalSeconds )
{
if ( m_maxIntervalSeconds != maxIntervalSeconds ) {
m_maxIntervalSeconds = maxIntervalSeconds;
XWPrefs.setPrefsInt( this, R.string.key_udp_interval,
maxIntervalSeconds );
}
}
private int getMaxIntervalSeconds()
{
if ( 0 == m_maxIntervalSeconds ) {
m_maxIntervalSeconds =
XWPrefs.getPrefsInt( this, R.string.key_udp_interval, 60 );
}
return m_maxIntervalSeconds;
}
/* Timers:
*
* Two goals: simulate the GCM experience for those who don't have