|
|
|
@ -18,14 +18,13 @@ import android.os.IBinder
|
|
|
|
|
import android.os.PowerManager |
|
|
|
|
import android.provider.Settings |
|
|
|
|
import android.widget.Toast |
|
|
|
|
import co.zzyzx.sensorlogger.db.Record |
|
|
|
|
import co.zzyzx.sensorlogger.db.RecordRepository |
|
|
|
|
import com.github.kittinunf.fuel.Fuel |
|
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
|
import kotlinx.coroutines.GlobalScope |
|
|
|
|
import kotlinx.coroutines.delay |
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
import java.text.SimpleDateFormat |
|
|
|
|
import java.time.Instant |
|
|
|
|
import java.util.* |
|
|
|
|
import kotlin.collections.ArrayList |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun Double.format(digits: Int) = java.lang.String.format("%.${digits}f", this) |
|
|
|
@ -46,6 +45,17 @@ class EndlessService : Service(), SensorEventListener, LocationListener {
|
|
|
|
|
|
|
|
|
|
private var mLocationManager: LocationManager? = null // need to do this because of permission |
|
|
|
|
private lateinit var recRepo: RecordRepository |
|
|
|
|
private var dataTemp = ArrayList<Record>(0) |
|
|
|
|
|
|
|
|
|
fun addNewRecord(sensor: String, text: String) { |
|
|
|
|
if (dataTemp.size < 2000) { |
|
|
|
|
dataTemp.add(Record(Instant.now().toEpochMilli(), sensor, text)) |
|
|
|
|
} else { |
|
|
|
|
val toSave = dataTemp.clone() as List<Record> |
|
|
|
|
dataTemp.clear() |
|
|
|
|
recRepo.addBulkRecord(toSave) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onBind(intent: Intent): IBinder? { |
|
|
|
|
log("Some component want to bind with the service") |
|
|
|
@ -133,7 +143,7 @@ class EndlessService : Service(), SensorEventListener, LocationListener {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// we're starting a loop in a coroutine |
|
|
|
|
GlobalScope.launch(Dispatchers.IO) { |
|
|
|
|
/* GlobalScope.launch(Dispatchers.IO) { |
|
|
|
|
while (isServiceStarted) { |
|
|
|
|
launch(Dispatchers.IO) { |
|
|
|
|
pingFakeServer() |
|
|
|
@ -141,7 +151,7 @@ class EndlessService : Service(), SensorEventListener, LocationListener {
|
|
|
|
|
delay(1 * 180 * 1000) |
|
|
|
|
} |
|
|
|
|
log("End of the loop for the service") |
|
|
|
|
} |
|
|
|
|
} */ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun stopService() { |
|
|
|
@ -178,7 +188,7 @@ class EndlessService : Service(), SensorEventListener, LocationListener {
|
|
|
|
|
result.isFromMockProvider |
|
|
|
|
).joinToString(",") |
|
|
|
|
|
|
|
|
|
recRepo.addNewRecord("location", txt) |
|
|
|
|
addNewRecord("location", txt) |
|
|
|
|
val notification = createNotification(notiText) |
|
|
|
|
nm.notify(notificationId, notification) |
|
|
|
|
} |
|
|
|
@ -219,7 +229,7 @@ class EndlessService : Service(), SensorEventListener, LocationListener {
|
|
|
|
|
accelLin[1].format(3), |
|
|
|
|
accelLin[2].format(3) |
|
|
|
|
).joinToString(",") |
|
|
|
|
recRepo.addNewRecord("accelerometer", txt) |
|
|
|
|
addNewRecord("accelerometer", txt) |
|
|
|
|
} |
|
|
|
|
Sensor.TYPE_GYROSCOPE -> { |
|
|
|
|
val txt = arrayOf( |
|
|
|
@ -227,7 +237,8 @@ class EndlessService : Service(), SensorEventListener, LocationListener {
|
|
|
|
|
evt.values[1].format(3), |
|
|
|
|
evt.values[2].format(3) |
|
|
|
|
).joinToString(",") |
|
|
|
|
recRepo.addNewRecord("gyroscope", txt) |
|
|
|
|
|
|
|
|
|
addNewRecord("gyroscope", txt) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|