Make mLock non-static

This commit is contained in:
Nullptr 2023-01-11 11:03:05 +08:00
parent 0eb5899226
commit a9a5b62e5a
No known key found for this signature in database
2 changed files with 6 additions and 8 deletions

View File

@ -50,7 +50,7 @@ publishing {
register<MavenPublication>("service") {
artifactId = "service"
group = "io.github.libxposed"
version = "100"
version = "100-1.0.0"
pom {
name.set("service")
description.set("Modern Xposed Service Interface")

View File

@ -28,11 +28,11 @@ public final class RemotePreferences implements SharedPreferences {
private static final String TAG = "RemotePreferences";
private static final Object CONTENT = new Object();
private static final Lock LOCK = new ReentrantLock();
private static final Handler HANDLER = new Handler(Looper.getMainLooper());
private final XposedService mService;
private final String mGroup;
private final Lock mLock = new ReentrantLock();
private final Map<String, Object> mMap = new ConcurrentHashMap<>();
private final Map<OnSharedPreferenceChangeListener, Object> mListeners = Collections.synchronizedMap(new WeakHashMap<>());
@ -199,10 +199,8 @@ public final class RemotePreferences implements SharedPreferences {
List<String> changes = new ArrayList<>(mDelete.size() + mMap.size());
changes.addAll(mDelete);
changes.addAll(mMap.keySet());
synchronized (mListeners) {
for (var key : changes) {
mListeners.keySet().forEach(listener -> listener.onSharedPreferenceChanged(RemotePreferences.this, key));
}
for (var key : changes) {
mListeners.keySet().forEach(listener -> listener.onSharedPreferenceChanged(RemotePreferences.this, key));
}
var bundle = new Bundle();
@ -224,12 +222,12 @@ public final class RemotePreferences implements SharedPreferences {
@Override
public boolean commit() {
if (!LOCK.tryLock()) return false;
if (!mLock.tryLock()) return false;
try {
doUpdate(true);
return true;
} finally {
LOCK.unlock();
mLock.unlock();
}
}