add settings for debugging/tracking GCM

This commit is contained in:
Eric House 2018-01-03 19:31:08 -08:00
parent 11be66eb3f
commit 8c9e79f0fc
7 changed files with 55 additions and 14 deletions

View file

@ -801,11 +801,11 @@ public class RelayService extends XWService
private void requestMessagesImpl( XWRelayReg reg )
{
ByteArrayOutputStream bas = new ByteArrayOutputStream();
try {
DevIDType[] typp = new DevIDType[1];
String devid = getDevID( typp );
if ( null != devid ) {
ByteArrayOutputStream bas = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream( bas );
writeVLIString( out, devid );
// Log.d( TAG, "requestMessagesImpl(): devid: %s; type: " + typp[0], devid );
@ -1606,7 +1606,8 @@ public class RelayService extends XWService
private boolean shouldMaintainConnection()
{
boolean result = relayEnabled( this )
&& (XWApp.GCM_IGNORED || !s_gcmWorking);
&& (!s_gcmWorking || XWPrefs.getIgnoreGCM( this ));
if ( result ) {
long interval = Utils.getCurSeconds() - m_lastGamePacketReceived;
result = interval < MAX_KEEPALIVE_SECS;

View file

@ -39,7 +39,6 @@ public class XWApp extends Application {
public static final boolean ATTACH_SUPPORTED = false;
public static final boolean LOG_LIFECYLE = false;
public static final boolean DEBUG_EXP_TIMERS = false;
public static final boolean GCM_IGNORED = false;
public static final boolean UDP_ENABLED = true;
public static final boolean SMS_INVITE_ENABLED = true;
public static final boolean LOCUTILS_ENABLED = false;

View file

@ -67,6 +67,16 @@ public class XWPrefs {
return getPrefsBoolean( context, R.string.key_enable_nfc_toself, false );
}
public static boolean getIgnoreGCM( Context context )
{
return getPrefsBoolean( context, R.string.key_ignore_gcm, false );
}
public static boolean getToastGCM( Context context )
{
return getPrefsBoolean( context, R.string.key_show_gcm, false );
}
public static boolean getRelayInviteToSelfEnabled( Context context )
{
return getPrefsBoolean( context, R.string.key_enable_relay_toself, false );

View file

@ -126,6 +126,8 @@
<string name="key_enable_nfc_toself">key_enable_nfc_toself</string>
<string name="key_enable_sms_toself">key_enable_sms_toself</string>
<string name="key_enable_relay_toself">key_enable_relay_toself</string>
<string name="key_ignore_gcm">key_ignore_gcm</string>
<string name="key_show_gcm">key_show_gcm</string>
<string name="key_nag_intervals">key_nag_intervals</string>
<string name="key_download_path">key_download_path</string>
<string name="key_got_langdict">key_got_langdict</string>

View file

@ -2601,6 +2601,12 @@
<string name="enable_relay_toself_title">Enable relay invites to self</string>
<string name="enable_relay_toself_summary">(To aid testing and debugging)</string>
<string name="ignore_gcm_title">Ignore incoming GCM messages</string>
<string name="ignore_gcm_summary">Mimic life without a google account</string>
<string name="show_sms_title">Show SMS sends, receives</string>
<string name="show_gcm_title">Show GCM receives</string>
<!-- Shown after "resend messages" menuitem chosen -->
<plurals name="resent_msgs_fmt">
<item quantity="one">One move sent</item>

View file

@ -407,7 +407,7 @@
/>
<CheckBoxPreference android:key="@string/key_show_sms"
android:title="Show SMS sends, receives"
android:title="@string/show_sms_title"
android:defaultValue="false"
/>
</PreferenceScreen>
@ -420,6 +420,15 @@
android:summary="@string/enable_relay_toself_summary"
android:defaultValue="false"
/>
<CheckBoxPreference android:key="@string/key_ignore_gcm"
android:title="@string/ignore_gcm_title"
android:summary="@string/ignore_gcm_summary"
android:defaultValue="false"
/>
<CheckBoxPreference android:key="@string/key_show_gcm"
android:title="@string/show_gcm_title"
android:defaultValue="false"
/>
<org.eehouse.android.xw4.XWEditTextPreference
android:key="@string/key_relay_host"
android:title="@string/relay_host"

View file

@ -34,6 +34,8 @@ import junit.framework.Assert;
public class GCMIntentService extends GCMBaseIntentService {
private static final String TAG = GCMIntentService.class.getSimpleName();
private Boolean m_toastGCM;
public GCMIntentService()
{
super( BuildConfig.GCM_SENDER_ID );
@ -67,14 +69,19 @@ public class GCMIntentService extends GCMBaseIntentService {
protected void onMessage( Context context, Intent intent )
{
Log.d( TAG, "onMessage()" );
notifyRelayService( context, true );
String value;
boolean ignoreIt = XWApp.GCM_IGNORED;
if ( ignoreIt ) {
Log.d( TAG, "received GCM but ignoring it" );
if ( null == m_toastGCM ) {
m_toastGCM = new Boolean( XWPrefs.getToastGCM( context ) );
}
if ( XWPrefs.getIgnoreGCM( context ) ) {
String logMsg = "received GCM but ignoring it";
Log.d( TAG, logMsg );
DbgUtils.showf( context, logMsg );
} else {
value = intent.getStringExtra( "checkUpdates" );
notifyRelayService( context, true );
String value = intent.getStringExtra( "checkUpdates" );
if ( null != value && Boolean.parseBoolean( value ) ) {
UpdateCheckReceiver.checkVersions( context, true );
}
@ -82,6 +89,9 @@ public class GCMIntentService extends GCMBaseIntentService {
value = intent.getStringExtra( "getMoves" );
if ( null != value && Boolean.parseBoolean( value ) ) {
RelayService.timerFired( context );
if ( m_toastGCM ) {
DbgUtils.showf( context, "onMessage(): got 'getMoves'" );
}
}
value = intent.getStringExtra( "msgs64" );
@ -90,6 +100,11 @@ public class GCMIntentService extends GCMBaseIntentService {
try {
JSONArray msgs64 = new JSONArray( value );
String[] strs64 = new String[msgs64.length()];
if ( m_toastGCM ) {
DbgUtils.showf( context, "onMessage(): got %d msgs",
strs64.length );
}
for ( int ii = 0; ii < strs64.length; ++ii ) {
strs64[ii] = msgs64.optString(ii);
}
@ -100,6 +115,7 @@ public class GCMIntentService extends GCMBaseIntentService {
}
} catch (org.json.JSONException jse ) {
Log.ex( TAG, jse );
Assert.assertFalse( BuildConfig.DEBUG );
}
}
@ -145,10 +161,8 @@ public class GCMIntentService extends GCMBaseIntentService {
private void notifyRelayService( Context context, boolean working )
{
if ( working && XWApp.GCM_IGNORED ) {
working = false;
if ( !XWPrefs.getIgnoreGCM( context ) ) {
RelayService.gcmConfirmed( context, working );
}
RelayService.gcmConfirmed( context, working );
}
}