don't crash when can't reach relay via http

This commit is contained in:
Eric House 2017-11-12 08:53:19 -08:00
parent ec075eff18
commit 8650795a81

View file

@ -166,7 +166,6 @@ public class RelayService extends XWService
{
boolean enabled = ! XWPrefs
.getPrefsBoolean( context, R.string.key_disable_relay, false );
Log.d( TAG, "relayEnabled() => %b", enabled );
return enabled;
}
@ -656,6 +655,10 @@ public class RelayService extends XWService
{
Log.d( TAG, "sendViaWeb(): sending %d at once", packets.size() );
int sentLen = 0;
HttpURLConnection conn = NetUtils.makeHttpRelayConn( this, "post" );
if ( null == conn ) {
Log.e( TAG, "sendViaWeb(): null conn for POST" );
} else {
try {
JSONArray dataArray = new JSONArray();
for ( PacketData packet : packets ) {
@ -666,7 +669,6 @@ public class RelayService extends XWService
JSONObject params = new JSONObject();
params.put( "data", dataArray );
HttpURLConnection conn = NetUtils.makeHttpRelayConn( this, "post" );
String result = NetUtils.runConn(conn, params);
if ( null != result ) {
Log.d( TAG, "sendViaWeb(): POST => %s", result );
@ -691,6 +693,7 @@ public class RelayService extends XWService
} catch ( JSONException ex ) {
Assert.assertFalse( BuildConfig.DEBUG );
}
}
return sentLen;
}
@ -962,11 +965,15 @@ public class RelayService extends XWService
{
ByteArrayOutputStream bas = new ByteArrayOutputStream();
try {
String devid = getDevID( null );
DevIDType[] typp = new DevIDType[1];
String devid = getDevID( typp );
if ( null != devid ) {
DataOutputStream out = new DataOutputStream( bas );
writeVLIString( out, devid );
Log.d(TAG, "requestMessagesImpl(): devid: %s; type: " + typp[0], devid );
postPacket( bas, reg );
} else {
Log.d(TAG, "requestMessagesImpl(): devid is null" );
}
} catch ( java.io.IOException ioe ) {
Log.ex( TAG, ioe );