Skip to content

Commit 5a384e2

Browse files
committed
- moved XML operations off of the calling thread
1 parent 58982f3 commit 5a384e2

8 files changed

Lines changed: 37 additions & 31 deletions

File tree

50 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repositories {
2222
}
2323
2424
dependencies {
25-
implementation 'com.github.sofwerx:swe-android:1.0.3'
25+
implementation 'com.github.sofwerx:swe-android:1.0.4'
2626
}
2727
```
2828

@@ -39,7 +39,7 @@ dependencies {
3939
<dependency>
4040
<groupId>com.github.sofwerx</groupId>
4141
<artifactId>swe-android</artifactId>
42-
<version>1.0.3</version>
42+
<version>1.0.4</version>
4343
</dependency>
4444
```
4545

SweLib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ android {
1010
minSdkVersion 21
1111
targetSdkVersion 28
1212
versionCode 3
13-
versionName '1.0.2'
13+
versionName '1.0.4'
1414
}
1515
buildTypes {
1616
release {

SweLib/src/main/java/org/sofwerx/ogc/sos/SosIpcTransceiver.java

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -88,51 +88,57 @@ public void onReceive(Context context, Intent intent) {
8888
* @param source the application that sent the request; mostly to prevent circular reporting
8989
* @param input the SOS operation received
9090
*/
91-
public void onMessageReceived(Context context,String source,String input) {
91+
public void onMessageReceived(final Context context,final String source, final String input) {
9292
if (source == null) {
9393
Log.e(TAG,"SOS broadcasts from anonymous senders is not supported");
9494
return;
9595
}
96-
if (input == null)
97-
Log.e(TAG,"Null operation received from SOS broadcast IPC");
98-
try {
99-
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
100-
DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
101-
Document doc = docBuilder.parse(new InputSource(new ByteArrayInputStream(input.getBytes("utf-8"))));
102-
if (doc != null) {
103-
AbstractSosOperation operation = AbstractSosOperation.newFromXML(doc);
104-
if (operation != null) {
105-
if (listener != null)
106-
listener.onSosOperationReceived(operation);
96+
if (input == null) {
97+
Log.e(TAG, "Null operation received from SOS broadcast IPC");
98+
return;
99+
}
100+
new Thread(() -> {
101+
try {
102+
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
103+
DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
104+
Document doc = docBuilder.parse(new InputSource(new ByteArrayInputStream(input.getBytes("utf-8"))));
105+
if (doc != null) {
106+
AbstractSosOperation operation = AbstractSosOperation.newFromXML(doc);
107+
if (operation != null) {
108+
if (listener != null)
109+
listener.onSosOperationReceived(operation);
110+
}
107111
}
108-
return;
112+
} catch (ParserConfigurationException | IOException | SAXException e) {
113+
Log.e(TAG,"SOS IPC broadcast was not XML: "+input);
109114
}
110-
} catch (ParserConfigurationException | IOException | SAXException e) {
111-
}
112-
Log.e(TAG,"SOS IPC broadcast was not XML: "+input);
115+
}).start();
113116
}
114117

115118
/**
116119
* Broadcasts this SOS operation via IPC
117120
* @param context
118121
* @param operation
119122
*/
120-
public void broadcast(Context context, AbstractSosOperation operation) throws SosException {
123+
public void broadcast(final Context context, final AbstractSosOperation operation) throws SosException {
121124
if (operation != null) {
122125
if (!operation.isValid()) {
123126
throw new SosException(operation.getClass().getSimpleName()+" does not have all required information");
124127
}
125-
Document doc = null;
126-
try {
127-
doc = operation.toXML();
128-
} catch (ParserConfigurationException e) {
129-
throw new SosException("Unable to create document: "+e.getMessage());
130-
}
131-
try {
132-
broadcast(context,toString(doc));
133-
} catch (Exception ex) {
134-
throw new SosException("Unable to convert XML document to string: "+ex.getMessage());
135-
}
128+
new Thread(() -> {
129+
Document doc = null;
130+
try {
131+
doc = operation.toXML();
132+
} catch (ParserConfigurationException e) {
133+
//throw new SosException("Unable to create document: " + e.getMessage());
134+
}
135+
try {
136+
if (doc != null)
137+
broadcast(context, toString(doc));
138+
} catch (Exception ex) {
139+
//throw new SosException("Unable to convert XML document to string: " + ex.getMessage());
140+
}
141+
}).start();
136142
}
137143
}
138144

0 commit comments

Comments
 (0)