Skip to content

Commit 9083c8c

Browse files
committed
prepare to support backing up multiple directories and fix bluetooth adapter deprecation
1 parent 20c99fb commit 9083c8c

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

app/src/main/java/de/lolhens/resticui/BackupManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class BackupManager private constructor(context: Context) {
248248
updateNotification(context, folder.id, activeBackup)
249249

250250
resticRepo.backup(
251-
folder.path,
251+
listOf(folder.path),
252252
{ progress ->
253253
val activeBackupProgress = activeBackupLiveData.value!!.progress(progress)
254254
activeBackupLiveData.postValue(activeBackupProgress)

app/src/main/java/de/lolhens/resticui/config/FolderConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import java.time.ZonedDateTime
1212
data class FolderConfig(
1313
val id: FolderConfigId,
1414
val repoId: RepoConfigId,
15+
// TODO: support multiple paths
1516
val path: @Serializable(with = FileSerializer::class) File,
1617
val schedule: String,
1718
val keepLast: Int? = null,

app/src/main/java/de/lolhens/resticui/restic/ResticRepo.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,20 @@ abstract class ResticRepo(
123123
}
124124

125125
fun backup(
126-
path: File,
126+
paths: List<File>,
127127
onProgress: (ResticBackupProgress) -> Unit,
128128
cancel: CompletableFuture<Unit>? = null
129-
): CompletableFuture<ResticBackupSummary> =
130-
restic(
131-
listOf("--json", "backup", "--host", restic.hostname, path.absolutePath),
129+
): CompletableFuture<ResticBackupSummary> {
130+
require(paths.isNotEmpty())
131+
return restic(
132+
listOf(
133+
"--json",
134+
"backup",
135+
"--host",
136+
restic.hostname
137+
).plus(
138+
paths.map { it.absolutePath }
139+
),
132140
filterOut = { line ->
133141
val isStatus = line.contains("\"message_type\":\"status\"")
134142
if (isStatus) {
@@ -142,4 +150,5 @@ abstract class ResticRepo(
142150
val json = out.joinToString("\n")
143151
format.decodeFromString<ResticBackupSummary>(json)
144152
}
153+
}
145154
}

app/src/main/java/de/lolhens/resticui/util/HostnameUtil.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package de.lolhens.resticui.util
22

33
import android.Manifest
4-
import android.bluetooth.BluetoothAdapter
4+
import android.bluetooth.BluetoothManager
55
import android.content.Context
66
import android.content.pm.PackageManager
77
import androidx.core.app.ActivityCompat
@@ -10,17 +10,14 @@ object HostnameUtil {
1010
private const val DEFAULT_HOSTNAME = "android-device"
1111

1212
fun detectHostname(context: Context): String {
13+
// Some Devices do not have a BluetoothAdapter e.g. the Android Emulator. They should not pass the permission check
1314
if (ActivityCompat.checkSelfPermission(
1415
context,
1516
Manifest.permission.BLUETOOTH_CONNECT
1617
) == PackageManager.PERMISSION_GRANTED
1718
) {
18-
val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
19-
20-
// Some Devices do not have a BluetoothAdapter e.g. the Android Emulator
21-
if (bluetoothAdapter != null) {
22-
return bluetoothAdapter.name
23-
}
19+
return (context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager)
20+
.adapter.name
2421
}
2522

2623
return DEFAULT_HOSTNAME

0 commit comments

Comments
 (0)