Skip to content

Commit 6bf0bca

Browse files
committed
message written by sendMessage are in storage as expected.
1 parent cf35ff7 commit 6bf0bca

File tree

6 files changed

+73
-14
lines changed

6 files changed

+73
-14
lines changed

app/libs/ASAP_Engine_0.5.0.jar

14 Bytes
Binary file not shown.

app/src/main/java/net/sharksystem/asap/android/apps/ASAPActivity.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
import android.widget.Toast;
1717

1818
import net.sharksystem.asap.ASAPException;
19+
import net.sharksystem.asap.MultiASAPEngineFS;
20+
import net.sharksystem.asap.MultiASAPEngineFS_Impl;
1921
import net.sharksystem.asap.android.ASAP;
2022
import net.sharksystem.asap.android.ASAPServiceMethods;
23+
import net.sharksystem.asap.android.Util;
2124
import net.sharksystem.asap.android.service.ASAPService;
2225
import net.sharksystem.asap.android.service2AppMessaging.ASAPServiceNotificationListener;
2326
import net.sharksystem.asap.android.service2AppMessaging.ASAPServiceRequestListener;
@@ -26,6 +29,8 @@
2629
import net.sharksystem.asap.apps.ASAPMessages;
2730
import net.sharksystem.asap.util.Helper;
2831

