Skip to content

Instantly share code, notes, and snippets.

@witwall
Last active November 10, 2015 10:11
Show Gist options
  • Save witwall/eccb11a618153c0aea9a to your computer and use it in GitHub Desktop.
Save witwall/eccb11a618153c0aea9a to your computer and use it in GitHub Desktop.
package org.getlantern.firetweet.model;
import org.getlantern.firetweet.FiretweetConstants;
// Flashlight client
import go.client.Client;
import android.content.Context;
import android.util.Log;
import android.os.StrictMode;
import com.crashlytics.android.Crashlytics;
/**
* Created by todd on 4/25/15.
*/
public class Lantern {
private static final String TAG = "Lantern";
private static boolean lanternStarted = false;
public static Analytics analytics;
public static void start(final Context context) {
if (!lanternStarted) {
// Initializing application context.
try {
Client.GoCallback.Stub callback = new Client.GoCallback.Stub() {
@Override
public void Do() {
Log.d(TAG, "Lantern successfully started.");
// specify that all of our HTTP traffic should be routed through
// our local proxy
System.setProperty("http.proxyHost", "127.0.0.1");
System.setProperty("http.proxyPort", "9192");
System.setProperty("https.proxyHost", "127.0.0.1");
System.setProperty("https.proxyPort", "9192");
lanternStarted = true;
analytics = new Analytics(context);
analytics.sendNewSessionEvent();
}
public void AfterConfigure() {
}
};
// init loads libgojni.so and starts the runtime
Client.RunClientProxy("0.0.0.0:9192",
FiretweetConstants.APP_NAME,
callback);
} catch (Exception e) {
Crashlytics.logException(e);
throw new RuntimeException(e);
}
}
}
public static void stop() {
if (lanternStarted) {
try {
Client.StopClientProxy();
lanternStarted = false;
} catch (Exception e) {
Crashlytics.logException(e);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment