Skip to content

Commit cc0f849

Browse files
committed
service and engine is created with valid owner settings
1 parent f6bc5a7 commit cc0f849

4 files changed

Lines changed: 66 additions & 10 deletions

File tree

app/src/main/java/net/sharksystem/asap/android/ASAP.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ public class ASAP {
2323

2424
public static final String ONLINE_EXCHANGE = "ASAP_ONLINE_EXCHANGE";
2525
public static final boolean ONLINE_EXCHANGE_DEFAULT = true;
26+
public static final String MAX_EXECUTION_TIME = "ASAP_MAX_EXECUTION_TIME";
2627
}

app/src/main/java/net/sharksystem/asap/android/ASAPServiceCreationIntent.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
package net.sharksystem.asap.android;
22

33
import android.app.Activity;
4-
import android.content.Context;
54
import android.content.Intent;
65

6+
import net.sharksystem.asap.ASAPEngine;
77
import net.sharksystem.asap.ASAPException;
8+
import net.sharksystem.asap.MultiASAPEngineFS;
89
import net.sharksystem.asap.android.service.ASAPService;
910

1011
public class ASAPServiceCreationIntent extends Intent {
1112

1213
private final CharSequence owner;
1314
private final CharSequence rootFolder;
1415
private final boolean onlineExchange;
16+
private final long maxExecutionTime;
1517

1618
public ASAPServiceCreationIntent(Activity activity, CharSequence owner, CharSequence rootFolder,
17-
boolean onlineExchange) throws ASAPException {
19+
boolean onlineExchange)
20+
throws ASAPException {
21+
22+
this(activity, owner, rootFolder, onlineExchange,
23+
MultiASAPEngineFS.DEFAULT_MAX_PROCESSING_TIME);
24+
}
25+
26+
public ASAPServiceCreationIntent(Activity activity, CharSequence owner, CharSequence rootFolder,
27+
boolean onlineExchange, long maxExecutionTime)
28+
throws ASAPException {
1829

1930
super(activity, ASAPService.class);
2031

@@ -24,10 +35,12 @@ public ASAPServiceCreationIntent(Activity activity, CharSequence owner, CharSequ
2435
this.putExtra(ASAP.USER, owner);
2536
this.putExtra(ASAP.FOLDER, rootFolder);
2637
this.putExtra(ASAP.ONLINE_EXCHANGE, onlineExchange);
38+
this.putExtra(ASAP.MAX_EXECUTION_TIME, maxExecutionTime);
2739

2840
this.owner = owner;
2941
this.rootFolder = rootFolder;
3042
this.onlineExchange = onlineExchange;
43+
this.maxExecutionTime = maxExecutionTime;
3144
}
3245

3346
public ASAPServiceCreationIntent(Intent intent) {
@@ -38,6 +51,8 @@ public ASAPServiceCreationIntent(Intent intent) {
3851
this.rootFolder = intent.getStringExtra(ASAP.FOLDER);
3952
this.onlineExchange = intent.getBooleanExtra(ASAP.ONLINE_EXCHANGE,
4053
ASAP.ONLINE_EXCHANGE_DEFAULT);
54+
this.maxExecutionTime = intent.getLongExtra(ASAP.MAX_EXECUTION_TIME,
55+
MultiASAPEngineFS.DEFAULT_MAX_PROCESSING_TIME);
4156

4257
}
4358

@@ -52,4 +67,24 @@ public CharSequence getRootFolder() {
5267
public boolean isOnlineExchange() {
5368
return this.onlineExchange;
5469
}
70+
71+
public long getMaxExecutionTime() {
72+
return this.maxExecutionTime;
73+
}
74+
75+
public String toString() {
76+
StringBuilder sb = new StringBuilder();
77+
78+
sb.append("owner: ");
79+
sb.append(this.owner);
80+
sb.append(" | folder: ");
81+
sb.append(this.rootFolder);
82+
sb.append(" | onlineExchange: ");
83+
sb.append(this.onlineExchange);
84+
sb.append(" | maxExecutionTime: ");
85+
sb.append(this.maxExecutionTime);
86+
87+
return sb.toString();
88+
}
89+
5590
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.support.v4.app.ActivityCompat;
1010
import android.support.v4.content.ContextCompat;
1111
import android.util.Log;
12+
import android.widget.Toast;
1213

1314
import net.sharksystem.asap.ASAPChunkReceivedListener;
1415
import net.sharksystem.asap.ASAPException;
@@ -93,6 +94,9 @@ private void initialize() {
9394
Intent asapServiceCreationIntent = new ASAPServiceCreationIntent(activity,
9495
this.asapOwner, this.rootFolder, this.onlineExchange);
9596

97+
Log.d(this.getLogStart(), "start service with intent: "
98+
+ asapServiceCreationIntent.toString());
99+
96100
this.activity.startService(asapServiceCreationIntent);
97101
this.initialized = true;
98102
} catch (ASAPException e) {
@@ -317,6 +321,12 @@ public void setOnlinePeersList(List<CharSequence> peerList) {
317321
}
318322

319323
Log.d(this.getLogStart(), sb.toString());
324+
if(onlinePeerList.size() < peerList.size()) {
325+
Toast.makeText(this.getActivity(), "new online connections", Toast.LENGTH_SHORT);
326+
} else {
327+
Toast.makeText(this.getActivity(), "online connections changed", Toast.LENGTH_SHORT);
328+
}
329+
320330
this.onlinePeerList = peerList;
321331
}
322332
}

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import net.sharksystem.asap.MultiASAPEngineFS_Impl;
2020
import net.sharksystem.asap.android.ASAP;
2121
import net.sharksystem.asap.android.ASAPChunkReceivedBroadcastIntent;
22+
import net.sharksystem.asap.android.ASAPServiceCreationIntent;
2223
import net.sharksystem.asap.android.Util;
2324
import net.sharksystem.asap.android.bluetooth.BluetoothEngine;
2425
import net.sharksystem.asap.android.service2AppMessaging.ASAPServiceRequestNotifyIntent;
@@ -47,6 +48,7 @@ public class ASAPService extends Service implements ASAPChunkReceivedListener,
4748
private CharSequence owner;
4849
private CharSequence rootFolder;
4950
private boolean onlineExchange;
51+
private long maxExecutionTime;
5052

5153
String getASAPRootFolderName() {
5254
return this.asapEngineRootFolderName;
@@ -77,7 +79,7 @@ public MultiASAPEngineFS getASAPEngine() {
7779
Log.d(LOGSTART,"createdFolder");
7880
}
7981
this.asapMultiEngine = MultiASAPEngineFS_Impl.createMultiEngine(
80-
this.asapEngineRootFolderName, this);
82+
this.owner, this.asapEngineRootFolderName, this.maxExecutionTime, this);
8183
Log.d(LOGSTART,"engine created");
8284

8385
this.asapMultiEngine.addOnlinePeersChangedListener(this);
@@ -116,13 +118,20 @@ public int onStartCommand(Intent intent, int flags, int startId) {
116118
this.owner = ASAP.UNKNOWN_USER;
117119
this.rootFolder = ASAPEngineFS.DEFAULT_ROOT_FOLDER_NAME;
118120
this.onlineExchange = ASAP.ONLINE_EXCHANGE_DEFAULT;
121+
this.maxExecutionTime = MultiASAPEngineFS.DEFAULT_MAX_PROCESSING_TIME;
119122
} else {
120-
Log.d(LOGSTART, "intent is not null");
121-
this.owner = intent.getCharSequenceExtra(ASAP.USER);
122-
this.rootFolder = intent.getCharSequenceExtra(ASAP.FOLDER);
123-
this.onlineExchange = intent.getBooleanExtra(ASAP.ONLINE_EXCHANGE, ASAP.ONLINE_EXCHANGE_DEFAULT);
124-
Log.d(LOGSTART, "owner | folder | online == " + this.owner
125-
+ " | " + this.rootFolder + " | " + this.onlineExchange);
123+
Log.d(LOGSTART, "service was created with an intent");
124+
125+
ASAPServiceCreationIntent asapServiceCreationIntent =
126+
new ASAPServiceCreationIntent(intent);
127+
128+
Log.d(this.getLogStart(), "started with intent: "
129+
+ asapServiceCreationIntent.toString());
130+
131+
this.owner = asapServiceCreationIntent.getOwner();
132+
this.rootFolder = asapServiceCreationIntent.getRootFolder();
133+
this.onlineExchange = asapServiceCreationIntent.isOnlineExchange();
134+
this.maxExecutionTime = asapServiceCreationIntent.getMaxExecutionTime();
126135
}
127136

128137
// get root directory
@@ -248,7 +257,8 @@ public void propagateProtocolStatus() throws ASAPException {
248257

249258
@Override
250259
public void chunkReceived(String sender, String uri, int era) {
251-
Log.d(LOGSTART, "was notified ba engine that chunk received. Uri: " + uri);
260+
Log.d(LOGSTART, "was notified by asap engine that chunk received - broadcast. Uri: "
261+
+ uri);
252262
// issue broadcast
253263
ASAPChunkReceivedBroadcastIntent intent = null;
254264
try {

0 commit comments

Comments
 (0)