Skip to content

Commit

Permalink
Add version check for getDeviceId (#890)
Browse files Browse the repository at this point in the history
* Add version check for getDeviceId

* Add Deprecated annotation for DEVICE_ID

add @deprecated("DEVICE_ID will be null on Android Q and above") for DEVICE_ID in ReportField
  • Loading branch information
DSOTM-pf authored Dec 10, 2021
1 parent 8456ef3 commit 805581c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class DeviceIdCollector : BaseReportFieldCollector(ReportField.DEVICE_ID) {
@Throws(Exception::class)
override fun collect(reportField: ReportField, context: Context, config: CoreConfiguration, reportBuilder: ReportBuilder, target: CrashReportData) {
@Suppress("DEPRECATION")
target.put(ReportField.DEVICE_ID, getTelephonyManager(context).deviceId)
val deviceId = if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) getTelephonyManager(context).deviceId else null
target.put(ReportField.DEVICE_ID, deviceId)
}
}
}
3 changes: 2 additions & 1 deletion acra-javacore/src/main/java/org/acra/ReportField.kt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ enum class ReportField {
/**
* Device unique ID (IMEI). Requires READ_PHONE_STATE permission.
*/
@Deprecated("DEVICE_ID will be null on Android Q and above")
DEVICE_ID,

/**
Expand Down Expand Up @@ -235,4 +236,4 @@ enum class ReportField {
* Retrieves the user IP address(es).
*/
USER_IP
}
}

0 comments on commit 805581c

Please sign in to comment.