Bug 1368969 - Disconnect socket when Leanplum stop. WIP
MozReview-Commit-ID: 9TT5Iahr95O
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaLeanplumImp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaLeanplumImp.java
@@ -75,16 +75,18 @@ public class MmaLeanplumImp implements M
@Override
public void track(String leanplumEvent, double value) {
Leanplum.track(leanplumEvent, value);
}
@Override
public void stop() {
+
+ Leanplum.enableTestMode();
Leanplum.stop();
}
private static boolean isPackageInstalled(final Context context, String packageName) {
try {
PackageManager pm = context.getPackageManager();
pm.getPackageInfo(packageName, 0);
return true;
--- a/mobile/android/thirdparty/com/leanplum/Leanplum.java
+++ b/mobile/android/thirdparty/com/leanplum/Leanplum.java
@@ -42,16 +42,17 @@ import com.leanplum.internal.FileManager
import com.leanplum.internal.JsonConverter;
import com.leanplum.internal.LeanplumInternal;
import com.leanplum.internal.LeanplumMessageMatchFilter;
import com.leanplum.internal.LeanplumUIEditorWrapper;
import com.leanplum.internal.Log;
import com.leanplum.internal.OsHandler;
import com.leanplum.internal.Registration;
import com.leanplum.internal.Request;
+import com.leanplum.internal.Socket;
import com.leanplum.internal.Util;
import com.leanplum.internal.Util.DeviceIdInfo;
import com.leanplum.internal.VarCache;
import com.leanplum.messagetemplates.MessageTemplates;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -1042,16 +1043,17 @@ public class Leanplum {
Util.handleException(t);
}
}
});
}
}
private static void stopInternal() {
+ Socket.getInstance().disconnect();
Request.post(Constants.Methods.STOP, null).sendIfConnected();
}
/**
* Whether or not Leanplum has finished starting.
*/
public static boolean hasStarted() {
return LeanplumInternal.hasStarted();
--- a/mobile/android/thirdparty/com/leanplum/internal/Socket.java
+++ b/mobile/android/thirdparty/com/leanplum/internal/Socket.java
@@ -146,16 +146,17 @@ public class Socket {
};
try {
sio = new SocketIOClient(new URI("http://" + Constants.SOCKET_HOST + ":" +
Constants.SOCKET_PORT), socketIOClientHandler);
} catch (URISyntaxException e) {
Log.e(e.getMessage());
}
+
connect();
Timer reconnectTimer = new Timer();
reconnectTimer.schedule(new TimerTask() {
@Override
public void run() {
try {
reconnect();
} catch (Throwable t) {
@@ -168,16 +169,21 @@ public class Socket {
/**
* Connect to the remote socket.
*/
private void connect() {
connecting = true;
sio.connect();
}
+ public void disconnect() {
+ connecting = false;
+ sio.disconnect();
+ }
+
/**
* Disconnect from the remote socket.
*/
private void reconnect() {
if (!connected && !connecting) {
connect();
}
}
--- a/mobile/android/thirdparty/com/leanplum/internal/SocketIOClient.java
+++ b/mobile/android/thirdparty/com/leanplum/internal/SocketIOClient.java
@@ -223,21 +223,21 @@ class SocketIOClient {
}
}, mHeartbeat);
mHandler.onConnect();
}
}, null);
mClient.connect();
}
- public void disconnect() throws IOException {
+ public void disconnect() {
cleanup();
}
- private void cleanup() {
+ public void cleanup() {
if (mClient != null) {
mClient.disconnect();
mClient = null;
}
if (mSendLooper != null) {
mSendLooper.quit();
}