Skip to content

Commit

Permalink
Add checks to prevent re-initialization of the connectivitywatcher an…
Browse files Browse the repository at this point in the history
…d unregistering before registering the same watcher to prevent too manyrequests to networkcallback registeration (awslabs#387)
  • Loading branch information
gpanshu authored and sang le committed Nov 19, 2022
1 parent b36ea49 commit 9f7b339
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ public AppSyncOfflineMutationManager(Context context,

//Setup Network Monitoring objects
this.networkUpdateHandler = new NetworkUpdateHandler(handlerThread.getLooper());
this.connectivityWatcher = new ConnectivityWatcher(context,
new NetworkInfoReceiver(this.networkUpdateHandler));
if (this.connectivityWatcher == null) {
this.connectivityWatcher = new ConnectivityWatcher(context,
new NetworkInfoReceiver(this.networkUpdateHandler));
} else {
this.connectivityWatcher.unregister();
}
this.connectivityWatcher.register();

//Setup ancillary stuff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ public void onConnectivityChanged(boolean isNetworkConnected) {
if (isNetworkConnected) reportNetworkUp();
}
};
connectivityWatcher = new ConnectivityWatcher(applicationContext, callback);
if (connectivityWatcher == null) {
connectivityWatcher = new ConnectivityWatcher(applicationContext, callback);
} else {
connectivityWatcher.unregister();
}
connectivityWatcher.register();
}

Expand Down

0 comments on commit 9f7b339

Please sign in to comment.