1. int dexopt(const char *apk_path, uid_t uid, int is_public)
2. {
3. struct utimbuf ut;
4. struct stat apk_stat, dex_stat;
5. char out_path[PKG_PATH_MAX];
6. char dexopt_flags[PROPERTY_VALUE_MAX];
7. char persist_sys_dalvik_vm_lib[PROPERTY_VALUE_MAX];
8. char *end;
9. int res, zip_fd=-1, out_fd=-1;
10.
if
(strlen(apk_path) >= (PKG_PATH_MAX - 8)) {
11.
return
-1;
12. }
13. property_get(
"persist.sys.dalvik.vm.lib"
, persist_sys_dalvik_vm_lib,
"libdvm.so"
);
14. sprintf(out_path,
"%s%s"
, apk_path,
".odex"
);
15.
if
(stat(out_path, &dex_stat) == 0) {
16.
return
0;
17. }
18.
if
(create_cache_path(out_path, apk_path)) {
19.
return
-1;
20. }
21. ......
22. pid_t pid;
23. pid = fork();
24.
if
(pid == 0) {
25. ......
26.
if
(strncmp(persist_sys_dalvik_vm_lib,
"libdvm"
, 6) == 0) {
27. run_dexopt(zip_fd, out_fd, apk_path, out_path, dexopt_flags);
28. }
else
if
(strncmp(persist_sys_dalvik_vm_lib,
"libart"
, 6) == 0) {
29. run_dex2oat(zip_fd, out_fd, apk_path, out_path, dexopt_flags);
30. }
else
{
31.
exit
(69); /* Unexpected persist.sys.dalvik.vm.lib value */
32. }
33.
exit
(68); /* only get here on
exec
failure */
34. }
35. ......
36. }