diff --git a/app/build.gradle b/app/build.gradle index b236582d1..5523aeddb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -81,6 +81,7 @@ dependencies { implementation project(":lib_theme") implementation project(":lib_utils") implementation project(":lib_service") + implementation project(":lib_log") implementation libs.nordic.ble.common implementation libs.nordic.ui.scanner diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 97ae6e8ff..cdb78c6e8 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -5,6 +5,8 @@ -keep class org.simpleframework.xml.core.** { *; } -keep class org.simpleframework.xml.util.** { *; } +-keep class no.nordicsemi.android.log.** { *; } + -keepattributes ElementList, Root, InnerClasses, LineNumberTable -keepclasseswithmembers class * { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d022eac1b..25355ea93 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,6 +12,16 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e982745d9..9e2bf434b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -21,6 +21,9 @@ Device Firmware Update Open DFU application. Download from Google Play. + nRF Logger + nRF Logger + Open nRF Logger application. ViewModel profiles Service profiles diff --git a/lib_log/build.gradle b/lib_log/build.gradle new file mode 100644 index 000000000..c68ef9bac --- /dev/null +++ b/lib_log/build.gradle @@ -0,0 +1,5 @@ +apply from: rootProject.file("library.gradle") + +dependencies { + implementation libs.nordic.log +} diff --git a/lib_log/src/main/AndroidManifest.xml b/lib_log/src/main/AndroidManifest.xml new file mode 100644 index 000000000..23204e16b --- /dev/null +++ b/lib_log/src/main/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/lib_log/src/main/java/no/nordicsemi/android/log/ToolboxLogger.kt b/lib_log/src/main/java/no/nordicsemi/android/log/ToolboxLogger.kt new file mode 100644 index 000000000..5aad0cea3 --- /dev/null +++ b/lib_log/src/main/java/no/nordicsemi/android/log/ToolboxLogger.kt @@ -0,0 +1,28 @@ +package no.nordicsemi.android.log + +import android.content.Context +import android.util.Log +import no.nordicsemi.android.log.annotation.LogLevel + +internal const val LOG_TAG = "nRF Toolbox" + +class ToolboxLogger( + private val context: Context, + private val key: String, +) { + + private var logSession: LogSession? = null + + fun log(@LogLevel level: Int, message: String) { + val logSession = getLogger() + if (logSession != null) { + Logger.log(logSession, LogContract.Log.Level.fromPriority(level), message) + } + Log.println(level, LOG_TAG, message) + } + + private fun getLogger(): LogSession? { + logSession = logSession ?: Logger.newSession(context, key, LOG_TAG) + return logSession + } +} diff --git a/lib_service/build.gradle b/lib_service/build.gradle index 7f85c861a..8515601d7 100644 --- a/lib_service/build.gradle +++ b/lib_service/build.gradle @@ -6,7 +6,6 @@ dependencies { implementation libs.nordic.ble.common implementation libs.nordic.ble.ktx - implementation libs.nordic.log implementation libs.nordic.ui.scanner implementation libs.lifecycle.service diff --git a/profile_bps/build.gradle b/profile_bps/build.gradle index 45260992a..5a2ccbc89 100644 --- a/profile_bps/build.gradle +++ b/profile_bps/build.gradle @@ -5,13 +5,13 @@ dependencies { implementation project(":lib_service") implementation project(":lib_theme") implementation project(":lib_utils") + implementation project(":lib_log") implementation libs.nordic.ble.common implementation libs.nordic.ble.ktx implementation libs.nordic.navigation implementation libs.nordic.theme - implementation libs.nordic.log implementation libs.nordic.ui.scanner implementation libs.bundles.compose diff --git a/profile_bps/src/main/java/no/nordicsemi/android/bps/data/BPSManager.kt b/profile_bps/src/main/java/no/nordicsemi/android/bps/data/BPSManager.kt index d5286f41e..9f2afa49a 100644 --- a/profile_bps/src/main/java/no/nordicsemi/android/bps/data/BPSManager.kt +++ b/profile_bps/src/main/java/no/nordicsemi/android/bps/data/BPSManager.kt @@ -36,8 +36,7 @@ import no.nordicsemi.android.ble.common.callback.battery.BatteryLevelResponse import no.nordicsemi.android.ble.common.callback.bps.BloodPressureMeasurementResponse import no.nordicsemi.android.ble.common.callback.bps.IntermediateCuffPressureResponse import no.nordicsemi.android.ble.ktx.asValidResponseFlow -import no.nordicsemi.android.bps.data.BPSData -import no.nordicsemi.android.bps.data.copyWithNewResponse +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.service.ConnectionObserverAdapter import java.util.* @@ -50,7 +49,8 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1 internal class BPSManager( @ApplicationContext context: Context, - private val scope: CoroutineScope + private val scope: CoroutineScope, + private val logger: ToolboxLogger ) : BleManager(context) { private var batteryLevelCharacteristic: BluetoothGattCharacteristic? = null @@ -68,6 +68,10 @@ internal class BPSManager( }.launchIn(scope) } + override fun log(priority: Int, message: String) { + logger.log(priority, message) + } + override fun getMinLogPriority(): Int { return Log.VERBOSE } diff --git a/profile_bps/src/main/java/no/nordicsemi/android/bps/repository/BPSRepository.kt b/profile_bps/src/main/java/no/nordicsemi/android/bps/repository/BPSRepository.kt index 1187201db..f01a8644b 100644 --- a/profile_bps/src/main/java/no/nordicsemi/android/bps/repository/BPSRepository.kt +++ b/profile_bps/src/main/java/no/nordicsemi/android/bps/repository/BPSRepository.kt @@ -11,18 +11,19 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import no.nordicsemi.android.bps.data.BPSData import no.nordicsemi.android.bps.data.BPSManager +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.service.BleManagerResult import javax.inject.Inject @ViewModelScoped internal class BPSRepository @Inject constructor( @ApplicationContext - private val context: Context, + private val context: Context ) { fun downloadData(device: BluetoothDevice): Flow> = callbackFlow { val scope = this - val manager = BPSManager(context, scope) + val manager = BPSManager(context, scope, ToolboxLogger(context, "BPS")) manager.dataHolder.status.onEach { trySend(it) diff --git a/profile_cgms/build.gradle b/profile_cgms/build.gradle index 129cd8749..4b3823120 100644 --- a/profile_cgms/build.gradle +++ b/profile_cgms/build.gradle @@ -5,11 +5,11 @@ dependencies { implementation project(":lib_service") implementation project(":lib_theme") implementation project(":lib_utils") + implementation project(":lib_log") implementation libs.nordic.ble.common implementation libs.nordic.ble.ktx - implementation libs.nordic.log implementation libs.nordic.theme implementation libs.nordic.ui.scanner implementation libs.nordic.navigation diff --git a/profile_cgms/src/main/java/no/nordicsemi/android/cgms/data/CGMManager.kt b/profile_cgms/src/main/java/no/nordicsemi/android/cgms/data/CGMManager.kt index c1827dd13..979e9f43f 100644 --- a/profile_cgms/src/main/java/no/nordicsemi/android/cgms/data/CGMManager.kt +++ b/profile_cgms/src/main/java/no/nordicsemi/android/cgms/data/CGMManager.kt @@ -45,6 +45,7 @@ import no.nordicsemi.android.ble.ktx.asValidResponseFlow import no.nordicsemi.android.ble.ktx.suspend import no.nordicsemi.android.ble.ktx.suspendForValidResponse import no.nordicsemi.android.cgms.repository.toList +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.service.ConnectionObserverAdapter import no.nordicsemi.android.utils.launchWithCatch import java.util.* @@ -62,7 +63,8 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1 internal class CGMManager( context: Context, - private val scope: CoroutineScope + private val scope: CoroutineScope, + private val logger: ToolboxLogger ) : BleManager(context) { private var cgmStatusCharacteristic: BluetoothGattCharacteristic? = null @@ -95,8 +97,11 @@ internal class CGMManager( } override fun log(priority: Int, message: String) { - super.log(priority, message) - Log.d("CGM-PROFILE", message) + logger.log(priority, message) + } + + override fun getMinLogPriority(): Int { + return Log.VERBOSE } private inner class CGMManagerGattCallback : BleManagerGattCallback() { diff --git a/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMRepository.kt b/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMRepository.kt index 51b730687..39d363528 100644 --- a/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMRepository.kt +++ b/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMRepository.kt @@ -9,10 +9,10 @@ import kotlinx.coroutines.launch import no.nordicsemi.android.ble.ktx.suspend import no.nordicsemi.android.cgms.data.CGMData import no.nordicsemi.android.cgms.data.CGMManager +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.service.BleManagerResult import no.nordicsemi.android.service.ConnectingResult import no.nordicsemi.android.service.ServiceManager -import java.lang.Exception import javax.inject.Inject import javax.inject.Singleton @@ -20,7 +20,7 @@ import javax.inject.Singleton class CGMRepository @Inject constructor( @ApplicationContext private val context: Context, - private val serviceManager: ServiceManager, + private val serviceManager: ServiceManager ) { private var manager: CGMManager? = null @@ -35,7 +35,7 @@ class CGMRepository @Inject constructor( } fun start(device: BluetoothDevice, scope: CoroutineScope) { - val manager = CGMManager(context, scope) + val manager = CGMManager(context, scope, ToolboxLogger(context, "CGMS")) this.manager = manager manager.dataHolder.status.onEach { diff --git a/profile_csc/build.gradle b/profile_csc/build.gradle index 859f90046..82f77d954 100644 --- a/profile_csc/build.gradle +++ b/profile_csc/build.gradle @@ -5,11 +5,11 @@ dependencies { implementation project(":lib_service") implementation project(":lib_theme") implementation project(":lib_utils") + implementation project(":lib_log") implementation libs.nordic.ble.common implementation libs.nordic.ble.ktx - implementation libs.nordic.log implementation libs.nordic.theme implementation libs.nordic.navigation implementation libs.nordic.ui.scanner diff --git a/profile_csc/src/main/java/no/nordicsemi/android/csc/data/CSCManager.kt b/profile_csc/src/main/java/no/nordicsemi/android/csc/data/CSCManager.kt index fd87e227c..aaf5e9395 100644 --- a/profile_csc/src/main/java/no/nordicsemi/android/csc/data/CSCManager.kt +++ b/profile_csc/src/main/java/no/nordicsemi/android/csc/data/CSCManager.kt @@ -24,6 +24,7 @@ package no.nordicsemi.android.csc.data import android.bluetooth.BluetoothGatt import android.bluetooth.BluetoothGattCharacteristic import android.content.Context +import android.util.Log import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.launchIn @@ -32,8 +33,7 @@ import no.nordicsemi.android.ble.BleManager import no.nordicsemi.android.ble.common.callback.battery.BatteryLevelResponse import no.nordicsemi.android.ble.common.callback.csc.CyclingSpeedAndCadenceMeasurementResponse import no.nordicsemi.android.ble.ktx.asValidResponseFlow -import no.nordicsemi.android.csc.data.CSCData -import no.nordicsemi.android.csc.data.WheelSize +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.service.ConnectionObserverAdapter import java.util.* @@ -46,6 +46,7 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1 internal class CSCManager( context: Context, private val scope: CoroutineScope, + private val logger: ToolboxLogger ) : BleManager(context) { private var batteryLevelCharacteristic: BluetoothGattCharacteristic? = null @@ -65,6 +66,14 @@ internal class CSCManager( }.launchIn(scope) } + override fun log(priority: Int, message: String) { + logger.log(priority, message) + } + + override fun getMinLogPriority(): Int { + return Log.VERBOSE + } + override fun getGattCallback(): BleManagerGattCallback { return CSCManagerGattCallback() } diff --git a/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCRepository.kt b/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCRepository.kt index dde96028b..7fdaed7ae 100644 --- a/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCRepository.kt +++ b/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCRepository.kt @@ -10,6 +10,7 @@ import no.nordicsemi.android.ble.ktx.suspend import no.nordicsemi.android.csc.data.CSCData import no.nordicsemi.android.csc.data.CSCManager import no.nordicsemi.android.csc.data.WheelSize +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.service.BleManagerResult import no.nordicsemi.android.service.ConnectingResult import no.nordicsemi.android.service.ServiceManager @@ -20,7 +21,7 @@ import javax.inject.Singleton class CSCRepository @Inject constructor( @ApplicationContext private val context: Context, - private val serviceManager: ServiceManager, + private val serviceManager: ServiceManager ) { private var manager: CSCManager? = null @@ -35,7 +36,7 @@ class CSCRepository @Inject constructor( } fun start(device: BluetoothDevice, scope: CoroutineScope) { - val manager = CSCManager(context, scope) + val manager = CSCManager(context, scope, ToolboxLogger(context, "CSC")) this.manager = manager manager.dataHolder.status.onEach { diff --git a/profile_gls/build.gradle b/profile_gls/build.gradle index e76677f42..682278091 100644 --- a/profile_gls/build.gradle +++ b/profile_gls/build.gradle @@ -5,6 +5,7 @@ dependencies { implementation project(":lib_service") implementation project(":lib_theme") implementation project(":lib_utils") + implementation project(":lib_log") implementation libs.chart @@ -14,8 +15,6 @@ dependencies { implementation libs.nordic.ui.scanner implementation libs.nordic.navigation - implementation libs.nordic.log - implementation libs.bundles.compose implementation libs.androidx.core implementation libs.material diff --git a/profile_gls/src/main/java/no/nordicsemi/android/gls/data/GLSManager.kt b/profile_gls/src/main/java/no/nordicsemi/android/gls/data/GLSManager.kt index 55b50b8d4..89f590bea 100644 --- a/profile_gls/src/main/java/no/nordicsemi/android/gls/data/GLSManager.kt +++ b/profile_gls/src/main/java/no/nordicsemi/android/gls/data/GLSManager.kt @@ -39,6 +39,7 @@ import no.nordicsemi.android.ble.common.callback.glucose.GlucoseMeasurementRespo import no.nordicsemi.android.ble.common.data.RecordAccessControlPointData import no.nordicsemi.android.ble.ktx.asValidResponseFlow import no.nordicsemi.android.ble.ktx.suspend +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.service.ConnectionObserverAdapter import no.nordicsemi.android.utils.launchWithCatch import java.util.* @@ -58,7 +59,8 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID = internal class GLSManager @Inject constructor( @ApplicationContext context: Context, - private val scope: CoroutineScope + private val scope: CoroutineScope, + private val logger: ToolboxLogger ) : BleManager(context) { private var batteryLevelCharacteristic: BluetoothGattCharacteristic? = null @@ -77,6 +79,14 @@ internal class GLSManager @Inject constructor( }.launchIn(scope) } + override fun log(priority: Int, message: String) { + logger.log(priority, message) + } + + override fun getMinLogPriority(): Int { + return Log.VERBOSE + } + override fun getGattCallback(): BleManagerGattCallback { return GlucoseManagerGattCallback() } diff --git a/profile_gls/src/main/java/no/nordicsemi/android/gls/repository/GLSRepository.kt b/profile_gls/src/main/java/no/nordicsemi/android/gls/repository/GLSRepository.kt index d8bb73fdd..f3a497f18 100644 --- a/profile_gls/src/main/java/no/nordicsemi/android/gls/repository/GLSRepository.kt +++ b/profile_gls/src/main/java/no/nordicsemi/android/gls/repository/GLSRepository.kt @@ -14,6 +14,7 @@ import no.nordicsemi.android.ble.ktx.suspend import no.nordicsemi.android.gls.data.GLSData import no.nordicsemi.android.gls.data.GLSManager import no.nordicsemi.android.gls.data.WorkingMode +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.service.BleManagerResult import no.nordicsemi.android.utils.exhaustive import javax.inject.Inject @@ -21,14 +22,14 @@ import javax.inject.Inject @ViewModelScoped internal class GLSRepository @Inject constructor( @ApplicationContext - private val context: Context, + private val context: Context ) { private var manager: GLSManager? = null fun downloadData(device: BluetoothDevice): Flow> = callbackFlow { val scope = this - val managerInstance = manager ?: GLSManager(context, scope).apply { + val managerInstance = manager ?: GLSManager(context, scope, ToolboxLogger(context, "GLS")).apply { try { connect(device) .useAutoConnect(false) diff --git a/profile_hrs/build.gradle b/profile_hrs/build.gradle index 84d45e316..64ef56eff 100644 --- a/profile_hrs/build.gradle +++ b/profile_hrs/build.gradle @@ -5,6 +5,7 @@ dependencies { implementation project(":lib_service") implementation project(":lib_theme") implementation project(":lib_utils") + implementation project(":lib_log") implementation libs.chart @@ -14,8 +15,6 @@ dependencies { implementation libs.nordic.navigation implementation libs.nordic.ui.scanner - implementation libs.nordic.log - implementation libs.bundles.compose implementation libs.androidx.core implementation libs.material diff --git a/profile_hrs/src/main/java/no/nordicsemi/android/hrs/data/HRSManager.kt b/profile_hrs/src/main/java/no/nordicsemi/android/hrs/data/HRSManager.kt index 287156bbd..fbde12f9f 100644 --- a/profile_hrs/src/main/java/no/nordicsemi/android/hrs/data/HRSManager.kt +++ b/profile_hrs/src/main/java/no/nordicsemi/android/hrs/data/HRSManager.kt @@ -24,6 +24,7 @@ package no.nordicsemi.android.hrs.data import android.bluetooth.BluetoothGatt import android.bluetooth.BluetoothGattCharacteristic import android.content.Context +import android.util.Log import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.launchIn @@ -34,6 +35,7 @@ import no.nordicsemi.android.ble.common.callback.hr.BodySensorLocationResponse import no.nordicsemi.android.ble.common.callback.hr.HeartRateMeasurementResponse import no.nordicsemi.android.ble.ktx.asValidResponseFlow import no.nordicsemi.android.ble.ktx.suspendForValidResponse +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.service.ConnectionObserverAdapter import no.nordicsemi.android.utils.launchWithCatch import java.util.* @@ -48,6 +50,7 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1 internal class HRSManager( context: Context, private val scope: CoroutineScope, + private val logger: ToolboxLogger ) : BleManager(context) { private var batteryLevelCharacteristic: BluetoothGattCharacteristic? = null @@ -65,6 +68,14 @@ internal class HRSManager( }.launchIn(scope) } + override fun log(priority: Int, message: String) { + logger.log(priority, message) + } + + override fun getMinLogPriority(): Int { + return Log.VERBOSE + } + override fun getGattCallback(): BleManagerGattCallback { return HeartRateManagerCallback() } diff --git a/profile_hrs/src/main/java/no/nordicsemi/android/hrs/service/HRSRepository.kt b/profile_hrs/src/main/java/no/nordicsemi/android/hrs/service/HRSRepository.kt index ca18a1308..4d5ba9f5f 100644 --- a/profile_hrs/src/main/java/no/nordicsemi/android/hrs/service/HRSRepository.kt +++ b/profile_hrs/src/main/java/no/nordicsemi/android/hrs/service/HRSRepository.kt @@ -9,6 +9,7 @@ import kotlinx.coroutines.launch import no.nordicsemi.android.ble.ktx.suspend import no.nordicsemi.android.hrs.data.HRSData import no.nordicsemi.android.hrs.data.HRSManager +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.service.BleManagerResult import no.nordicsemi.android.service.ConnectingResult import no.nordicsemi.android.service.ServiceManager @@ -19,7 +20,7 @@ import javax.inject.Singleton class HRSRepository @Inject constructor( @ApplicationContext private val context: Context, - private val serviceManager: ServiceManager, + private val serviceManager: ServiceManager ) { private var manager: HRSManager? = null @@ -34,7 +35,7 @@ class HRSRepository @Inject constructor( } fun start(device: BluetoothDevice, scope: CoroutineScope) { - val manager = HRSManager(context, scope) + val manager = HRSManager(context, scope, ToolboxLogger(context, "HRS")) this.manager = manager manager.dataHolder.status.onEach { diff --git a/profile_hts/build.gradle b/profile_hts/build.gradle index 129cd8749..4b3823120 100644 --- a/profile_hts/build.gradle +++ b/profile_hts/build.gradle @@ -5,11 +5,11 @@ dependencies { implementation project(":lib_service") implementation project(":lib_theme") implementation project(":lib_utils") + implementation project(":lib_log") implementation libs.nordic.ble.common implementation libs.nordic.ble.ktx - implementation libs.nordic.log implementation libs.nordic.theme implementation libs.nordic.ui.scanner implementation libs.nordic.navigation diff --git a/profile_hts/src/main/java/no/nordicsemi/android/hts/data/HTSManager.kt b/profile_hts/src/main/java/no/nordicsemi/android/hts/data/HTSManager.kt index e8770758d..a4c312e75 100644 --- a/profile_hts/src/main/java/no/nordicsemi/android/hts/data/HTSManager.kt +++ b/profile_hts/src/main/java/no/nordicsemi/android/hts/data/HTSManager.kt @@ -24,6 +24,7 @@ package no.nordicsemi.android.hts.data import android.bluetooth.BluetoothGatt import android.bluetooth.BluetoothGattCharacteristic import android.content.Context +import android.util.Log import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.launchIn @@ -32,7 +33,7 @@ import no.nordicsemi.android.ble.BleManager import no.nordicsemi.android.ble.common.callback.battery.BatteryLevelResponse import no.nordicsemi.android.ble.common.callback.ht.TemperatureMeasurementResponse import no.nordicsemi.android.ble.ktx.asValidResponseFlow -import no.nordicsemi.android.hts.data.HTSData +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.service.ConnectionObserverAdapter import java.util.* @@ -45,6 +46,7 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1 internal class HTSManager internal constructor( context: Context, private val scope: CoroutineScope, + private val logger: ToolboxLogger ) : BleManager(context) { private var batteryLevelCharacteristic: BluetoothGattCharacteristic? = null @@ -61,6 +63,14 @@ internal class HTSManager internal constructor( }.launchIn(scope) } + override fun log(priority: Int, message: String) { + logger.log(priority, message) + } + + override fun getMinLogPriority(): Int { + return Log.VERBOSE + } + override fun getGattCallback(): BleManagerGattCallback { return HTManagerGattCallback() } diff --git a/profile_hts/src/main/java/no/nordicsemi/android/hts/repository/HTSRepository.kt b/profile_hts/src/main/java/no/nordicsemi/android/hts/repository/HTSRepository.kt index d0870c492..f3ce5923d 100644 --- a/profile_hts/src/main/java/no/nordicsemi/android/hts/repository/HTSRepository.kt +++ b/profile_hts/src/main/java/no/nordicsemi/android/hts/repository/HTSRepository.kt @@ -9,6 +9,7 @@ import kotlinx.coroutines.launch import no.nordicsemi.android.ble.ktx.suspend import no.nordicsemi.android.hts.data.HTSData import no.nordicsemi.android.hts.data.HTSManager +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.service.BleManagerResult import no.nordicsemi.android.service.ConnectingResult import no.nordicsemi.android.service.ServiceManager @@ -19,7 +20,7 @@ import javax.inject.Singleton class HTSRepository @Inject constructor( @ApplicationContext private val context: Context, - private val serviceManager: ServiceManager, + private val serviceManager: ServiceManager ) { private var manager: HTSManager? = null @@ -34,7 +35,7 @@ class HTSRepository @Inject constructor( } fun start(device: BluetoothDevice, scope: CoroutineScope) { - val manager = HTSManager(context, scope) + val manager = HTSManager(context, scope, ToolboxLogger(context, "HTS")) this.manager = manager manager.dataHolder.status.onEach { diff --git a/profile_prx/build.gradle b/profile_prx/build.gradle index 20e406b3c..0f6774540 100644 --- a/profile_prx/build.gradle +++ b/profile_prx/build.gradle @@ -5,12 +5,12 @@ dependencies { implementation project(":lib_service") implementation project(":lib_theme") implementation project(":lib_utils") + implementation project(":lib_log") implementation libs.nordic.ble.common implementation libs.nordic.ble.ktx implementation libs.nordic.theme - implementation libs.nordic.log implementation libs.nordic.ui.scanner implementation libs.nordic.navigation diff --git a/profile_prx/src/main/java/no/nordicsemi/android/prx/data/PRXManager.kt b/profile_prx/src/main/java/no/nordicsemi/android/prx/data/PRXManager.kt index d85a8a551..e05cd03a8 100644 --- a/profile_prx/src/main/java/no/nordicsemi/android/prx/data/PRXManager.kt +++ b/profile_prx/src/main/java/no/nordicsemi/android/prx/data/PRXManager.kt @@ -26,6 +26,7 @@ import android.bluetooth.BluetoothGatt import android.bluetooth.BluetoothGattCharacteristic import android.bluetooth.BluetoothGattServer import android.content.Context +import android.util.Log import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.launchIn @@ -36,8 +37,7 @@ import no.nordicsemi.android.ble.common.callback.battery.BatteryLevelResponse import no.nordicsemi.android.ble.common.data.alert.AlertLevelData import no.nordicsemi.android.ble.ktx.asValidResponseFlow import no.nordicsemi.android.ble.ktx.suspend -import no.nordicsemi.android.prx.data.AlarmLevel -import no.nordicsemi.android.prx.data.PRXData +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.service.ConnectionObserverAdapter import no.nordicsemi.android.utils.launchWithCatch import java.util.* @@ -52,6 +52,7 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1 internal class PRXManager( context: Context, private val scope: CoroutineScope, + private val logger: ToolboxLogger ) : BleManager(context) { private var batteryLevelCharacteristic: BluetoothGattCharacteristic? = null @@ -74,6 +75,14 @@ internal class PRXManager( }.launchIn(scope) } + override fun log(priority: Int, message: String) { + logger.log(priority, message) + } + + override fun getMinLogPriority(): Int { + return Log.VERBOSE + } + private inner class ProximityManagerGattCallback : BleManagerGattCallback() { override fun initialize() { super.initialize() diff --git a/profile_prx/src/main/java/no/nordicsemi/android/prx/repository/PRXRepository.kt b/profile_prx/src/main/java/no/nordicsemi/android/prx/repository/PRXRepository.kt index a78f134b4..0a74710b2 100644 --- a/profile_prx/src/main/java/no/nordicsemi/android/prx/repository/PRXRepository.kt +++ b/profile_prx/src/main/java/no/nordicsemi/android/prx/repository/PRXRepository.kt @@ -5,6 +5,7 @@ import android.content.Context import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.* +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.prx.data.AlarmLevel import no.nordicsemi.android.prx.data.PRXData import no.nordicsemi.android.prx.data.PRXManager @@ -36,7 +37,7 @@ class PRXRepository @Inject internal constructor( } fun start(device: BluetoothDevice, scope: CoroutineScope) { - val manager = PRXManager(context, scope) + val manager = PRXManager(context, scope, ToolboxLogger(context, "PRX")) this.manager = manager manager.useServer(proximityServerManager) diff --git a/profile_rscs/build.gradle b/profile_rscs/build.gradle index 9bf5ddae5..4b3823120 100644 --- a/profile_rscs/build.gradle +++ b/profile_rscs/build.gradle @@ -5,12 +5,12 @@ dependencies { implementation project(":lib_service") implementation project(":lib_theme") implementation project(":lib_utils") + implementation project(":lib_log") implementation libs.nordic.ble.common implementation libs.nordic.ble.ktx implementation libs.nordic.theme - implementation libs.nordic.log implementation libs.nordic.ui.scanner implementation libs.nordic.navigation diff --git a/profile_rscs/src/main/java/no/nordicsemi/android/rscs/data/RSCSManager.kt b/profile_rscs/src/main/java/no/nordicsemi/android/rscs/data/RSCSManager.kt index 6301ab0fe..021380e0e 100644 --- a/profile_rscs/src/main/java/no/nordicsemi/android/rscs/data/RSCSManager.kt +++ b/profile_rscs/src/main/java/no/nordicsemi/android/rscs/data/RSCSManager.kt @@ -24,6 +24,7 @@ package no.nordicsemi.android.rscs.data import android.bluetooth.BluetoothGatt import android.bluetooth.BluetoothGattCharacteristic import android.content.Context +import android.util.Log import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.launchIn @@ -32,10 +33,8 @@ import no.nordicsemi.android.ble.BleManager import no.nordicsemi.android.ble.common.callback.battery.BatteryLevelResponse import no.nordicsemi.android.ble.common.callback.rsc.RunningSpeedAndCadenceMeasurementResponse import no.nordicsemi.android.ble.ktx.asValidResponseFlow -import no.nordicsemi.android.ble.ktx.suspend -import no.nordicsemi.android.rscs.data.RSCSData +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.service.ConnectionObserverAdapter -import no.nordicsemi.android.utils.launchWithCatch import java.util.* val RSCS_SERVICE_UUID: UUID = UUID.fromString("00001814-0000-1000-8000-00805F9B34FB") @@ -46,7 +45,8 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1 internal class RSCSManager internal constructor( context: Context, - private val scope: CoroutineScope + private val scope: CoroutineScope, + private val logger: ToolboxLogger ) : BleManager(context) { private var batteryLevelCharacteristic: BluetoothGattCharacteristic? = null @@ -63,6 +63,14 @@ internal class RSCSManager internal constructor( }.launchIn(scope) } + override fun log(priority: Int, message: String) { + logger.log(priority, message) + } + + override fun getMinLogPriority(): Int { + return Log.VERBOSE + } + private inner class RSCManagerGattCallback : BleManagerGattCallback() { override fun initialize() { diff --git a/profile_rscs/src/main/java/no/nordicsemi/android/rscs/repository/RSCSRepository.kt b/profile_rscs/src/main/java/no/nordicsemi/android/rscs/repository/RSCSRepository.kt index 21c4ddfd8..8adcb6d13 100644 --- a/profile_rscs/src/main/java/no/nordicsemi/android/rscs/repository/RSCSRepository.kt +++ b/profile_rscs/src/main/java/no/nordicsemi/android/rscs/repository/RSCSRepository.kt @@ -7,6 +7,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch import no.nordicsemi.android.ble.ktx.suspend +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.rscs.data.RSCSData import no.nordicsemi.android.rscs.data.RSCSManager import no.nordicsemi.android.service.BleManagerResult @@ -19,7 +20,7 @@ import javax.inject.Singleton class RSCSRepository @Inject constructor( @ApplicationContext private val context: Context, - private val serviceManager: ServiceManager, + private val serviceManager: ServiceManager ) { private var manager: RSCSManager? = null @@ -34,7 +35,7 @@ class RSCSRepository @Inject constructor( } fun start(device: BluetoothDevice, scope: CoroutineScope) { - val manager = RSCSManager(context, scope) + val manager = RSCSManager(context, scope, ToolboxLogger(context, "RSCS")) this.manager = manager manager.dataHolder.status.onEach { diff --git a/profile_uart/build.gradle b/profile_uart/build.gradle index b4d95a07e..9a25a4299 100644 --- a/profile_uart/build.gradle +++ b/profile_uart/build.gradle @@ -26,6 +26,7 @@ dependencies { implementation project(":lib_service") implementation project(":lib_theme") implementation project(":lib_utils") + implementation project(":lib_log") implementation libs.room.runtime implementation libs.room.ktx @@ -34,7 +35,6 @@ dependencies { implementation libs.nordic.ble.common implementation libs.nordic.ble.ktx - implementation libs.nordic.log implementation libs.nordic.theme implementation libs.nordic.ui.scanner implementation libs.nordic.navigation diff --git a/profile_uart/src/main/java/no/nordicsemi/android/uart/data/UARTManager.kt b/profile_uart/src/main/java/no/nordicsemi/android/uart/data/UARTManager.kt index e01e63d02..046c53c2e 100644 --- a/profile_uart/src/main/java/no/nordicsemi/android/uart/data/UARTManager.kt +++ b/profile_uart/src/main/java/no/nordicsemi/android/uart/data/UARTManager.kt @@ -26,6 +26,7 @@ import android.bluetooth.BluetoothGattCharacteristic import android.bluetooth.BluetoothGattService import android.content.Context import android.text.TextUtils +import android.util.Log import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.launchIn @@ -35,6 +36,7 @@ import no.nordicsemi.android.ble.WriteRequest import no.nordicsemi.android.ble.common.callback.battery.BatteryLevelResponse import no.nordicsemi.android.ble.ktx.asFlow import no.nordicsemi.android.ble.ktx.asValidResponseFlow +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.service.ConnectionObserverAdapter import no.nordicsemi.android.utils.EMPTY import no.nordicsemi.android.utils.launchWithCatch @@ -50,6 +52,7 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1 internal class UARTManager( context: Context, private val scope: CoroutineScope, + private val logger: ToolboxLogger ) : BleManager(context) { private var batteryLevelCharacteristic: BluetoothGattCharacteristic? = null @@ -70,6 +73,14 @@ internal class UARTManager( }.launchIn(scope) } + override fun log(priority: Int, message: String) { + logger.log(priority, message) + } + + override fun getMinLogPriority(): Int { + return Log.VERBOSE + } + private inner class UARTManagerGattCallback : BleManagerGattCallback() { override fun initialize() { diff --git a/profile_uart/src/main/java/no/nordicsemi/android/uart/repository/UARTRepository.kt b/profile_uart/src/main/java/no/nordicsemi/android/uart/repository/UARTRepository.kt index b453f8583..8d5daa4f6 100644 --- a/profile_uart/src/main/java/no/nordicsemi/android/uart/repository/UARTRepository.kt +++ b/profile_uart/src/main/java/no/nordicsemi/android/uart/repository/UARTRepository.kt @@ -7,12 +7,11 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch import no.nordicsemi.android.ble.ktx.suspend +import no.nordicsemi.android.log.ToolboxLogger import no.nordicsemi.android.service.BleManagerResult import no.nordicsemi.android.service.ConnectingResult import no.nordicsemi.android.service.ServiceManager import no.nordicsemi.android.uart.data.* -import no.nordicsemi.android.uart.data.UARTData -import no.nordicsemi.android.uart.data.UARTManager import javax.inject.Inject import javax.inject.Singleton @@ -38,7 +37,7 @@ class UARTRepository @Inject internal constructor( } fun start(device: BluetoothDevice, scope: CoroutineScope) { - val manager = UARTManager(context, scope) + val manager = UARTManager(context, scope, ToolboxLogger(context, "UART")) this.manager = manager manager.dataHolder.status.onEach { diff --git a/settings.gradle b/settings.gradle index b7b751a62..dd1537ea6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -13,10 +13,7 @@ dependencyResolutionManagement { library('nordic-ble-ktx', 'no.nordicsemi.android:ble-ktx:2.4.0-beta03') library('nordic-scanner', 'no.nordicsemi.android.support.v18:scanner:1.6.0') - library('nordic-log', 'no.nordicsemi.android:log-timber:2.3.0') - library('timber-main', 'com.jakewharton.timber:timber:5.0.1') - library('timber-arcao', 'com.arcao:slf4j-timber:3.1') - bundle('icons', ['nordic-log', 'timber-main', 'timber-arcao']) + library('nordic-log', 'no.nordicsemi.android:log:2.3.0') version('commonlibraries', '1.0.5') library('nordic-ui-scanner', 'no.nordicsemi.android.common', 'uiscanner').versionRef('commonlibraries') @@ -100,6 +97,7 @@ include ':profile_uart' include ':lib_service' include ':lib_theme' include ':lib_utils' +include ':lib_log' if (file('../Android-Common-Libraries').exists()) { includeBuild('../Android-Common-Libraries')