Skip to content

Commit 99cfeb2

Browse files
committed
fix: WxHookProvider.query() fallback to SharedPreferences when static var is null
1 parent b3fd6e6 commit 99cfeb2

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

app/src/main/java/com/nous/wxhook/db/WxHookProvider.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,18 @@ class WxHookProvider : ContentProvider() {
2929
return when (uri.path) {
3030
"/key" -> {
3131
val cursor = MatrixCursor(arrayOf("key", "time", "len"))
32-
val key = capturedKey
32+
var key = capturedKey
33+
var time = capturedTime
34+
if (key == null) {
35+
// Fallback to SharedPreferences (persists across app restarts)
36+
try {
37+
val prefs = context?.getSharedPreferences("wxhook", android.content.Context.MODE_PRIVATE)
38+
key = prefs?.getString("last_key", null)
39+
time = prefs?.getLong("last_key_time", 0) ?: 0L
40+
} catch (_: Exception) {}
41+
}
3342
if (key != null) {
34-
cursor.addRow(arrayOf(key, capturedTime, key.length / 2))
43+
cursor.addRow(arrayOf(key, time, key.length / 2))
3544
}
3645
cursor
3746
}

0 commit comments

Comments
 (0)