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:
parent
db3f8f7f74
commit
209f0f8f43
@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user