2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-09-05 08:35:10 +00:00
Commit Graph

137 Commits

Author SHA1 Message Date
Marko Zajc
db615b82df Fix trusted networks
## Summary
1) Fix the code responsible for loading the trusted network list.
2) The old `#_#` delimiter has been replaced with a less likely NUL character. This requires re-adding trusted networks, so I can revert it if necessary.
3) Ignore incoming identity packets on untrusted devices if they come from an untrusted device.

BUG: 492302

## Test Plan

### Before:
1) Trusted networks were completely broken, an would show variations of `#` and `_` on the list due to a bug in the splitting code.
2) Any network with `#_#` in the SSID - although unlikely - would not be possible to use as a trusted network.
3) The device was still discoverable on an untrusted network by manually refreshing the devices list.

### After:
1) Trusted networks now load the SSID list correctly.
2) Networks with `#_#` in the SSID can be added as trusted networks.
3) The device is no longer discoverable on an untrusted network.
2024-09-21 22:24:46 +00:00
Albert Vaca Cintora
711eef97e7 Handle identity packets received because of existing device renames 2024-06-06 08:16:03 +02:00
Albert Vaca Cintora
0d0672e59f Same in LanLinkProvider 2024-05-19 15:34:02 +02:00
Albert Vaca Cintora
440f1d4fa3 Filter device name
Following the spec: https://invent.kde.org/network/kdeconnect-meta/-/blob/master/protocol.md?ref_type=heads#kdeconnectidentity
2024-05-19 10:02:28 +00:00
Rob Emery
19ec81eec4 Working bluetooth implementation 2023-11-17 22:52:20 +00:00
Albert Vaca Cintora
cd0ae95e58 Revert "Partially revert "Add MDNS discovery""
Adds back MDNS discovery and the setting to toggle UDP broacasts on/off.

We can probably remove the setting at some point, and just keep it enabled.

Another thing we can probably improve is the acquisition of the multicast
lock, so we only hold it when the app is open, or at least only when the
device is connected to Wifi (which we know). For more context, see commit
https://invent.kde.org/network/kdeconnect-android/-/merge_requests/375/diffs?commit_id=f71a3fe6b95af404d2a675afb78f24847064f8a9

This reverts commit 5da804939d.
2023-09-07 09:40:22 +02:00
Albert Vaca Cintora
5da804939d Partially revert "Add MDNS discovery"
This partially reverts commit 8f8a09a99a.

Removing MDNS to do one last bugfix-only release.
2023-09-07 09:27:55 +02:00
Albert Vaca Cintora
37db0810aa Bind only the socket we use for UDP broadcast, not the process 2023-08-30 23:12:17 +02:00
Albert Vaca Cintora
8f8a09a99a Add MDNS discovery
Uses Android's `NsdManager` to announce a `_kdeconnect._udp` service using MDNS. This is done in addition to sending UDP broadcasts.

When we detect a device this way, we send a UDP identity packet to it (identical to the ones we broadcast but sent to a single device).

I also added a toggle in settings to disable the UDP broadcasts, so we can test MDNS by itself.
2023-08-28 21:37:55 +00:00
Albert Vaca Cintora
5c99b1d32e Avoid starting more than 1 connection to the same device
Since we close old connections when a new connection is received, due to
race conditions we could end up without a valid connection in this case.

Equivalent to https://invent.kde.org/network/kdeconnect-kde/-/merge_requests/580
2023-08-04 08:25:11 +00:00
Albert Vaca Cintora
8c1603f6e4 Add DeviceInfo class
`DeviceInfo` contains all the properties we need to instantiate a `Device`:
id, name, type, cert, capabilities and protocol version. Before, we had a mix
of passing those around as arguments or passing identity packets (ie: json).
This simplifies the `Device` class quite a bit.

Now, `BaseLink` subclasses need to implement the `getDeviceInfo()` interface
that returns a `DeviceInfo`, which is what we will pass around and eventually
use to instantiate a `Device`.

This means that identity packets are an implementation detail of the
`LanLinkProvider` and that other implementations could get the `DeviceInfo`
in a different way.

