Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/BackgroundService.java
Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Line(s) | 77 | public void releaseDiscoveryMode(Object key) { | |||
---|---|---|---|---|---|
82 | } | 82 | } | ||
83 | } | 83 | } | ||
84 | 84 | | |||
85 | public static void addGuiInUseCounter(Context activity) { | 85 | public static void addGuiInUseCounter(Context activity) { | ||
86 | addGuiInUseCounter(activity, false); | 86 | addGuiInUseCounter(activity, false); | ||
87 | } | 87 | } | ||
88 | 88 | | |||
89 | public static void addGuiInUseCounter(final Context activity, final boolean forceNetworkRefresh) { | 89 | public static void addGuiInUseCounter(final Context activity, final boolean forceNetworkRefresh) { | ||
90 | BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() { | 90 | BackgroundService.RunCommand(activity, service -> { | ||
91 | @Override | | |||
92 | public void onServiceStart(BackgroundService service) { | | |||
93 | boolean refreshed = service.acquireDiscoveryMode(activity); | 91 | boolean refreshed = service.acquireDiscoveryMode(activity); | ||
94 | if (!refreshed && forceNetworkRefresh) { | 92 | if (!refreshed && forceNetworkRefresh) { | ||
95 | service.onNetworkChange(); | 93 | service.onNetworkChange(); | ||
96 | } | 94 | } | ||
97 | } | | |||
98 | }); | 95 | }); | ||
99 | } | 96 | } | ||
100 | 97 | | |||
101 | public static void removeGuiInUseCounter(final Context activity) { | 98 | public static void removeGuiInUseCounter(final Context activity) { | ||
102 | BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() { | 99 | BackgroundService.RunCommand(activity, service -> { | ||
103 | @Override | | |||
104 | public void onServiceStart(BackgroundService service) { | | |||
105 | //If no user interface is open, close the connections open to other devices | 100 | //If no user interface is open, close the connections open to other devices | ||
106 | service.releaseDiscoveryMode(activity); | 101 | service.releaseDiscoveryMode(activity); | ||
107 | } | | |||
108 | }); | 102 | }); | ||
109 | } | 103 | } | ||
110 | 104 | | |||
111 | private final Device.PairingCallback devicePairingCallback = new Device.PairingCallback() { | 105 | private final Device.PairingCallback devicePairingCallback = new Device.PairingCallback() { | ||
112 | @Override | 106 | @Override | ||
113 | public void incomingRequest() { | 107 | public void incomingRequest() { | ||
114 | onDeviceListChanged(); | 108 | onDeviceListChanged(); | ||
115 | } | 109 | } | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 155 | public ArrayList<BaseLinkProvider> getLinkProviders() { | |||
162 | return linkProviders; | 156 | return linkProviders; | ||
163 | } | 157 | } | ||
164 | 158 | | |||
165 | public Device getDevice(String id) { | 159 | public Device getDevice(String id) { | ||
166 | return devices.get(id); | 160 | return devices.get(id); | ||
167 | } | 161 | } | ||
168 | 162 | | |||
169 | private void cleanDevices() { | 163 | private void cleanDevices() { | ||
170 | new Thread(new Runnable() { | 164 | new Thread(() -> { | ||
171 | @Override | | |||
172 | public void run() { | | |||
173 | for (Device d : devices.values()) { | 165 | for (Device d : devices.values()) { | ||
174 | if (!d.isPaired() && !d.isPairRequested() && !d.isPairRequestedByPeer() && !d.deviceShouldBeKeptAlive()) { | 166 | if (!d.isPaired() && !d.isPairRequested() && !d.isPairRequestedByPeer() && !d.deviceShouldBeKeptAlive()) { | ||
175 | d.disconnect(); | 167 | d.disconnect(); | ||
176 | } | 168 | } | ||
177 | } | 169 | } | ||
178 | } | | |||
179 | }).start(); | 170 | }).start(); | ||
180 | } | 171 | } | ||
181 | 172 | | |||
182 | private final BaseLinkProvider.ConnectionReceiver deviceListener = new BaseLinkProvider.ConnectionReceiver() { | 173 | private final BaseLinkProvider.ConnectionReceiver deviceListener = new BaseLinkProvider.ConnectionReceiver() { | ||
183 | @Override | 174 | @Override | ||
184 | public void onConnectionReceived(final NetworkPacket identityPacket, final BaseLink link) { | 175 | public void onConnectionReceived(final NetworkPacket identityPacket, final BaseLink link) { | ||
185 | 176 | | |||
186 | String deviceId = identityPacket.getString("deviceId"); | 177 | String deviceId = identityPacket.getString("deviceId"); | ||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Line(s) | 303 | public int onStartCommand(Intent intent, int flags, int startId) { | |||
323 | return Service.START_STICKY; | 314 | return Service.START_STICKY; | ||
324 | } | 315 | } | ||
325 | 316 | | |||
326 | public static void Start(Context c) { | 317 | public static void Start(Context c) { | ||
327 | RunCommand(c, null); | 318 | RunCommand(c, null); | ||
328 | } | 319 | } | ||
329 | 320 | | |||
330 | public static void RunCommand(final Context c, final InstanceCallback callback) { | 321 | public static void RunCommand(final Context c, final InstanceCallback callback) { | ||
331 | new Thread(new Runnable() { | 322 | new Thread(() -> { | ||
332 | @Override | | |||
333 | public void run() { | | |||
334 | if (callback != null) { | 323 | if (callback != null) { | ||
335 | mutex.lock(); | 324 | mutex.lock(); | ||
336 | try { | 325 | try { | ||
337 | callbacks.add(callback); | 326 | callbacks.add(callback); | ||
338 | } finally { | 327 | } finally { | ||
339 | mutex.unlock(); | 328 | mutex.unlock(); | ||
340 | } | 329 | } | ||
341 | } | 330 | } | ||
342 | Intent serviceIntent = new Intent(c, BackgroundService.class); | 331 | Intent serviceIntent = new Intent(c, BackgroundService.class); | ||
343 | c.startService(serviceIntent); | 332 | c.startService(serviceIntent); | ||
344 | } | | |||
345 | }).start(); | 333 | }).start(); | ||
346 | } | 334 | } | ||
347 | 335 | | |||
348 | } | 336 | } |