From a3558614d1739a92cfe0d3a040eca97f2e7d82b3 Mon Sep 17 00:00:00 2001 From: denzilferreira Date: Mon, 10 Jul 2017 10:32:04 +0300 Subject: [PATCH] - Improve case when wifi is available to be more efficient. --- .../src/main/java/com/aware/utils/WebserviceHelper.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/aware-core/src/main/java/com/aware/utils/WebserviceHelper.java b/aware-core/src/main/java/com/aware/utils/WebserviceHelper.java index b7d458bb1..45f67f2b8 100644 --- a/aware-core/src/main/java/com/aware/utils/WebserviceHelper.java +++ b/aware-core/src/main/java/com/aware/utils/WebserviceHelper.java @@ -322,9 +322,13 @@ public boolean isWifiNeededAndConnected() { NetworkInfo activeNetwork = connManager.getActiveNetworkInfo(); boolean sync = (activeNetwork != null && activeNetwork.getType() == ConnectivityManager.TYPE_WIFI && activeNetwork.isConnected()); - if ( Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_FALLBACK_NETWORK).length() > 0 + //we are connected to WiFi, we are done here. + if (sync) return sync; + + //Fallback to 3G if no wifi for x hours + if (Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_FALLBACK_NETWORK).length() > 0 && !Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_FALLBACK_NETWORK).equals("0")) { - //Allow fallback to 3G if it's been xh+ since the last time we synced over WiFi (force data sync by any means necessary) + Cursor lastSynched = getContentResolver().query(Aware_Provider.Aware_Log.CONTENT_URI, null, Aware_Provider.Aware_Log.LOG_MESSAGE + " LIKE 'STUDY-SYNC'", null, Aware_Provider.Aware_Log.LOG_TIMESTAMP + " DESC LIMIT 1"); if (lastSynched != null && lastSynched.moveToFirst()) { long synched = lastSynched.getLong(lastSynched.getColumnIndex(Aware_Provider.Aware_Log.LOG_TIMESTAMP));