mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-23 07:27:22 +01:00
display latest FCM receipt as part of netstats for relay
This commit is contained in:
parent
be6b74ab12
commit
49ef455e50
3 changed files with 32 additions and 38 deletions
|
@ -30,8 +30,6 @@ import android.graphics.drawable.Drawable;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.text.format.Time;
|
|
||||||
|
|
||||||
|
|
||||||
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
||||||
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
|
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
|
||||||
|
@ -62,7 +60,6 @@ public class ConnStatusHandler {
|
||||||
private static ConnStatusCBacks s_cbacks;
|
private static ConnStatusCBacks s_cbacks;
|
||||||
private static Paint s_fillPaint = new Paint( Paint.ANTI_ALIAS_FLAG );
|
private static Paint s_fillPaint = new Paint( Paint.ANTI_ALIAS_FLAG );
|
||||||
private static boolean[] s_showSuccesses = { false, false };
|
private static boolean[] s_showSuccesses = { false, false };
|
||||||
private static Time s_time = new Time();
|
|
||||||
|
|
||||||
private static class SuccessRecord implements java.io.Serializable {
|
private static class SuccessRecord implements java.io.Serializable {
|
||||||
public long lastSuccess;
|
public long lastSuccess;
|
||||||
|
@ -81,24 +78,12 @@ public class ConnStatusHandler {
|
||||||
|
|
||||||
public String newerStr( Context context )
|
public String newerStr( Context context )
|
||||||
{
|
{
|
||||||
String result = null;
|
return format( context, successNewer? lastSuccess : lastFailure );
|
||||||
long time = successNewer? lastSuccess : lastFailure;
|
|
||||||
if ( time > 0 ) {
|
|
||||||
s_time.set( time );
|
|
||||||
result = format( context, s_time );
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String olderStr( Context context )
|
public String olderStr( Context context )
|
||||||
{
|
{
|
||||||
String result = null;
|
return format( context, successNewer? lastFailure : lastSuccess );
|
||||||
long time = successNewer? lastFailure : lastSuccess;
|
|
||||||
if ( time > 0 ) {
|
|
||||||
s_time.set( time );
|
|
||||||
result = format( context, s_time );
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update( boolean success )
|
public void update( boolean success )
|
||||||
|
@ -112,15 +97,18 @@ public class ConnStatusHandler {
|
||||||
successNewer = success;
|
successNewer = success;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String format( Context context, Time time )
|
private static String format( Context context, long millis )
|
||||||
{
|
{
|
||||||
CharSequence seq =
|
String result = null;
|
||||||
DateUtils.getRelativeDateTimeString( context,
|
if ( millis > 0 ) {
|
||||||
time.toMillis(true),
|
CharSequence seq =
|
||||||
DateUtils.SECOND_IN_MILLIS,
|
DateUtils.getRelativeDateTimeString( context, millis,
|
||||||
DateUtils.WEEK_IN_MILLIS,
|
DateUtils.SECOND_IN_MILLIS,
|
||||||
0 );
|
DateUtils.WEEK_IN_MILLIS,
|
||||||
return seq.toString();
|
0 );
|
||||||
|
result = seq.toString();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,9 +533,12 @@ public class ConnStatusHandler {
|
||||||
if ( BuildConfig.DEBUG ) {
|
if ( BuildConfig.DEBUG ) {
|
||||||
switch ( typ ) {
|
switch ( typ ) {
|
||||||
case COMMS_CONN_RELAY:
|
case COMMS_CONN_RELAY:
|
||||||
result = String.format( "DevID: %d; host: %s",
|
String fcmMsg = SuccessRecord
|
||||||
|
.format( context, RelayService.getLastFCMMillis() );
|
||||||
|
result = String.format( "DevID: %d; host: %s; latest FCM: %s",
|
||||||
DevID.getRelayDevIDInt(context),
|
DevID.getRelayDevIDInt(context),
|
||||||
XWPrefs.getDefaultRelayHost(context) );
|
XWPrefs.getDefaultRelayHost(context),
|
||||||
|
fcmMsg );
|
||||||
break;
|
break;
|
||||||
case COMMS_CONN_P2P:
|
case COMMS_CONN_P2P:
|
||||||
result = WiDirService.formatNetStateInfo();
|
result = WiDirService.formatNetStateInfo();
|
||||||
|
|
|
@ -112,7 +112,7 @@ public class RelayService extends JobIntentService
|
||||||
private static List<PacketData> s_packetsSentWeb = new ArrayList<>();
|
private static List<PacketData> s_packetsSentWeb = new ArrayList<>();
|
||||||
private static final PacketData sEOQPacket = new PacketData();
|
private static final PacketData sEOQPacket = new PacketData();
|
||||||
private static AtomicInteger s_nextPacketID = new AtomicInteger();
|
private static AtomicInteger s_nextPacketID = new AtomicInteger();
|
||||||
private static boolean s_gcmWorking = false;
|
private static long s_lastFCM = 0L;
|
||||||
private static boolean s_registered = false;
|
private static boolean s_registered = false;
|
||||||
private static CommsAddrRec s_addr =
|
private static CommsAddrRec s_addr =
|
||||||
new CommsAddrRec( CommsConnType.COMMS_CONN_RELAY );
|
new CommsAddrRec( CommsConnType.COMMS_CONN_RELAY );
|
||||||
|
@ -162,11 +162,12 @@ public class RelayService extends JobIntentService
|
||||||
|
|
||||||
public static void fcmConfirmed( Context context, boolean working )
|
public static void fcmConfirmed( Context context, boolean working )
|
||||||
{
|
{
|
||||||
if ( s_gcmWorking != working ) {
|
long newVal = working ? System.currentTimeMillis() : 0L;
|
||||||
Log.i( TAG, "fcmConfirmed(): changing s_gcmWorking to %b",
|
if ( (s_lastFCM == 0) != working ) {
|
||||||
working );
|
Log.i( TAG, "fcmConfirmed(): changing s_lastFCM to %d",
|
||||||
s_gcmWorking = working;
|
newVal );
|
||||||
}
|
}
|
||||||
|
s_lastFCM = newVal;
|
||||||
|
|
||||||
// If we've gotten a GCM id and haven't registered it, do so!
|
// If we've gotten a GCM id and haven't registered it, do so!
|
||||||
if ( working && !s_curType.equals( DevIDType.ID_TYPE_ANDROID_FCM ) ) {
|
if ( working && !s_curType.equals( DevIDType.ID_TYPE_ANDROID_FCM ) ) {
|
||||||
|
@ -176,6 +177,12 @@ public class RelayService extends JobIntentService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long getLastFCMMillis()
|
||||||
|
{
|
||||||
|
Log.d( TAG, "getLastFCMMillis() => %d", s_lastFCM );
|
||||||
|
return s_lastFCM;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean relayEnabled( Context context )
|
public static boolean relayEnabled( Context context )
|
||||||
{
|
{
|
||||||
boolean enabled = ! XWPrefs
|
boolean enabled = ! XWPrefs
|
||||||
|
@ -1655,14 +1662,14 @@ public class RelayService extends JobIntentService
|
||||||
* Goal: maintain connection by keeping this service alive with
|
* Goal: maintain connection by keeping this service alive with
|
||||||
* its periodic pings to relay. When it dies or is killed,
|
* its periodic pings to relay. When it dies or is killed,
|
||||||
* notice, and use RelayReceiver's timer to get it restarted a bit
|
* notice, and use RelayReceiver's timer to get it restarted a bit
|
||||||
* later. But note: s_gcmWorking will not be set when the app is
|
* later. But note: s_lastFCM will not be set when the app is
|
||||||
* relaunched.
|
* relaunched.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private boolean shouldMaintainConnection()
|
private boolean shouldMaintainConnection()
|
||||||
{
|
{
|
||||||
boolean result = relayEnabled( this )
|
boolean result = relayEnabled( this )
|
||||||
&& (!s_gcmWorking || XWPrefs.getIgnoreFCM( this ));
|
&& (0 == s_lastFCM || XWPrefs.getIgnoreFCM( this ));
|
||||||
|
|
||||||
if ( result ) {
|
if ( result ) {
|
||||||
long interval = Utils.getCurSeconds() - m_lastGamePacketReceived;
|
long interval = Utils.getCurSeconds() - m_lastGamePacketReceived;
|
||||||
|
|
|
@ -160,9 +160,5 @@ public class FBMService extends FirebaseMessagingService {
|
||||||
|
|
||||||
DBUtils.setStringFor( context, KEY_FCMID, token );
|
DBUtils.setStringFor( context, KEY_FCMID, token );
|
||||||
DevID.setFCMDevID( context, token );
|
DevID.setFCMDevID( context, token );
|
||||||
|
|
||||||
if ( !XWPrefs.getIgnoreFCM( context ) ) {
|
|
||||||
RelayService.fcmConfirmed( context, true );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue