AdguardTeam / AdguardTeam/ContentBlocker

updateFilterEnabled() performs synchronous SQLite writes on the UI thread, causing UI freezes

Offen
#484 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Java
Sterne
751
Forks
154
Ø Merge
28 Min.
Gemergte PRs (30 T.)
1

Beschreibung

**Description:**
The `updateFilterEnabled()` method is invoked directly inside a View `FilterViewAdapter.onClick()` callback, which always runs on the main (UI) thread. However, this method performs **synchronous SQLite write operations**, including:

* `db.beginTransaction()`
* `db.update(...)`
* `db.setTransactionSuccessful()`
* `db.endTransaction()`

These calls involve **disk I/O**, **database locking**, and **fsync operations**, all executed synchronously.
Executing them on the main thread can lead to noticeable UI jank or freezes, especially on:

* devices with slower storage
* devices under heavy I/O load
* large or fragmented database files

Because this logic is triggered inside a click handler, the UI freeze is visible as delayed button response or stuttering.

Additionally, `ApplyAndRefreshTask` is executed **after** the blocking database operations have already completed, so it does **not** prevent the UI thread from stalling.

---

### **Why this is a problem**

Android documentation explicitly warns:

> Do not access SQLiteDatabase on the main thread.
> Disk I/O can block the UI thread and cause ANRs.

This implementation violates that guideline and introduces potential jank every time a filter is enabled/disabled.

---

### **Suggested Fix**

Move the database write operation off the UI thread. After the write completes, post back to the UI thread to update the checkbox state.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.