Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ android {
resValue "string", "DEFAULT_PROFILE", "profile_8"
resValue "string", "applicationId", "org.obd.graphs.my.giulia.performance_monitor"
applicationId "org.obd.graphs.my.giulia.performance_monitor"
versionCode 88
versionCode 89
}

giulia {
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/java/org/obd/graphs/activity/Receivers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import org.obd.graphs.BACKUP_SUCCESSFUL
import org.obd.graphs.GOOGLE_SIGN_IN_GENERAL_FAILURE
import org.obd.graphs.GOOGLE_SIGN_IN_NO_CREDENTIAL_FAILURE
import org.obd.graphs.LOCATION_IS_DISABLED
import org.obd.graphs.MODULES_LIST_CHANGED_EVENT
import org.obd.graphs.Permissions
import org.obd.graphs.PowerBroadcastReceiver
import org.obd.graphs.R
Expand All @@ -64,7 +63,6 @@ import org.obd.graphs.bl.datalogger.DATA_LOGGER_SCHEDULED_STOP_EVENT
import org.obd.graphs.bl.datalogger.DATA_LOGGER_STOPPED_EVENT
import org.obd.graphs.bl.datalogger.DATA_LOGGER_WIFI_INCORRECT
import org.obd.graphs.bl.datalogger.DATA_LOGGER_WIFI_NOT_CONNECTED
import org.obd.graphs.bl.datalogger.DataLoggerRepository
import org.obd.graphs.bl.datalogger.dataLoggerSettings
import org.obd.graphs.bl.extra.EVENT_VEHICLE_STATUS_IGNITION_OFF
import org.obd.graphs.bl.extra.EVENT_VEHICLE_STATUS_IGNITION_ON
Expand Down Expand Up @@ -319,7 +317,6 @@ internal fun MainActivity.toggleNavigationItem(
internal fun MainActivity.unregisterReceiver() {
unregisterReceiver(activityBroadcastReceiver)
unregisterReceiver(powerReceiver)
unregisterReceiver(DataLoggerRepository.eventsReceiver)
}

internal fun MainActivity.registerReceiver() {
Expand Down Expand Up @@ -384,9 +381,4 @@ internal fun MainActivity.registerReceiver() {
it.addAction("android.intent.action.ACTION_POWER_CONNECTED")
it.addAction("android.intent.action.ACTION_POWER_DISCONNECTED")
}

registerReceiver(this, DataLoggerRepository.eventsReceiver) {
it.addAction(MODULES_LIST_CHANGED_EVENT)
it.addAction(PROFILE_CHANGED_EVENT)
}
}
40 changes: 28 additions & 12 deletions common/src/main/java/org/obd/graphs/Broadcast.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,42 @@ import android.os.Build

private const val EXTRA_PARAM_NAME = "extra"

fun Intent.getExtraParam(): String = extras?.get(EXTRA_PARAM_NAME) as String
fun Intent.getExtraParam(): String = extras?.get(EXTRA_PARAM_NAME) as String

fun sendBroadcastEvent(actionName: String, extra: String? = "") {
fun sendBroadcastEvent(
actionName: String,
extra: String? = "",
) {
getContext()?.run {
sendBroadcast(Intent().apply {
action = actionName
putExtra(EXTRA_PARAM_NAME, extra)
})
sendBroadcast(
Intent().apply {
action = actionName
putExtra(EXTRA_PARAM_NAME, extra)
},
)
}
}

fun registerReceiver(context: Context?, receiver: BroadcastReceiver, func: (filter: IntentFilter) -> Unit){
fun registerReceiver(
context: Context?,
receiver: BroadcastReceiver,
exportReceiver: Boolean = true,
func: (filter: IntentFilter) -> Unit,
) {
context?.let {
val intent = IntentFilter()
func(intent)
val intentFilter = IntentFilter()
func(intentFilter)

if (Build.VERSION.SDK_INT >= 34 && context.applicationInfo.targetSdkVersion >= 34) {
context.registerReceiver(receiver, intent , Context.RECEIVER_EXPORTED)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
val flags =
if (exportReceiver) {
Context.RECEIVER_EXPORTED
} else {
Context.RECEIVER_NOT_EXPORTED
}
it.registerReceiver(receiver, intentFilter, flags)
} else {
context.registerReceiver(receiver,intent)
it.registerReceiver(receiver, intentFilter)
}
}
}
2 changes: 1 addition & 1 deletion datalogger/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dependencies {

implementation 'com.google.android.gms:play-services-location:21.0.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'org.slf4j:slf4j-api:1.7.25'
implementation 'com.github.tony19:logback-android:2.0.0'
implementation 'org.apache.commons:commons-collections4:4.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.obd.graphs.bl.datalogger

import android.content.BroadcastReceiver
import android.util.Log
import androidx.annotation.VisibleForTesting
import androidx.lifecycle.LifecycleOwner
Expand Down Expand Up @@ -62,8 +61,4 @@ object DataLoggerRepository {
workflowOrchestrator.observe(metricsProcessor)
return this
}


val eventsReceiver: BroadcastReceiver
get() = workflowOrchestrator.eventsReceiver
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ import android.os.Build
import android.os.IBinder
import android.util.Log
import androidx.core.app.NotificationCompat
import org.obd.graphs.MODULES_LIST_CHANGED_EVENT
import org.obd.graphs.Permissions
import org.obd.graphs.REQUEST_LOCATION_PERMISSIONS
import org.obd.graphs.REQUEST_NOTIFICATION_PERMISSIONS
import org.obd.graphs.bl.query.Query
import org.obd.graphs.datalogger.R
import org.obd.graphs.profile.PROFILE_CHANGED_EVENT
import org.obd.graphs.sendBroadcastEvent

private const val SCHEDULED_ACTION_START = "org.obd.graphs.logger.scheduled.START"
Expand Down Expand Up @@ -62,6 +64,16 @@ class DataLoggerService : Service() {
override fun onDestroy() {
super.onDestroy()
Log.i(LOG_TAG, "Destroying DataLoggerService")
unregisterReceiver(DataLoggerRepository.workflowOrchestrator.eventsReceiver)
}

override fun onCreate() {
super.onCreate()

org.obd.graphs.registerReceiver(this, DataLoggerRepository.workflowOrchestrator.eventsReceiver) {
it.addAction(MODULES_LIST_CHANGED_EVENT)
it.addAction(PROFILE_CHANGED_EVENT)
}
}

override fun onStartCommand(
Expand Down Expand Up @@ -119,9 +131,15 @@ class DataLoggerService : Service() {
}

fun updateQuery(query: Query) {
Log.i(LOG_TAG, "Updating query for strategy=${query.getStrategy()}. PIDs=${query.getIDs()}")
if (DataLoggerRepository.isRunning()) {
enqueueWork(UPDATE_QUERY) { it.putExtra(QUERY, query) }
if (DataLoggerRepository.workflowOrchestrator.isSameQuery(query)) {
if (Log.isLoggable(LOG_TAG, Log.DEBUG)) {
Log.d(LOG_TAG, "Do not update the query for strategy=${query.getStrategy()}. It is the same query that already running")
}
} else {
Log.i(LOG_TAG, "Updating query for strategy=${query.getStrategy()}. PIDs=${query.getIDs()}")
enqueueWork(UPDATE_QUERY) { it.putExtra(QUERY, query) }
}
} else {
Log.w(LOG_TAG, "No workflow is currently running. Query won't be updated.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ internal class WorkflowOrchestrator internal constructor() {
fun getCurrentQuery (): Query? = if (::currentQuery.isInitialized) currentQuery else null

fun updateQuery(query: Query) {
if (::currentQuery.isInitialized && query.getIDs() == currentQuery.getIDs()) {
if (isSameQuery(query)) {
Log.w(LOG_TAG, "Received same query=${query.getIDs()}. Do not update.")
} else {

Expand All @@ -235,6 +235,8 @@ internal class WorkflowOrchestrator internal constructor() {
currentQuery = query
}

fun isSameQuery(query: Query) = ::currentQuery.isInitialized && query.getIDs() == currentQuery.getIDs()

fun isDTCEnabled(): Boolean = workflow.pidRegistry.findBy(PIDsGroup.DTC_READ).isNotEmpty()

private fun init(preferences: DataLoggerSettings = dataLoggerSettings.instance()) = Init.builder()
Expand Down
Loading