Refine service & Add flash ksu script (#2714)

This commit is contained in:
Nullptr 2023-08-28 19:52:18 +08:00 committed by GitHub
parent 4d5588778d
commit b9d282cdfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 20 deletions

View File

@ -37,7 +37,7 @@ public class LSPInjectedModuleService extends ILSPInjectedModuleService.Stub {
@Override
public Bundle requestRemotePreferences(String group, IRemotePreferenceCallback callback) {
var bundle = new Bundle();
var userId = Binder.getCallingUid() % PER_USER_RANGE;
var userId = Binder.getCallingUid() / PER_USER_RANGE;
bundle.putSerializable("map", ConfigManager.getInstance().getModulePrefs(loadedModule.packageName, userId, group));
if (callback != null) {
var groupCallbacks = callbacks.computeIfAbsent(group, k -> ConcurrentHashMap.newKeySet());

View File

@ -35,6 +35,7 @@ import androidx.annotation.NonNull;
import org.lsposed.daemon.BuildConfig;
import org.lsposed.lspd.models.Module;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -228,13 +229,25 @@ public class LSPModuleService extends IXposedService.Stub {
}
@Override
public ParcelFileDescriptor openRemoteFile(String path, int mode) throws RemoteException {
public String[] listRemoteFiles() throws RemoteException {
var userId = ensureModule();
try {
var dir = ConfigFileManager.resolveModuleDir(loadedModule.packageName, FILES_DIR, userId, Binder.getCallingUid());
var files = dir.toFile().list();
return files == null ? new String[0] : files;
} catch (IOException e) {
throw new RemoteException(e.getMessage());
}
}
@Override
public ParcelFileDescriptor openRemoteFile(String path) throws RemoteException {
var userId = ensureModule();
ConfigFileManager.ensureModuleFilePath(path);
try {
var dir = ConfigFileManager.resolveModuleDir(loadedModule.packageName, FILES_DIR, userId, Binder.getCallingUid());
return ParcelFileDescriptor.open(dir.resolve(path).toFile(), mode);
} catch (Throwable e) {
return ParcelFileDescriptor.open(dir.resolve(path).toFile(), ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_READ_WRITE);
} catch (IOException e) {
throw new RemoteException(e.getMessage());
}
}
@ -246,19 +259,7 @@ public class LSPModuleService extends IXposedService.Stub {
try {
var dir = ConfigFileManager.resolveModuleDir(loadedModule.packageName, FILES_DIR, userId, Binder.getCallingUid());
return dir.resolve(path).toFile().delete();
} catch (Throwable e) {
throw new RemoteException(e.getMessage());
}
}
@Override
public String[] listRemoteFiles() throws RemoteException {
var userId = ensureModule();
try {
var dir = ConfigFileManager.resolveModuleDir(loadedModule.packageName, FILES_DIR, userId, Binder.getCallingUid());
var files = dir.toFile().list();
return files == null ? new String[0] : files;
} catch (Throwable e) {
} catch (IOException e) {
throw new RemoteException(e.getMessage());
}
}

View File

@ -248,7 +248,7 @@ fun afterEval() = android.applicationVariants.forEach { variant ->
workingDir("${projectDir}/release")
commandLine(adb, "push", zipFileName, "/data/local/tmp/")
}
val flashTask = task<Exec>("flash${variantCapped}") {
val flashMagiskTask = task<Exec>("flashMagisk${variantCapped}") {
group = "LSPosed"
dependsOn(pushTask)
commandLine(
@ -256,9 +256,22 @@ fun afterEval() = android.applicationVariants.forEach { variant ->
"magisk --install-module /data/local/tmp/${zipFileName}"
)
}
task<Exec>("flashAndReboot${variantCapped}") {
task<Exec>("flashMagiskAndReboot${variantCapped}") {
group = "LSPosed"
dependsOn(flashTask)
dependsOn(flashMagiskTask)
commandLine(adb, "shell", "/system/bin/svc", "power", "reboot")
}
val flashKsuTask = task<Exec>("flashKsu${variantCapped}") {
group = "LSPosed"
dependsOn(pushTask)
commandLine(
adb, "shell", "su", "-c",
"ksud module install /data/local/tmp/${zipFileName}"
)
}
task<Exec>("flashKsuAndReboot${variantCapped}") {
group = "LSPosed"
dependsOn(flashKsuTask)
commandLine(adb, "shell", "/system/bin/svc", "power", "reboot")
}
}