mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 05:37:43 +00:00
Merge branch 'stable'
# Conflicts: # src/org/kde/kdeconnect/Device.java
This commit is contained in:
commit
132a223b8c
@ -23,10 +23,11 @@ package org.kde.kdeconnect.Backends;
|
|||||||
import org.kde.kdeconnect.NetworkPackage;
|
import org.kde.kdeconnect.NetworkPackage;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
public abstract class BaseLinkProvider {
|
public abstract class BaseLinkProvider {
|
||||||
|
|
||||||
private final ArrayList<ConnectionReceiver> connectionReceivers = new ArrayList<>();
|
private final CopyOnWriteArrayList<ConnectionReceiver> connectionReceivers = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
public interface ConnectionReceiver {
|
public interface ConnectionReceiver {
|
||||||
void onConnectionReceived(NetworkPackage identityPackage, BaseLink link);
|
void onConnectionReceived(NetworkPackage identityPackage, BaseLink link);
|
||||||
|
@ -61,12 +61,13 @@ public class BackgroundService extends Service {
|
|||||||
|
|
||||||
private final HashSet<Object> discoveryModeAcquisitions = new HashSet<>();
|
private final HashSet<Object> discoveryModeAcquisitions = new HashSet<>();
|
||||||
|
|
||||||
public void acquireDiscoveryMode(Object key) {
|
public boolean acquireDiscoveryMode(Object key) {
|
||||||
boolean wasEmpty = discoveryModeAcquisitions.isEmpty();
|
boolean wasEmpty = discoveryModeAcquisitions.isEmpty();
|
||||||
discoveryModeAcquisitions.add(key);
|
discoveryModeAcquisitions.add(key);
|
||||||
if (wasEmpty) {
|
if (wasEmpty) {
|
||||||
onNetworkChange();
|
onNetworkChange();
|
||||||
}
|
}
|
||||||
|
return wasEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void releaseDiscoveryMode(Object key) {
|
public void releaseDiscoveryMode(Object key) {
|
||||||
@ -76,11 +77,18 @@ public class BackgroundService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addGuiInUseCounter(final Activity activity) {
|
public static void addGuiInUseCounter(Activity activity) {
|
||||||
|
addGuiInUseCounter(activity, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addGuiInUseCounter(final Activity activity, final boolean forceNetworkRefresh) {
|
||||||
BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
service.acquireDiscoveryMode(activity);
|
boolean refreshed = service.acquireDiscoveryMode(activity);
|
||||||
|
if (!refreshed && forceNetworkRefresh) {
|
||||||
|
service.onNetworkChange();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,7 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
public class Device implements BaseLink.PackageReceiver {
|
public class Device implements BaseLink.PackageReceiver {
|
||||||
|
|
||||||
@ -67,10 +68,11 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
|
|
||||||
private DeviceType deviceType;
|
private DeviceType deviceType;
|
||||||
private PairStatus pairStatus;
|
private PairStatus pairStatus;
|
||||||
private final ArrayList<PairingCallback> pairingCallback = new ArrayList<>();
|
|
||||||
|
private final CopyOnWriteArrayList<PairingCallback> pairingCallback = new CopyOnWriteArrayList<>();
|
||||||
private Timer pairingTimer;
|
private Timer pairingTimer;
|
||||||
|
|
||||||
private final ArrayList<BaseLink> links = new ArrayList<>();
|
private final CopyOnWriteArrayList<BaseLink> links = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
private ArrayList<String> incomingCapabilities;
|
private ArrayList<String> incomingCapabilities;
|
||||||
private ArrayList<String> outgoingCapabilities;
|
private ArrayList<String> outgoingCapabilities;
|
||||||
@ -90,6 +92,12 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
return unsupportedPlugins;
|
return unsupportedPlugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final CopyOnWriteArrayList<PluginsChangedListener> pluginsChangedListeners = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
|
public interface PluginsChangedListener {
|
||||||
|
void onPluginsChanged(Device device);
|
||||||
|
}
|
||||||
|
|
||||||
public enum PairStatus {
|
public enum PairStatus {
|
||||||
NotPaired,
|
NotPaired,
|
||||||
Requested,
|
Requested,
|
||||||
@ -640,8 +648,7 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
boolean useEncryption = (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_PAIR) && isPaired());
|
boolean useEncryption = (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_PAIR) && isPaired());
|
||||||
|
|
||||||
//Make a copy to avoid concurrent modification exception if the original list changes
|
//Make a copy to avoid concurrent modification exception if the original list changes
|
||||||
ArrayList<BaseLink> mLinks = new ArrayList<>(links);
|
for (final BaseLink link : links) {
|
||||||
for (final BaseLink link : mLinks) {
|
|
||||||
if (link == null) continue; //Since we made a copy, maybe somebody destroyed the link in the meanwhile
|
if (link == null) continue; //Since we made a copy, maybe somebody destroyed the link in the meanwhile
|
||||||
if (useEncryption) {
|
if (useEncryption) {
|
||||||
link.sendPackageEncrypted(np, callback, publicKey);
|
link.sendPackageEncrypted(np, callback, publicKey);
|
||||||
@ -652,7 +659,7 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!callback.success) {
|
if (!callback.success) {
|
||||||
Log.e("KDE/sendPackage", "No device link (of "+mLinks.size()+" available) could send the package. Package "+np.getType()+" to " + name + " lost!");
|
Log.e("KDE/sendPackage", "No device link (of "+links.size()+" available) could send the package. Package "+np.getType()+" to " + name + " lost!");
|
||||||
backtrace.printStackTrace();
|
backtrace.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -859,12 +866,6 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
return failedPlugins;
|
return failedPlugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface PluginsChangedListener {
|
|
||||||
void onPluginsChanged(Device device);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final ArrayList<PluginsChangedListener> pluginsChangedListeners = new ArrayList<>();
|
|
||||||
|
|
||||||
public void addPluginsChangedListener(PluginsChangedListener listener) {
|
public void addPluginsChangedListener(PluginsChangedListener listener) {
|
||||||
pluginsChangedListeners.add(listener);
|
pluginsChangedListeners.add(listener);
|
||||||
}
|
}
|
||||||
|
@ -159,21 +159,33 @@ public class MaterialActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
BackgroundService.addGuiInUseCounter(this);
|
BackgroundService.addGuiInUseCounter(this, true);
|
||||||
|
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
||||||
|
@Override
|
||||||
|
public void onServiceStart(BackgroundService service) {
|
||||||
|
service.addDeviceListChangedCallback("MaterialActivity", new BackgroundService.DeviceListChangedCallback() {
|
||||||
|
@Override
|
||||||
|
public void onDeviceListChanged() {
|
||||||
|
updateComputerList();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
updateComputerList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
BackgroundService.removeGuiInUseCounter(this);
|
BackgroundService.removeGuiInUseCounter(this);
|
||||||
|
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
||||||
|
@Override
|
||||||
|
public void onServiceStart(BackgroundService service) {
|
||||||
|
service.removeDeviceListChangedCallback("MaterialActivity");
|
||||||
|
}
|
||||||
|
});
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
updateComputerList();
|
|
||||||
}
|
|
||||||
|
|
||||||
//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)
|
||||||
|
@ -98,9 +98,10 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
if (listRefreshCalledThisFrame) {
|
if (listRefreshCalledThisFrame) {
|
||||||
return; // This makes sure we don't try to call list.getFirstVisiblePosition()
|
// This makes sure we don't try to call list.getFirstVisiblePosition()
|
||||||
// twice per frame, because the second time the list hasn't been drawn
|
// twice per frame, because the second time the list hasn't been drawn
|
||||||
// yet and it would always return 0.
|
// yet and it would always return 0.
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
listRefreshCalledThisFrame = true;
|
listRefreshCalledThisFrame = true;
|
||||||
|
|
||||||
@ -183,9 +184,9 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
updateComputerList();
|
updateComputerList();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
service.onNetworkChange();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
updateComputerList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -199,12 +200,6 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
updateComputerList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pairingClicked(Device device) {
|
public void pairingClicked(Device device) {
|
||||||
mActivity.onDeviceSelected(device.getDeviceId(), !device.isPaired() || !device.isReachable());
|
mActivity.onDeviceSelected(device.getDeviceId(), !device.isPaired() || !device.isReachable());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user