Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,25 @@ For developers of other Syncthing apps, the custom filesystem scheme that BasicS

## Remote control

When the "Allow remote control" setting is enabled, BasicSync allows other apps to control when Syncthing runs via Android's broadcast mechanism. The following broadcast actions are supported, which behave exactly the same as the corresponding buttons in BasicSync's notification:
When the "Allow remote control" setting is enabled, BasicSync will report the current state of Syncthing to other apps and allow them to control when Syncthing runs. This uses Android's broadcast mechanism.

Whenever the state changes (eg. Syncthing paused due to metered network), BasicSync will send the following broadcast with the listed extras:

* `com.chiller3.basicsync.STATE_CHANGED`
* `mode`
* `AUTO_MODE` - Currently set to auto mode
* `MANUAL_MODE_STARTED` - Currently set to manual mode and started
* `MANUAL_MODE_STOPPED` - Currently set to manual mode and stopped/paused
* `run_state`
* `RUNNING` - Syncthing is running and permitted to sync
* `NOT_RUNNING` - Syncthing is not running at all
* `PAUSED` - Syncthing is running, but not permitted to sync
* `STARTING` - Syncthing is in the process of starting up
* `STOPPING` - Syncthing is in the process of shutting down entirely
* `IMPORTING` - Syncthing is not running due to an ongoing config import
* `EXPORTING` - Syncthing is not running due to an ongoing config export

BasicSync also accepts the following broadcasts from other apps:

* `com.chiller3.basicsync.AUTO_MODE`
* Switch to auto mode where Syncthing runs based on the configured run conditions.
Expand All @@ -117,6 +135,8 @@ When the "Allow remote control" setting is enabled, BasicSync allows other apps
* Switch to manual mode and start Syncthing.
* `com.chiller3.basicsync.STOP`
* Switch to manual mode and stop Syncthing.
* `com.chiller3.basicsync.REQUEST_STATE`
* Request a new `com.chiller3.basicsync.STATE_CHANGED` broadcast, even if the state has not changed.

