fix: opt-in external control for automation apps (MacroDroid, Tasker)

This commit is contained in:
hackdiaz-dev committed 2026-10-07 22:37:39 +00:00
1 parent d99767a3d0
commit 7b4e6d5b42
10 files changed
+64 -9

No files matched your search

+2 -2
View File
@@ -9,7 +9,7 @@
<intent <intent
android:action="com.freeturn.app.START_PROXY" android:action="com.freeturn.app.START_PROXY"
android:targetPackage="com.freeturn.app.debug" android:targetPackage="com.freeturn.app.debug"
android:targetClass="com.freeturn.app.service.ProxyShortcutActivity" /> android:targetClass="com.freeturn.app.service.ProxyTrampolineActivity" />
</shortcut> </shortcut>
<shortcut <shortcut
android:shortcutId="stop_proxy" android:shortcutId="stop_proxy"
@@ -20,6 +20,6 @@
<intent <intent
android:action="com.freeturn.app.STOP_PROXY" android:action="com.freeturn.app.STOP_PROXY"
android:targetPackage="com.freeturn.app.debug" android:targetPackage="com.freeturn.app.debug"
android:targetClass="com.freeturn.app.service.ProxyShortcutActivity" /> android:targetClass="com.freeturn.app.service.ProxyTrampolineActivity" />
</shortcut> </shortcut>
</shortcuts> </shortcuts>
+11 -1
View File
@@ -69,12 +69,22 @@
</activity> </activity>
<activity <activity
android:name=".service.ProxyShortcutActivity" android:name=".service.ProxyTrampolineActivity"
android:exported="false" android:exported="false"
android:excludeFromRecents="true" android:excludeFromRecents="true"
android:taskAffinity="" android:taskAffinity=""
android:theme="@android:style/Theme.Translucent.NoTitleBar" /> android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<!-- Внешний вход (MacroDroid, Tasker, Shortcut Maker). Имя сохранено ради готовых
связок Package+Class. Выключен, пока пользователь не включит
"Внешнее управление" в настройках. -->
<activity-alias
android:name=".service.ProxyShortcutActivity"
android:targetActivity=".service.ProxyTrampolineActivity"
android:enabled="false"
android:exported="true"
tools:ignore="ExportedActivity" />
<service <service
android:name=".service.ProxyService" android:name=".service.ProxyService"
android:exported="false" android:exported="false"
@@ -0,0 +1,23 @@
package com.freeturn.app.service
import android.content.ComponentName
import android.content.Context
import android.content.pm.PackageManager
/**
* Внешний вход для автоматизаторов (MacroDroid, Tasker, Shortcut Maker): activity-alias
* ProxyShortcutActivity. По умолчанию выключен, состояние хранится в самом компоненте.
*/
object ExternalControl {
private fun alias(context: Context) =
ComponentName(context, "com.freeturn.app.service.ProxyShortcutActivity")
fun isEnabled(context: Context): Boolean =
context.packageManager.getComponentEnabledSetting(alias(context)) ==
PackageManager.COMPONENT_ENABLED_STATE_ENABLED
fun setEnabled(context: Context, enabled: Boolean) {
context.packageManager.setComponentEnabledSetting(
alias(context),
if (enabled) PackageManager.COMPONENT_ENABLED_STATE_ENABLED
else PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
PackageManager.DONT_KILL_APP
)
}
}
@@ -56,7 +56,7 @@ class ProxyTileService : TileService(), KoinComponent {
return return
} }
// START - через activity-трамплин: согласие на VPN спрашивается только оттуда. // START - через activity-трамплин: согласие на VPN спрашивается только оттуда.
val intent = ProxyShortcutActivity.startIntent(this) val intent = ProxyTrampolineActivity.startIntent(this)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startActivityAndCollapse( startActivityAndCollapse(
PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE) PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)
@@ -20,7 +20,7 @@ import org.koin.android.ext.android.inject
* START может спросить согласие на VPN - системный диалог поднимается только из activity, * START может спросить согласие на VPN - системный диалог поднимается только из activity,
* а без него в WG-режиме `establish()` вернёт null и сессия умрёт с "откройте приложение". * а без него в WG-режиме `establish()` вернёт null и сессия умрёт с "откройте приложение".
*/ */
class ProxyShortcutActivity : ComponentActivity() { class ProxyTrampolineActivity : ComponentActivity() {
private val prefs: AppPreferences by inject() private val prefs: AppPreferences by inject()
private val launcher: ProxyServiceLauncher by inject() private val launcher: ProxyServiceLauncher by inject()
@@ -63,7 +63,7 @@ class ProxyShortcutActivity : ComponentActivity() {
companion object { companion object {
fun startIntent(context: Context): Intent = fun startIntent(context: Context): Intent =
Intent(context, ProxyShortcutActivity::class.java) Intent(context, ProxyTrampolineActivity::class.java)
.setAction(ProxyActions.START) .setAction(ProxyActions.START)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
} }
@@ -125,7 +125,7 @@ class ProxyWidgetProvider : AppWidgetProvider(), KoinComponent {
PendingIntent.getActivity( PendingIntent.getActivity(
context, context,
2, 2,
ProxyShortcutActivity.startIntent(context), ProxyTrampolineActivity.startIntent(context),
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
) )
} }
@@ -20,6 +20,10 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import com.freeturn.app.service.ExternalControl
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.input.nestedscroll.nestedScroll
@@ -174,6 +178,20 @@ fun AdvancedScreen(
onCheckedChange = { settingsViewModel.setRestartServerOnSwitch(it) } onCheckedChange = { settingsViewModel.setRestartServerOnSwitch(it) }
) )
} }
SettingsCard {
val context = LocalContext.current
val externalControl = remember { mutableStateOf(ExternalControl.isEnabled(context)) }
SettingsSwitchRow(
title = stringResource(R.string.external_control),
subtitle = stringResource(R.string.external_control_desc),
iconRes = R.drawable.bolt_24px,
checked = externalControl.value,
onCheckedChange = {
ExternalControl.setEnabled(context, it)
externalControl.value = it
}
)
}
} }
} }
} }
+2
View File
@@ -390,6 +390,8 @@
<string name="hotspot_proxy_desc">Listen on 0.0.0.0:1080 to share the WireGuard tunnel over a hotspot</string> <string name="hotspot_proxy_desc">Listen on 0.0.0.0:1080 to share the WireGuard tunnel over a hotspot</string>
<string name="restart_server_on_switch">Restart server on profile switch</string> <string name="restart_server_on_switch">Restart server on profile switch</string>
<string name="restart_server_on_switch_desc">Restart the server with the new profile parameters</string> <string name="restart_server_on_switch_desc">Restart the server with the new profile parameters</string>
<string name="external_control">External control</string>
<string name="external_control_desc">Let Tasker, MacroDroid and other apps start and stop the proxy. Enable only if you trust your installed apps</string>
<string name="nerd_section_title">Debug info</string> <string name="nerd_section_title">Debug info</string>
<string name="nerd_section_desc">Core state, server journal and SSH log</string> <string name="nerd_section_desc">Core state, server journal and SSH log</string>
<string name="nerd_core_state">Core state</string> <string name="nerd_core_state">Core state</string>
+2
View File
@@ -420,6 +420,8 @@
<string name="hotspot_proxy_desc">Слушать на 0.0.0.0:1080 для раздачи WireGuard-туннеля через точку доступа</string> <string name="hotspot_proxy_desc">Слушать на 0.0.0.0:1080 для раздачи WireGuard-туннеля через точку доступа</string>
<string name="restart_server_on_switch">Перезапуск сервера при смене профиля</string> <string name="restart_server_on_switch">Перезапуск сервера при смене профиля</string>
<string name="restart_server_on_switch_desc">Перезапускать сервер под параметры нового профиля</string> <string name="restart_server_on_switch_desc">Перезапускать сервер под параметры нового профиля</string>
<string name="external_control">Внешнее управление</string>
<string name="external_control_desc">Разрешить Tasker, MacroDroid и другим приложениям запускать и останавливать прокси. Включайте, только если доверяете установленным приложениям</string>
<string name="nerd_section_title">Отладочная информация</string> <string name="nerd_section_title">Отладочная информация</string>
<string name="nerd_section_desc">Состояние ядра, журнал сервера и SSH-лог</string> <string name="nerd_section_desc">Состояние ядра, журнал сервера и SSH-лог</string>
<string name="nerd_core_state">Состояние ядра</string> <string name="nerd_core_state">Состояние ядра</string>
+2 -2
View File
@@ -9,7 +9,7 @@
<intent <intent
android:action="com.freeturn.app.START_PROXY" android:action="com.freeturn.app.START_PROXY"
android:targetPackage="com.freeturn.app" android:targetPackage="com.freeturn.app"
android:targetClass="com.freeturn.app.service.ProxyShortcutActivity" /> android:targetClass="com.freeturn.app.service.ProxyTrampolineActivity" />
</shortcut> </shortcut>
<shortcut <shortcut
android:shortcutId="stop_proxy" android:shortcutId="stop_proxy"
@@ -20,6 +20,6 @@
<intent <intent
android:action="com.freeturn.app.STOP_PROXY" android:action="com.freeturn.app.STOP_PROXY"
android:targetPackage="com.freeturn.app" android:targetPackage="com.freeturn.app"
android:targetClass="com.freeturn.app.service.ProxyShortcutActivity" /> android:targetClass="com.freeturn.app.service.ProxyTrampolineActivity" />
</shortcut> </shortcut>
</shortcuts> </shortcuts>