forked from OpenSensing/funf-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
COMMIT_LOG
461 lines (417 loc) · 17.1 KB
/
COMMIT_LOG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
commit 7b165d8ca2a7fe234ba796b11feab99dc3523e06
Author: Piotr <[email protected]>
Date: Fri Dec 14 16:18:32 2012 +0100
SMS problem fixed
diff --git a/funf-open-sensing-framework/src/edu/mit/media/funf/probe/ContentProviderProbe.java b/funf-open-sensing-framework/src/edu/mit/media/funf/probe/ContentProviderProbe.java
index a09745b..98e35a6 100644
--- a/funf-open-sensing-framework/src/edu/mit/media/funf/probe/ContentProviderProbe.java
+++ b/funf-open-sensing-framework/src/edu/mit/media/funf/probe/ContentProviderProbe.java
@@ -21,11 +21,14 @@
*/
package edu.mit.media.funf.probe;
+import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
+import java.util.Queue;
+import java.util.concurrent.Executor;
import android.content.Context;
import android.database.Cursor;
@@ -46,6 +49,7 @@ public abstract class ContentProviderProbe extends Probe {
protected Iterable<Bundle> mostRecentScan;
private Thread onRunThread;
+ private ThreadPerTaskExecutor onRunExecutor;
@Override
public Parameter[] getAvailableParameters() {
@@ -78,6 +82,7 @@ public abstract class ContentProviderProbe extends Probe {
@Override
protected void onRun(Bundle params) {
Log.d(TAG, "onRun of ContentProviderProbe");
+ /*
if (onRunThread == null) {
onRunThread = new Thread(new Runnable() {
@Override
@@ -89,6 +94,19 @@ public abstract class ContentProviderProbe extends Probe {
}
});
onRunThread.start();
+ }*/
+ if (onRunExecutor == null) {
+ onRunExecutor = new ThreadPerTaskExecutor();
+ onRunExecutor.execute(new Runnable() {
+ @Override
+ public void run() {
+ mostRecentScan = parseCursorResults();
+ sendProbeData();
+ onRunThread = null;
+ stop();
+ }
+ });
+
}
}
@@ -115,13 +133,17 @@ public abstract class ContentProviderProbe extends Probe {
}
@Override
public void sendProbeData() {
- // TODO: make this always run on separate thread
+ int counter = 0;
+ // TODO: make this always run on separate thread
if (mostRecentScan != null ) {
if (sendEachRowSeparately()) {
for (Bundle data : mostRecentScan) {
+
if (data != null) {
+ Log.e(TAG, "Adding item : " + counter + " from " + getTimestamp(data) + "@" + System.currentTimeMillis());
sendProbeData(getTimestamp(data), data);
throttle();
+ counter ++;
}
}
} else {
@@ -150,11 +172,11 @@ public abstract class ContentProviderProbe extends Probe {
}
sendProbeData(timestamp, data);
}
- }
+ }
}
protected boolean sendEachRowSeparately() {
- return false;
+ return true;
}
protected abstract String getDataName();
@@ -190,6 +212,45 @@ public abstract class ContentProviderProbe extends Probe {
};
}
+ class ThreadPerTaskExecutor implements Executor {
+ final Queue<Runnable> tasks = new ArrayDeque<Runnable>();
+ final Executor executor;
+ Runnable active;
+
+ ThreadPerTaskExecutor(Executor executor) {
+ this.executor = executor;
+ }
+ ThreadPerTaskExecutor() {
+ this.executor = new SmallExecutor();
+ }
+
+ public synchronized void execute(final Runnable r) {
+ tasks.offer(new Runnable() {
+ public void run() {
+ try {
+ r.run();
+ } finally {
+ scheduleNext();
+ }
+ }
+ });
+ if (active == null) {
+ scheduleNext();
+ }
+ }
+
+ protected synchronized void scheduleNext() {
+ if ((active = tasks.poll()) != null) {
+ executor.execute(active);
+ }
+ }
+ class SmallExecutor implements Executor {
+ public void execute(Runnable r) {
+ new Thread(r).start();
+
+ }}
+ }
+
class ContentProviderIterator implements Iterator<Bundle> {
private final Cursor c;
@@ -204,6 +265,7 @@ public abstract class ContentProviderProbe extends Probe {
this.c = getCursor(projection);
int count = c.getCount();
this.brandNew = true;
+
Log.v(TAG, "cursor returned " + count +" result");
}
diff --git a/funf-open-sensing-framework/src/edu/mit/media/funf/probe/DatedContentProviderProbe.java b/funf-open-sensing-framework/src/edu/mit/media/funf/probe/DatedContentProviderProbe.java
index 1291d0a..9e2b4ed 100644
--- a/funf-open-sensing-framework/src/edu/mit/media/funf/probe/DatedContentProviderProbe.java
+++ b/funf-open-sensing-framework/src/edu/mit/media/funf/probe/DatedContentProviderProbe.java
@@ -23,6 +23,7 @@ package edu.mit.media.funf.probe;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Calendar;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -45,13 +46,23 @@ public abstract class DatedContentProviderProbe extends ContentProviderProbe {
projection = new String[projectionList.size()];
projectionList.toArray(projection);
}
- Log.i(TAG, "Previous Date Sent Time: " + getDateColumnTimeUnit().convert(getPreviousDataSentTime(), TimeUnit.SECONDS));
+ String debugmessage = "Previous Run Time [ms]: " + getDateColumnTimeUnit().convert(getPreviousDataSentTime(), TimeUnit.SECONDS);
+ debugmessage += ".Previous Run Time [original]: " + getPreviousDataSentTime();
+ debugmessage+= ". Time now: " + System.currentTimeMillis();
+ Log.i(TAG, debugmessage);
+
return getContentResolver().query(
getContentProviderUri(),
projection, // TODO: different platforms have different fields supported for content providers, need to resolve this
dateColumn + " > ?",
new String[] {String.valueOf(getDateColumnTimeUnit().convert(getPreviousDataSentTime() + 1, TimeUnit.SECONDS))}, // Add one because of unit truncation
- dateColumn + " DESC");
+ dateColumn + " ASC");
+ /*return getContentResolver().query(
+ getContentProviderUri(),
+ projection, // TODO: different platforms have different fields supported for content providers, need to resolve this
+ dateColumn + " > ?",
+ new String[] {String.valueOf(2355475157000l)}, // Add one because of unit truncation
+ dateColumn + " DESC");*/
}
protected abstract Uri getContentProviderUri();
diff --git a/funf-open-sensing-framework/src/edu/mit/media/funf/probe/Probe.java b/funf-open-sensing-framework/src/edu/mit/media/funf/probe/Probe.java
index 7566af6..c520b21 100644
--- a/funf-open-sensing-framework/src/edu/mit/media/funf/probe/Probe.java
+++ b/funf-open-sensing-framework/src/edu/mit/media/funf/probe/Probe.java
@@ -531,6 +531,7 @@ public abstract class Probe extends CustomizedIntentService implements BaseProbe
}
sendProbeStatus(null);
long nowTimestamp = Utils.millisToSeconds(System.currentTimeMillis());
+ Log.i(TAG, "Setting probe " + getClass().getName() + "'s last time to: " + String.valueOf(nowTimestamp));
getHistoryPrefs().edit().putLong(MOST_RECENT_RUN_KEY, nowTimestamp).commit();
onRun(parameters);
}
@@ -743,6 +744,7 @@ public abstract class Probe extends CustomizedIntentService implements BaseProbe
}
// Save the data sent times
+ Log.d(TAG, "Saving sent time as: " + String.valueOf(epochTimestamp));
getHistoryPrefs().edit()
.putString(MOST_RECENT_DATA_BY_REQUEST_KEY, dataSentTimes.toString())
.putLong(MOST_RECENT_DATA_KEY, epochTimestamp)
diff --git a/funf-open-sensing-framework/src/edu/mit/media/funf/probe/builtin/ContactProbe.java b/funf-open-sensing-framework/src/edu/mit/media/funf/probe/builtin/ContactProbe.java
index 3763e5c..c135c32 100644
--- a/funf-open-sensing-framework/src/edu/mit/media/funf/probe/builtin/ContactProbe.java
+++ b/funf-open-sensing-framework/src/edu/mit/media/funf/probe/builtin/ContactProbe.java
@@ -358,7 +358,7 @@ public class ContactProbe extends ContentProviderProbe implements ContactKeys {
@Override
protected boolean sendEachRowSeparately() {
- return false;
+ return true;
}
diff --git a/funf-open-sensing-framework/src/edu/mit/media/funf/storage/UploadService.java b/funf-open-sensing-framework/src/edu/mit/media/funf/storage/UploadService.java
index 3f39d5e..5cd7dda 100644
--- a/funf-open-sensing-framework/src/edu/mit/media/funf/storage/UploadService.java
+++ b/funf-open-sensing-framework/src/edu/mit/media/funf/storage/UploadService.java
@@ -49,7 +49,7 @@ public abstract class UploadService extends Service {
public static final int
MAX_REMOTE_ARCHIVE_RETRIES = 6,
MAX_FILE_RETRIES = 3,
- MAX_BACKLOG_LENGTH = 200;
+ MAX_BACKLOG_LENGTH = 1000;
public static final int
NETWORK_ANY = 0,
commit e3380a133b367b9a20740b6813084572a42d2d59
Author: Piotr <[email protected]>
Date: Wed Dec 12 14:41:58 2012 +0100
updating the required SDK version in AndroidManifest.xml
diff --git a/datacollector/AndroidManifest.xml b/datacollector/AndroidManifest.xml
index 3ed48f4..46d7b4a 100644
--- a/datacollector/AndroidManifest.xml
+++ b/datacollector/AndroidManifest.xml
@@ -24,8 +24,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.mit.media.funf.bgcollector"
android:versionCode="1"
- android:versionName="1.0">
- <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="8" />
+ android:versionName="0.5">
+ <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="15" />
<application android:label="@string/app_name" android:largeHeap="true" android:icon="@drawable/icon" >
commit b9e6a24cc6394c328b5f6da0a7cb95619a04313b
Author: Piotr <[email protected]>
Date: Wed Dec 12 13:32:30 2012 +0100
fixed bug with empty phone numbers
diff --git a/funf-open-sensing-framework/src/edu/mit/media/funf/HashUtil.java b/funf-open-sensing-framework/src/edu/mit/media/funf/HashUtil.java
index 04436a9..5d132ee 100644
--- a/funf-open-sensing-framework/src/edu/mit/media/funf/HashUtil.java
+++ b/funf-open-sensing-framework/src/edu/mit/media/funf/HashUtil.java
@@ -122,16 +122,20 @@ public class HashUtil {
}
public static String formatPhoneNumber(String numberString) {
- numberString = numberString.replaceAll("[^0-9]+", "");
-
- int i = numberString.length();
- int maxLength = 8; // only look at the last n digits
-
- if (i <= maxLength) {
- return numberString;
- }
- else {
- return numberString.substring(i - maxLength);
+ if (numberString != null) {
+ numberString = numberString.replaceAll("[^0-9]+", "");
+
+ int i = numberString.length();
+ int maxLength = 8; // only look at the last n digits
+
+ if (i <= maxLength) {
+ return numberString;
+ }
+ else {
+ return numberString.substring(i - maxLength);
+ }
+ } else {
+ return "";
}
}
commit d4129091fab2e11d1a7f2fcceded5a100ab19725
Author: Piotr <[email protected]>
Date: Tue Dec 11 17:46:56 2012 +0100
fixed bug that prevented WiFi from scanning while off
diff --git a/funf-open-sensing-framework/src/edu/mit/media/funf/probe/builtin/WifiProbe.java b/funf-open-sensing-framework/src/edu/mit/media/funf/probe/builtin/WifiProbe.java
index 1de0439..ffc8026 100644
--- a/funf-open-sensing-framework/src/edu/mit/media/funf/probe/builtin/WifiProbe.java
+++ b/funf-open-sensing-framework/src/edu/mit/media/funf/probe/builtin/WifiProbe.java
@@ -151,6 +151,7 @@ public class WifiProbe extends Probe implements WifiKeys {
private void runScan() {
numberOfAttempts += 1;
int state = wifiManager.getWifiState();
+ Log.i(TAG, "WiFi state: " + state);
if (state == WifiManager.WIFI_STATE_ENABLED) {
boolean successfulStart = wifiManager.startScan();
if (successfulStart) {
@@ -159,9 +160,10 @@ public class WifiProbe extends Probe implements WifiKeys {
Log.e(TAG, "WIFI scan failed.");
}
numberOfAttempts = 0;
- } else if (numberOfAttempts <= 3) {
+ } else if (numberOfAttempts <= 10) {
// Prevent infinite recursion by keeping track of number of attempts to change wifi state
// TODO: investigate what is needed to keep Service alive while waiting for wifi state
+ Log.i(TAG, "Waiting for WiFi enabled, will retry " + (10 - numberOfAttempts) + " more times");
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context ctx, Intent i) {
@@ -176,8 +178,18 @@ public class WifiProbe extends Probe implements WifiKeys {
}
}
}, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));
- wifiManager.setWifiEnabled(true);
- } else { // After 3 attempts stop trying
+ // no use asking to enable, if already enabling
+ if (state != WifiManager.WIFI_STATE_ENABLING)
+ wifiManager.setWifiEnabled(true);
+
+ // increasing the counter without waiting makes no sense, so we wait a second.
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ } else { // After 10 attempts stop trying
// TODO: possibly send error
stop();
}
commit b6211e37f6dcbcd60b027d2a845b38227d07e60c
Author: Piotr <[email protected]>
Date: Tue Dec 11 13:25:37 2012 +0100
Fixed Failed Binder Transaction as start of the app
diff --git a/funf-open-sensing-framework/src/edu/mit/media/funf/probe/Probe.java b/funf-open-sensing-framework/src/edu/mit/media/funf/probe/Probe.java
index eb92fca..9991d54 100644
--- a/funf-open-sensing-framework/src/edu/mit/media/funf/probe/Probe.java
+++ b/funf-open-sensing-framework/src/edu/mit/media/funf/probe/Probe.java
@@ -799,7 +799,14 @@ public abstract class Probe extends CustomizedIntentService implements BaseProbe
return null;
}
- private static boolean packageHasRequiredPermissions(Context context, String packageName, String[] requiredPermissions) {
+ /**
+ * This function causes FAILED_BINDER_TRANSACTION because it requests all permissions for all apps installed. Fixed version below.
+ * @param context
+ * @param packageName
+ * @param requiredPermissions
+ * @return
+ */
+ /**private static boolean packageHasRequiredPermissions(Context context, String packageName, String[] requiredPermissions) {
Log.v(Utils.TAG, "Getting package info for '" + packageName + "'");
PackageInfo info = getPackageInfo(context, packageName);
if (info == null) {
@@ -816,6 +823,17 @@ public abstract class Probe extends CustomizedIntentService implements BaseProbe
}
}
return true;
+ }*/
+
+ private static boolean packageHasRequiredPermissions(Context context, String packageName, String[] requiredPermissions) {
+ Log.v(Utils.TAG, "PIOTR'S VERSION. Getting package info for '" + packageName + "'");
+ for (String permission : nonNullStrings(requiredPermissions)) {
+ if (context.getPackageManager().checkPermission(permission, packageName) == PackageManager.PERMISSION_DENIED) {
+ Log.w(Utils.TAG, "Package '" + packageName + "' does not have the required permission '" + permission + "' to run this probe.");
+ return false;
+ }
+ }
+ return true;
}
/**
commit ac6456c09951d54b7f9c011a22ffa8601d511c29
Author: Piotr <[email protected]>
Date: Sat Dec 8 13:24:27 2012 +0100
added the counter in UploadService.java to prevent uploading too long a backlog
diff --git a/funf-open-sensing-framework/src/edu/mit/media/funf/AsyncSharedPrefs.java b/funf-open-sensing-framework/src/edu/mit/media/funf/AsyncSharedPrefs.java
index 43c5618..34702e0 100644
--- a/funf-open-sensing-framework/src/edu/mit/media/funf/AsyncSharedPrefs.java
+++ b/funf-open-sensing-framework/src/edu/mit/media/funf/AsyncSharedPrefs.java
@@ -254,6 +254,16 @@ public class AsyncSharedPrefs implements SharedPreferences, OnSharedPreferenceCh
}).start();
return true;
}
+ @Override
+ public void apply() {
+ // TODO Auto-generated method stub
+
+ }
+ @Override
+ public Editor putStringSet(String arg0, Set<String> arg1) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
@@ -296,4 +306,10 @@ public class AsyncSharedPrefs implements SharedPreferences, OnSharedPreferenceCh
}).start();
}
+ @Override
+ public Set<String> getStringSet(String arg0, Set<String> arg1) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
diff --git a/funf-open-sensing-framework/src/edu/mit/media/funf/storage/UploadService.java b/funf-open-sensing-framework/src/edu/mit/media/funf/storage/UploadService.java
index 49b49bf..f94ae9b 100644
--- a/funf-open-sensing-framework/src/edu/mit/media/funf/storage/UploadService.java
+++ b/funf-open-sensing-framework/src/edu/mit/media/funf/storage/UploadService.java
@@ -109,8 +109,15 @@ public abstract class UploadService extends Service {
Archive<File> archive = getArchive(archiveName);
RemoteArchive remoteArchive = getRemoteArchive(remoteArchiveName);
if (archive != null && remoteArchive != null) {
+ int counter = 0;
for (File file : archive.getAll()) {
+ Log.d("FileCounter","File ID: " + counter);
archive(archive, remoteArchive, file, network);
+ if (counter == 50) {
+ break;
+ } else {
+ counter++;
+ }
}
}
}
@@ -144,7 +151,7 @@ public abstract class UploadService extends Service {
public void archive(Archive<File> archive, RemoteArchive remoteArchive, File file, int network) {
ArchiveFile archiveFile = new ArchiveFile(archive, remoteArchive, file, network);
if (!filesToUpload.contains(archiveFile)) {
- Log.i(TAG, "Queuing " + file.getName());
+ Log.i(TAG, "Putting to a queue " + file.getName());
filesToUpload.offer(archiveFile);
}
}