mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-28 12:47:43 +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 android.service.quicksettings.TileService
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import org.kde.kdeconnect.BackgroundService
|
import org.kde.kdeconnect.BackgroundService
|
||||||
|
import org.kde.kdeconnect.Device
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.N)
|
@RequiresApi(Build.VERSION_CODES.N)
|
||||||
class ClipboardTileService : TileService() {
|
class ClipboardTileService : TileService() {
|
||||||
@ -19,10 +20,14 @@ class ClipboardTileService : TileService() {
|
|||||||
|
|
||||||
startActivityAndCollapse(Intent(this, ClipboardFloatingActivity::class.java).apply {
|
startActivityAndCollapse(Intent(this, ClipboardFloatingActivity::class.java).apply {
|
||||||
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
|
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
putExtra("connectedDeviceIds", ArrayList(BackgroundService.getInstance().devices.values
|
var ids : List<String> = emptyList()
|
||||||
.filter { it.isReachable && it.isPaired }
|
val service = BackgroundService.getInstance()
|
||||||
.map { it.deviceId })
|
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? {
|
private fun getCommandByControlId(controlId: String): CommandEntryWithDevice? {
|
||||||
val controlIdParts = controlId.split("-")
|
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
|
if (device == null || !device.isPaired) return null
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user