-
Notifications
You must be signed in to change notification settings - Fork 510
android: replace broadcast intent with service intent #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,12 @@ import com.tailscale.ipn.mdm.MDMSettings | |
import com.tailscale.ipn.ui.model.Ipn | ||
import com.tailscale.ipn.ui.notifier.Notifier | ||
import com.tailscale.ipn.util.TSLog | ||
import java.util.UUID | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.launch | ||
import libtailscale.Libtailscale | ||
import java.util.UUID | ||
|
||
open class IPNService : VpnService(), libtailscale.IPNService { | ||
private val TAG = "IPNService" | ||
|
@@ -46,6 +46,13 @@ open class IPNService : VpnService(), libtailscale.IPNService { | |
close() | ||
START_NOT_STICKY | ||
} | ||
ACTION_RESTART_VPN -> { | ||
app.setWantRunning(false){ | ||
close() | ||
app.startVPN() | ||
} | ||
START_NOT_STICKY | ||
} | ||
Comment on lines
+49
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In android/src/main/java/com/tailscale/ipn/IPNService.kt, the ACTION_RESTART_VPN handling first calls app.setWantRunning(false) followed by close() which no longer contains app.setWantRunning(false). Should we be concerned about this state management change or potential duplicate calls? |
||
ACTION_START_VPN -> { | ||
scope.launch { showForegroundNotification() } | ||
app.setWantRunning(true) | ||
|
@@ -82,7 +89,6 @@ open class IPNService : VpnService(), libtailscale.IPNService { | |
} | ||
|
||
override fun close() { | ||
app.setWantRunning(false) {} | ||
Notifier.setState(Ipn.State.Stopping) | ||
disconnectVPN() | ||
Libtailscale.serviceDisconnect(this) | ||
Comment on lines
91
to
94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The IPNService.kt |
||
|
@@ -180,5 +186,6 @@ open class IPNService : VpnService(), libtailscale.IPNService { | |
companion object { | ||
const val ACTION_START_VPN = "com.tailscale.ipn.START_VPN" | ||
const val ACTION_STOP_VPN = "com.tailscale.ipn.STOP_VPN" | ||
const val ACTION_RESTART_VPN = "com.tailscale.ipn.RESTART_VPN" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,18 @@ | |
package com.tailscale.ipn.ui.viewModel | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.tailscale.ipn.App | ||
import com.tailscale.ipn.mdm.MDMSettings | ||
import com.tailscale.ipn.mdm.SettingState | ||
import com.tailscale.ipn.ui.util.InstalledApp | ||
import com.tailscale.ipn.ui.util.InstalledAppsManager | ||
import com.tailscale.ipn.ui.util.set | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.launch | ||
|
||
class SplitTunnelAppPickerViewModel : ViewModel() { | ||
val installedAppsManager = InstalledAppsManager(packageManager = App.get().packageManager) | ||
|
@@ -20,6 +24,8 @@ class SplitTunnelAppPickerViewModel : ViewModel() { | |
val mdmExcludedPackages: StateFlow<SettingState<String?>> = MDMSettings.excludedPackages.flow | ||
val mdmIncludedPackages: StateFlow<SettingState<String?>> = MDMSettings.includedPackages.flow | ||
|
||
private var saveJob: Job? = null | ||
|
||
init { | ||
installedApps.set(installedAppsManager.fetchInstalledApps()) | ||
excludedPackageNames.set( | ||
|
@@ -30,15 +36,22 @@ class SplitTunnelAppPickerViewModel : ViewModel() { | |
} | ||
|
||
fun exclude(packageName: String) { | ||
if (excludedPackageNames.value.contains(packageName)) { | ||
return | ||
} | ||
if (excludedPackageNames.value.contains(packageName)) return | ||
excludedPackageNames.set(excludedPackageNames.value + packageName) | ||
App.get().addUserDisallowedPackageName(packageName) | ||
debounceSave() | ||
} | ||
|
||
fun unexclude(packageName: String) { | ||
excludedPackageNames.set(excludedPackageNames.value - packageName) | ||
App.get().removeUserDisallowedPackageName(packageName) | ||
debounceSave() | ||
} | ||
|
||
private fun debounceSave() { | ||
saveJob?.cancel() | ||
saveJob = | ||
viewModelScope.launch { | ||
delay(500) // Wait to batch multiple rapid updates | ||
App.get().updateUserDisallowedPackageNames(excludedPackageNames.value) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In android/src/main/java/com/tailscale/ipn/ui/viewModel/SplitTunnelAppPickerViewModel.kt, the pendingChanges set is added but only used for tracking add/remove operations. Since the actual updates are based on excludedPackageNames.value, can you clarify the purpose of this set? It appears unused in the final update operation. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In android/src/main/java/com/tailscale/ipn/App.kt's restartVPN method, consider adding a more specific catch for SecurityException which can occur when the VPN service start is disallowed by the user. This would help distinguish between security-related failures and other runtime exceptions, allowing for more targeted error handling.