In a future, we can add a mechanism for links to notify when their `DeviceInfo` changed.
This will allow us to better support device renames (which now are implemented by 
reconnecting to the device and don't always work) or sending the capabilities fields
later in the case of MacOS/iOS where we can't send them in a UDP packet due to the
size limit of 1500 bytes.
2023-06-27 11:14:36 +00:00
Albert Vaca Cintora
41e296b16d Better exception handling in LanLinkProvider
Bubble up exceptions instead of using giant, generic try-catch blocks.

The UDP and TCP listener loops are now where we catch all the exceptions that might happen handling the incoming packets.

Also, the creation of worker threads now happens in the listener loops as well instead of the inner functions.

Finally the `broadcastUdpPacket` function has been split in `broadcastUdpIdentityPacket` and `sendUdpIdentityPacket` (the first calls the second).
2023-06-20 08:26:00 +00:00
Albert Vaca Cintora
12de65f234 Rename "signal" function to match the name of the listeners' interface 2023-06-16 19:23:05 +02:00
Albert Vaca Cintora
ffd99858e6 Remove interface not needed 2023-06-16 19:23:04 +02:00
Albert Vaca Cintora
3e595cb262 Rename computer -> device 2023-06-15 14:45:54 +02:00
Albert Vaca Cintora
81270f724d Remove reverseConnectionBlackList used to support Android < 4 2023-06-14 18:17:21 +02:00
Albert Vaca Cintora
1ef3d75eb1 Update comments 2023-06-14 18:16:26 +02:00
Albert Vaca Cintora
d63f2cfb67 Set socket options before binding to a port and not after
By passing a port the implementation of DatagramSocket already binds to
it, making it fail if the port was already in use even if we did
setReuseAddress because that happened after binding.
2023-06-11 19:15:00 +02:00
Albert Vaca Cintora
b14df9d09c Fail earlier if we don't have a certificate 2023-06-05 10:29:27 +02:00
Albert Vaca Cintora
a20fb00b7d Have a single PairingHandler for all links 2023-06-05 10:28:45 +02:00
Albert Vaca Cintora
8ba4b532d4 Fix catch not working because broadcastUdpPacket starts a thread
We don't want to crash if we get onNetworkChange before tcpServer has been
initialized, however the way to do it was wrong because the exception was
being thrown from a new thread.
2023-06-03 18:59:14 +02:00
Albert Vaca Cintora
8c86ef4ac5 Remove unused argument 2023-05-31 17:24:05 +02:00
Albert Vaca Cintora
f00e420535 Do not ignore exceptions in LanLink onStart
broadcastUdpPacket will throw if setupTcpListener isn't successful, and
at that point we no longer know the real issue. Re-throw exceptions in
setupTcpListener so we can see what goes wrong.
2023-05-30 00:14:39 +02:00
Albert Vaca Cintora
ae23413971 Refactor BackgroundService
Added a new KdeConnect Application class that holds the Devices now, while
BackgroundService "only" takes care of the LinkProviders.

Since KdeConnect subclasses Application we have the guarantee that it will
exist as long as our process does, so we can use it as a singleton. This
removes the "BackgroundService.RunCommand" hack (which sent an Intent that
would awake BackgroundService in case it wasn't running already and then
call our code in a callback). This saves lots of round trips between the
system and us and makes things simpler (and stack traces useful) by making
the code sequential.

We already had an Application subclass that I moved to a new helper, which
now the KdeConnect class initializes together with all the other helpers.
2023-05-24 19:28:02 +02:00
Albert Vaca Cintora
961a839ac3 Fix crash when onNetworkChanged was called before link was initialized
This race condition could happen on slow devices
2023-05-03 19:38:21 +02:00
Albert Vaca Cintora
9379d89d03 Lower delay between broadcasts 2023-04-16 11:46:53 +02:00
Albert Vaca Cintora
01f44f524a package -> packet typo fixes 2023-03-17 18:57:02 +01:00
Wojciech Matuszewski
70d70dcb33 Use a common thread pool instead of creating new threads manually
## Summary

Spawning new threads in Java is costly. This MR aims to use a common thread pool instead.

I've replaced all cases where a new thread is started just to perform a task in the background. This does not include cases where a reference to the newly created thread is kept as a part of application logic – this is probably a problem in itself, but it exceeds the scope of this quick optimization. ;) 

There was a couple of cases where a new thread was spawned just to sleep for a while an then change the state on a View on the main thread. I've replaced those with posting those deferred tasks to the View's message queue.

## Test Plan

Everything should work the same as it has before, just a bit faster and easier on the memory.
2022-10-31 20:59:17 +00:00
Albert Vaca Cintora
fd3346626e Fix old typo 2021-03-16 21:21:15 +01:00
Albert Vaca Cintora
bb5b6f4fea Fail if server is not ready when we try to broadcast 2021-03-16 21:21:15 +01:00
Nicolas Fella
b3b74f25f4 Convert license headers to SPDX 2020-08-17 16:17:20 +02:00
Isira Seneviratne
1a2a01d3ff Use Kotlin's Charsets class. 2020-07-24 10:53:09 +00:00
Albert Vaca Cintora
235e49c80f Fixes as per code review 2020-01-05 17:27:16 +01:00
Juan David Vega
7f8f1bee30 T8539 - Create a new flow to manage trusted networks
Summary: I have created a new activity that allows you to trust all networks or add networks one by one to a list when you are connected to that network

Test Plan:
Test Cases:
1. By default everything should works like it works before, If you uncheck the "Allow all" option in trusted network menu and there isn't any ssid in the trusted
network list the app doesn't send the first udp package and log "Current WiFi isn't a Trusted Network"
2. With the "Allow all" uncheck, use "Add: YOUR_SSID_NAME" button to add your current ssid to the trusted networks list, once you added, go back and the app should
works as always

{F6152314}

1 -> https://youtu.be/ZpCEFTstbJI

2 -> https://youtu.be/cVB1LXlFVyk

Reviewers: #kde_connect, jdvr

Subscribers: sredman, albertvaka, nicolasfella, apol, kdeconnect

Tags: #kde_connect

Maniphest Tasks: T8539

Differential Revision: https://phabricator.kde.org/D13505
2019-10-27 22:16:12 +01:00
Albert Vaca Cintora
432294c64c Broacast when we open the app but ratelimit broadcasts
Reviewed-by: Aleix Pol
2019-10-25 21:22:10 +02:00
Matthijs Tijink
7f283d8995 Tell the user that no Wi-Fi is connected and click to fix it 2019-07-22 20:35:57 +00:00
Simon Redman
dc5f10c073 Revert "Try-with-resources on inputstreams"
This reverts commit aa776739b7
2019-04-19 05:10:11 +00:00
Nicolas Fella
25a0972606 Fix javadoc regression 2019-04-19 00:34:15 +02:00
Albert Vaca Cintora
aa776739b7 Try-with-resources on inputstreams
As suggested by lgtm.com
2019-04-18 20:59:54 +02:00
Albert Vaca Cintora
168b16527c Remove compat with protocol 6 with RSA encryption
Since we already removed compat with protocol 7 ^.^u
2019-04-18 19:52:30 +02:00
Nicolas Fella
f1194e88c2 Use Log.e instead of printStackTrace 2019-03-31 20:09:44 +02:00
Erik Duisters
0b2858d222 Revamp CustomDevicesActivity 2019-02-16 23:58:18 +00:00
Albert Vaca
d4286e7f17 Made setupTcpListener and setupUdpListener more similar
No real behaviour change
2019-02-09 00:16:57 +01:00
Albert Vaca
b529ab7484 Removed stale comment from old code 2019-02-08 23:57:57 +01:00
Albert Vaca
dca60706a3 Remove legacy UDP port support 2019-02-08 12:50:48 +01:00
Nicolas Fella
4f54d55cc5 Use one port more
Summary: The desktop side goes as far up as 1764.

Reviewers: #kde_connect, albertvaka

Reviewed By: #kde_connect, albertvaka

Subscribers: kdeconnect

Tags: #kde_connect

Differential Revision: https://phabricator.kde.org/D17271
2018-12-09 13:48:47 +01:00
Nicolas Fella
e1096f5bc8 Make final where possible 2018-10-27 00:01:30 +02:00
Nicolas Fella
a49a145d69 Only use required access modifiers 2018-10-26 23:59:20 +02:00
Nicolas Fella
3a8cb14c19 Remove unneeded imports 2018-10-26 23:12:31 +02:00
Nicolas Fella
7a24310cea Remove unneeded version checks
We require API 14 now which makes some checks needless
2018-10-26 22:51:13 +02:00