0

我想在我的 VpnService 上调用函数,但我无法决定什么是最好的方法。

目前我有连接、挂起和断开连接:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    if (intent != null) {
        LAST_ACTION = intent.getAction();
    }

    if (intent != null && ACTION_DISCONNECT.equals(intent.getAction())) {
        stopVpn();
        return START_NOT_STICKY;
    } else if (intent != null && ACTION_SUSPEND.equals(intent.getAction())) {
        stopVpnWithoutTurningVpnSharedPref();
        return START_NOT_STICKY;
    } else {
        return START_STICKY;
    }
}

这种执行这些操作的方法看起来很完美,但我不确定我是否也可以使用这种方法来更新我想要的 VPN 规则。

对于更新或调用函数,我能做什么?

我不喜欢使用:

  1. 静态方法
  2. 广播接收器/EventBus

我的需要是将新规则推送到我当前的 VPN,目前它是由

 public static void pushNewRules(Rules roles) {

谢谢

4

0 回答 0