@@ -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