From 25b7e6c8c6198b71f6cea07af85781065ac5d258 Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Tue, 2 Oct 2018 01:35:53 -0500 Subject: [PATCH 1/2] Adding a very high latency to nodes that fail their connection --- .../graphenej/api/android/NetworkService.java | 5 +++++ .../api/android/NetworkServiceManager.java | 18 ++++++------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java index 7a1ba3a..919fbb5 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java @@ -595,6 +595,11 @@ public class NetworkService extends Service { Log.e(TAG,"Response: "+response.message()); } + // Adding a very high latency value to this node in order to prevent + // us from getting it again + mSelectedNode.addLatencyValue(Long.MAX_VALUE); + nodeProvider.updateNode(mSelectedNode); + RxBus.getBusInstance().send(new ConnectionStatusUpdate(ConnectionStatusUpdate.DISCONNECTED, ApiAccess.API_NONE)); if(nodeProvider.getBestNode() == null){ diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkServiceManager.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkServiceManager.java index 5d5fb02..28f17b1 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkServiceManager.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkServiceManager.java @@ -9,6 +9,7 @@ import android.content.ServiceConnection; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; +import android.util.Log; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -74,14 +75,7 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb } @Override - public void onActivityCreated(Activity activity, Bundle bundle) { - if(mService == null){ - // Starting a NetworkService instance - Context context = mContextReference.get(); - Intent intent = new Intent(context, NetworkService.class); - context.startService(intent); - } - } + public void onActivityCreated(Activity activity, Bundle bundle) { } @Override public void onActivityStarted(Activity activity) { @@ -148,8 +142,8 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb return mUserName; } - public void setUserName(String mUserName) { - this.mUserName = mUserName; + public void setUserName(String userName) { + this.mUserName = userName; } public String getPassword() { @@ -286,8 +280,8 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb */ public NetworkServiceManager build(Context context){ NetworkServiceManager manager = new NetworkServiceManager(context); - if(username != null) manager.setUserName(username); - if(password != null) manager.setPassword(password); + if(username != null) manager.setUserName(username); else manager.setUserName(""); + if(password != null) manager.setPassword(password); else manager.setPassword(""); if(customNodeUrls != null) manager.setCustomNodeUrls(customNodeUrls); manager.setRequestedApis(requestedApis); manager.setAutoConnect(autoconnect); From 857236a1ea7c6432e292326777b4e3cdceacf1cb Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Tue, 2 Oct 2018 12:36:36 -0500 Subject: [PATCH 2/2] Moved the service binding to the onActivityResumed callback --- .../graphenej/api/android/NetworkServiceManager.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkServiceManager.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkServiceManager.java index 28f17b1..beb4f05 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkServiceManager.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkServiceManager.java @@ -78,7 +78,10 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb public void onActivityCreated(Activity activity, Bundle bundle) { } @Override - public void onActivityStarted(Activity activity) { + public void onActivityStarted(Activity activity) { } + + @Override + public void onActivityResumed(Activity activity) { mHandler.removeCallbacks(mDisconnectRunnable); if(mService == null){ // Creating a new Intent that will be used to start the NetworkService @@ -101,14 +104,10 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb .putExtra(NetworkService.KEY_CUSTOM_NODE_URLS, customNodes) .putExtra(NetworkService.KEY_AUTO_CONNECT, mAutoConnect) .putExtra(NetworkService.KEY_ENABLE_LATENCY_VERIFIER, mVerifyLatency); - context.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE); } } - @Override - public void onActivityResumed(Activity activity) {} - @Override public void onActivityPaused(Activity activity) { mHandler.postDelayed(mDisconnectRunnable, DISCONNECT_DELAY);