-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create new interface for diagnostics
- Loading branch information
1 parent
7ff97ab
commit 4ba7f44
Showing
8 changed files
with
411 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/kylecorry/trail_sense/diagnostics/diagnostic2/AggregateDiagnostic.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.kylecorry.trail_sense.diagnostics.diagnostic2 | ||
|
||
import com.kylecorry.andromeda.core.coroutines.onDefault | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.joinAll | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.withTimeout | ||
|
||
class AggregateDiagnostic( | ||
private val diagnostics: List<Diagnostic>, | ||
private val progressChanged: (Int, Int) -> Unit = { _, _ -> } | ||
) : Diagnostic { | ||
override suspend fun scan(): List<DiagnosticCode2> = onDefault { | ||
// Run diagnostics in parallel | ||
val codes = mutableSetOf<DiagnosticCode2>() | ||
val codeLock = Any() | ||
val progressLock = Any() | ||
val jobs = mutableListOf<Job>() | ||
var progress = 0 | ||
for (diagnostic in diagnostics) { | ||
jobs.add( | ||
launch { | ||
withTimeout(10000) { | ||
val results = diagnostic.scan() | ||
synchronized(codeLock) { | ||
codes.addAll(results) | ||
} | ||
synchronized(progressLock) { | ||
progress++ | ||
progressChanged(progress, diagnostics.size) | ||
} | ||
} | ||
} | ||
) | ||
} | ||
|
||
jobs.joinAll() | ||
|
||
codes.toList() | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/kylecorry/trail_sense/diagnostics/diagnostic2/Diagnostic.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.kylecorry.trail_sense.diagnostics.diagnostic2 | ||
|
||
interface Diagnostic { | ||
suspend fun scan(): List<DiagnosticCode2> | ||
} |
225 changes: 225 additions & 0 deletions
225
app/src/main/java/com/kylecorry/trail_sense/diagnostics/diagnostic2/DiagnosticCode2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
package com.kylecorry.trail_sense.diagnostics.diagnostic2 | ||
|
||
import com.kylecorry.trail_sense.shared.database.Identifiable | ||
|
||
enum class DiagnosticCode2(override val id: Long) : Identifiable { | ||
/** | ||
* There is no compass sensor | ||
*/ | ||
NoCompass(1), | ||
|
||
/** | ||
* The compass sensor is poor quality | ||
*/ | ||
PoorCompass(2), | ||
|
||
/** | ||
* There is no GPS | ||
*/ | ||
NoGPS(3), | ||
|
||
/** | ||
* The GPS is poor quality | ||
*/ | ||
PoorGPS(4), | ||
|
||
/** | ||
* The fine location permission is not granted | ||
*/ | ||
NoFineLocationPermission(5), | ||
|
||
/** | ||
* The background location permission is not granted | ||
*/ | ||
NoBackgroundLocationPermission(6), | ||
|
||
/** | ||
* The GPS is using a manual location | ||
*/ | ||
ManualLocation(7), | ||
|
||
/** | ||
* The GPS is using a manual location, but it is unset | ||
*/ | ||
UnsetManualLocation(8), | ||
|
||
/** | ||
* The GPS has timed out | ||
*/ | ||
TimedOutGPS(9), | ||
|
||
/** | ||
* The GPS exists, but is disabled | ||
*/ | ||
DisabledGPS(10), | ||
|
||
/** | ||
* There is no barometer sensor | ||
*/ | ||
NoBarometer(11), | ||
|
||
/** | ||
* The barometer sensor is poor quality | ||
*/ | ||
PoorBarometer(12), | ||
|
||
/** | ||
* The altimeter is using a manual elevation | ||
*/ | ||
ManualElevation(13), | ||
|
||
/** | ||
* There is no pedometer sensor | ||
*/ | ||
NoPedometer(14), | ||
|
||
/** | ||
* The activity recognition permission is not granted | ||
*/ | ||
NoActivityRecognitionPermission(15), | ||
|
||
/** | ||
* There is no gyroscope sensor | ||
*/ | ||
NoGyroscope(16), | ||
|
||
/** | ||
* The gyroscope sensor is poor quality | ||
*/ | ||
PoorGyroscope(17), | ||
|
||
/** | ||
* There is no camera | ||
*/ | ||
NoCamera(18), | ||
|
||
/** | ||
* The camera permission is not granted | ||
*/ | ||
NoCameraPermission(19), | ||
|
||
/** | ||
* The exact alarm permission is not granted | ||
*/ | ||
NoScheduleExactAlarmPermission(20), | ||
|
||
/** | ||
* The power saving mode is on | ||
*/ | ||
PowerSavingMode(21), | ||
|
||
/** | ||
* The battery usage is restricted | ||
*/ | ||
BatteryUsageRestricted(22), | ||
|
||
/** | ||
* The battery health is poor | ||
*/ | ||
BatteryHealthPoor(23), | ||
|
||
/** | ||
* There is no flashlight | ||
*/ | ||
NoFlashlight(24), | ||
|
||
/** | ||
* There is no light sensor | ||
*/ | ||
NoLightSensor(25), | ||
|
||
/** | ||
* All notifications are blocked | ||
*/ | ||
NotificationsBlocked(26), | ||
|
||
/** | ||
* The flashlight notification is blocked | ||
*/ | ||
FlashlightNotificationsBlocked(27), | ||
|
||
/** | ||
* The sunset notification is blocked | ||
*/ | ||
SunsetAlertsBlocked(28), | ||
|
||
/** | ||
* The storm notification is blocked | ||
*/ | ||
StormAlertsBlocked(29), | ||
|
||
/** | ||
* The daily forecast notification is blocked | ||
*/ | ||
DailyForecastNotificationsBlocked(30), | ||
|
||
/** | ||
* The pedometer notification is blocked | ||
*/ | ||
PedometerNotificationsBlocked(31), | ||
|
||
/** | ||
* The weather notification is blocked | ||
*/ | ||
WeatherNotificationsBlocked(32), | ||
|
||
/** | ||
* The astronomy notification is blocked | ||
*/ | ||
AstronomyAlertsBlocked(33), | ||
|
||
/** | ||
* The clock sync notification is blocked | ||
*/ | ||
ClockSyncNotificationBlocked(34), | ||
|
||
/** | ||
* The water boil notification is blocked | ||
*/ | ||
WaterBoilNotificationBlocked(35), | ||
|
||
/** | ||
* The white noise notification is blocked | ||
*/ | ||
WhiteNoiseNotificationBlocked(36), | ||
|
||
/** | ||
* The distance alert notification is blocked | ||
*/ | ||
DistanceAlertsBlocked(37), | ||
|
||
/** | ||
* The backtrack notification is blocked | ||
*/ | ||
BacktrackNotificationBlocked(38), | ||
|
||
/** | ||
* The weather monitor is disabled | ||
*/ | ||
WeatherMonitorDisabled(39), | ||
|
||
/** | ||
* The sunset alerts are disabled | ||
*/ | ||
SunsetAlertsDisabled(40), | ||
|
||
/** | ||
* The pedometer is disabled | ||
*/ | ||
PedometerDisabled(41), | ||
|
||
/** | ||
* Backtrack is disabled | ||
*/ | ||
BacktrackDisabled(42), | ||
|
||
/** | ||
* There is no accelerometer | ||
*/ | ||
NoAccelerometer(43), | ||
|
||
/** | ||
* The accelerometer is poor quality | ||
*/ | ||
PoorAccelerometer(44), | ||
} |
17 changes: 17 additions & 0 deletions
17
...n/java/com/kylecorry/trail_sense/diagnostics/diagnostic2/notifications/AlarmDiagnostic.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.kylecorry.trail_sense.diagnostics.diagnostic2.notifications | ||
|
||
import android.content.Context | ||
import com.kylecorry.andromeda.permissions.Permissions | ||
import com.kylecorry.andromeda.permissions.SpecialPermission | ||
import com.kylecorry.trail_sense.diagnostics.diagnostic2.Diagnostic | ||
import com.kylecorry.trail_sense.diagnostics.diagnostic2.DiagnosticCode2 | ||
|
||
class AlarmDiagnostic(private val context: Context) : Diagnostic { | ||
override suspend fun scan(): List<DiagnosticCode2> { | ||
if (!Permissions.hasPermission(context, SpecialPermission.SCHEDULE_EXACT_ALARMS)) { | ||
return listOf(DiagnosticCode2.NoScheduleExactAlarmPermission) | ||
} | ||
|
||
return emptyList() | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...java/com/kylecorry/trail_sense/diagnostics/diagnostic2/sensors/AccelerometerDiagnostic.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.kylecorry.trail_sense.diagnostics.diagnostic2.sensors | ||
|
||
import android.content.Context | ||
import android.hardware.Sensor | ||
import com.kylecorry.andromeda.sense.Sensors | ||
import com.kylecorry.andromeda.sense.accelerometer.Accelerometer | ||
import com.kylecorry.andromeda.sense.accelerometer.IAccelerometer | ||
import com.kylecorry.trail_sense.diagnostics.diagnostic2.DiagnosticCode2 | ||
import com.kylecorry.trail_sense.shared.sensors.SensorService | ||
|
||
class AccelerometerDiagnostic(context: Context) : BaseSensorDiagnostic<IAccelerometer>(context) { | ||
|
||
override fun getNoSensorCode(): DiagnosticCode2 { | ||
return DiagnosticCode2.NoAccelerometer | ||
} | ||
|
||
override fun getPoorSensorCode(): DiagnosticCode2 { | ||
return DiagnosticCode2.PoorAccelerometer | ||
} | ||
|
||
override fun getSensor(context: Context): IAccelerometer? { | ||
return if (Sensors.hasSensor(context, Sensor.TYPE_ACCELEROMETER)) { | ||
Accelerometer(context, SensorService.MOTION_SENSOR_DELAY) | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...ain/java/com/kylecorry/trail_sense/diagnostics/diagnostic2/sensors/BarometerDiagnostic.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.kylecorry.trail_sense.diagnostics.diagnostic2.sensors | ||
|
||
import android.content.Context | ||
import android.hardware.Sensor | ||
import com.kylecorry.andromeda.sense.Sensors | ||
import com.kylecorry.andromeda.sense.barometer.IBarometer | ||
import com.kylecorry.trail_sense.diagnostics.diagnostic2.DiagnosticCode2 | ||
import com.kylecorry.trail_sense.shared.sensors.SensorService | ||
|
||
class BarometerDiagnostic(context: Context) : BaseSensorDiagnostic<IBarometer>(context) { | ||
|
||
override fun getNoSensorCode(): DiagnosticCode2 { | ||
return DiagnosticCode2.NoBarometer | ||
} | ||
|
||
override fun getPoorSensorCode(): DiagnosticCode2 { | ||
return DiagnosticCode2.PoorBarometer | ||
} | ||
|
||
override fun getSensor(context: Context): IBarometer? { | ||
val sensors = SensorService(context) | ||
return if (Sensors.hasSensor(context, Sensor.TYPE_PRESSURE)) { | ||
sensors.getBarometer() | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.