XSharedPreferences: properly handle reg/unreg of change listeners

Throw exception in case file watcher feature is disabled.
This commit is contained in:
C3C0 2021-01-15 13:40:06 +01:00 committed by 双草酸酯
parent f8aa9d0e11
commit 1e8a94e490
1 changed files with 6 additions and 0 deletions

View File

@ -483,6 +483,9 @@ public final class XSharedPreferences implements SharedPreferences {
@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);
}
@ -491,6 +494,9 @@ public final class XSharedPreferences implements SharedPreferences {
@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);
}