display latest FCM receipt as part of netstats for relay

This commit is contained in:
Eric House 2019-02-02 15:18:45 -08:00
parent c67bda8683
commit ac5cbea83f
3 changed files with 32 additions and 38 deletions

View file

@ -30,8 +30,6 @@ import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.provider.Settings;
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.CommsConnTypeSet;
@ -62,7 +60,6 @@ public class ConnStatusHandler {
private static ConnStatusCBacks s_cbacks;
private static Paint s_fillPaint = new Paint( Paint.ANTI_ALIAS_FLAG );
private static boolean[] s_showSuccesses = { false, false };
private static Time s_time = new Time();
private static class SuccessRecord implements java.io.Serializable {
public long lastSuccess;
@ -81,24 +78,12 @@ public class ConnStatusHandler {
public String newerStr( Context context )
{
String result = null;
long time = successNewer? lastSuccess : lastFailure;
if ( time > 0 ) {
s_time.set( time );
result = format( context, s_time );
}
return result;
return format( context, successNewer? lastSuccess : lastFailure );
}
public String olderStr( Context context )
{
String result = null;
long time = successNewer? lastFailure : lastSuccess;
if ( time > 0 ) {
s_time.set( time );
result = format( context, s_time );
}
return result;
return format( context, successNewer? lastFailure : lastSuccess );
}
public void update( boolean success )
@ -112,15 +97,18 @@ public class ConnStatusHandler {
successNewer = success;
}
private String format( Context context, Time time )
private static String format( Context context, long millis )
{
CharSequence seq =
DateUtils.getRelativeDateTimeString( context,
time.toMillis(true),
DateUtils.SECOND_IN_MILLIS,
DateUtils.WEEK_IN_MILLIS,
0 );
return seq.toString();
String result = null;
if ( millis > 0 ) {
CharSequence seq =
DateUtils.getRelativeDateTimeString( context, millis,
DateUtils.SECOND_IN_MILLIS,
DateUtils.WEEK_IN_MILLIS,
0 );
result = seq.toString();
}
return result;
}
}
@ -545,9 +533,12 @@ public class ConnStatusHandler {
if ( BuildConfig.DEBUG ) {
switch ( typ ) {
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),
XWPrefs.getDefaultRelayHost(context) );
XWPrefs.getDefaultRelayHost(context),
fcmMsg );
break;
case COMMS_CONN_P2P:
result = WiDirService.formatNetStateInfo();

View file

@ -112,7 +112,7 @@ public class RelayService extends JobIntentService
private static List<PacketData> s_packetsSentWeb = new ArrayList<>();
private static final PacketData sEOQPacket = new PacketData();
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 CommsAddrRec s_addr =
new CommsAddrRec( CommsConnType.COMMS_CONN_RELAY );
@ -162,11 +162,12 @@ public class RelayService extends JobIntentService
public static void fcmConfirmed( Context context, boolean working )
{
if ( s_gcmWorking != working ) {
Log.i( TAG, "fcmConfirmed(): changing s_gcmWorking to %b",
working );
s_gcmWorking = working;
long newVal = working ? System.currentTimeMillis() : 0L;
if ( (s_lastFCM == 0) != working ) {
Log.i( TAG, "fcmConfirmed(): changing s_lastFCM to %d",
newVal );
}
s_lastFCM = newVal;
// If we've gotten a GCM id and haven't registered it, do so!
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 )
{
boolean enabled = ! XWPrefs
@ -1655,14 +1662,14 @@ public class RelayService extends JobIntentService
* Goal: maintain connection by keeping this service alive with
* its periodic pings to relay. When it dies or is killed,
* 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.
*/
private boolean shouldMaintainConnection()
{
boolean result = relayEnabled( this )
&& (!s_gcmWorking || XWPrefs.getIgnoreFCM( this ));
&& (0 == s_lastFCM || XWPrefs.getIgnoreFCM( this ));
if ( result ) {
long interval = Utils.getCurSeconds() - m_lastGamePacketReceived;

View file

@ -160,9 +160,5 @@ public class FBMService extends FirebaseMessagingService {
DBUtils.setStringFor( context, KEY_FCMID, token );
DevID.setFCMDevID( context, token );
if ( !XWPrefs.getIgnoreFCM( context ) ) {
RelayService.fcmConfirmed( context, true );
}
}
}