Skip to content

Commit 0675058

Browse files
author
David Graeff
committed
Do not save scenes from homescreen icons when executed. Complete plugin SimpleUDP. Reduce changelog to version 7 and 8. Buildsystem: Ignore incomlete translation for the time beeing.
1 parent 1b99466 commit 0675058

17 files changed

+336
-2049
lines changed

app/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ android {
1616
defaultConfig {
1717
minSdkVersion 17
1818
targetSdkVersion 22
19-
versionCode 119
19+
versionCode 120
2020
versionName "8.0"
2121
applicationId appID
2222
testApplicationId "oly.netpowerctrl.tests"
@@ -26,6 +26,7 @@ android {
2626

2727
lintOptions {
2828
abortOnError false
29+
warning "MissingTranslation"
2930
}
3031

3132
compileOptions {

app/hs_err_pid12500.log

-722
This file was deleted.

app/hs_err_pid15286.log

-723
This file was deleted.

app/proguard-rules.txt

-8
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,11 @@
2121
*;
2222
}
2323

24-
-keep oly.netpowerctrl.debug {
25-
*;
26-
}
27-
2824
# keep this around for some enums that ACRA needs
2925
-keep class org.acra.ReportingInteractionMode {
3026
*;
3127
}
3228

33-
-assumenosideeffects class oly.netpowerctrl.plugin.** { *; }
34-
35-
-assumenosideeffects class oly.netpowerctrl.consistency_tests.** { *; }
36-
3729
-keepnames class org.acra.sender.HttpSender$** {
3830
*;
3931
}

app/src/main/AndroidManifest.xml

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
2222
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
2323
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
24-
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
25-
<uses-permission android:name="com.android.vending.BILLING" />
2624
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
2725

2826
<uses-feature
@@ -41,7 +39,7 @@
4139
<!--android:permission="android.permission.MANAGE_DOCUMENTS"-->
4240
<provider
4341
android:name=".utils.AssetDocumentProvider"
44-
android:authorities="@string/authority"
42+
android:authorities="oly.netpowerctrl.utils.AssetDocumentProvider"
4543
android:enabled="@bool/atLeastKitKat"
4644
android:exported="true"
4745
android:grantUriPermissions="true"

app/src/main/java/oly/netpowerctrl/executables/Executable.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,20 @@ public class Executable implements Comparable, IOInterface {
5555
private boolean cached_executionInProgress;
5656
private Credentials credentials;
5757
private ReachabilityStates cached_reachabilityStates = ReachabilityStates.NotReachable;
58+
private boolean isSaveable = true;
5859

5960
public Executable() {
6061
}
6162

63+
public boolean isSaveable() {
64+
return this.isSaveable;
65+
}
66+
67+
public void setIsSaveable(boolean isSaveable) {
68+
this.isSaveable = isSaveable;
69+
}
70+
71+
6272
/**
6373
* Notice: Only call this method if the NetpowerctrlService service is running!
6474
*
@@ -219,9 +229,14 @@ public int computeChangedCode() {
219229
return (ui_type.hashCode() + uid.hashCode() + current_value + max_value + min_value + (hidden ? 1 : 0) + group_uids.hashCode());
220230
}
221231

232+
/**
233+
* An executable may not always be safeable, for example if it is a homescreen icon for execution.
234+
*
235+
* @return
236+
*/
222237
@Override
223238
public boolean hasChanged() {
224-
return last_hash_code != computeChangedCode();
239+
return isSaveable && last_hash_code != computeChangedCode();
225240
}
226241

227242
@Override
@@ -339,4 +354,9 @@ public boolean updateCachedReachability(ReachabilityStates new_state) {
339354
cached_reachabilityStates = new_state;
340355
return new_state != a;
341356
}
357+
358+
public void destroy(DataService dataService) {
359+
credentials = null;
360+
//uid = null;
361+
}
342362
}

app/src/main/java/oly/netpowerctrl/executables/ExecutableCollection.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,20 @@ public void put(Executable executable) {
7777
return;
7878
}
7979

80-
items.put(executable.getUid(), executable);
81-
notifyObservers(executable, ObserverUpdateActions.AddAction);
82-
if (!executable.needCredentials() || executable.getCredentials().isConfigured())
83-
storage.save(executable);
80+
if (executable.isSaveable()) {
81+
items.put(executable.getUid(), executable);
82+
notifyObservers(executable, ObserverUpdateActions.AddAction);
83+
if (!executable.needCredentials() || executable.getCredentials().isConfigured())
84+
storage.save(executable);
85+
}
8486
}
8587

8688
public void remove(Executable executable) {
87-
items.remove(executable.deviceUID);
89+
items.remove(executable.getUid());
90+
dataService.favourites.setFavourite(executable.getUid(), false);
8891
storage.remove(executable);
8992
notifyObservers(executable, ObserverUpdateActions.RemoveAction);
93+
executable.destroy(dataService);
9094
}
9195

9296
/**
@@ -100,8 +104,10 @@ public void remove(Credentials credentials) {
100104
Executable executable = iterator.next();
101105
if (executable.deviceUID.equals(credentials.deviceUID)) {
102106
iterator.remove();
103-
notifyObservers(executable, ObserverUpdateActions.RemoveAction);
107+
storage.remove(executable);
104108
dataService.favourites.setFavourite(executable.getUid(), false);
109+
notifyObservers(executable, ObserverUpdateActions.RemoveAction);
110+
executable.destroy(dataService);
105111
}
106112
}
107113
}
@@ -131,7 +137,7 @@ public void notifyReachability(String deviceUID, ReachabilityStates r) {
131137
}
132138
}
133139

134-
public void notifyReachability(Executable executable, ReachabilityStates r) {
140+
public void notifyReachability(Executable executable) {
135141
notifyObservers(executable, ObserverUpdateActions.UpdateReachableAction);
136142
}
137143

app/src/main/java/oly/netpowerctrl/main/ExecutionActivity.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,12 @@ public boolean onDataQueryFinished(DataService dataService) {
9898

9999
// Read data from intent
100100
destination_uuid = extra.getString(EXECUTE_ACTION_UUID, destination_uuid);
101-
String scene_json = extra.getString(EXECUTE_SCENE_JSON);
101+
String execution_json = extra.getString(EXECUTE_SCENE_JSON);
102102

103-
if (scene_json != null) {
103+
if (execution_json != null) {
104104
try {
105-
Executable executable = new ExecutableFabric().newInstance(JSONHelper.getReader(scene_json));
105+
Executable executable = new ExecutableFabric().newInstance(JSONHelper.getReader(execution_json));
106+
executable.setIsSaveable(false);
106107
executable.execute(dataService, action_command, executionFinished);
107108
} catch (IOException | ClassNotFoundException ignored) {
108109
}

app/src/main/java/oly/netpowerctrl/network/UDPReceiving.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import oly.netpowerctrl.ui.notifications.InAppNotifications;
1414

1515
abstract public class UDPReceiving extends Thread {
16-
private final int receive_port;
16+
protected final int receive_port;
1717
protected DatagramPacket receivedDatagram;
1818
private boolean keep_running;
1919
private DatagramSocket socket;
@@ -39,7 +39,7 @@ public void run() {
3939
socket.bind(new InetSocketAddress(receive_port));
4040
while (keep_running) {
4141
socket.receive(receivedDatagram);
42-
parsePacket(message, receivedDatagram.getLength(), receive_port, socket.getLocalAddress(), receivedDatagram.getAddress());
42+
parsePacket(message, receivedDatagram.getLength(), socket.getLocalAddress(), receivedDatagram.getAddress());
4343
//NetworkInterface.getByInetAddress(socket.getLocalAddress()));
4444
}
4545
socket.close();
@@ -66,7 +66,7 @@ public void interrupt() {
6666
}
6767

6868
protected abstract void parsePacket(final byte[] message, int length,
69-
int receive_port, InetAddress local, InetAddress peer);
69+
InetAddress local, InetAddress peer);
7070

7171
/**
7272
* @return Return the receive port of this thread

app/src/main/java/oly/netpowerctrl/plugin_anel/AnelPlugin.java

+51-55
Original file line numberDiff line numberDiff line change
@@ -224,59 +224,6 @@ private int executeDeviceBatch(@NonNull IOConnection ioConnection,
224224
return command_list.size();
225225
}
226226

227-
private void startNetworkReceivers(boolean changed) {
228-
// Get all ports of configured devices and add the additional_port if != 0
229-
Set<Integer> ports = dataService.connections.getAllUDPReceivePorts(this);
230-
ports.add(SharedPrefs.getInstance().getDefaultReceivePort());
231-
232-
if (!changed && discoveryThreads.size() == ports.size()) return;
233-
234-
boolean new_threads_started = false;
235-
List<AnelReceiveUDP> unusedThreads = new ArrayList<>(discoveryThreads);
236-
237-
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
238-
String methodName = stacktrace[3].getClassName() + ":" + stacktrace[3].getMethodName() + "->" + stacktrace[4].getClassName() + ":" + stacktrace[4].getMethodName();
239-
Log.w(PLUGIN_ID, "startNetworkReceivers " + methodName);
240-
241-
// Go through all ports and start a thread for it if none is running for it so far
242-
for (int port : ports) {
243-
boolean already_running = false;
244-
for (AnelReceiveUDP running_thread : discoveryThreads) {
245-
if (running_thread.getPort() == port) {
246-
already_running = true;
247-
unusedThreads.remove(running_thread);
248-
break;
249-
}
250-
}
251-
252-
if (already_running) {
253-
continue;
254-
}
255-
256-
new_threads_started = true;
257-
AnelReceiveUDP thr = new AnelReceiveUDP(this, port);
258-
thr.start();
259-
discoveryThreads.add(thr);
260-
}
261-
262-
if (unusedThreads.size() > 0) {
263-
for (AnelReceiveUDP thr : unusedThreads) {
264-
thr.interrupt();
265-
discoveryThreads.remove(thr);
266-
}
267-
}
268-
269-
if (new_threads_started) {
270-
// give the threads a chance to start
271-
try {
272-
Thread.sleep(100);
273-
} catch (InterruptedException ignored) {
274-
}
275-
}
276-
277-
HttpThreadPool.startHTTP();
278-
}
279-
280227
private void stopNetwork() {
281228
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
282229
String methodName = stacktrace[3].getClassName() + ":" + stacktrace[3].getMethodName() + "->" + stacktrace[4].getClassName() + ":" + stacktrace[4].getMethodName();
@@ -343,7 +290,7 @@ else if (command == Executable.TOGGLE)
343290
}
344291
return success;
345292
} else if (ioConnection instanceof IOConnectionUDP) {
346-
final Credentials credentials = dataService.credentials.findByUID(executable.deviceUID);
293+
final Credentials credentials = ioConnection.credentials;
347294
if (credentials == null) {
348295
Log.e(PLUGIN_ID, "execute. No credentials found!");
349296
if (callback != null) callback.addFail();
@@ -383,7 +330,56 @@ public void onDestroy() {
383330

384331
@Override
385332
public void onStart(Context context) {
386-
startNetworkReceivers(true);
333+
// Get all ports of configured devices and add the additional_port if != 0
334+
Set<Integer> ports = dataService.connections.getAllUDPReceivePorts(this);
335+
ports.add(SharedPrefs.getInstance().getDefaultReceivePort());
336+
337+
if (discoveryThreads.size() == ports.size()) return;
338+
339+
boolean new_threads_started = false;
340+
List<AnelReceiveUDP> unusedThreads = new ArrayList<>(discoveryThreads);
341+
342+
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
343+
String methodName = stacktrace[3].getClassName() + ":" + stacktrace[3].getMethodName() + "->" + stacktrace[4].getClassName() + ":" + stacktrace[4].getMethodName();
344+
Log.w(PLUGIN_ID, "startNetworkReceivers " + methodName);
345+
346+
// Go through all ports and start a thread for it if none is running for it so far
347+
for (int port : ports) {
348+
boolean already_running = false;
349+
for (AnelReceiveUDP running_thread : discoveryThreads) {
350+
if (running_thread.getPort() == port) {
351+
already_running = true;
352+
unusedThreads.remove(running_thread);
353+
break;
354+
}
355+
}
356+
357+
if (already_running) {
358+
continue;
359+
}
360+
361+
new_threads_started = true;
362+
AnelReceiveUDP thr = new AnelReceiveUDP(this, port);
363+
thr.start();
364+
discoveryThreads.add(thr);
365+
}
366+
367+
if (unusedThreads.size() > 0) {
368+
for (AnelReceiveUDP thr : unusedThreads) {
369+
thr.interrupt();
370+
discoveryThreads.remove(thr);
371+
}
372+
}
373+
374+
if (new_threads_started) {
375+
// give the threads a chance to start
376+
try {
377+
Thread.sleep(100);
378+
} catch (InterruptedException ignored) {
379+
}
380+
}
381+
382+
HttpThreadPool.startHTTP();
387383
}
388384

389385
@Override

0 commit comments

Comments
 (0)