You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailscale-android/android/src/main/java/com/tailscale/ipn/StopVPNWorker.java

30 lines
646 B
Java

// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
package com.tailscale.ipn;
import android.content.Context;
android: fix quick settings tile status (#377) * android: fix quick settings tile https://github.com/tailscale/tailscale-android/pull/358 updated the Quick Settings tile to only depend on ipn state. This was only partially correct in the sense that we made changes to only check for whether the state was > stopped and not whether Tailscale was on. This checks for two states, whether Tailscale is on, and whether the tile is ready to be used. The former requires ipn state to be >= Starting, and the latter checks whether ipn state is > RequiresMachineAuth. Tile readiness determines whether an intent is to open MainActivity or whether an intent to connect/disconnect VPN is sent. Whether Tailscale is on or off determines whether the tile status is active or not. We lazily initialize App to avoid starting Tailscale when unnecessary - for example, when viewing the QuickSettings tile, there's no need to start Tailscale's backend. We also persistently store a flag indicating whether VPN can be started by quick settings tile: this allows us to start the VPN from the quick settings tile even when the application was previously stopped. Updates tailscale/tailscale#11920 Co-authored-by: kari-ts <kari@tailscale.com> Co-authored-by: Percy Wegmann <percy@tailscale.com> * android: simplify IPNService lifecycle Reserves use of IPNReceiver only for external requests to start the VPN. Updates tailscale/corp#19860 Signed-off-by: Percy Wegmann <percy@tailscale.com> * Revert "android: temporarily remove quick settings tile" This reverts commit edb3f5b0c52ae5cb9cc2fa89310e395df5c08c6e. Signed-off-by: Percy Wegmann <percy@tailscale.com> --------- Signed-off-by: Percy Wegmann <percy@tailscale.com> Co-authored-by: Percy Wegmann <percy@tailscale.com>
2 months ago
import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
android: fix quick settings tile status (#377) * android: fix quick settings tile https://github.com/tailscale/tailscale-android/pull/358 updated the Quick Settings tile to only depend on ipn state. This was only partially correct in the sense that we made changes to only check for whether the state was > stopped and not whether Tailscale was on. This checks for two states, whether Tailscale is on, and whether the tile is ready to be used. The former requires ipn state to be >= Starting, and the latter checks whether ipn state is > RequiresMachineAuth. Tile readiness determines whether an intent is to open MainActivity or whether an intent to connect/disconnect VPN is sent. Whether Tailscale is on or off determines whether the tile status is active or not. We lazily initialize App to avoid starting Tailscale when unnecessary - for example, when viewing the QuickSettings tile, there's no need to start Tailscale's backend. We also persistently store a flag indicating whether VPN can be started by quick settings tile: this allows us to start the VPN from the quick settings tile even when the application was previously stopped. Updates tailscale/tailscale#11920 Co-authored-by: kari-ts <kari@tailscale.com> Co-authored-by: Percy Wegmann <percy@tailscale.com> * android: simplify IPNService lifecycle Reserves use of IPNReceiver only for external requests to start the VPN. Updates tailscale/corp#19860 Signed-off-by: Percy Wegmann <percy@tailscale.com> * Revert "android: temporarily remove quick settings tile" This reverts commit edb3f5b0c52ae5cb9cc2fa89310e395df5c08c6e. Signed-off-by: Percy Wegmann <percy@tailscale.com> --------- Signed-off-by: Percy Wegmann <percy@tailscale.com> Co-authored-by: Percy Wegmann <percy@tailscale.com>
2 months ago
/**
* A worker that exists to support IPNReceiver.
*/
public final class StopVPNWorker extends Worker {
public StopVPNWorker(
Context appContext,
WorkerParameters workerParams) {
super(appContext, workerParams);
}
android: fix quick settings tile status (#377) * android: fix quick settings tile https://github.com/tailscale/tailscale-android/pull/358 updated the Quick Settings tile to only depend on ipn state. This was only partially correct in the sense that we made changes to only check for whether the state was > stopped and not whether Tailscale was on. This checks for two states, whether Tailscale is on, and whether the tile is ready to be used. The former requires ipn state to be >= Starting, and the latter checks whether ipn state is > RequiresMachineAuth. Tile readiness determines whether an intent is to open MainActivity or whether an intent to connect/disconnect VPN is sent. Whether Tailscale is on or off determines whether the tile status is active or not. We lazily initialize App to avoid starting Tailscale when unnecessary - for example, when viewing the QuickSettings tile, there's no need to start Tailscale's backend. We also persistently store a flag indicating whether VPN can be started by quick settings tile: this allows us to start the VPN from the quick settings tile even when the application was previously stopped. Updates tailscale/tailscale#11920 Co-authored-by: kari-ts <kari@tailscale.com> Co-authored-by: Percy Wegmann <percy@tailscale.com> * android: simplify IPNService lifecycle Reserves use of IPNReceiver only for external requests to start the VPN. Updates tailscale/corp#19860 Signed-off-by: Percy Wegmann <percy@tailscale.com> * Revert "android: temporarily remove quick settings tile" This reverts commit edb3f5b0c52ae5cb9cc2fa89310e395df5c08c6e. Signed-off-by: Percy Wegmann <percy@tailscale.com> --------- Signed-off-by: Percy Wegmann <percy@tailscale.com> Co-authored-by: Percy Wegmann <percy@tailscale.com>
2 months ago
@NonNull
@Override
public Result doWork() {
android: fix quick settings tile status (#377) * android: fix quick settings tile https://github.com/tailscale/tailscale-android/pull/358 updated the Quick Settings tile to only depend on ipn state. This was only partially correct in the sense that we made changes to only check for whether the state was > stopped and not whether Tailscale was on. This checks for two states, whether Tailscale is on, and whether the tile is ready to be used. The former requires ipn state to be >= Starting, and the latter checks whether ipn state is > RequiresMachineAuth. Tile readiness determines whether an intent is to open MainActivity or whether an intent to connect/disconnect VPN is sent. Whether Tailscale is on or off determines whether the tile status is active or not. We lazily initialize App to avoid starting Tailscale when unnecessary - for example, when viewing the QuickSettings tile, there's no need to start Tailscale's backend. We also persistently store a flag indicating whether VPN can be started by quick settings tile: this allows us to start the VPN from the quick settings tile even when the application was previously stopped. Updates tailscale/tailscale#11920 Co-authored-by: kari-ts <kari@tailscale.com> Co-authored-by: Percy Wegmann <percy@tailscale.com> * android: simplify IPNService lifecycle Reserves use of IPNReceiver only for external requests to start the VPN. Updates tailscale/corp#19860 Signed-off-by: Percy Wegmann <percy@tailscale.com> * Revert "android: temporarily remove quick settings tile" This reverts commit edb3f5b0c52ae5cb9cc2fa89310e395df5c08c6e. Signed-off-by: Percy Wegmann <percy@tailscale.com> --------- Signed-off-by: Percy Wegmann <percy@tailscale.com> Co-authored-by: Percy Wegmann <percy@tailscale.com>
2 months ago
UninitializedApp.get().stopVPN();
return Result.success();
}
}