New XSharedPreferences
This commit is contained in:
parent
4672edc4ad
commit
70f967944c
|
|
@ -8,8 +8,6 @@ import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.CompatibilityInfo;
|
import android.content.res.CompatibilityInfo;
|
||||||
import android.content.res.XResources;
|
import android.content.res.XResources;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.os.UserHandle;
|
|
||||||
|
|
||||||
import com.elderdrivers.riru.edxp.config.ConfigManager;
|
import com.elderdrivers.riru.edxp.config.ConfigManager;
|
||||||
import com.elderdrivers.riru.edxp.util.Hookers;
|
import com.elderdrivers.riru.edxp.util.Hookers;
|
||||||
|
|
@ -18,7 +16,6 @@ import com.elderdrivers.riru.edxp.util.Utils;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import de.robv.android.xposed.XC_MethodHook;
|
import de.robv.android.xposed.XC_MethodHook;
|
||||||
import de.robv.android.xposed.XC_MethodReplacement;
|
|
||||||
import de.robv.android.xposed.XposedBridge;
|
import de.robv.android.xposed.XposedBridge;
|
||||||
import de.robv.android.xposed.XposedHelpers;
|
import de.robv.android.xposed.XposedHelpers;
|
||||||
import de.robv.android.xposed.XposedInit;
|
import de.robv.android.xposed.XposedInit;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.elderdrivers.riru.edxp.config.ConfigManager;
|
||||||
import com.elderdrivers.riru.edxp.deopt.PrebuiltMethodsDeopter;
|
import com.elderdrivers.riru.edxp.deopt.PrebuiltMethodsDeopter;
|
||||||
|
|
||||||
import de.robv.android.xposed.SELinuxHelper;
|
import de.robv.android.xposed.SELinuxHelper;
|
||||||
|
import de.robv.android.xposed.XposedInit;
|
||||||
|
|
||||||
import static com.elderdrivers.riru.edxp.util.FileUtils.getDataPathPrefix;
|
import static com.elderdrivers.riru.edxp.util.FileUtils.getDataPathPrefix;
|
||||||
|
|
||||||
|
|
@ -55,6 +56,7 @@ public class NormalProxy extends BaseProxy {
|
||||||
private void forkPostCommon(int pid, boolean isSystem, String appDataDir, String niceName) {
|
private void forkPostCommon(int pid, boolean isSystem, String appDataDir, String niceName) {
|
||||||
ConfigManager.appDataDir = appDataDir;
|
ConfigManager.appDataDir = appDataDir;
|
||||||
ConfigManager.niceName = niceName;
|
ConfigManager.niceName = niceName;
|
||||||
|
XposedInit.prefsBasePath = ConfigManager.getPrefsPath("");
|
||||||
mRouter.prepare(isSystem);
|
mRouter.prepare(isSystem);
|
||||||
mRouter.onEnterChildProcess();
|
mRouter.onEnterChildProcess();
|
||||||
mRouter.loadModulesSafely(true);
|
mRouter.loadModulesSafely(true);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
package de.robv.android.xposed;
|
package de.robv.android.xposed;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.ActivityThread;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.PackageInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
@ -38,6 +41,7 @@ public final class XSharedPreferences implements SharedPreferences {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read settings from the specified file.
|
* Read settings from the specified file.
|
||||||
|
*
|
||||||
* @param prefFile The file to read the preferences from.
|
* @param prefFile The file to read the preferences from.
|
||||||
*/
|
*/
|
||||||
public XSharedPreferences(File prefFile) {
|
public XSharedPreferences(File prefFile) {
|
||||||
|
|
@ -49,6 +53,7 @@ public final class XSharedPreferences implements SharedPreferences {
|
||||||
/**
|
/**
|
||||||
* Read settings from the default preferences for a package.
|
* Read settings from the default preferences for a package.
|
||||||
* These preferences are returned by {@link PreferenceManager#getDefaultSharedPreferences}.
|
* These preferences are returned by {@link PreferenceManager#getDefaultSharedPreferences}.
|
||||||
|
*
|
||||||
* @param packageName The package name.
|
* @param packageName The package name.
|
||||||
*/
|
*/
|
||||||
public XSharedPreferences(String packageName) {
|
public XSharedPreferences(String packageName) {
|
||||||
|
|
@ -58,11 +63,24 @@ public final class XSharedPreferences implements SharedPreferences {
|
||||||
/**
|
/**
|
||||||
* Read settings from a custom preferences file for a package.
|
* Read settings from a custom preferences file for a package.
|
||||||
* These preferences are returned by {@link Context#getSharedPreferences(String, int)}.
|
* These preferences are returned by {@link Context#getSharedPreferences(String, int)}.
|
||||||
|
*
|
||||||
* @param packageName The package name.
|
* @param packageName The package name.
|
||||||
* @param prefFileName The file name without ".xml".
|
* @param prefFileName The file name without ".xml".
|
||||||
*/
|
*/
|
||||||
public XSharedPreferences(String packageName, String prefFileName) {
|
public XSharedPreferences(String packageName, String prefFileName) {
|
||||||
|
boolean newModule = false;
|
||||||
|
Set<String> modules = XposedInit.getLoadedModules();
|
||||||
|
for (String m : modules) {
|
||||||
|
if (m.contains("/" + packageName + "-")) {
|
||||||
|
PackageInfo packageInfo = ((Context) ActivityThread.currentActivityThread().getSystemContext()).getPackageManager().getPackageArchiveInfo(m, PackageManager.GET_META_DATA);
|
||||||
|
newModule = packageInfo != null && packageInfo.applicationInfo != null && packageInfo.applicationInfo.metaData.getBoolean("xposedmodule") && packageInfo.applicationInfo.metaData.getInt("xposedminversion", -1) > 92;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (newModule && XposedInit.prefsBasePath != null) {
|
||||||
|
mFile = new File(XposedInit.prefsBasePath, packageName + "/" + prefFileName + ".xml");
|
||||||
|
} else {
|
||||||
mFile = new File(Environment.getDataDirectory(), "data/" + packageName + "/shared_prefs/" + prefFileName + ".xml");
|
mFile = new File(Environment.getDataDirectory(), "data/" + packageName + "/shared_prefs/" + prefFileName + ".xml");
|
||||||
|
}
|
||||||
mFilename = mFile.getAbsolutePath();
|
mFilename = mFile.getAbsolutePath();
|
||||||
startLoadFromDisk();
|
startLoadFromDisk();
|
||||||
}
|
}
|
||||||
|
|
@ -194,7 +212,9 @@ public final class XSharedPreferences implements SharedPreferences {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<String, ?> getAll() {
|
public Map<String, ?> getAll() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
|
@ -203,7 +223,9 @@ public final class XSharedPreferences implements SharedPreferences {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getString(String key, String defValue) {
|
public String getString(String key, String defValue) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
|
@ -213,7 +235,9 @@ public final class XSharedPreferences implements SharedPreferences {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Set<String> getStringSet(String key, Set<String> defValues) {
|
public Set<String> getStringSet(String key, Set<String> defValues) {
|
||||||
|
|
@ -224,7 +248,9 @@ public final class XSharedPreferences implements SharedPreferences {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getInt(String key, int defValue) {
|
public int getInt(String key, int defValue) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
|
@ -234,7 +260,9 @@ public final class XSharedPreferences implements SharedPreferences {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long getLong(String key, long defValue) {
|
public long getLong(String key, long defValue) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
|
@ -244,7 +272,9 @@ public final class XSharedPreferences implements SharedPreferences {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public float getFloat(String key, float defValue) {
|
public float getFloat(String key, float defValue) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
|
@ -254,7 +284,9 @@ public final class XSharedPreferences implements SharedPreferences {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean getBoolean(String key, boolean defValue) {
|
public boolean getBoolean(String key, boolean defValue) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
|
@ -264,7 +296,9 @@ public final class XSharedPreferences implements SharedPreferences {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(String key) {
|
public boolean contains(String key) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
|
@ -273,21 +307,27 @@ public final class XSharedPreferences implements SharedPreferences {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Not supported by this implementation. */
|
/**
|
||||||
|
* @deprecated Not supported by this implementation.
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public Editor edit() {
|
public Editor edit() {
|
||||||
throw new UnsupportedOperationException("read-only implementation");
|
throw new UnsupportedOperationException("read-only implementation");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Not supported by this implementation. */
|
/**
|
||||||
|
* @deprecated Not supported by this implementation.
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public void registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener) {
|
public void registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener) {
|
||||||
throw new UnsupportedOperationException("listeners are not supported in this implementation");
|
throw new UnsupportedOperationException("listeners are not supported in this implementation");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Not supported by this implementation. */
|
/**
|
||||||
|
* @deprecated Not supported by this implementation.
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public void unregisterOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener) {
|
public void unregisterOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener) {
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ public final class XposedInit {
|
||||||
private static final String INSTANT_RUN_CLASS = "com.android.tools.fd.runtime.BootstrapApplication";
|
private static final String INSTANT_RUN_CLASS = "com.android.tools.fd.runtime.BootstrapApplication";
|
||||||
public static volatile boolean disableResources = false;
|
public static volatile boolean disableResources = false;
|
||||||
private static final String[] XRESOURCES_CONFLICTING_PACKAGES = {"com.sygic.aura"};
|
private static final String[] XRESOURCES_CONFLICTING_PACKAGES = {"com.sygic.aura"};
|
||||||
|
public static String prefsBasePath = null;
|
||||||
|
|
||||||
private XposedInit() {
|
private XposedInit() {
|
||||||
}
|
}
|
||||||
|
|
@ -310,6 +311,12 @@ public final class XposedInit {
|
||||||
// @GuardedBy("moduleLoadLock")
|
// @GuardedBy("moduleLoadLock")
|
||||||
private static final ArraySet<String> loadedModules = new ArraySet<>();
|
private static final ArraySet<String> loadedModules = new ArraySet<>();
|
||||||
|
|
||||||
|
public static ArraySet<String> getLoadedModules() {
|
||||||
|
synchronized (moduleLoadLock) {
|
||||||
|
return loadedModules;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean loadModules(boolean callInitZygote) throws IOException {
|
public static boolean loadModules(boolean callInitZygote) throws IOException {
|
||||||
boolean hasLoaded = !modulesLoaded.compareAndSet(false, true);
|
boolean hasLoaded = !modulesLoaded.compareAndSet(false, true);
|
||||||
if (hasLoaded) {
|
if (hasLoaded) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue