Skip to content

Commit

Permalink
XSharedPreferences: properly handle reg/unreg of change listeners
Browse files Browse the repository at this point in the history
Throw exception in case file watcher feature is disabled.
  • Loading branch information
C3C0 authored and kotori2 committed Jan 15, 2021
1 parent f8aa9d0 commit 1e8a94e
Showing 1 changed file with 6 additions and 0 deletions.
Expand Up @@ -483,6 +483,9 @@ public Editor edit() {
@Deprecated
@Override
public void registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener) {
if (!mWatcherEnabled)
throw new UnsupportedOperationException("File watcher feature is disabled for this instance");

synchronized(this) {
mListeners.put(listener, sContent);
}
Expand All @@ -491,6 +494,9 @@ public void registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeLis
@Deprecated
@Override
public void unregisterOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener) {
if (!mWatcherEnabled)
throw new UnsupportedOperationException("File watcher feature is disabled for this instance");

synchronized(this) {
mListeners.remove(listener);
}
Expand Down

0 comments on commit 1e8a94e

Please sign in to comment.