From ac13e32ade558428dedbf01a693eff00fb7faebd Mon Sep 17 00:00:00 2001 From: Dennis Arndt Date: Thu, 1 Aug 2024 13:17:58 +0200 Subject: [PATCH 1/6] update dependencies --- app/build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7352de2d..180940d1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -92,8 +92,8 @@ dependencies { implementation 'androidx.vectordrawable:vectordrawable:1.2.0' implementation 'androidx.navigation:navigation-fragment-ktx:2.7.7' implementation 'androidx.navigation:navigation-ui-ktx:2.7.7' - implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.8.3' - implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.3' + implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.8.4' + implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.4' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'androidx.preference:preference-ktx:1.2.1' implementation 'androidx.cardview:cardview:1.0.0' @@ -149,7 +149,7 @@ dependencies { //Compose // Integration with activities - implementation 'androidx.activity:activity-compose:1.9.0' + implementation 'androidx.activity:activity-compose:1.9.1' // Compose Material Design implementation 'androidx.compose.material:material:1.6.8' // Animations @@ -157,7 +157,7 @@ dependencies { // Tooling support (Previews, etc.) implementation 'androidx.compose.ui:ui-tooling:1.6.8' // Integration with ViewModels - implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.8.3' + implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.8.4' // UI Tests androidTestImplementation 'androidx.compose.ui:ui-test-junit4:1.6.8' // When using a MDC theme From 19ad05c5a4e07ffedf48dbbaafe3a1ff7e37151f Mon Sep 17 00:00:00 2001 From: Dennis Arndt Date: Thu, 1 Aug 2024 15:27:36 +0200 Subject: [PATCH 2/6] add pebblebee icon --- .../database/models/device/DeviceType.kt | 2 +- .../database/models/device/types/PebbleBee.kt | 2 +- .../main/res/drawable/ic_pebblebee_clip.xml | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/drawable/ic_pebblebee_clip.xml diff --git a/app/src/main/java/de/seemoo/at_tracking_detection/database/models/device/DeviceType.kt b/app/src/main/java/de/seemoo/at_tracking_detection/database/models/device/DeviceType.kt index e772b16d..6238952f 100644 --- a/app/src/main/java/de/seemoo/at_tracking_detection/database/models/device/DeviceType.kt +++ b/app/src/main/java/de/seemoo/at_tracking_detection/database/models/device/DeviceType.kt @@ -45,7 +45,7 @@ enum class DeviceType { FIND_MY -> R.drawable.ic_chipolo TILE -> R.drawable.ic_tile CHIPOLO -> R.drawable.ic_chipolo - PEBBLEBEE -> R.drawable.ic_baseline_device_unknown_24 + PEBBLEBEE -> R.drawable.ic_pebblebee_clip SAMSUNG -> R.drawable.ic_baseline_device_unknown_24 GALAXY_SMART_TAG -> R.drawable.ic_smarttag_icon GALAXY_SMART_TAG_PLUS -> R.drawable.ic_smarttag_icon diff --git a/app/src/main/java/de/seemoo/at_tracking_detection/database/models/device/types/PebbleBee.kt b/app/src/main/java/de/seemoo/at_tracking_detection/database/models/device/types/PebbleBee.kt index 850f6a63..fdc38ca5 100644 --- a/app/src/main/java/de/seemoo/at_tracking_detection/database/models/device/types/PebbleBee.kt +++ b/app/src/main/java/de/seemoo/at_tracking_detection/database/models/device/types/PebbleBee.kt @@ -24,7 +24,7 @@ import java.util.UUID class PebbleBee (val id: Int) : Device(), Connectable { override val imageResource: Int @DrawableRes - get() = R.drawable.ic_baseline_device_unknown_24 + get() = R.drawable.ic_pebblebee_clip override val defaultDeviceNameWithId: String get() = ATTrackingDetectionApplication.getAppContext().resources.getString(R.string.device_name_pebblebee) diff --git a/app/src/main/res/drawable/ic_pebblebee_clip.xml b/app/src/main/res/drawable/ic_pebblebee_clip.xml new file mode 100644 index 00000000..a5ecc506 --- /dev/null +++ b/app/src/main/res/drawable/ic_pebblebee_clip.xml @@ -0,0 +1,19 @@ + + + + From f3d8da64d484a0fcdb20fd405d392a1478df26e2 Mon Sep 17 00:00:00 2001 From: Dennis Arndt Date: Thu, 1 Aug 2024 22:45:17 +0200 Subject: [PATCH 3/6] update proguard rules --- app/proguard-rules.pro | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index ac1f9a7d..d56c7e96 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -84,3 +84,6 @@ # Keep ProGuard/R8 from stripping out important methods or classes -keep class * implements com.google.gson.reflect.TypeToken { *; } + +# Ensure that the DeviceType class is not stripped or obfuscated +-keep class de.seemoo.at_tracking_detection.database.models.device.DeviceType { *; } From 480166c331dc8fc907670796918836725cbdd215 Mon Sep 17 00:00:00 2001 From: Dennis Arndt Date: Mon, 5 Aug 2024 14:30:56 +0200 Subject: [PATCH 4/6] migrate to work version 2.9.0 --- .../at_tracking_detection/ATTrackingDetectionApplication.kt | 4 ++-- build.gradle | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/seemoo/at_tracking_detection/ATTrackingDetectionApplication.kt b/app/src/main/java/de/seemoo/at_tracking_detection/ATTrackingDetectionApplication.kt index 6dafe4c5..3d52d1eb 100644 --- a/app/src/main/java/de/seemoo/at_tracking_detection/ATTrackingDetectionApplication.kt +++ b/app/src/main/java/de/seemoo/at_tracking_detection/ATTrackingDetectionApplication.kt @@ -71,8 +71,8 @@ class ATTrackingDetectionApplication : Application(), Configuration.Provider { private val activityLifecycleCallbacks = ATTDLifecycleCallbacks() - override fun getWorkManagerConfiguration() = - Configuration.Builder() + override val workManagerConfiguration: Configuration + get() = Configuration.Builder() .setMinimumLoggingLevel(Log.DEBUG) .setWorkerFactory(workerFactory) .build() diff --git a/build.gradle b/build.gradle index 0feee313..0d58fa0c 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { ext.room_version = '2.6.1' ext.compose_version = '1.6.10' ext.about_libraries_version = '11.2.2' - ext.work_version = '2.8.1' + ext.work_version = '2.9.0' ext.ksp_version = '2.0.0-1.0.23' repositories { From 03a2aa8cc5a62479a5e179df99f6e0cf99a6eba8 Mon Sep 17 00:00:00 2001 From: Dennis Arndt Date: Mon, 5 Aug 2024 15:21:44 +0200 Subject: [PATCH 5/6] clean up Notification Functions and fix DeviceType Display when accessing TrackingFragment via Notification --- .../notifications/NotificationBuilder.kt | 74 +++---------------- .../notifications/NotificationService.kt | 36 +-------- .../ui/TrackingNotificationActivity.kt | 2 + .../ui/debug/DebugFragment.kt | 17 ++++- .../util/BindingAdapter.kt | 1 - .../worker/ObserveTrackerWorker.kt | 15 +++- 6 files changed, 44 insertions(+), 101 deletions(-) diff --git a/app/src/main/java/de/seemoo/at_tracking_detection/notifications/NotificationBuilder.kt b/app/src/main/java/de/seemoo/at_tracking_detection/notifications/NotificationBuilder.kt index d370f3ec..54080630 100644 --- a/app/src/main/java/de/seemoo/at_tracking_detection/notifications/NotificationBuilder.kt +++ b/app/src/main/java/de/seemoo/at_tracking_detection/notifications/NotificationBuilder.kt @@ -15,7 +15,6 @@ import de.seemoo.at_tracking_detection.R import de.seemoo.at_tracking_detection.database.models.device.BaseDevice import de.seemoo.at_tracking_detection.database.models.device.DeviceManager import de.seemoo.at_tracking_detection.database.models.device.DeviceType -import de.seemoo.at_tracking_detection.ui.MainActivity import de.seemoo.at_tracking_detection.ui.TrackingNotificationActivity import de.seemoo.at_tracking_detection.util.SharedPrefs import de.seemoo.at_tracking_detection.util.risk.RiskLevelEvaluator @@ -72,8 +71,9 @@ class NotificationBuilder @Inject constructor( // } - private fun packBundle(deviceAddress: String, notificationId: Int): Bundle = Bundle().apply { + private fun packBundle(deviceAddress: String, deviceTypeString: String, notificationId: Int): Bundle = Bundle().apply { putString("deviceAddress", deviceAddress) + putString("deviceTypeAsString", deviceTypeString) putInt("notificationId", notificationId) } @@ -94,72 +94,21 @@ class NotificationBuilder @Inject constructor( ) } - fun buildTrackingNotification( - deviceAddress: String, - notificationId: Int - ): Notification { - Timber.d("Notification with id $notificationId for device $deviceAddress has been build!") - val bundle: Bundle = packBundle(deviceAddress, notificationId) - val minutesAtLeastTracked = RiskLevelEvaluator.getMinutesAtLeastTrackedBeforeAlarm() - val notifyText = context.resources.getQuantityString( - R.plurals.notification_text_base, - minutesAtLeastTracked.toInt(), - minutesAtLeastTracked - ) - - var notification = NotificationCompat.Builder(context, NotificationConstants.CHANNEL_ID) - .setContentTitle(context.getString(R.string.notification_title_base)) - .setContentText(notifyText) - .setPriority(getNotificationPriority()) - .setContentIntent(pendingNotificationIntent(bundle, notificationId)) - .setCategory(getNotificationCategory()) - .setSmallIcon(R.drawable.ic_warning) - .setStyle(NotificationCompat.BigTextStyle().bigText(notifyText)) - .addAction( - R.drawable.ic_warning, - context.getString(R.string.notification_false_alarm), - buildPendingIntent( - bundle, - NotificationConstants.FALSE_ALARM_ACTION, - NotificationConstants.FALSE_ALARM_CODE - ) - ) - - val deviceRepository = ATTrackingDetectionApplication.getCurrentApp().deviceRepository - val device = deviceRepository.getDevice(deviceAddress) - - if (device?.deviceType != null && device.deviceType.canBeIgnored()) { - notification = notification.addAction( - R.drawable.ic_warning, - context.getString(R.string.notification_ignore_device), - buildPendingIntent( - bundle, - NotificationConstants.IGNORE_DEVICE_ACTION, - NotificationConstants.IGNORE_DEVICE_CODE - ) - ) - } - - notification = notification.setDeleteIntent( - buildPendingIntent( - bundle, - NotificationConstants.DISMISSED_ACTION, - NotificationConstants.DISMISSED_CODE - ) - ).setAutoCancel(true) - - return notification.build() - - } - fun buildTrackingNotification( baseDevice: BaseDevice, notificationId: Int ): Notification { Timber.d("Notification with id $notificationId for device ${baseDevice.address} has been build!") + val deviceAddress = baseDevice.address + val deviceTypeString: String = baseDevice.deviceType?.let { + DeviceManager.deviceTypeToString( + it + ) + } + ?: "UNKNOWN" - val bundle: Bundle = packBundle(deviceAddress, notificationId) + val bundle: Bundle = packBundle(deviceAddress, deviceTypeString, notificationId) val device = baseDevice.device val notificationText: String val notificationTitle: String @@ -223,12 +172,13 @@ class NotificationBuilder @Inject constructor( fun buildObserveTrackerNotification( deviceAddress: String, + deviceTypeString: String, notificationId: Int, observationDuration: Long, observationPositive: Boolean ): Notification { Timber.d("Notification with id $notificationId for device $deviceAddress has been build!") - val bundle: Bundle = packBundle(deviceAddress, notificationId) + val bundle: Bundle = packBundle(deviceAddress, deviceTypeString, notificationId) val notifyText = if (observationPositive) { context.resources.getQuantityString( diff --git a/app/src/main/java/de/seemoo/at_tracking_detection/notifications/NotificationService.kt b/app/src/main/java/de/seemoo/at_tracking_detection/notifications/NotificationService.kt index a30eeb67..bd99e250 100644 --- a/app/src/main/java/de/seemoo/at_tracking_detection/notifications/NotificationService.kt +++ b/app/src/main/java/de/seemoo/at_tracking_detection/notifications/NotificationService.kt @@ -27,21 +27,6 @@ class NotificationService @Inject constructor( private val notificationBuilder: NotificationBuilder, private val notificationViewModel: NotificationViewModel ) { - @SuppressLint("MissingPermission") - suspend fun sendTrackingNotification(deviceAddress: String) { - val notificationId = generateUniqueNotificationId() - notificationViewModel.insert(deviceAddress) - with(notificationManagerCompat) { - if (this.areNotificationsEnabled()) { - notify( - TRACKING_NOTIFICATION_TAG, - notificationId, - notificationBuilder.buildTrackingNotification(deviceAddress, notificationId) - ) - } - } - } - @SuppressLint("MissingPermission") suspend fun sendTrackingNotification(baseDevice: BaseDevice) { val notificationId = generateUniqueNotificationId() @@ -58,14 +43,14 @@ class NotificationService @Inject constructor( } @SuppressLint("MissingPermission") - fun sendObserveTrackerNotification(deviceAddress: String, observationDuration: Long, observationPositive: Boolean) { + fun sendObserveTrackerNotification(deviceAddress: String, deviceTypeString: String, observationDuration: Long, observationPositive: Boolean) { val notificationId = generateUniqueNotificationId() with(notificationManagerCompat) { if (this.areNotificationsEnabled()) { notify( OBSERVE_TRACKER_NOTIFICATION_TAG, notificationId, - notificationBuilder.buildObserveTrackerNotification(deviceAddress, notificationId, observationDuration, observationPositive) + notificationBuilder.buildObserveTrackerNotification(deviceAddress, deviceTypeString, notificationId, observationDuration, observationPositive) ) } } @@ -85,23 +70,6 @@ class NotificationService @Inject constructor( } } - /* - @SuppressLint("MissingPermission") - suspend fun sendObserveTrackerNotification(baseDevice: BaseDevice) { - val notificationId = notificationViewModel.insert(deviceAddress = baseDevice.address) - with(notificationManagerCompat) { - if (this.areNotificationsEnabled()) { - notify( - OBSERVE_TRACKER_NOTIFICATION_TAG, - notificationId, - notificationBuilder.buildTrackingNotification(baseDevice, notificationId) - ) - } - } - } - - */ - @SuppressLint("MissingPermission") fun sendBLEErrorNotification() { diff --git a/app/src/main/java/de/seemoo/at_tracking_detection/ui/TrackingNotificationActivity.kt b/app/src/main/java/de/seemoo/at_tracking_detection/ui/TrackingNotificationActivity.kt index 4a4577fc..5abc3a83 100644 --- a/app/src/main/java/de/seemoo/at_tracking_detection/ui/TrackingNotificationActivity.kt +++ b/app/src/main/java/de/seemoo/at_tracking_detection/ui/TrackingNotificationActivity.kt @@ -23,6 +23,7 @@ class TrackingNotificationActivity : AppCompatActivity() { navController = navHostFragment.navController val deviceAddress = intent.getStringExtra("deviceAddress") + val deviceTypeAsString = intent.getStringExtra("deviceTypeAsString") ?: "UNKNOWN" val notificationId = intent.getIntExtra("notificationId", -1) Timber.d("Tracking Activity with device $deviceAddress and notification $notificationId started!") @@ -32,6 +33,7 @@ class TrackingNotificationActivity : AppCompatActivity() { } else { val args = TrackingFragmentArgs( deviceAddress = deviceAddress, + deviceTypeAsString = deviceTypeAsString, notificationId = notificationId ).toBundle() navController.setGraph(R.navigation.tracking_navigation, args) diff --git a/app/src/main/java/de/seemoo/at_tracking_detection/ui/debug/DebugFragment.kt b/app/src/main/java/de/seemoo/at_tracking_detection/ui/debug/DebugFragment.kt index 1341f56e..0385ed1a 100644 --- a/app/src/main/java/de/seemoo/at_tracking_detection/ui/debug/DebugFragment.kt +++ b/app/src/main/java/de/seemoo/at_tracking_detection/ui/debug/DebugFragment.kt @@ -27,6 +27,7 @@ import de.seemoo.at_tracking_detection.ATTrackingDetectionApplication import de.seemoo.at_tracking_detection.R import de.seemoo.at_tracking_detection.database.models.device.BaseDevice import de.seemoo.at_tracking_detection.database.models.device.DeviceManager +import de.seemoo.at_tracking_detection.database.models.device.DeviceType import de.seemoo.at_tracking_detection.databinding.FragmentDebugBinding import de.seemoo.at_tracking_detection.notifications.NotificationService import de.seemoo.at_tracking_detection.statistics.api.Api @@ -36,6 +37,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import timber.log.Timber +import java.time.LocalDateTime import javax.inject.Inject @AndroidEntryPoint @@ -89,7 +91,20 @@ class DebugFragment : Fragment() { scanLeDevice() } view.findViewById