mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 14:15:14 +00:00
Merge branch 'stable'
This commit is contained in:
@@ -71,8 +71,11 @@ public abstract class BaseLink {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void disconnect() {
|
||||||
|
linkProvider.connectionLost(this);
|
||||||
|
}
|
||||||
|
|
||||||
//TO OVERRIDE, should be sync
|
//TO OVERRIDE, should be sync
|
||||||
public abstract void sendPackage(NetworkPackage np,Device.SendPackageStatusCallback callback);
|
public abstract void sendPackage(NetworkPackage np,Device.SendPackageStatusCallback callback);
|
||||||
public abstract void sendPackageEncrypted(NetworkPackage np,Device.SendPackageStatusCallback callback, PublicKey key);
|
public abstract void sendPackageEncrypted(NetworkPackage np,Device.SendPackageStatusCallback callback, PublicKey key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -43,7 +43,13 @@ public class LanLink extends BaseLink {
|
|||||||
|
|
||||||
private IoSession session = null;
|
private IoSession session = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
|
closeSocket();
|
||||||
|
super.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeSocket() {
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
Log.e("KDE/LanLink", "Not yet connected");
|
Log.e("KDE/LanLink", "Not yet connected");
|
||||||
return;
|
return;
|
||||||
|
@@ -80,7 +80,7 @@ public class LanLinkProvider extends BaseLinkProvider {
|
|||||||
nioSessions.remove(id);
|
nioSessions.remove(id);
|
||||||
//Log.i("KDE/LanLinkProvider", "nioSessions.size(): " + nioSessions.size() + " (-)");
|
//Log.i("KDE/LanLinkProvider", "nioSessions.size(): " + nioSessions.size() + " (-)");
|
||||||
try {
|
try {
|
||||||
brokenLink.disconnect();
|
brokenLink.closeSocket();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Log.e("KDE/LanLinkProvider", "Exception. Already disconnected?");
|
Log.e("KDE/LanLinkProvider", "Exception. Already disconnected?");
|
||||||
@@ -244,7 +244,7 @@ public class LanLinkProvider extends BaseLinkProvider {
|
|||||||
connectionAccepted(identityPackage, link);
|
connectionAccepted(identityPackage, link);
|
||||||
if (oldLink != null) {
|
if (oldLink != null) {
|
||||||
Log.i("KDE/LanLinkProvider","Removing old connection to same device");
|
Log.i("KDE/LanLinkProvider","Removing old connection to same device");
|
||||||
oldLink.disconnect();
|
oldLink.closeSocket();
|
||||||
connectionLost(oldLink);
|
connectionLost(oldLink);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -57,6 +57,25 @@ public class BackgroundService extends Service {
|
|||||||
|
|
||||||
private final ConcurrentHashMap<String, Device> devices = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<String, Device> devices = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
private boolean discoveryEnabled = false;
|
||||||
|
|
||||||
|
public void setDiscoveryEnabled(boolean b) {
|
||||||
|
if (discoveryEnabled == b)
|
||||||
|
return;
|
||||||
|
|
||||||
|
discoveryEnabled = b;
|
||||||
|
|
||||||
|
if (b) {
|
||||||
|
onNetworkChange();
|
||||||
|
} else {
|
||||||
|
cleanDevices();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDiscoveryEnabled() {
|
||||||
|
return discoveryEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
private final Device.PairingCallback devicePairingCallback = new Device.PairingCallback() {
|
private final Device.PairingCallback devicePairingCallback = new Device.PairingCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void incomingRequest() {
|
public void incomingRequest() {
|
||||||
@@ -114,6 +133,12 @@ public class BackgroundService extends Service {
|
|||||||
return devices.get(id);
|
return devices.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void cleanDevices() {
|
||||||
|
for(Device d : devices.values()) {
|
||||||
|
d.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final BaseLinkProvider.ConnectionReceiver deviceListener = new BaseLinkProvider.ConnectionReceiver() {
|
private final BaseLinkProvider.ConnectionReceiver deviceListener = new BaseLinkProvider.ConnectionReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionReceived(final NetworkPackage identityPackage, final BaseLink link) {
|
public void onConnectionReceived(final NetworkPackage identityPackage, final BaseLink link) {
|
||||||
@@ -130,8 +155,10 @@ public class BackgroundService extends Service {
|
|||||||
} else {
|
} else {
|
||||||
Log.i("KDE/BackgroundService", "addLink,unknown device: " + deviceId);
|
Log.i("KDE/BackgroundService", "addLink,unknown device: " + deviceId);
|
||||||
device = new Device(BackgroundService.this, identityPackage, link);
|
device = new Device(BackgroundService.this, identityPackage, link);
|
||||||
devices.put(deviceId, device);
|
if (isDiscoveryEnabled() || device.isPaired()) {
|
||||||
device.addPairingCallback(devicePairingCallback);
|
devices.put(deviceId, device);
|
||||||
|
device.addPairingCallback(devicePairingCallback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onDeviceListChanged();
|
onDeviceListChanged();
|
||||||
@@ -159,20 +186,6 @@ public class BackgroundService extends Service {
|
|||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startDiscovery() {
|
|
||||||
Log.i("KDE/BackgroundService","StartDiscovery");
|
|
||||||
for (BaseLinkProvider a : linkProviders) {
|
|
||||||
a.onStart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopDiscovery() {
|
|
||||||
Log.i("KDE/BackgroundService","StopDiscovery");
|
|
||||||
for (BaseLinkProvider a : linkProviders) {
|
|
||||||
a.onStop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onNetworkChange() {
|
public void onNetworkChange() {
|
||||||
Log.i("KDE/BackgroundService","OnNetworkChange");
|
Log.i("KDE/BackgroundService","OnNetworkChange");
|
||||||
for (BaseLinkProvider a : linkProviders) {
|
for (BaseLinkProvider a : linkProviders) {
|
||||||
@@ -210,7 +223,7 @@ public class BackgroundService extends Service {
|
|||||||
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
|
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
|
||||||
registerReceiver(new KdeConnectBroadcastReceiver(), filter);
|
registerReceiver(new KdeConnectBroadcastReceiver(), filter);
|
||||||
|
|
||||||
Log.i("KDE/BackgroundService","Service not started yet, initializing...");
|
Log.i("KDE/BackgroundService", "Service not started yet, initializing...");
|
||||||
|
|
||||||
initializeRsaKeys();
|
initializeRsaKeys();
|
||||||
loadRememberedDevicesFromSettings();
|
loadRememberedDevicesFromSettings();
|
||||||
@@ -218,7 +231,11 @@ public class BackgroundService extends Service {
|
|||||||
|
|
||||||
//Link Providers need to be already registered
|
//Link Providers need to be already registered
|
||||||
addConnectionListener(deviceListener);
|
addConnectionListener(deviceListener);
|
||||||
startDiscovery();
|
|
||||||
|
Log.i("KDE/BackgroundService", "StartDiscovery");
|
||||||
|
for (BaseLinkProvider a : linkProviders) {
|
||||||
|
a.onStart();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,7 +297,10 @@ public class BackgroundService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
Log.i("KDE/BackgroundService", "Destroying");
|
Log.i("KDE/BackgroundService", "Destroying");
|
||||||
stopDiscovery();
|
Log.i("KDE/BackgroundService", "StopDiscovery");
|
||||||
|
for (BaseLinkProvider a : linkProviders) {
|
||||||
|
a.onStop();
|
||||||
|
}
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -873,4 +873,9 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
pluginsChangedListeners.remove(listener);
|
pluginsChangedListeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void disconnect() {
|
||||||
|
for(BaseLink link : links) {
|
||||||
|
link.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -187,9 +187,28 @@ public class MaterialActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
|
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
||||||
|
@Override
|
||||||
|
public void onServiceStart(BackgroundService service) {
|
||||||
|
service.setDiscoveryEnabled(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
updateComputerList();
|
updateComputerList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
||||||
|
@Override
|
||||||
|
public void onServiceStart(BackgroundService service) {
|
||||||
|
service.setDiscoveryEnabled(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: Make it accept two parameters, a constant with the type of screen and the device id in
|
//TODO: Make it accept two parameters, a constant with the type of screen and the device id in
|
||||||
//case the screen is for a device, or even three parameters and the third one be the plugin id?
|
//case the screen is for a device, or even three parameters and the third one be the plugin id?
|
||||||
//This way we can keep adding more options with null plugin id (eg: about)
|
//This way we can keep adding more options with null plugin id (eg: about)
|
||||||
|
Reference in New Issue
Block a user