Overview
I execute the command: adb shell cmd package compile -m speed -f my-package
immediately returned Success.
Next, I determine success with the following command.
adb shell dumpsys package my-package
The relevant result is as follows.
Dexopt state:
[my-package]
path: /data/app/~~RlA_7phUWI_QeKL5Ez0VaQ==/my-package-8Q64dwzm_qioAdSVBF3J5g==/base.apk
arm64: [status=speed-profile] [reason=bg-dexopt]
odex file size: base.art: 4712Kb base.odex: 6408Kb base.vdex: 82542Kb
The above information shows that [status=speed-profile] [reason=bg-dexopt]
did not work.
My cell phone information
Basic Information:
- adb Version: 33.0.2-8557947
- Android version: 12
- Kernel version: 5.10.66
- Whether to root: No
System Properties:
# Note: Only useful information is listed
$ adb shell getprop
[dalvik.vm.usejit]: [true]
[dalvik.vm.usejitprofiles]: [true]
[pm.dexopt.ab-ota]: [speed-profile]
[pm.dexopt.bg-dexopt]: [speed-profile]
[pm.dexopt.boot-after-ota]: [verify]
[pm.dexopt.cmdline]: [verify]
[pm.dexopt.first-boot]: [verify]
[pm.dexopt.first-use]: [speed-profile]
[pm.dexopt.inactive]: [verify]
[pm.dexopt.install]: [speed-profile]
[pm.dexopt.install-bulk]: [speed-profile]
[pm.dexopt.install-bulk-downgraded]: [verify]
[pm.dexopt.install-bulk-secondary]: [verify]
[pm.dexopt.install-bulk-secondary-downgraded]: [extract]
[pm.dexopt.install-fast]: [skip]
[pm.dexopt.post-boot]: [extract]
[pm.dexopt.shared]: [speed]
My Discovery Process
The following logs were obtained via logcat.
PackageManager: Skipped dexOpt for start by shell: my-package
Looking at the Android code, the compilation process returns PackageDexOptimizer.DEX_OPT_SKIPPED
In the DexOptHelper class, there is the following code.
/*package*/ boolean performDexOpt(DexoptOptions options) {
final Computer snapshot = mPm.snapshotComputer();
if (snapshot.getInstantAppPackageName(Binder.getCallingUid()) != null) {
return false;
} else if (snapshot.isInstantApp(options.getPackageName(), UserHandle.getCallingUserId())) {
return false;
}
if (options.isDexoptOnlySecondaryDex()) {
return mPm.getDexManager().dexoptSecondaryDex(options);
} else {
int dexoptStatus = performDexOptWithStatus(options);
return dexoptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
}
}
As you can see, the non-SecondaryDex case is considered successful as long as the result is not PackageDexOptimizer.DEX_OPT_FAILED.
My Questions
Question 1: Why did the adb shell cmd package compile
command return Success but did not take effect?
My answer. Referring to the log message above, it was ignored and processed by the system
Question 2: I compile a random package that does not exist, but it also returns Success. e.g. adb shell cmd package compile -m speed -f not-found-package
Same answer as question 1
Question 3: Why is dexOpt not allowed to run in the shell?
Additional Information
Related codes
Logs
Adjust the logging level to verbose inside the developer mode.
The following logs are obtained via logcat.
PackageManager: Skipped dexOpt for start by shell: my-package