// Path: app/src/main/java/com/samourai/sentinel/util/LogUtil.java
// public class LogUtil {
// 
//     public static void debug(final String tag, String message) {
//         if (BuildConfig.DEBUG) {
//             android.util.Log.d(tag, message);
//         }
//     }
// 
//     public static void info(final String tag, String message) {
//         if (BuildConfig.DEBUG) {
//             android.util.Log.i(tag, message);
//         }
//     }
// 
//     public static void error(final String tag, String message) {
//         if (BuildConfig.DEBUG) {
//             android.util.Log.e(tag, message);
//         }
//     }
// 
// }
// 
// Path: app/src/main/java/com/samourai/sentinel/SentinelApplication.java
// public static String TOR_CHANNEL_ID = "TOR_CHANNEL";


import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.widget.Toast;
import com.samourai.sentinel.BuildConfig;
import com.samourai.sentinel.R;
import com.samourai.sentinel.util.LogUtil;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import static android.support.v4.app.NotificationCompat.GROUP_ALERT_SUMMARY;
import static com.samourai.sentinel.SentinelApplication.TOR_CHANNEL_ID;
        torDisposable = TorManager
                .getInstance(getApplicationContext())
                .startTor()
                .debounce(100, TimeUnit.MILLISECONDS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(proxy -> {
                    title = "Tor: Running";
                    updateNotification("Running....");
                }, Throwable::printStackTrace);
        compositeDisposable.add(torDisposable);


        Disposable statusDisposable = TorManager.getInstance(this)
                .torStatus
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(state -> {
                });
        logger();
        compositeDisposable.add(statusDisposable);
    }

    private void logger() {
        Disposable logger = Observable.interval(2, TimeUnit.SECONDS, Schedulers.io())
                .map(tick -> TorManager.getInstance(getApplicationContext()).getLatestLogs())
                .observeOn(AndroidSchedulers.mainThread())
                .retryWhen(errors -> errors.zipWith(Observable.range(1, 3), (n, i) -> i))
                .subscribe(this::updateNotification, error -> {
                    error.printStackTrace();
// Path: app/src/main/java/com/samourai/sentinel/util/LogUtil.java
// public class LogUtil {
// 
//     public static void debug(final String tag, String message) {
//         if (BuildConfig.DEBUG) {
//             android.util.Log.d(tag, message);
//         }
//     }
// 
//     public static void info(final String tag, String message) {
//         if (BuildConfig.DEBUG) {
//             android.util.Log.i(tag, message);
//         }
//     }
// 
//     public static void error(final String tag, String message) {
//         if (BuildConfig.DEBUG) {
//             android.util.Log.e(tag, message);
//         }
//     }
// 
// }
// 
// Path: app/src/main/java/com/samourai/sentinel/SentinelApplication.java
// public static String TOR_CHANNEL_ID = "TOR_CHANNEL";


// Path: app/src/main/java/com/samourai/sentinel/tor/TorService.java
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.widget.Toast;
import com.samourai.sentinel.BuildConfig;
import com.samourai.sentinel.R;
import com.samourai.sentinel.util.LogUtil;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import static android.support.v4.app.NotificationCompat.GROUP_ALERT_SUMMARY;
import static com.samourai.sentinel.SentinelApplication.TOR_CHANNEL_ID;

        torDisposable = TorManager
                .getInstance(getApplicationContext())
                .startTor()
                .debounce(100, TimeUnit.MILLISECONDS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(proxy -> {
                    title = "Tor: Running";
                    updateNotification("Running....");
                }, Throwable::printStackTrace);
        compositeDisposable.add(torDisposable);


        Disposable statusDisposable = TorManager.getInstance(this)
                .torStatus
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(state -> {
                });
        logger();
        compositeDisposable.add(statusDisposable);
    }

    private void logger() {
        Disposable logger = Observable.interval(2, TimeUnit.SECONDS, Schedulers.io())
                .map(tick -> TorManager.getInstance(getApplicationContext()).getLatestLogs())
                .observeOn(AndroidSchedulers.mainThread())
                .retryWhen(errors -> errors.zipWith(Observable.range(1, 3), (n, i) -> i))
                .subscribe(this::updateNotification, error -> {
                    error.printStackTrace();
                    if (!TorManager.getInstance(getApplicationContext()).isConnected())