55import android .os .Message ;
66import android .util .Log ;
77
8+ import net .sharksystem .asap .ASAPEngine ;
9+ import net .sharksystem .asap .ASAPEngineFS ;
810import net .sharksystem .asap .ASAPException ;
911import net .sharksystem .asap .ASAPOnlineMessageSender ;
12+ import net .sharksystem .asap .MultiASAPEngineFS ;
1013import net .sharksystem .asap .android .ASAP ;
1114import net .sharksystem .asap .android .ASAPServiceMethods ;
15+ import net .sharksystem .asap .util .Helper ;
1216
1317import java .io .IOException ;
1418import java .util .ArrayList ;
@@ -24,9 +28,11 @@ class ASAPMessageHandler extends Handler {
2428
2529 @ Override
2630 public void handleMessage (Message msg ) {
31+ Log .d (LOGSTART , "handleMessage called with what == " + msg .what );
2732 try {
2833 switch (msg .what ) {
2934 case ASAPServiceMethods .SEND_MESSAGE :
35+ Log .d (LOGSTART , "handleMessage SEND_MESSAGE called" );
3036 this .handleSendMessage (msg );
3137 break ;
3238
@@ -81,8 +87,8 @@ private void handleSendMessage(Message msg) {
8187 if (msgData != null ) {
8288 String format = msgData .getString (ASAP .FORMAT );
8389 String uri = msgData .getString (ASAP .URI );
84- String recipient = msgData .getString (ASAP .RECIPIENT );
85- byte [] content = msgData .getByteArray (ASAP .MESSAGE_CONTENT );
90+ String recipientsString = msgData .getString (ASAP .RECIPIENTS );
91+ byte [] message = msgData .getByteArray (ASAP .MESSAGE_CONTENT );
8692 int era = msgData .getInt (ASAP .ERA );
8793
8894 Log .d (LOGSTART , "received send message request" );
@@ -91,8 +97,8 @@ private void handleSendMessage(Message msg) {
9197 return ;
9298 }
9399
94- if (content == null ) {
95- Log .e (LOGSTART , "format content must not be empty" );
100+ if (message == null ) {
101+ Log .e (LOGSTART , "message must not be empty" );
96102 return ;
97103 }
98104
@@ -101,6 +107,35 @@ private void handleSendMessage(Message msg) {
101107 return ;
102108 }
103109
110+ MultiASAPEngineFS multiASAPEngine = asapService .getMultiASAPEngine ();
111+ try {
112+ ASAPEngine asapEngine = null ;
113+ try {
114+ asapEngine = multiASAPEngine .getEngineByFormat (format );
115+ }
116+ catch (ASAPException e ) {
117+ // engine does not yet exist
118+ Log .d (LOGSTART , " (TODO): asap engine for format not exists - going to create one - potential security leak:" + format );
119+ }
120+
121+ if (asapEngine == null ) {
122+ // still null - create on - TODO security leak?
123+ asapEngine = multiASAPEngine .createEngineByFormat (format );
124+ }
125+
126+ if (recipientsString != null ) {
127+ // extract recipients - and setup closed channel.
128+ asapEngine .createChannel (uri , Helper .string2CharSequenceSet (recipientsString ));
129+ }
130+
131+ asapEngine .add (uri , message );
132+
133+ } catch (ASAPException | IOException e ) {
134+ Log .w (LOGSTART , e .getLocalizedMessage ());
135+ }
136+
137+
138+ /*
104139 try {
105140 StringBuilder sb = new StringBuilder();
106141 sb.append("going to send message over an open connection:");
@@ -128,11 +163,12 @@ private void handleSendMessage(Message msg) {
128163 }
129164
130165 asapOnlineMessageSender.sendASAPAssimilate(
131- format , uri , recipient , content , era );
166+ format, uri, recipient, message , era);
132167
133168 } catch (Throwable e) {
134169 e.printStackTrace();
135170 }
171+ */
136172 }
137173 }
138174}
0 commit comments