[core] Prefs for modules in non-primary user space (#582)
This commit is contained in:
parent
64efa50685
commit
5032bc0b15
|
|
@ -11,7 +11,5 @@ interface ILSPApplicationService {
|
|||
|
||||
String getPrefsPath(String packageName) = 7;
|
||||
|
||||
String getCachePath(String fileName) = 8;
|
||||
|
||||
ParcelFileDescriptor getModuleLogger() = 9;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,17 +108,6 @@ public class LSPApplicationServiceClient implements ILSPApplicationService {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCachePath(String fileName) {
|
||||
try {
|
||||
if (baseCachePath == null)
|
||||
baseCachePath = service.getCachePath("");
|
||||
return baseCachePath + File.separator + fileName;
|
||||
} catch (RemoteException | NullPointerException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParcelFileDescriptor getModuleLogger() {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -36,8 +36,6 @@ import org.lsposed.lspd.util.Utils;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
|
||||
import de.robv.android.xposed.XC_MethodHook;
|
||||
|
|
@ -84,7 +82,6 @@ public class HandleBindAppHooker extends XC_MethodHook {
|
|||
boolean isModule = moduleBinder != null;
|
||||
int xposedminversion = -1;
|
||||
boolean xposedsharedprefs = false;
|
||||
boolean xposedmigrateprefs = false;
|
||||
try {
|
||||
if (isModule) {
|
||||
Map<String, Object> metaData = MetaDataReader.getMetaData(new File(appInfo.sourceDir));
|
||||
|
|
@ -95,7 +92,6 @@ public class HandleBindAppHooker extends XC_MethodHook {
|
|||
xposedminversion = MetaDataReader.extractIntPart((String) minVersionRaw);
|
||||
}
|
||||
xposedsharedprefs = metaData.containsKey("xposedsharedprefs");
|
||||
xposedmigrateprefs = metaData.containsKey("xposedmigrateprefs");
|
||||
}
|
||||
} catch (NumberFormatException | IOException e) {
|
||||
Hookers.logE("ApkParser fails", e);
|
||||
|
|
@ -113,32 +109,10 @@ public class HandleBindAppHooker extends XC_MethodHook {
|
|||
}
|
||||
}
|
||||
});
|
||||
final boolean migratePrefs = xposedmigrateprefs;
|
||||
XposedHelpers.findAndHookMethod(ContextImpl.class, "getPreferencesDir", new XC_MethodHook() {
|
||||
@Override
|
||||
protected void afterHookedMethod(MethodHookParam param) {
|
||||
File newDir = new File(serviceClient.getPrefsPath(appInfo.packageName));
|
||||
if (migratePrefs) {
|
||||
File oldDir = (File) param.getResult();
|
||||
for (File oldFile : oldDir.listFiles()) {
|
||||
Path oldPath = oldFile.toPath();
|
||||
if (!Files.isSymbolicLink(oldPath)) {
|
||||
Utils.logD("Migrating prefs file: " + oldFile.getAbsolutePath());
|
||||
Path newPath = new File(newDir, oldFile.getName()).toPath();
|
||||
try {
|
||||
Files.move(oldPath, newPath);
|
||||
try {
|
||||
Files.createSymbolicLink(oldPath, newPath);
|
||||
} catch (IOException e) {
|
||||
Utils.logD("Symlink creation failed", e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Utils.logD("File move operation failed", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
param.setResult(newDir);
|
||||
param.setResult(new File(serviceClient.getPrefsPath(appInfo.packageName)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -620,8 +620,9 @@ public class ConfigManager {
|
|||
return miscPath + File.separator + "cache" + File.separator + fileName;
|
||||
}
|
||||
|
||||
public String getPrefsPath(String fileName) {
|
||||
return miscPath + File.separator + "prefs" + File.separator + fileName;
|
||||
public String getPrefsPath(String fileName, int uid) {
|
||||
int userId = uid % PER_USER_RANGE;
|
||||
return miscPath + File.separator + "prefs" + (userId == 0 ? "" : String.valueOf(userId)) + File.separator + fileName + File.separator;
|
||||
}
|
||||
|
||||
public static void grantManagerPermission() {
|
||||
|
|
@ -651,7 +652,7 @@ public class ConfigManager {
|
|||
public boolean ensureModulePrefsPermission(int uid) {
|
||||
String packageName = cachedModule.get(uid);
|
||||
if (packageName == null) return false;
|
||||
File path = new File(getPrefsPath(packageName));
|
||||
File path = new File(getPrefsPath(packageName, uid));
|
||||
try {
|
||||
if (path.exists() && !path.isDirectory()) path.delete();
|
||||
if (!path.exists()) Files.createDirectories(path.toPath());
|
||||
|
|
|
|||
|
|
@ -79,13 +79,7 @@ public class LSPApplicationService extends ILSPApplicationService.Stub {
|
|||
@Override
|
||||
public String getPrefsPath(String packageName) throws RemoteException {
|
||||
ensureRegistered();
|
||||
return ConfigManager.getInstance().getPrefsPath(packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCachePath(String fileName) throws RemoteException {
|
||||
ensureRegistered();
|
||||
return ConfigManager.getInstance().getCachePath(fileName);
|
||||
return ConfigManager.getInstance().getPrefsPath(packageName, Binder.getCallingUid());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue