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 ) private void requestMessagesImpl( XWRelayReg reg )
{ {
ByteArrayOutputStream bas = new ByteArrayOutputStream();
try { try {
DevIDType[] typp = new DevIDType[1]; DevIDType[] typp = new DevIDType[1];
String devid = getDevID( typp ); String devid = getDevID( typp );
if ( null != devid ) { if ( null != devid ) {
ByteArrayOutputStream bas = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream( bas ); DataOutputStream out = new DataOutputStream( bas );
writeVLIString( out, devid ); writeVLIString( out, devid );
// Log.d( TAG, "requestMessagesImpl(): devid: %s; type: " + typp[0], devid ); // Log.d( TAG, "requestMessagesImpl(): devid: %s; type: " + typp[0], devid );
@ -1606,7 +1606,8 @@ public class RelayService extends XWService
private boolean shouldMaintainConnection() private boolean shouldMaintainConnection()
{ {
boolean result = relayEnabled( this ) boolean result = relayEnabled( this )
&& (XWApp.GCM_IGNORED || !s_gcmWorking); && (!s_gcmWorking || XWPrefs.getIgnoreGCM( this ));
if ( result ) { if ( result ) {
long interval = Utils.getCurSeconds() - m_lastGamePacketReceived; long interval = Utils.getCurSeconds() - m_lastGamePacketReceived;
result = interval < MAX_KEEPALIVE_SECS; 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 ATTACH_SUPPORTED = false;
public static final boolean LOG_LIFECYLE = false; public static final boolean LOG_LIFECYLE = false;
public static final boolean DEBUG_EXP_TIMERS = 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 UDP_ENABLED = true;
public static final boolean SMS_INVITE_ENABLED = true; public static final boolean SMS_INVITE_ENABLED = true;
public static final boolean LOCUTILS_ENABLED = false; 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 ); 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 ) public static boolean getRelayInviteToSelfEnabled( Context context )
{ {
return getPrefsBoolean( context, R.string.key_enable_relay_toself, false ); 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_nfc_toself">key_enable_nfc_toself</string>
<string name="key_enable_sms_toself">key_enable_sms_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_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_nag_intervals">key_nag_intervals</string>
<string name="key_download_path">key_download_path</string> <string name="key_download_path">key_download_path</string>
<string name="key_got_langdict">key_got_langdict</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_title">Enable relay invites to self</string>
<string name="enable_relay_toself_summary">(To aid testing and debugging)</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 --> <!-- Shown after "resend messages" menuitem chosen -->
<plurals name="resent_msgs_fmt"> <plurals name="resent_msgs_fmt">
<item quantity="one">One move sent</item> <item quantity="one">One move sent</item>

View file

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

View file

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