Skip to content
This repository was archived by the owner on Feb 12, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions daemon/src/main/java/org/lsposed/lspd/service/PackageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

import org.lsposed.lspd.models.Application;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
Expand Down Expand Up @@ -345,10 +347,47 @@ public static void clearApplicationProfileData(String packageName) throws Remote
}

public static boolean performDexOptMode(String packageName) throws RemoteException {
IPackageManager pm = getPackageManager();
if (pm == null) return false;
return pm.performDexOptMode(packageName,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
Process process = null;
try {
// The 'speed-profile' filter is a balanced choice for performance.
String command = "cmd package compile -m speed-profile -f " + packageName;
process = Runtime.getRuntime().exec(command);

// Capture and log the output for debugging.
StringBuilder output = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append("\n");
}
}

int exitCode = process.waitFor();
Log.i(TAG, "Dexopt command finished for " + packageName + " with exit code: " + exitCode);

// A successful command returns exit code 0 and typically "Success" in its output.
return exitCode == 0 && output.toString().contains("Success");

} catch (Exception e) {
Log.e(TAG, "Failed to execute dexopt shell command for " + packageName, e);
if (e instanceof InterruptedException) {
// Preserve the interrupted status.
Thread.currentThread().interrupt();
}
return false;
} finally {
if (process != null) {
process.destroy();
}
}
} else {
// Fallback to the original reflection method for older Android versions.
IPackageManager pm = getPackageManager();
if (pm == null) return false;
return pm.performDexOptMode(packageName,
SystemProperties.getBoolean("dalvik.vm.usejitprofiles", false),
SystemProperties.get("pm.dexopt.install", "speed-profile"), true, true, null);
}
}
}