Support list files

This commit is contained in:
LoveSy 2023-01-08 14:09:02 +08:00 committed by LoveSy
parent 2dd0080956
commit d429e51900
3 changed files with 27 additions and 2 deletions

View File

@ -288,7 +288,7 @@ public class LSPosedContext extends XposedContext {
try { try {
return new LSPosedRemotePreferences(service, n); return new LSPosedRemotePreferences(service, n);
} catch (Throwable e) { } catch (Throwable e) {
Log.e(TAG, "Failed to get remote preferences", e); log("Failed to get remote preferences", e);
return null; return null;
} }
}); });
@ -309,6 +309,7 @@ public class LSPosedContext extends XposedContext {
@Override @Override
public FileInputStream openFileInput(String name) throws FileNotFoundException { public FileInputStream openFileInput(String name) throws FileNotFoundException {
if (name == null) throw new IllegalArgumentException("name must not be null");
if (name.startsWith("remote://")) { if (name.startsWith("remote://")) {
try { try {
return new FileInputStream(service.openRemoteFile(name.substring(9)).getFileDescriptor()); return new FileInputStream(service.openRemoteFile(name.substring(9)).getFileDescriptor());
@ -399,7 +400,19 @@ public class LSPosedContext extends XposedContext {
@Override @Override
public String[] fileList() { public String[] fileList() {
throw new AbstractMethodError(); String[] remoteFiles = new String[0];
try {
remoteFiles = service.getRemoteFileList();
} catch (RemoteException e) {
log("Failed to get remote file list", e);
}
var localFiles = mBase.fileList();
var files = new String[remoteFiles.length + localFiles.length];
for (int i = 0; i < remoteFiles.length; i++) {
files[i] = "remote://" + remoteFiles[i];
}
System.arraycopy(localFiles, 0, files, remoteFiles.length, localFiles.length);
return files;
} }
@Override @Override

View File

@ -52,6 +52,16 @@ public class LSPInjectedModuleService extends ILSPInjectedModuleService.Stub {
} }
} }
@Override
public String[] getRemoteFileList() throws RemoteException {
try {
var absolutePath = ConfigFileManager.resolveModulePath(loadedModule.packageName, ".");
return absolutePath.toFile().list();
} catch (Throwable e) {
throw new RemoteException(e.getMessage());
}
}
void onUpdateRemotePreferences(String group, Bundle diff) { void onUpdateRemotePreferences(String group, Bundle diff) {
var groupCallbacks = callbacks.get(group); var groupCallbacks = callbacks.get(group);
if (groupCallbacks != null) { if (groupCallbacks != null) {

View File

@ -8,4 +8,6 @@ interface ILSPInjectedModuleService {
Bundle requestRemotePreferences(String group, IRemotePreferenceCallback callback); Bundle requestRemotePreferences(String group, IRemotePreferenceCallback callback);
ParcelFileDescriptor openRemoteFile(String path); ParcelFileDescriptor openRemoteFile(String path);
String[] getRemoteFileList();
} }