Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/BackgroundService.java
Show All 40 Lines | |||||
41 | import java.util.HashSet; | 41 | import java.util.HashSet; | ||
42 | import java.util.Set; | 42 | import java.util.Set; | ||
43 | import java.util.concurrent.ConcurrentHashMap; | 43 | import java.util.concurrent.ConcurrentHashMap; | ||
44 | import java.util.concurrent.locks.Lock; | 44 | import java.util.concurrent.locks.Lock; | ||
45 | import java.util.concurrent.locks.ReentrantLock; | 45 | import java.util.concurrent.locks.ReentrantLock; | ||
46 | 46 | | |||
47 | public class BackgroundService extends Service { | 47 | public class BackgroundService extends Service { | ||
48 | 48 | | |||
49 | private static BackgroundService instance; | ||||
50 | | ||||
49 | public interface DeviceListChangedCallback { | 51 | public interface DeviceListChangedCallback { | ||
50 | void onDeviceListChanged(); | 52 | void onDeviceListChanged(); | ||
51 | } | 53 | } | ||
52 | 54 | | |||
53 | private final ConcurrentHashMap<String, DeviceListChangedCallback> deviceListChangedCallbacks = new ConcurrentHashMap<>(); | 55 | private final ConcurrentHashMap<String, DeviceListChangedCallback> deviceListChangedCallbacks = new ConcurrentHashMap<>(); | ||
54 | 56 | | |||
55 | private final ArrayList<BaseLinkProvider> linkProviders = new ArrayList<>(); | 57 | private final ArrayList<BaseLinkProvider> linkProviders = new ArrayList<>(); | ||
56 | 58 | | |||
57 | private final ConcurrentHashMap<String, Device> devices = new ConcurrentHashMap<>(); | 59 | private final ConcurrentHashMap<String, Device> devices = new ConcurrentHashMap<>(); | ||
58 | 60 | | |||
59 | private final HashSet<Object> discoveryModeAcquisitions = new HashSet<>(); | 61 | private final HashSet<Object> discoveryModeAcquisitions = new HashSet<>(); | ||
60 | 62 | | |||
63 | public static BackgroundService getInstance(){ | ||||
64 | return instance; | ||||
65 | } | ||||
66 | | ||||
61 | public boolean acquireDiscoveryMode(Object key) { | 67 | public boolean acquireDiscoveryMode(Object key) { | ||
62 | boolean wasEmpty = discoveryModeAcquisitions.isEmpty(); | 68 | boolean wasEmpty = discoveryModeAcquisitions.isEmpty(); | ||
63 | discoveryModeAcquisitions.add(key); | 69 | discoveryModeAcquisitions.add(key); | ||
64 | if (wasEmpty) { | 70 | if (wasEmpty) { | ||
65 | onNetworkChange(); | 71 | onNetworkChange(); | ||
66 | } | 72 | } | ||
67 | //Log.e("acquireDiscoveryMode",key.getClass().getName() +" ["+discoveryModeAcquisitions.size()+"]"); | 73 | //Log.e("acquireDiscoveryMode",key.getClass().getName() +" ["+discoveryModeAcquisitions.size()+"]"); | ||
68 | return wasEmpty; | 74 | return wasEmpty; | ||
▲ Show 20 Lines • Show All 176 Lines • ▼ Show 20 Line(s) | 250 | public void removeDeviceListChangedCallback(String key) { | |||
245 | deviceListChangedCallbacks.remove(key); | 251 | deviceListChangedCallbacks.remove(key); | ||
246 | } | 252 | } | ||
247 | 253 | | |||
248 | //This will called only once, even if we launch the service intent several times | 254 | //This will called only once, even if we launch the service intent several times | ||
249 | @Override | 255 | @Override | ||
250 | public void onCreate() { | 256 | public void onCreate() { | ||
251 | super.onCreate(); | 257 | super.onCreate(); | ||
252 | 258 | | |||
259 | instance = this; | ||||
260 | | ||||
253 | // Register screen on listener | 261 | // Register screen on listener | ||
254 | IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); | 262 | IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); | ||
255 | registerReceiver(new KdeConnectBroadcastReceiver(), filter); | 263 | registerReceiver(new KdeConnectBroadcastReceiver(), filter); | ||
256 | 264 | | |||
257 | Log.i("KDE/BackgroundService", "Service not started yet, initializing..."); | 265 | Log.i("KDE/BackgroundService", "Service not started yet, initializing..."); | ||
258 | 266 | | |||
259 | initializeSecurityParameters(); | 267 | initializeSecurityParameters(); | ||
260 | loadRememberedDevicesFromSettings(); | 268 | loadRememberedDevicesFromSettings(); | ||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |