File tree Expand file tree Collapse file tree 4 files changed +23
-11
lines changed
Expand file tree Collapse file tree 4 files changed +23
-11
lines changed Original file line number Diff line number Diff line change 22<manifest xmlns : android =" http://schemas.android.com/apk/res/android" >
33
44 <uses-permission android : name =" android.permission.ACCESS_NETWORK_STATE" />
5+ <uses-permission android : name =" android.permission.BLUETOOTH_CONNECT" />
56 <uses-permission android : name =" android.permission.INTERNET" />
6- <uses-permission android : name =" android.permission.BLUETOOTH" />
77 <uses-permission android : name =" android.permission.POST_NOTIFICATIONS" />
88 <uses-permission android : name =" android.permission.READ_EXTERNAL_STORAGE" />
99 <uses-permission android : name =" android.permission.RECEIVE_BOOT_COMPLETED" />
Original file line number Diff line number Diff line change @@ -57,16 +57,16 @@ class BackupManager private constructor(context: Context) {
5757 ResticNameServers .fromContext(context)
5858 _restic = Restic (
5959 ResticStorage .fromContext(context),
60- hostname = config.hostname ? : HostnameUtil .detectHostname(),
60+ hostname = config.hostname ? : HostnameUtil .detectHostname(context ),
6161 nameServers = resticNameServers
6262 )
6363 }
6464
65- fun setHostname (hostname : String? ): String {
65+ fun setHostname (hostname : String? , defaultHostname : () -> String ): String {
6666 configure { config ->
6767 config.copy(hostname = hostname)
6868 }
69- val hostname = hostname ? : HostnameUtil .detectHostname ()
69+ val hostname = hostname ? : defaultHostname ()
7070 _restic = _restic .withHostname(hostname)
7171 return hostname
7272 }
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import androidx.fragment.app.Fragment
88import de.lolhens.resticui.BackupManager
99import de.lolhens.resticui.databinding.FragmentSettingsBinding
1010import de.lolhens.resticui.ui.InputDialogUtil
11+ import de.lolhens.resticui.util.HostnameUtil
1112
1213class SettingsFragment : Fragment () {
1314 private var _binding : FragmentSettingsBinding ? = null
@@ -66,7 +67,9 @@ class SettingsFragment : Fragment() {
6667 binding.textHostname.text = BackupManager .instance(requireContext()).setHostname(
6768 if (hostname.isBlank()) null
6869 else hostname.trim()
69- )
70+ ) {
71+ HostnameUtil .detectHostname(requireContext())
72+ }
7073 }
7174 }
7275
Original file line number Diff line number Diff line change 11package de.lolhens.resticui.util
22
3+ import android.Manifest
34import android.bluetooth.BluetoothAdapter
5+ import android.content.Context
6+ import android.content.pm.PackageManager
7+ import androidx.core.app.ActivityCompat
48
59object HostnameUtil {
610 private const val DEFAULT_HOSTNAME = " android-device"
711
8- fun detectHostname (): String {
9- val blueToothAdapter = BluetoothAdapter .getDefaultAdapter()
12+ fun detectHostname (context : Context ): String {
13+ if (ActivityCompat .checkSelfPermission(
14+ context,
15+ Manifest .permission.BLUETOOTH_CONNECT
16+ ) == PackageManager .PERMISSION_GRANTED
17+ ) {
18+ val bluetoothAdapter = BluetoothAdapter .getDefaultAdapter()
1019
11- if (blueToothAdapter != null ) {
12- // Some Devices do not have a BluetoothAdapter e.g. the Android Emulator. For this case we use a default
13- // value
14- return BluetoothAdapter .getDefaultAdapter().name
20+ // Some Devices do not have a BluetoothAdapter e.g. the Android Emulator
21+ if (bluetoothAdapter != null ) {
22+ return bluetoothAdapter.name
23+ }
1524 }
1625
1726 return DEFAULT_HOSTNAME
You can’t perform that action at this time.
0 commit comments