fix: CREATE_SHORTCUT entries for automation apps
Opt-in start/stop shortcuts for MacroDroid, Tasker and Shortcut Maker
This commit is contained in:
1 parent
c7f6ac048f
commit
79d6aefe43
4 files changed
+96
No files matched your search
@@ -85,6 +85,37 @@
|
||||
android:exported="true"
|
||||
tools:ignore="ExportedActivity" />
|
||||
|
||||
<!-- CREATE_SHORTCUT: автоматизаторы показывают Start/Stop в списке ярлыков. -->
|
||||
<activity
|
||||
android:name=".service.CreateStartShortcutActivity"
|
||||
android:exported="true"
|
||||
android:excludeFromRecents="true"
|
||||
android:taskAffinity=""
|
||||
android:label="@string/shortcut_start_short"
|
||||
android:icon="@drawable/play_arrow_24px"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
||||
tools:ignore="ExportedActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.CREATE_SHORTCUT" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".service.CreateStopShortcutActivity"
|
||||
android:exported="true"
|
||||
android:excludeFromRecents="true"
|
||||
android:taskAffinity=""
|
||||
android:label="@string/shortcut_stop_short"
|
||||
android:icon="@drawable/stop_24px"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
||||
tools:ignore="ExportedActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.CREATE_SHORTCUT" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".service.ProxyService"
|
||||
android:exported="false"
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.freeturn.app.service
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import com.freeturn.app.R
|
||||
/**
|
||||
* CREATE_SHORTCUT для автоматизаторов (MacroDroid, Tasker): отдаёт готовый intent ярлыка
|
||||
* Start/Stop. Сама ничего не запускает. Intent целится в ProxyShortcutActivity (алиас),
|
||||
* поэтому ярлык работает, только когда включено "Внешнее управление".
|
||||
*/
|
||||
abstract class CreateShortcutActivity : Activity() {
|
||||
protected abstract val proxyAction: String
|
||||
protected abstract val labelRes: Int
|
||||
protected abstract val iconRes: Int
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (intent?.action != Intent.ACTION_CREATE_SHORTCUT) {
|
||||
runDirect()
|
||||
finish()
|
||||
return
|
||||
}
|
||||
val launch = Intent(proxyAction)
|
||||
.setClassName(packageName, ENTRY_CLASS)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
val result = Intent()
|
||||
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launch)
|
||||
.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(labelRes))
|
||||
.putExtra(
|
||||
Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
|
||||
Intent.ShortcutIconResource.fromContext(this, iconRes)
|
||||
)
|
||||
setResult(RESULT_OK, result)
|
||||
if (!ExternalControl.isEnabled(this)) {
|
||||
Toast.makeText(this, R.string.external_control_hint, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
finish()
|
||||
}
|
||||
// Прямой запуск (Shortcut Maker, Activity Launcher): ведёт себя как сам ярлык.
|
||||
private fun runDirect() {
|
||||
if (ExternalControl.isEnabled(this)) {
|
||||
startActivity(
|
||||
Intent(this, ProxyTrampolineActivity::class.java).setAction(proxyAction)
|
||||
)
|
||||
} else {
|
||||
Toast.makeText(this, R.string.external_control_hint, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val ENTRY_CLASS = "com.freeturn.app.service.ProxyShortcutActivity"
|
||||
}
|
||||
}
|
||||
class CreateStartShortcutActivity : CreateShortcutActivity() {
|
||||
override val proxyAction = ProxyActions.START
|
||||
override val labelRes = R.string.shortcut_start_short
|
||||
override val iconRes = R.drawable.play_arrow_24px
|
||||
}
|
||||
class CreateStopShortcutActivity : CreateShortcutActivity() {
|
||||
override val proxyAction = ProxyActions.STOP
|
||||
override val labelRes = R.string.shortcut_stop_short
|
||||
override val iconRes = R.drawable.stop_24px
|
||||
}
|
||||
@@ -390,6 +390,7 @@
|
||||
<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_desc">Restart the server with the new profile parameters</string>
|
||||
<string name="external_control_hint">Turn on External control in settings, otherwise the shortcut will not work</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>
|
||||
|
||||
@@ -420,6 +420,7 @@
|
||||
<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_desc">Перезапускать сервер под параметры нового профиля</string>
|
||||
<string name="external_control_hint">Включите «Внешнее управление» в настройках, иначе ярлык не сработает</string>
|
||||
<string name="external_control">Внешнее управление</string>
|
||||
<string name="external_control_desc">Разрешить Tasker, MacroDroid и другим приложениям запускать и останавливать прокси. Включайте, только если доверяете установленным приложениям</string>
|
||||
<string name="nerd_section_title">Отладочная информация</string>
|
||||
|
||||
Reference in new issue
Block a user