mirror of
https://invent.kde.org/network/kdeconnect-android.git
synced 2025-10-06 00:23:01 +02:00
Use asSequence in more places
This commit is contained in:
@@ -429,17 +429,20 @@ class Device : PacketReceiver {
|
||||
Log.w("Device", "Ignoring packet with type ${np.type} because no plugin can handle it")
|
||||
return
|
||||
}
|
||||
targetPlugins.asSequence().mapNotNull { loadedPlugins[it] }.forEach { plugin ->
|
||||
runCatching {
|
||||
if (isPaired) {
|
||||
plugin.onPacketReceived(np)
|
||||
} else {
|
||||
plugin.onUnpairedDevicePacketReceived(np)
|
||||
targetPlugins
|
||||
.asSequence()
|
||||
.mapNotNull { loadedPlugins[it] }
|
||||
.forEach { plugin ->
|
||||
runCatching {
|
||||
if (isPaired) {
|
||||
plugin.onPacketReceived(np)
|
||||
} else {
|
||||
plugin.onUnpairedDevicePacketReceived(np)
|
||||
}
|
||||
}.onFailure { e ->
|
||||
Log.e("Device", "Exception in ${plugin.pluginKey}'s onPacketReceived()", e)
|
||||
}
|
||||
}.onFailure { e ->
|
||||
Log.e("Device", "Exception in ${plugin.pluginKey}'s onPacketReceived()", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract class SendPacketStatusCallback {
|
||||
|
@@ -96,30 +96,30 @@ class KdeConnect : Application() {
|
||||
// Log.e("BackgroundService", "Loading remembered trusted devices")
|
||||
val preferences = getSharedPreferences("trusted_devices", MODE_PRIVATE)
|
||||
val trustedDevices: Set<String> = preferences.all.keys
|
||||
trustedDevices.map { id ->
|
||||
Log.d("KdeConnect", "Loading device $id")
|
||||
id
|
||||
}.filter { preferences.getBoolean(it, false) }.forEach {
|
||||
try {
|
||||
val device = Device(applicationContext, it)
|
||||
val now = Date()
|
||||
val x509Cert = device.certificate as X509Certificate
|
||||
if(now < x509Cert.notBefore) {
|
||||
throw CertificateException("Certificate not effective yet: "+x509Cert.notBefore)
|
||||
trustedDevices.asSequence()
|
||||
.onEach { Log.d("KdeConnect", "Loading device $it") }
|
||||
.filter { preferences.getBoolean(it, false) }
|
||||
.forEach {
|
||||
try {
|
||||
val device = Device(applicationContext, it)
|
||||
val now = Date()
|
||||
val x509Cert = device.certificate as X509Certificate
|
||||
if(now < x509Cert.notBefore) {
|
||||
throw CertificateException("Certificate not effective yet: "+x509Cert.notBefore)
|
||||
}
|
||||
else if(now > x509Cert.notAfter) {
|
||||
throw CertificateException("Certificate already expired: "+x509Cert.notAfter)
|
||||
}
|
||||
devices[it] = device
|
||||
device.addPairingCallback(devicePairingCallback)
|
||||
} catch (e: CertificateException) {
|
||||
Log.w(
|
||||
"KdeConnect",
|
||||
"Couldn't load the certificate for a remembered device. Removing from trusted list.", e
|
||||
)
|
||||
preferences.edit { remove(it) }
|
||||
}
|
||||
else if(now > x509Cert.notAfter) {
|
||||
throw CertificateException("Certificate already expired: "+x509Cert.notAfter)
|
||||
}
|
||||
devices[it] = device
|
||||
device.addPairingCallback(devicePairingCallback)
|
||||
} catch (e: CertificateException) {
|
||||
Log.w(
|
||||
"KdeConnect",
|
||||
"Couldn't load the certificate for a remembered device. Removing from trusted list.", e
|
||||
)
|
||||
preferences.edit { remove(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
fun removeRememberedDevices() {
|
||||
// Log.e("BackgroundService", "Removing remembered trusted devices")
|
||||
|
@@ -24,9 +24,11 @@ class ClipboardTileService : TileService() {
|
||||
this, 0, Intent(this, ClipboardFloatingActivity::class.java).apply {
|
||||
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
val ids = KdeConnect.getInstance().devices.values
|
||||
.asSequence()
|
||||
.filter { it.isReachable && it.isPaired }
|
||||
.map { it.deviceId }
|
||||
putExtra("connectedDeviceIds", ArrayList(ids))
|
||||
.toCollection(ArrayList())
|
||||
putExtra("connectedDeviceIds", ids)
|
||||
}, PendingIntent.FLAG_ONE_SHOT, true
|
||||
))
|
||||
}
|
||||
|
@@ -17,11 +17,11 @@ object PluginFactory {
|
||||
|
||||
fun initPluginInfo(context: Context) {
|
||||
try {
|
||||
val plugins = com.albertvaka.classindexksp.LoadablePlugin
|
||||
pluginInfo = com.albertvaka.classindexksp.LoadablePlugin
|
||||
.asSequence()
|
||||
.map { it.java.getDeclaredConstructor().newInstance() as Plugin }
|
||||
.map { plugin -> plugin.apply { setContext(context, null) } }
|
||||
|
||||
pluginInfo = plugins.associate { plugin -> Pair(plugin.pluginKey, PluginInfo(plugin)) }
|
||||
.onEach { it.setContext(context, null) }
|
||||
.associate { Pair(it.pluginKey, PluginInfo(it)) }
|
||||
} catch (e: Exception) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
|
Reference in New Issue
Block a user