diff --git a/core/src/main/java/org/lsposed/lspd/core/ApplicationServiceClient.java b/core/src/main/java/org/lsposed/lspd/core/ApplicationServiceClient.java index 616b8b69..1bc6fe50 100644 --- a/core/src/main/java/org/lsposed/lspd/core/ApplicationServiceClient.java +++ b/core/src/main/java/org/lsposed/lspd/core/ApplicationServiceClient.java @@ -94,7 +94,11 @@ public class ApplicationServiceClient implements ILSPApplicationService, IBinder } @Override - public Bundle requestRemotePreference(String packageName, int userId, IBinder callback) { + public Bundle requestRemotePreference(String packageName, int userId, String group, IBinder callback) { + try { + return service.requestRemotePreference(packageName, userId, group, callback); + } catch (RemoteException | NullPointerException ignored) { + } return null; } diff --git a/core/src/main/java/org/lsposed/lspd/impl/LSPosedContext.java b/core/src/main/java/org/lsposed/lspd/impl/LSPosedContext.java index 84e84c0d..38b2263e 100644 --- a/core/src/main/java/org/lsposed/lspd/impl/LSPosedContext.java +++ b/core/src/main/java/org/lsposed/lspd/impl/LSPosedContext.java @@ -44,6 +44,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -56,6 +57,7 @@ import io.github.libxposed.XposedModuleInterface; public class LSPosedContext extends XposedContext { public static final String TAG = "LSPosedContext"; + public static final int PER_USER_RANGE = 100000; static final Set modules = ConcurrentHashMap.newKeySet(); @@ -64,6 +66,7 @@ public class LSPosedContext extends XposedContext { private final Context mBase; private final String mPackageName; private final String mApkPath; + private final Map mRemotePrefs = new ConcurrentHashMap<>(); LSPosedContext(Context base, String packageName, String apkPath) { this.mBase = base; @@ -235,7 +238,8 @@ public class LSPosedContext extends XposedContext { @Override public SharedPreferences getSharedPreferences(String name, int mode) { - throw new AbstractMethodError(); + if (name == null) throw new IllegalArgumentException("name must not be null"); + return mRemotePrefs.computeIfAbsent(name, __ -> new LSPosedRemotePreference(mPackageName, Process.myPid() / PER_USER_RANGE, name)); } @Override diff --git a/core/src/main/java/de/robv/android/xposed/XRemotePreference.java b/core/src/main/java/org/lsposed/lspd/impl/LSPosedRemotePreference.java similarity index 86% rename from core/src/main/java/de/robv/android/xposed/XRemotePreference.java rename to core/src/main/java/org/lsposed/lspd/impl/LSPosedRemotePreference.java index a9710171..81c210a7 100644 --- a/core/src/main/java/de/robv/android/xposed/XRemotePreference.java +++ b/core/src/main/java/org/lsposed/lspd/impl/LSPosedRemotePreference.java @@ -1,6 +1,7 @@ -package de.robv.android.xposed; +package org.lsposed.lspd.impl; import static org.lsposed.lspd.core.ApplicationServiceClient.serviceClient; + import android.content.SharedPreferences; import android.os.Bundle; import android.os.RemoteException; @@ -13,12 +14,13 @@ import java.util.TreeMap; import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap; +import de.robv.android.xposed.XposedBridge; import io.github.xposed.xposedservice.IXRemotePreferenceCallback; @SuppressWarnings("unchecked") -public class XRemotePreference implements SharedPreferences { +public class LSPosedRemotePreference implements SharedPreferences { - private Map mMap = new ConcurrentHashMap<>(); + private final Map mMap = new ConcurrentHashMap<>(); private static final Object CONTENT = new Object(); final WeakHashMap mListeners = new WeakHashMap<>(); @@ -27,12 +29,12 @@ public class XRemotePreference implements SharedPreferences { @Override synchronized public void onUpdate(Bundle bundle) { if (bundle.containsKey("map")) - mMap = (ConcurrentHashMap) bundle.getSerializable("map"); + mMap.putAll((Map) bundle.getSerializable("map")); if (bundle.containsKey("diff")) { for (var key : bundle.getStringArrayList("diff")) { synchronized (mListeners) { mListeners.forEach((listener, __) -> { - listener.onSharedPreferenceChanged(XRemotePreference.this, key); + listener.onSharedPreferenceChanged(LSPosedRemotePreference.this, key); }); } } @@ -40,13 +42,9 @@ public class XRemotePreference implements SharedPreferences { } }; - public XRemotePreference(String packageName) { - this(packageName, 0); - } - - public XRemotePreference(String packageName, int userId) { + public LSPosedRemotePreference(String packageName, int userId, String group) { try { - Bundle output = serviceClient.requestRemotePreference(packageName, userId, callback.asBinder()); + Bundle output = serviceClient.requestRemotePreference(packageName, userId, group, callback.asBinder()); callback.onUpdate(output); } catch (RemoteException e) { XposedBridge.log(e); @@ -124,6 +122,5 @@ public class XRemotePreference implements SharedPreferences { synchronized (mListeners) { mListeners.remove(listener); } - } } diff --git a/daemon/src/main/java/org/lsposed/lspd/service/LSPApplicationService.java b/daemon/src/main/java/org/lsposed/lspd/service/LSPApplicationService.java index a787e0e8..56ab2f7f 100644 --- a/daemon/src/main/java/org/lsposed/lspd/service/LSPApplicationService.java +++ b/daemon/src/main/java/org/lsposed/lspd/service/LSPApplicationService.java @@ -46,10 +46,10 @@ public class LSPApplicationService extends ILSPApplicationService.Stub { private final static Map, ProcessInfo> processes = new ConcurrentHashMap<>(); static class ProcessInfo implements DeathRecipient { - int uid; - int pid; - String processName; - IBinder heartBeat; + final int uid; + final int pid; + final String processName; + final IBinder heartBeat; ProcessInfo(int uid, int pid, String processName, IBinder heartBeat) throws RemoteException { this.uid = uid; @@ -96,7 +96,7 @@ public class LSPApplicationService extends ILSPApplicationService.Stub { var obfuscation = ConfigManager.getInstance().dexObfuscate(); var signatures = ObfuscationManager.getSignatures(); reply.writeInt(signatures.size() * 2); - for(Map.Entry entry : signatures.entrySet()){ + for (Map.Entry entry : signatures.entrySet()) { reply.writeString(entry.getKey()); // return val = key if obfuscation disabled reply.writeString(obfuscation ? entry.getValue() : entry.getKey()); @@ -143,9 +143,12 @@ public class LSPApplicationService extends ILSPApplicationService.Stub { } @Override - public Bundle requestRemotePreference(String packageName, int userId, IBinder callback) throws RemoteException { + public Bundle requestRemotePreference(String packageName, int userId, String group, IBinder callback) throws RemoteException { ensureRegistered(); - return null; + // TODO: Handle callback + var bundle = new Bundle(); + bundle.putSerializable("map", ConfigManager.getInstance().getModulePrefs(packageName, userId, group)); + return bundle; } @Override diff --git a/services/daemon-service/src/main/aidl/org/lsposed/lspd/service/ILSPApplicationService.aidl b/services/daemon-service/src/main/aidl/org/lsposed/lspd/service/ILSPApplicationService.aidl index 8ff6199c..e49d10f1 100644 --- a/services/daemon-service/src/main/aidl/org/lsposed/lspd/service/ILSPApplicationService.aidl +++ b/services/daemon-service/src/main/aidl/org/lsposed/lspd/service/ILSPApplicationService.aidl @@ -11,7 +11,7 @@ interface ILSPApplicationService { String getPrefsPath(String packageName); - Bundle requestRemotePreference(String packageName, int userId, IBinder callback); + Bundle requestRemotePreference(String packageName, int userId, String group, IBinder callback); ParcelFileDescriptor requestInjectedManagerBinder(out List binder); }