Only call remote file when starts with remote://

This commit is contained in:
LoveSy 2023-01-08 14:00:22 +08:00 committed by LoveSy
parent bbdc6084b9
commit 2dd0080956
2 changed files with 25 additions and 13 deletions

View File

@ -283,7 +283,18 @@ public class LSPosedContext extends XposedContext {
@Override @Override
public SharedPreferences getSharedPreferences(String name, int mode) { public SharedPreferences getSharedPreferences(String name, int mode) {
if (name == null) throw new IllegalArgumentException("name must not be null"); if (name == null) throw new IllegalArgumentException("name must not be null");
return mRemotePrefs.computeIfAbsent(name, __ -> new LSPosedRemotePreferences(service, name)); if (name.startsWith("remote://")) {
return mRemotePrefs.computeIfAbsent(name.substring(9), n -> {
try {
return new LSPosedRemotePreferences(service, n);
} catch (Throwable e) {
Log.e(TAG, "Failed to get remote preferences", e);
return null;
}
});
} else {
return mBase.getSharedPreferences(name, mode);
}
} }
@Override @Override
@ -298,11 +309,15 @@ public class LSPosedContext extends XposedContext {
@Override @Override
public FileInputStream openFileInput(String name) throws FileNotFoundException { public FileInputStream openFileInput(String name) throws FileNotFoundException {
if (name.startsWith("remote://")) {
try { try {
return new FileInputStream(service.openRemoteFile(name).getFileDescriptor()); return new FileInputStream(service.openRemoteFile(name.substring(9)).getFileDescriptor());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new FileNotFoundException(e.getMessage()); throw new FileNotFoundException(e.getMessage());
} }
} else {
return mBase.openFileInput(name);
}
} }
@Override @Override

View File

@ -2,6 +2,7 @@ package org.lsposed.lspd.impl;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.RemoteException;
import android.util.ArraySet; import android.util.ArraySet;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -49,15 +50,11 @@ public class LSPosedRemotePreferences implements SharedPreferences {
} }
}; };
public LSPosedRemotePreferences(ILSPInjectedModuleService service, String group) { public LSPosedRemotePreferences(ILSPInjectedModuleService service, String group) throws RemoteException {
try {
Bundle output = service.requestRemotePreferences(group, callback); Bundle output = service.requestRemotePreferences(group, callback);
if (output.containsKey("map")) { if (output.containsKey("map")) {
mMap.putAll((Map<String, Object>) output.getSerializable("map")); mMap.putAll((Map<String, Object>) output.getSerializable("map"));
} }
} catch (Throwable e) {
XposedBridge.log(e);
}
} }
@Override @Override