Skip to content

Commit

Permalink
Merge pull request #89 from Notificare/release/3.5.4
Browse files Browse the repository at this point in the history
3.5.4
  • Loading branch information
hpinhal committed Jun 27, 2023
2 parents 12d15ed + 364bc1e commit 29a6a33
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 33 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# CHANGELOG

- ## 3.5.3
## 3.5.4

- Prevent queued events without an associated device
- Prevent `logCustom` usage before Notificare becomes ready

## 3.5.3

- Explicit handling of Notificare Links in Deep Link notifications
- Improve supported deep links validation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "4a49089bc856715c56e1c30a1c1c3931",
"entities": [
{
"tableName": "events",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type` TEXT NOT NULL, `timestamp` INTEGER NOT NULL, `device_id` TEXT NOT NULL, `session_id` TEXT, `notification_id` TEXT, `user_id` TEXT, `data` TEXT, `ttl` INTEGER NOT NULL, `retries` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "type",
"columnName": "type",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "timestamp",
"columnName": "timestamp",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "deviceId",
"columnName": "device_id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "sessionId",
"columnName": "session_id",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "notificationId",
"columnName": "notification_id",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "userId",
"columnName": "user_id",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "data",
"columnName": "data",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "ttl",
"columnName": "ttl",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "retries",
"columnName": "retries",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '4a49089bc856715c56e1c30a1c1c3931')"
]
}
}
2 changes: 1 addition & 1 deletion notificare/src/main/java/re/notifica/internal/Version.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package re.notifica.internal

internal const val NOTIFICARE_VERSION = "3.5.3"
internal const val NOTIFICARE_VERSION = "3.5.4"
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@ import androidx.annotation.Keep
import re.notifica.Notificare
import re.notifica.internal.NotificareLogger
import re.notifica.internal.NotificareModule
import re.notifica.ktx.device
import re.notifica.ktx.eventsImplementation

@Keep
internal object NotificareCrashReporterModuleImpl : NotificareModule() {

private var defaultUncaughtExceptionHandler: Thread.UncaughtExceptionHandler? = null
private val uncaughtExceptionHandler = Thread.UncaughtExceptionHandler { thread: Thread, throwable: Throwable ->
val device = Notificare.device().currentDevice ?: run {
NotificareLogger.warning("Cannot process a crash report before the device becomes available.")
return@UncaughtExceptionHandler
}

// Save the crash report to be processed when the app recovers.
Notificare.sharedPreferences.crashReport = throwable.toEvent()
val event = Notificare.eventsImplementation().createThrowableEvent(throwable, device)
Notificare.sharedPreferences.crashReport = event
NotificareLogger.debug("Saved crash report in storage to upload on next start.")

// Let the app's default handler take over.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import re.notifica.Notificare
import re.notifica.NotificareCallback
import re.notifica.NotificareDeviceUnavailableException
import re.notifica.NotificareEventsModule
import re.notifica.NotificareInternalEventsModule
import re.notifica.NotificareNotReadyException
import re.notifica.internal.NotificareLogger
import re.notifica.internal.NotificareModule
import re.notifica.internal.NotificareUtils
Expand All @@ -18,6 +20,7 @@ import re.notifica.internal.storage.database.ktx.toEntity
import re.notifica.internal.workers.ProcessEventsWorker
import re.notifica.ktx.device
import re.notifica.ktx.session
import re.notifica.models.NotificareDevice
import re.notifica.models.NotificareEvent
import re.notifica.models.NotificareEventData

Expand Down Expand Up @@ -52,7 +55,11 @@ internal object NotificareEventsModuleImpl : NotificareModule(), NotificareEvent
// region Notificare Events Module

override suspend fun logApplicationException(throwable: Throwable) {
log(throwable.toEvent())
val device = Notificare.device().currentDevice
?: throw NotificareDeviceUnavailableException()

val event = createThrowableEvent(throwable, device)
log(event)
}

override fun logApplicationException(throwable: Throwable, callback: NotificareCallback<Unit>): Unit =
Expand All @@ -70,6 +77,8 @@ internal object NotificareEventsModuleImpl : NotificareModule(), NotificareEvent
toCallbackFunction(::logNotificationOpen)(id, callback)

override suspend fun logCustom(event: String, data: NotificareEventData?) {
if (!Notificare.isReady) throw NotificareNotReadyException()

log("re.notifica.event.custom.$event", data)
}

Expand All @@ -81,14 +90,17 @@ internal object NotificareEventsModuleImpl : NotificareModule(), NotificareEvent
// region Notificare Internal Events Module

override suspend fun log(event: String, data: NotificareEventData?, sessionId: String?, notificationId: String?) {
val device = Notificare.device().currentDevice
?: throw NotificareDeviceUnavailableException()

log(
NotificareEvent(
type = event,
timestamp = System.currentTimeMillis(),
deviceId = Notificare.device().currentDevice?.id,
deviceId = device.id,
sessionId = sessionId ?: Notificare.session().sessionId,
notificationId = notificationId,
userId = Notificare.device().currentDevice?.userId,
userId = device.userId,
data = data
)
)
Expand Down Expand Up @@ -168,28 +180,28 @@ internal object NotificareEventsModuleImpl : NotificareModule(), NotificareEvent
.build()
)
}
}

internal fun Throwable.toEvent(): NotificareEvent {
val timestamp = System.currentTimeMillis()

return NotificareEvent(
type = EVENT_APPLICATION_EXCEPTION,
timestamp = timestamp,
deviceId = Notificare.device().currentDevice?.id,
sessionId = Notificare.session().sessionId,
notificationId = null,
userId = Notificare.device().currentDevice?.userId,
data = mapOf(
"platform" to "Android",
"osVersion" to NotificareUtils.osVersion,
"deviceString" to NotificareUtils.deviceString,
"sdkVersion" to Notificare.SDK_VERSION,
"appVersion" to NotificareUtils.applicationVersion,
"timestamp" to timestamp.toString(),
"name" to this.message,
"reason" to this.cause?.toString(),
"stackSymbols" to this.stackTraceToString(),
internal fun createThrowableEvent(throwable: Throwable, device: NotificareDevice): NotificareEvent {
val timestamp = System.currentTimeMillis()

return NotificareEvent(
type = EVENT_APPLICATION_EXCEPTION,
timestamp = timestamp,
deviceId = device.id,
sessionId = Notificare.session().sessionId,
notificationId = null,
userId = device.userId,
data = mapOf(
"platform" to "Android",
"osVersion" to NotificareUtils.osVersion,
"deviceString" to NotificareUtils.deviceString,
"sdkVersion" to Notificare.SDK_VERSION,
"appVersion" to NotificareUtils.applicationVersion,
"timestamp" to timestamp.toString(),
"name" to throwable.message,
"reason" to throwable.cause?.toString(),
"stackSymbols" to throwable.stackTraceToString(),
)
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import re.notifica.internal.storage.database.dao.NotificareEventsDao
import re.notifica.internal.storage.database.entities.NotificareEventEntity

@Database(
version = 1,
version = 2,
entities = [
NotificareEventEntity::class
]
],
)
internal abstract class NotificareDatabase : RoomDatabase() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal data class NotificareEventEntity(
@PrimaryKey(autoGenerate = true) val id: Int = 0,
val type: String,
val timestamp: Long,
@ColumnInfo(name = "device_id") val deviceId: String?,
@ColumnInfo(name = "device_id") val deviceId: String,
@ColumnInfo(name = "session_id") val sessionId: String?,
@ColumnInfo(name = "notification_id") val notificationId: String?,
@ColumnInfo(name = "user_id") val userId: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public typealias NotificareEventData = Map<String, Any?>
public data class NotificareEvent(
val type: String,
val timestamp: Long,
@Json(name = "deviceID") val deviceId: String?,
@Json(name = "deviceID") val deviceId: String,
@Json(name = "sessionID") val sessionId: String?,
@Json(name = "notification") val notificationId: String?,
@Json(name = "userID") val userId: String?,
Expand Down
2 changes: 1 addition & 1 deletion variables.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {

// Maven
maven_artifact_group = 're.notifica'
maven_artifact_version = '3.5.3'
maven_artifact_version = '3.5.4'
aws_s3_access_key_id = System.env.AWS_ACCESS_KEY_ID ?: properties.getProperty('aws.s3.access_key_id')
aws_s3_secret_access_key = System.env.AWS_SECRET_ACCESS_KEY ?: properties.getProperty('aws.s3.secret_access_key')

Expand Down

0 comments on commit 29a6a33

Please sign in to comment.