Skip to content

Commit

Permalink
Don't say we are connected when push is disabled for current network
Browse files Browse the repository at this point in the history
This may cause a connection attempt, but in connect(), we'll notice that it is disabled and won't continue to connect.

Change-Id: Id5f00539a48fad16b5e5f55bd336fb8890aa1acc
  • Loading branch information
grote authored and mar-v-in committed Jan 25, 2022
1 parent bb68674 commit 2ba2c04
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.content.pm.PermissionInfo;
import android.content.pm.ResolveInfo;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
Expand Down Expand Up @@ -248,6 +249,7 @@ public synchronized static boolean isConnected(Context context) {
// if disabled for active network, heartbeatMs will be -1
if (heartbeatMs < 0) {
closeAll();
return false;
} else if (SystemClock.elapsedRealtime() - lastHeartbeatAckElapsedRealtime > 2L * heartbeatMs) {
logd(null, "No heartbeat for " + (SystemClock.elapsedRealtime() - lastHeartbeatAckElapsedRealtime) / 1000 + " seconds, connection assumed to be dead after " + 2 * heartbeatMs / 1000 + " seconds");
GcmPrefs.get(context).learnTimeout(context, activeNetworkPref);
Expand Down Expand Up @@ -436,8 +438,10 @@ private synchronized void connect() {
try {
closeAll();
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
activeNetworkPref = GcmPrefs.get(this).getNetworkPrefForInfo(cm.getActiveNetworkInfo());
if (!GcmPrefs.get(this).isEnabledFor(cm.getActiveNetworkInfo())) {
NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
activeNetworkPref = GcmPrefs.get(this).getNetworkPrefForInfo(activeNetworkInfo);
if (!GcmPrefs.get(this).isEnabledFor(activeNetworkInfo)) {
logd(this, "Don't connect, because disabled for " + activeNetworkInfo.getTypeName());
scheduleReconnect(this);
return;
}
Expand Down

0 comments on commit 2ba2c04

Please sign in to comment.