Merge "Add exception handling to ClockRegistry to prevent crashes" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
341b5a877a
@@ -72,18 +72,27 @@ open class ClockRegistry(
|
|||||||
|
|
||||||
open var currentClockId: ClockId
|
open var currentClockId: ClockId
|
||||||
get() {
|
get() {
|
||||||
val json = Settings.Secure.getString(
|
return try {
|
||||||
context.contentResolver,
|
val json = Settings.Secure.getString(
|
||||||
Settings.Secure.LOCK_SCREEN_CUSTOM_CLOCK_FACE
|
context.contentResolver,
|
||||||
)
|
Settings.Secure.LOCK_SCREEN_CUSTOM_CLOCK_FACE
|
||||||
return gson.fromJson(json, ClockSetting::class.java)?.clockId ?: DEFAULT_CLOCK_ID
|
)
|
||||||
|
gson.fromJson(json, ClockSetting::class.java)?.clockId ?: DEFAULT_CLOCK_ID
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
Log.e(TAG, "Failed to parse clock setting", ex)
|
||||||
|
DEFAULT_CLOCK_ID
|
||||||
|
}
|
||||||
}
|
}
|
||||||
set(value) {
|
set(value) {
|
||||||
val json = gson.toJson(ClockSetting(value, System.currentTimeMillis()))
|
try {
|
||||||
Settings.Secure.putString(
|
val json = gson.toJson(ClockSetting(value, System.currentTimeMillis()))
|
||||||
context.contentResolver,
|
Settings.Secure.putString(
|
||||||
Settings.Secure.LOCK_SCREEN_CUSTOM_CLOCK_FACE, json
|
context.contentResolver,
|
||||||
)
|
Settings.Secure.LOCK_SCREEN_CUSTOM_CLOCK_FACE, json
|
||||||
|
)
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
Log.e(TAG, "Failed to set clock setting", ex)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -170,6 +179,6 @@ open class ClockRegistry(
|
|||||||
|
|
||||||
private data class ClockSetting(
|
private data class ClockSetting(
|
||||||
val clockId: ClockId,
|
val clockId: ClockId,
|
||||||
val _applied_timestamp: Long
|
val _applied_timestamp: Long?
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user