diff options
| author | Jules Aguillon | 2025-12-26 16:43:34 +0100 |
|---|---|---|
| committer | GitHub | 2025-12-26 16:43:34 +0100 |
| commit | dab50e0572e98d00be1645e3c0843576eb1fb249 (patch) | |
| tree | 2812c2077c5afa85f0ed58a0722e163264910ef8 /srcs/juloo.keyboard2/ClipboardPinView.java | |
| parent | b40be68773939d3d3b55a819cdfe1d9e9a60bc4e (diff) | |
| download | unexpected-keyboard-dab50e0572e98d00be1645e3c0843576eb1fb249.tar.gz unexpected-keyboard-dab50e0572e98d00be1645e3c0843576eb1fb249.zip | |
Fix clipboard manager crashes (#1148)
* Fix background crash in clipboard history service
The clipboard history service might crash when the connection between
the keyboard and the system is in a bad state.
* Fix race condition in clipboard history service
The clipboard history service callback appears to be called concurrently
leading to concurrent accesses to data and to concurrent calls to
'on_clipboard_history_change'. Access are now synchronized.
* Fix clipboard manager crash when device is locked
Diffstat (limited to 'srcs/juloo.keyboard2/ClipboardPinView.java')
| -rw-r--r-- | srcs/juloo.keyboard2/ClipboardPinView.java | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/srcs/juloo.keyboard2/ClipboardPinView.java b/srcs/juloo.keyboard2/ClipboardPinView.java index 65f2f44..93c934a 100644 --- a/srcs/juloo.keyboard2/ClipboardPinView.java +++ b/srcs/juloo.keyboard2/ClipboardPinView.java @@ -30,9 +30,15 @@ public final class ClipboardPinView extends NonScrollListView { super(ctx, attrs); _entries = new ArrayList<String>(); - _persist_store = - ctx.getSharedPreferences("pinned_clipboards", Context.MODE_PRIVATE); - load_from_prefs(_persist_store, _entries); + // Storage is not be available in direct-boot mode. + _persist_store = null; + try + { + _persist_store = + ctx.getSharedPreferences("pinned_clipboards", Context.MODE_PRIVATE); + load_from_prefs(_persist_store, _entries); + } + catch (Exception _e) {} _adapter = this.new ClipboardPinEntriesAdapter(); setAdapter(_adapter); } @@ -63,8 +69,6 @@ public final class ClipboardPinView extends NonScrollListView ClipboardHistoryService.paste(_entries.get(pos)); } - void persist() { save_to_prefs(_persist_store, _entries); } - static void load_from_prefs(SharedPreferences store, List<String> dst) { String arr_s = store.getString(PERSIST_PREF, null); @@ -79,12 +83,14 @@ public final class ClipboardPinView extends NonScrollListView catch (JSONException _e) {} } - static void save_to_prefs(SharedPreferences store, List<String> entries) + void persist() { + if (_persist_store == null) + return; JSONArray arr = new JSONArray(); - for (int i = 0; i < entries.size(); i++) - arr.put(entries.get(i)); - store.edit() + for (int i = 0; i < _entries.size(); i++) + arr.put(_entries.get(i)); + _persist_store.edit() .putString(PERSIST_PREF, arr.toString()) .apply(); } |
