2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-22 09:58:08 +00:00

Fix NPE if BackgroundService.instance() doesn't exist

This commit is contained in:
Albert Vaca Cintora 2022-01-24 14:01:40 +01:00
parent db3f8f7f74
commit 209f0f8f43
2 changed files with 16 additions and 6 deletions

View File

@ -11,6 +11,7 @@ import android.os.Build
import android.service.quicksettings.TileService
import androidx.annotation.RequiresApi
import org.kde.kdeconnect.BackgroundService
import org.kde.kdeconnect.Device
@RequiresApi(Build.VERSION_CODES.N)
class ClipboardTileService : TileService() {
@ -19,10 +20,14 @@ class ClipboardTileService : TileService() {
startActivityAndCollapse(Intent(this, ClipboardFloatingActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
putExtra("connectedDeviceIds", ArrayList(BackgroundService.getInstance().devices.values
.filter { it.isReachable && it.isPaired }
.map { it.deviceId })
)
var ids : List<String> = emptyList()
val service = BackgroundService.getInstance()
if (service != null) {
ids = service.devices.values
.filter { it.isReachable && it.isPaired }
.map { it.deviceId }
}
putExtra("connectedDeviceIds", ArrayList(ids))
})
}
}
}

View File

@ -167,7 +167,12 @@ class RunCommandControlsProviderService : ControlsProviderService() {
private fun getCommandByControlId(controlId: String): CommandEntryWithDevice? {
val controlIdParts = controlId.split("-")
val device = BackgroundService.getInstance().getDevice(controlIdParts[0])
val service = BackgroundService.getInstance();
if (service == null) return null
val device = service.getDevice(controlIdParts[0])
if (device == null || !device.isPaired) return null