package com.dragonssh.xhttpdemo.core.tunnel;

import android.content.Context;
import android.content.Intent;
import android.os.Build;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import com.dragonssh.xhttpdemo.core.XHttpSshService;

/** Small public API used by the sample activity. */
public final class TunnelManagerHelper {
    private TunnelManagerHelper() {}

    public static void startXHttpSsh(Context context, String password) {
        Intent intent = new Intent(context, XHttpSshService.class)
                .putExtra(XHttpSshService.EXTRA_SSH_PASSWORD, password);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            context.startForegroundService(intent);
        } else {
            context.startService(intent);
        }
    }

    public static void stopXHttpSsh(Context context) {
        LocalBroadcastManager.getInstance(context).sendBroadcast(
                new Intent(XHttpSshService.TUNNEL_SSH_STOP_SERVICE));
    }
}