These broadcasts can also be sent via `adb`. For example:

Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
<action android:name="${applicationId}.MANUAL_MODE" />
<action android:name="${applicationId}.START" />
<action android:name="${applicationId}.STOP" />
<action android:name="${applicationId}.REQUEST_STATE" />
</intent-filter>
</receiver>

Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/chiller3/basicsync/Notifications.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class Notifications(private val context: Context) {
SyncthingService.RunState.PAUSED -> R.string.notification_persistent_paused_title
SyncthingService.RunState.STARTING -> R.string.notification_persistent_starting_title
SyncthingService.RunState.STOPPING -> R.string.notification_persistent_stopping_title
SyncthingService.RunState.PAUSING -> R.string.notification_persistent_pausing_title
SyncthingService.RunState.IMPORTING -> R.string.notification_persistent_importing_title
SyncthingService.RunState.EXPORTING -> R.string.notification_persistent_exporting_title
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,6 @@ private fun serviceStatusSummary(state: SyncthingService.ServiceState?) = state?
stringResource(R.string.notification_persistent_starting_title)
SyncthingService.RunState.STOPPING ->
stringResource(R.string.notification_persistent_stopping_title)
SyncthingService.RunState.PAUSING ->
stringResource(R.string.notification_persistent_pausing_title)
SyncthingService.RunState.IMPORTING ->
stringResource(R.string.notification_persistent_importing_title)
SyncthingService.RunState.EXPORTING ->
Expand Down Expand Up @@ -1040,6 +1038,7 @@ private fun PreviewSettingsScreen() {
isStarted = true,
isResumed = true,
manualMode = false,
manualShouldRun = false,
allowAutoMode = true,
preRunAction = null,
useLocation = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class RemoteControlReceiver : BroadcastReceiver() {
private const val ACTION_MANUAL_MODE = "${BuildConfig.APPLICATION_ID}.MANUAL_MODE"
private const val ACTION_START = "${BuildConfig.APPLICATION_ID}.START"
private const val ACTION_STOP = "${BuildConfig.APPLICATION_ID}.STOP"
private const val ACTION_REQUEST_STATE = "${BuildConfig.APPLICATION_ID}.REQUEST_STATE"
}

override fun onReceive(context: Context, intent: Intent?) {
Expand All @@ -33,6 +34,7 @@ class RemoteControlReceiver : BroadcastReceiver() {
ACTION_MANUAL_MODE -> SyncthingService.ACTION_MANUAL_MODE
ACTION_START -> SyncthingService.ACTION_START
ACTION_STOP -> SyncthingService.ACTION_STOP
ACTION_REQUEST_STATE -> SyncthingService.ACTION_RENOTIFY
else -> {
Log.w(TAG, "Ignoring unrecognized intent: $intent")
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.annotation.GuardedBy
import androidx.annotation.WorkerThread
import androidx.core.app.ServiceCompat
import androidx.core.net.toUri
import com.chiller3.basicsync.BuildConfig
import com.chiller3.basicsync.Notifications
import com.chiller3.basicsync.Permissions
import com.chiller3.basicsync.Preferences
Expand Down Expand Up @@ -64,6 +65,13 @@ class SyncthingService : Service(), SyncthingStatusReceiver, DeviceStateListener
val ACTION_RECHECK = "${SyncthingService::class.java.canonicalName}.restart"
val ACTION_EXIT = "${SyncthingService::class.java.canonicalName}.exit"

private const val BROADCAST_ACTION = "${BuildConfig.APPLICATION_ID}.STATE_CHANGED"
private const val BROADCAST_MODE = "mode"
private const val BROADCAST_MODE_AUTO_MODE = "AUTO_MODE"
private const val BROADCAST_MODE_MANUAL_MODE_STARTED = "MANUAL_MODE_STARTED"
private const val BROADCAST_MODE_MANUAL_MODE_STOPPED = "MANUAL_MODE_STOPPED"
private const val BROADCAST_RUN_STATE = "run_state"

private val isRunningListeners = HashSet<OnServiceRunningChange>()
private var isRunning: Boolean = false
set(value) {
Expand Down Expand Up @@ -150,7 +158,6 @@ class SyncthingService : Service(), SyncthingStatusReceiver, DeviceStateListener
PAUSED,
STARTING,
STOPPING,
PAUSING,
IMPORTING,
EXPORTING;

Expand All @@ -164,7 +171,7 @@ class SyncthingService : Service(), SyncthingStatusReceiver, DeviceStateListener
get() = this == NOT_RUNNING || this == PAUSED

val webUiAvailable: Boolean
get() = this == RUNNING || this == PAUSED || this == PAUSING
get() = this == RUNNING || this == PAUSED
}

data class ServiceState(
Expand All @@ -173,6 +180,7 @@ class SyncthingService : Service(), SyncthingStatusReceiver, DeviceStateListener
private val isStarted: Boolean,
private val isResumed: Boolean,
private val manualMode: Boolean,
private val manualShouldRun: Boolean,
private val allowAutoMode: Boolean,
private val preRunAction: PreRunAction?,
val useLocation: Boolean,
Expand All @@ -188,6 +196,7 @@ class SyncthingService : Service(), SyncthingStatusReceiver, DeviceStateListener
&& isStarted == prev.isStarted
&& isResumed == prev.isResumed
&& manualMode == prev.manualMode
&& manualShouldRun == prev.manualShouldRun
&& allowAutoMode == prev.allowAutoMode
&& preRunAction == prev.preRunAction
&& useLocation == prev.useLocation
Expand All @@ -209,9 +218,8 @@ class SyncthingService : Service(), SyncthingStatusReceiver, DeviceStateListener
if (isResumed) {
if (shouldResume) {
RunState.RUNNING
} else if (keepAlive) {
RunState.PAUSING
} else {
// If keepAlive is true, isResumed is going to equal shouldResume.
RunState.STOPPING
}
} else {
Expand All @@ -235,6 +243,15 @@ class SyncthingService : Service(), SyncthingStatusReceiver, DeviceStateListener
}
}

internal val broadcastMode: String
get() = if (!manualMode) {
BROADCAST_MODE_AUTO_MODE
} else if (manualShouldRun) {
BROADCAST_MODE_MANUAL_MODE_STARTED
} else {
BROADCAST_MODE_MANUAL_MODE_STOPPED
}

val actions: List<String>
get() = ArrayList<String>().apply {
if (preRunAction == null) {
Expand Down Expand Up @@ -663,6 +680,7 @@ class SyncthingService : Service(), SyncthingStatusReceiver, DeviceStateListener
isStarted = isStarted,
isResumed = isResumed,
manualMode = prefs.isManualMode,
manualShouldRun = prefs.manualShouldRun,
allowAutoMode = prefs.allowAutoMode,
preRunAction = currentPreRunAction,
useLocation = deviceStateTracker.canUseLocation(),
Expand All @@ -685,6 +703,15 @@ class SyncthingService : Service(), SyncthingStatusReceiver, DeviceStateListener
}

if (!serviceState.equivalent(lastServiceState) || forceShowNotification) {
if (prefs.remoteControl) {
sendBroadcast(
Intent(BROADCAST_ACTION).apply {
putExtra(BROADCAST_MODE, serviceState.broadcastMode)
putExtra(BROADCAST_RUN_STATE, serviceState.runState.name)
}
)
}

val (id, notification) = notifications.createPersistentNotification(serviceState)
var type = 0

Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
<string name="notification_persistent_paused_title">تم إيقاف Syncthing موقتًا</string>
<string name="notification_persistent_starting_title">جارٍ تشغيل Syncthing</string>
<string name="notification_persistent_stopping_title">جارٍ إيقاف Syncthing</string>
<string name="notification_persistent_pausing_title">جارٍ إيقاف Syncthing مؤقتًا</string>
<string name="notification_persistent_importing_title">جارٍ استيراد التضبيط</string>
<string name="notification_persistent_exporting_title">جارٍ تصدير التضبيط</string>
<string name="notification_failure_run_title">فشل تشغيل Syncthing</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-bg/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
<string name="notification_persistent_paused_title">Syncthing е на пауза</string>
<string name="notification_persistent_starting_title">Syncthing се стартира</string>
<string name="notification_persistent_stopping_title">Syncthing се спира</string>
<string name="notification_persistent_pausing_title">Syncthing се поставя на пауза</string>
<string name="notification_persistent_importing_title">Внасят се настройките</string>
<string name="notification_persistent_exporting_title">Изнасяне на настройки</string>
<string name="notification_failure_run_title">Грешка при стартиране на Syncthing</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
<string name="notification_persistent_paused_title">Syncthing ist angehalten</string>
<string name="notification_persistent_starting_title">Syncthing startet</string>
<string name="notification_persistent_stopping_title">Syncthing wird gestoppt</string>
<string name="notification_persistent_pausing_title">Syncthing wird angehalten</string>
<string name="notification_persistent_importing_title">Konfiguration wird importiert</string>
<string name="notification_persistent_exporting_title">Konfiguration wird exportiert</string>
<string name="notification_failure_run_title">Ausführen von Syncthing fehlgeschlagen</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
<string name="notification_persistent_paused_title">Syncthing está pausado</string>
<string name="notification_persistent_starting_title">Syncthing se está iniciando</string>
<string name="notification_persistent_stopping_title">Syncthing se está deteniendo</string>
<string name="notification_persistent_pausing_title">Syncthing se está pausando</string>
<string name="notification_persistent_importing_title">Importando configuración</string>
<string name="notification_persistent_exporting_title">Exportando configuración</string>
<string name="notification_failure_run_title">No se pudo ejecutar Syncthing</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
<string name="notification_persistent_paused_title">Syncthing est en pause</string>
<string name="notification_persistent_starting_title">Syncthing démarre</string>
<string name="notification_persistent_stopping_title">Syncthing s\'arrête</string>
<string name="notification_persistent_pausing_title">Syncthing se met en pause</string>
<string name="notification_persistent_importing_title">Importation de la configuration</string>
<string name="notification_persistent_exporting_title">Exportation de la configuration</string>
<string name="notification_failure_run_title">Échec de l\'exécution de Syncthing</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
<string name="notification_persistent_paused_title">A Syncthing szüneteltetve</string>
<string name="notification_persistent_starting_title">A Syncthing indul</string>
<string name="notification_persistent_stopping_title">A Syncthing leáll</string>
<string name="notification_persistent_pausing_title">A Syncthing szünetel</string>
<string name="notification_persistent_importing_title">Konfiguráció importálása</string>
<string name="notification_persistent_exporting_title">Konfiguráció exportálása</string>
<string name="notification_failure_run_title">Nem sikerült a Syncthing futtatása</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
<string name="notification_persistent_paused_title">Syncthing dijeda</string>
<string name="notification_persistent_starting_title">Syncthing sedang dimulai</string>
<string name="notification_persistent_stopping_title">Syncthing sedang dihentikan</string>
<string name="notification_persistent_pausing_title">Syncthing sedang dijeda</string>
<string name="notification_persistent_importing_title">Mengimpor konfigurasi</string>
<string name="notification_persistent_exporting_title">Mengekspor konfigurasi</string>
<string name="notification_failure_run_title">Gagal menjalankan Syncthing</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@
<string name="notification_persistent_paused_title">Syncthing è in pausa</string>
<string name="notification_persistent_starting_title">Syncthing si sta avviando</string>
<string name="notification_persistent_stopping_title">Syncthing si sta fermando</string>
<string name="notification_persistent_pausing_title">Syncthing si sta mettendo in pausa</string>
<string name="notification_persistent_importing_title">Importando configurazione</string>
<string name="notification_persistent_exporting_title">Esportando configurazione</string>
<string name="notification_failure_run_title">Impossibile eseguire Syncthing</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-iw/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
<string name="notification_persistent_paused_title">היישום Syncthing מופסק</string>
<string name="notification_persistent_starting_title">היישום Syncthing מתחיל</string>
<string name="notification_persistent_stopping_title">היישום Syncthing עוצר</string>
<string name="notification_persistent_pausing_title">היישום Syncthing מפסיק</string>
<string name="notification_persistent_importing_title">התצורה מיובאת</string>
<string name="notification_persistent_exporting_title">התצורה מיוצאת</string>
<string name="notification_failure_run_title">הרצת Syncthing נכשלה</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<string name="notification_persistent_running_title">Syncthingは稼働しています</string>
<string name="notification_persistent_starting_title">Syncthingを起動します</string>
<string name="notification_persistent_stopping_title">Syncthingを停止します</string>
<string name="notification_persistent_pausing_title">Syncthingを休止します</string>
<string name="pref_header_about">このアプリについて</string>
<string name="pref_header_debug">デバッグ</string>
<plurals name="device_state_connected">
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
<string name="notification_persistent_paused_title">Syncthing wstrzymano</string>
<string name="notification_persistent_starting_title">Syncthing się uruchamia</string>
<string name="notification_persistent_stopping_title">Syncthing się zatrzymuje</string>
<string name="notification_persistent_pausing_title">Synchronizacja się wstrzymuje</string>
<string name="notification_persistent_importing_title">Importowanie ustawień</string>
<string name="notification_persistent_exporting_title">Eksportowanie ustawień</string>
<string name="notification_failure_run_title">Nie udało się uruchomić Syncthing</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@
<string name="notification_persistent_paused_title">O Syncthing está pausado.</string>
<string name="notification_persistent_starting_title">O Syncthing está iniciando.</string>
<string name="notification_persistent_stopping_title">O Syncthing está parando.</string>
<string name="notification_persistent_pausing_title">O Syncthing está pausando.</string>
<string name="notification_persistent_importing_title">Importando configuração</string>
<string name="notification_persistent_exporting_title">Exportando configuração</string>
<string name="notification_failure_run_title">Falha ao executar o Syncthing</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-ro/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
<string name="notification_persistent_paused_title">Syncthing întrerupt</string>
<string name="notification_persistent_starting_title">Syncthing pornește</string>
<string name="notification_persistent_stopping_title">Syncthing se oprește</string>
<string name="notification_persistent_pausing_title">Syncthing se întrerupe</string>
<string name="notification_persistent_importing_title">Se importă configurația</string>
<string name="notification_persistent_exporting_title">Se exportă configurația</string>
<string name="notification_failure_run_title">Syncthing nu a putut porni</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
<string name="notification_persistent_paused_title">Syncthing приостановлен</string>
<string name="notification_persistent_starting_title">Syncthing запускается</string>
<string name="notification_persistent_stopping_title">Syncthing останавливается</string>
<string name="notification_persistent_pausing_title">Syncthing приостанавливается</string>
<string name="notification_channel_persistent_name_started">Закреплённое уведомление после запуска</string>
<string name="notification_channel_persistent_name_stopped">Закреплённое уведомление после остановки</string>
<string name="notification_channel_failure_name">Уведомления об ошибках</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
<string name="notification_persistent_paused_title">Syncthing duraklatıldı</string>
<string name="notification_persistent_starting_title">Syncthing başlatılıyor</string>
<string name="notification_persistent_stopping_title">Syncthing durduruluyor</string>
<string name="notification_persistent_pausing_title">Syncthing duraklatılıyor</string>
<string name="notification_persistent_importing_title">Yapılandırma içe aktarılıyor</string>
<string name="notification_persistent_exporting_title">Yapılandırma dışa aktarılıyor</string>
<string name="notification_failure_run_title">Syncthing\'i çalıştırma başarısız oldu</string>
Expand Down
Loading
Loading