Decouple persist and check logic

Move the persist to DB call outside of check call,
this way, we can still persist even when the current
checked actvity is in the black list.

Signed-off-by: Martin Abente Lahaye <tch@sugarlabs.org>
Simplify tracking logic

Instead of trying to track invidual application intances,
simply group usage time per day.

This approach losses detail but transfer the memory weight
to the disk instead of the ram, and allows to make the services
more robust against unavoidable restart scenarios.

Signed-off-by: Martin Abente Lahaye <tch@sugarlabs.org>
Increase duration instead of replacing it

Now that we are simplifying the logic of how this works,
we need to increase existing values in the DB with the samples
that have been collected in the memory.

Signed-off-by: Martin Abente Lahaye <tch@sugarlabs.org>
Clear in-memory entries instead of DB entries

From now on, the in-memory entries will work as a temporary
cache for the usage time thats happen between each time the
service persist data in the DB.

Signed-off-by: Martin Abente Lahaye <tch@sugarlabs.org>
Use monotonic time for delta calculation

Rely on SystemClock.elapsedRealtime() for usage-time delta
calculations. This is necessary to avoid problems with time
changes when the service is running.

Signed-off-by: Martin Abente Lahaye <tch@sugarlabs.org>
Close db and cursor explicitely

Signed-off-by: Martin Abente Lahaye <tch@sugarlabs.org>
Report only new entries

Use HarvestSettings.getLastReported to filter entries that
will be reported, to only those that were created after the
last report.

Signed-off-by: Martin Abente Lahaye <tch@sugarlabs.org>
Report to server on a separate thread asynchronously

Move HTTP communication bits inside an AsyncTask. This way
the service won't block while its reporting data to the
server.

This is also necessary to comply with strict Android checks.

Signed-off-by: Martin Abente Lahaye <tch@sugarlabs.org>
Include minSdkVersion in Manifest

This enables a series of policy checks that we now comply.

Signed-off-by: Martin Abente Lahaye <tch@sugarlabs.org>
Release 1.20

Signed-off-by: Martin Abente Lahaye <tch@sugarlabs.org>
Use monotonic time for all session-lived intervals checks

Move all timestamp generation logic to HarvestSettings class,
and provide two methods for getting Real (monotonic) time and
Clock time, in seconds.

This way ALL the intervals check won't be affected by system
clock adjustments.

Signed-off-by: Martin Abente Lahaye <tch@sugarlabs.org>
Start service from Activity

Do not wait until next re-start for starting the service, do
it also when the Activity is started for the first time.

Signed-off-by: Martin Abente Lahaye <tch@sugarlabs.org>
Set proper debugging level in Log calls

This will avoid unnecessary messages spam when is running
in production.

Also fix some typos in the strings.

Signed-off-by: Martin Abente Lahaye <tch@sugarlabs.org>
Release 1.21

Signed-off-by: Martin Abente Lahaye <tch@sugarlabs.org>