32+
import java.io.File;
33+
import java.io.IOException;
2934
import java.net.URI;
3035
import java.util.ArrayList;
3136
import java.util.Collection;
@@ -52,13 +57,26 @@ protected ASAPApplication getASAPApplication() {
5257

5358
public void sendASAPMessage(CharSequence appName, CharSequence uri,
5459
Collection<CharSequence> recipients, byte[] message)
55-
throws ASAPException {
60+
throws ASAPException, IOException {
5661

5762
if(appName == null || appName.length() == 0
5863
|| uri == null || uri.length() == 0
5964
|| message == null || message.length == 0
6065
) throw new ASAPException("parameter must not be null");
6166

67+
// ensure that any format is supporter by an engine
68+
Collection<CharSequence> supportedFormats = asapApplication.getSupportFormats();
69+
if(supportedFormats != null && supportedFormats.size() > 0) {
70+
Log.d(this.getLogStart(), "use Util.getASAPRootDirectory()");
71+
CharSequence asapRoot = this.asapApplication.getASAPRootFolder();
72+
73+
MultiASAPEngineFS multiEngine = MultiASAPEngineFS_Impl.createMultiEngine(asapRoot,null);
74+
75+
for(CharSequence supportedFormat : supportedFormats) {
76+
multiEngine.createEngineByFormat(supportedFormat);
77+
}
78+
}
79+
6280
// prepare message
6381
Message msg = Message.obtain(null, ASAPServiceMethods.SEND_MESSAGE, 0, 0);
6482
Bundle bundle = new Bundle();

app/src/main/java/net/sharksystem/asap/android/apps/ASAPApplication.java

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import net.sharksystem.asap.ASAPEngine;
1616
import net.sharksystem.asap.ASAPEngineFS;
1717
import net.sharksystem.asap.ASAPException;
18+
import net.sharksystem.asap.MultiASAPEngineFS;
19+
import net.sharksystem.asap.MultiASAPEngineFS_Impl;
1820
import net.sharksystem.asap.android.ASAP;
1921
import net.sharksystem.asap.android.ASAPChunkReceivedBroadcastIntent;
2022
import net.sharksystem.asap.android.ASAPServiceCreationIntent;
@@ -36,6 +38,7 @@
3638
public class ASAPApplication extends BroadcastReceiver {
3739
private static final int MY_ASK_FOR_PERMISSIONS_REQUEST = 100;
3840
private static ASAPApplication singleton;
41+
private final Collection<CharSequence> supportedFormats;
3942
private CharSequence asapOwner;
4043
private CharSequence rootFolder;
4144
private boolean onlineExchange;
@@ -54,16 +57,30 @@ public class ASAPApplication extends BroadcastReceiver {
5457
private List<CharSequence> onlinePeerList = new ArrayList<>();
5558

5659
/**
57-
* setup application by calling getASAPOwner(), getFolderName(), getASAPOnlineExchange().
58-
* Those messagen can and should be overwritten from actual implementations.
60+
* Setup application using default setting
61+
* @param supportedFormats ensure that asap engines using that formats are present -
62+
* create if necessary.
63+
*/
64+
protected ASAPApplication(Collection<CharSequence> supportedFormats) {
65+
this(supportedFormats, ASAP.UNKNOWN_USER, DEFAULT_ROOT_FOLDER_NAME,
66+
ASAP.ONLINE_EXCHANGE_DEFAULT);
67+
}
68+
69+
/**
70+
* setup application without parameter. Use default for owner, root folder for asap storage
71+
* and online exchange behaviour. Don't setup any asap engine - take engines which are
72+
* already present when starting up.
5973
*/
6074
protected ASAPApplication() {
61-
this(ASAP.UNKNOWN_USER, DEFAULT_ROOT_FOLDER_NAME, ASAP.ONLINE_EXCHANGE_DEFAULT);
75+
this(null, ASAP.UNKNOWN_USER, DEFAULT_ROOT_FOLDER_NAME,
76+
ASAP.ONLINE_EXCHANGE_DEFAULT);
6277
}
6378

64-
protected ASAPApplication(CharSequence asapOwner,
79+
protected ASAPApplication(Collection<CharSequence> supportedFormats,
80+
CharSequence asapOwner,
6581
CharSequence rootFolder,
6682
boolean onlineExchange) {
83+
this.supportedFormats = supportedFormats;
6784
this.asapOwner = asapOwner;
6885
this.rootFolder = rootFolder;
6986
this.onlineExchange = onlineExchange;
@@ -147,6 +164,10 @@ public CharSequence getASAPOwner() {
147164
return this.asapOwner;
148165
}
149166

167+
public Collection<CharSequence> getSupportFormats() {
168+
return this.supportedFormats;
169+
}
170+
150171
public static ASAPApplication getASAPApplication() {
151172
if(ASAPApplication.singleton == null) {
152173
ASAPApplication.singleton = new ASAPApplication();
@@ -155,6 +176,25 @@ public static ASAPApplication getASAPApplication() {
155176
return ASAPApplication.singleton;
156177
}
157178

179+
public static ASAPApplication getASAPApplication(Collection<CharSequence> supportedFormats) {
180+
if(ASAPApplication.singleton == null) {
181+
ASAPApplication.singleton = new ASAPApplication(supportedFormats);
182+
}
183+
184+
return ASAPApplication.singleton;
185+
}
186+
187+
public static ASAPApplication getASAPApplication(CharSequence supportedFormat) {
188+
189+
if(ASAPApplication.singleton == null) {
190+
Collection<CharSequence> formats = new HashSet<>();
191+
formats.add(supportedFormat);
192+
ASAPApplication.singleton = new ASAPApplication(formats);
193+
}
194+
195+
return ASAPApplication.singleton;
196+
}
197+
158198
public String getApplicationRootFolder(String appName) {
159199
return this.getASAPRootFolder() + "/" + appName;
160200
}

app/src/main/java/net/sharksystem/asap/android/example/ASAPExampleActivity.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ public class ASAPExampleActivity extends ASAPActivity implements ASAPMessageRece
2323
private static final CharSequence TESTURI ="asap://testuri";
2424
private static final CharSequence TESTMESSAGE = "Hi there from asap writing activity";
2525
private ASAPOnlineMessageSenderAndroidUserSide asapOnlineSender;
26+
private static final String APPNAME = "ASAP_TEST_APP";
2627

27-
public ASAPExampleActivity() {
28-
super(ASAPApplication.getASAPApplication());
28+
public ASAPExampleActivity() throws IOException, ASAPException {
29+
// super(ASAPApplication.getASAPApplication());
30+
super(ASAPApplication.getASAPApplication(APPNAME));
2931
}
3032

3133
@Override
@@ -161,7 +163,6 @@ public void asapNotifyBTEnvironmentStopped() {
161163
// asap store test scenario(s) //
162164
///////////////////////////////////////////////////////////////////////////////////////////
163165

164-
private final String APPNAME = "ASAP_TEST_APP";
165166
private final String URI = "sn://chat";
166167
private final String MESSAGE = "Hi, that's a message";
167168
private final byte[] BYTE_MESSAGE = MESSAGE.getBytes();

app/src/main/java/net/sharksystem/asap/android/service/ASAPMessageHandler.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,9 @@ private void handleSendMessage(Message msg) {
115115
}
116116
catch(ASAPException e ) {
117117
// 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);
118+
Log.d(LOGSTART, "asap engine for format not exists - give up " +
119+
"(better create ASAPApplication with supportedFormats):" + format);
120+
return;
124121
}
125122

126123
if(recipientsString != null) {

app/src/main/java/net/sharksystem/asap/android/service/ASAPService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ String getASAPRootFolderName() {
5555
}
5656

5757
public MultiASAPEngineFS getMultiASAPEngine() {
58+
Log.d(LOGSTART, "TODO: setup multi engine each time to keep in sync with external changes.");
59+
// TODO: setup multi engine each time to keep in sync with external changes.
60+
this.asapMultiEngine = null;
5861
if(this.asapMultiEngine == null) {
5962
Log.d(LOGSTART, "try to get asapMultiEngine");
6063

0 commit comments

Comments
 (0)