blob: 78eadf255f0b7b1815966d27ffb4994d8fe70de6 [file] [log] [blame]
Andreas Gampe73dae112015-11-19 14:12:14 -08001/*
2 ** Copyright 2016, The Android Open Source Project
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16
17#include <algorithm>
18#include <inttypes.h>
Andreas Gampec4ced4f2017-04-14 20:39:56 -070019#include <limits>
Andreas Gampe73dae112015-11-19 14:12:14 -080020#include <random>
Andreas Gampe1842af32016-03-16 14:28:50 -070021#include <regex>
Andreas Gampe73dae112015-11-19 14:12:14 -080022#include <selinux/android.h>
23#include <selinux/avc.h>
24#include <stdlib.h>
25#include <string.h>
26#include <sys/capability.h>
27#include <sys/prctl.h>
28#include <sys/stat.h>
29#include <sys/wait.h>
30
31#include <android-base/logging.h>
32#include <android-base/macros.h>
33#include <android-base/stringprintf.h>
Andreas Gampe6db8db92016-06-03 10:22:19 -070034#include <android-base/strings.h>
Andreas Gampe73dae112015-11-19 14:12:14 -080035#include <cutils/fs.h>
Andreas Gampe73dae112015-11-19 14:12:14 -080036#include <cutils/properties.h>
Andreas Gampe54e1a402017-03-20 18:42:49 -070037#include <dex2oat_return_codes.h>
Mark Salyzyn7823e122016-09-29 08:08:05 -070038#include <log/log.h>
Andreas Gampe73dae112015-11-19 14:12:14 -080039#include <private/android_filesystem_config.h>
40
Jeff Sharkey6c2c0562016-12-07 12:12:00 -070041#include "dexopt.h"
Jeff Sharkeyf3e30b92016-12-09 17:06:57 -070042#include "file_parsing.h"
43#include "globals.h"
Andreas Gampec4ced4f2017-04-14 20:39:56 -070044#include "installd_constants.h"
Jeff Sharkeyf3e30b92016-12-09 17:06:57 -070045#include "installd_deps.h" // Need to fill in requirements of commands.
46#include "otapreopt_utils.h"
47#include "system_properties.h"
48#include "utils.h"
Jeff Sharkey6c2c0562016-12-07 12:12:00 -070049
Andreas Gampe73dae112015-11-19 14:12:14 -080050#ifndef LOG_TAG
51#define LOG_TAG "otapreopt"
52#endif
53
54#define BUFFER_MAX 1024 /* input buffer for commands */
55#define TOKEN_MAX 16 /* max number of arguments in buffer */
56#define REPLY_MAX 256 /* largest reply allowed */
57
Andreas Gampe56f79f92016-06-08 15:11:37 -070058using android::base::EndsWith;
Andreas Gampe6db8db92016-06-03 10:22:19 -070059using android::base::Join;
60using android::base::Split;
Andreas Gampe56f79f92016-06-08 15:11:37 -070061using android::base::StartsWith;
Andreas Gampe73dae112015-11-19 14:12:14 -080062using android::base::StringPrintf;
63
64namespace android {
65namespace installd {
66
Andreas Gampe73dae112015-11-19 14:12:14 -080067template<typename T>
68static constexpr T RoundDown(T x, typename std::decay<T>::type n) {
69 return DCHECK_CONSTEXPR(IsPowerOfTwo(n), , T(0))(x & -n);
70}
71
72template<typename T>
73static constexpr T RoundUp(T x, typename std::remove_reference<T>::type n) {
74 return RoundDown(x + n - 1, n);
75}
76
77class OTAPreoptService {
78 public:
Andreas Gampe73dae112015-11-19 14:12:14 -080079 // Main driver. Performs the following steps.
80 //
81 // 1) Parse options (read system properties etc from B partition).
82 //
83 // 2) Read in package data.
84 //
85 // 3) Prepare environment variables.
86 //
87 // 4) Prepare(compile) boot image, if necessary.
88 //
89 // 5) Run update.
90 int Main(int argc, char** argv) {
Andreas Gamped089ca12016-06-27 14:25:30 -070091 if (!ReadArguments(argc, argv)) {
92 LOG(ERROR) << "Failed reading command line.";
93 return 1;
94 }
95
Andreas Gampe73dae112015-11-19 14:12:14 -080096 if (!ReadSystemProperties()) {
97 LOG(ERROR)<< "Failed reading system properties.";
Andreas Gamped089ca12016-06-27 14:25:30 -070098 return 2;
Andreas Gampe73dae112015-11-19 14:12:14 -080099 }
100
101 if (!ReadEnvironment()) {
102 LOG(ERROR) << "Failed reading environment properties.";
Andreas Gamped089ca12016-06-27 14:25:30 -0700103 return 3;
Andreas Gampe73dae112015-11-19 14:12:14 -0800104 }
105
Andreas Gamped089ca12016-06-27 14:25:30 -0700106 if (!CheckAndInitializeInstalldGlobals()) {
107 LOG(ERROR) << "Failed initializing globals.";
108 return 4;
Andreas Gampe73dae112015-11-19 14:12:14 -0800109 }
110
111 PrepareEnvironment();
112
Andreas Gamped089ca12016-06-27 14:25:30 -0700113 if (!PrepareBootImage(/* force */ false)) {
Andreas Gampe73dae112015-11-19 14:12:14 -0800114 LOG(ERROR) << "Failed preparing boot image.";
Andreas Gamped089ca12016-06-27 14:25:30 -0700115 return 5;
Andreas Gampe73dae112015-11-19 14:12:14 -0800116 }
117
118 int dexopt_retcode = RunPreopt();
119
120 return dexopt_retcode;
121 }
122
Andreas Gamped089ca12016-06-27 14:25:30 -0700123 int GetProperty(const char* key, char* value, const char* default_value) const {
Andreas Gampe73dae112015-11-19 14:12:14 -0800124 const std::string* prop_value = system_properties_.GetProperty(key);
125 if (prop_value == nullptr) {
126 if (default_value == nullptr) {
127 return 0;
128 }
129 // Copy in the default value.
130 strncpy(value, default_value, kPropertyValueMax - 1);
131 value[kPropertyValueMax - 1] = 0;
132 return strlen(default_value);// TODO: Need to truncate?
133 }
134 size_t size = std::min(kPropertyValueMax - 1, prop_value->length());
135 strncpy(value, prop_value->data(), size);
136 value[size] = 0;
137 return static_cast<int>(size);
138 }
139
Andreas Gamped089ca12016-06-27 14:25:30 -0700140 std::string GetOTADataDirectory() const {
141 return StringPrintf("%s/%s", GetOtaDirectoryPrefix().c_str(), target_slot_.c_str());
142 }
143
144 const std::string& GetTargetSlot() const {
145 return target_slot_;
146 }
147
Andreas Gampe73dae112015-11-19 14:12:14 -0800148private:
Andreas Gamped089ca12016-06-27 14:25:30 -0700149
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700150 struct Parameters {
151 const char *apk_path;
152 uid_t uid;
153 const char *pkgName;
154 const char *instruction_set;
155 int dexopt_needed;
156 const char* oat_dir;
157 int dexopt_flags;
158 const char* compiler_filter;
159 const char* volume_uuid;
160 const char* shared_libraries;
161 const char* se_info;
162 };
163
Andreas Gampe73dae112015-11-19 14:12:14 -0800164 bool ReadSystemProperties() {
Andreas Gampe1842af32016-03-16 14:28:50 -0700165 static constexpr const char* kPropertyFiles[] = {
166 "/default.prop", "/system/build.prop"
167 };
Andreas Gampe73dae112015-11-19 14:12:14 -0800168
Andreas Gampe1842af32016-03-16 14:28:50 -0700169 for (size_t i = 0; i < arraysize(kPropertyFiles); ++i) {
170 if (!system_properties_.Load(kPropertyFiles[i])) {
171 return false;
172 }
173 }
174
175 return true;
Andreas Gampe73dae112015-11-19 14:12:14 -0800176 }
177
178 bool ReadEnvironment() {
Andreas Gampe1842af32016-03-16 14:28:50 -0700179 // Parse the environment variables from init.environ.rc, which have the form
180 // export NAME VALUE
181 // For simplicity, don't respect string quotation. The values we are interested in can be
182 // encoded without them.
183 std::regex export_regex("\\s*export\\s+(\\S+)\\s+(\\S+)");
184 bool parse_result = ParseFile("/init.environ.rc", [&](const std::string& line) {
185 std::smatch export_match;
186 if (!std::regex_match(line, export_match, export_regex)) {
187 return true;
188 }
Andreas Gampe73dae112015-11-19 14:12:14 -0800189
Andreas Gampe1842af32016-03-16 14:28:50 -0700190 if (export_match.size() != 3) {
191 return true;
192 }
193
194 std::string name = export_match[1].str();
195 std::string value = export_match[2].str();
196
197 system_properties_.SetProperty(name, value);
198
199 return true;
200 });
201 if (!parse_result) {
Andreas Gampe73dae112015-11-19 14:12:14 -0800202 return false;
203 }
Andreas Gampe1842af32016-03-16 14:28:50 -0700204
Andreas Gamped089ca12016-06-27 14:25:30 -0700205 if (system_properties_.GetProperty(kAndroidDataPathPropertyName) == nullptr) {
206 return false;
207 }
208 android_data_ = *system_properties_.GetProperty(kAndroidDataPathPropertyName);
209
210 if (system_properties_.GetProperty(kAndroidRootPathPropertyName) == nullptr) {
211 return false;
212 }
213 android_root_ = *system_properties_.GetProperty(kAndroidRootPathPropertyName);
214
215 if (system_properties_.GetProperty(kBootClassPathPropertyName) == nullptr) {
216 return false;
217 }
218 boot_classpath_ = *system_properties_.GetProperty(kBootClassPathPropertyName);
219
220 if (system_properties_.GetProperty(ASEC_MOUNTPOINT_ENV_NAME) == nullptr) {
221 return false;
222 }
223 asec_mountpoint_ = *system_properties_.GetProperty(ASEC_MOUNTPOINT_ENV_NAME);
224
225 return true;
226 }
227
228 const std::string& GetAndroidData() const {
229 return android_data_;
230 }
231
232 const std::string& GetAndroidRoot() const {
233 return android_root_;
234 }
235
236 const std::string GetOtaDirectoryPrefix() const {
237 return GetAndroidData() + "/ota";
238 }
239
240 bool CheckAndInitializeInstalldGlobals() {
241 // init_globals_from_data_and_root requires "ASEC_MOUNTPOINT" in the environment. We
242 // do not use any datapath that includes this, but we'll still have to set it.
243 CHECK(system_properties_.GetProperty(ASEC_MOUNTPOINT_ENV_NAME) != nullptr);
244 int result = setenv(ASEC_MOUNTPOINT_ENV_NAME, asec_mountpoint_.c_str(), 0);
245 if (result != 0) {
246 LOG(ERROR) << "Could not set ASEC_MOUNTPOINT environment variable";
247 return false;
248 }
249
250 if (!init_globals_from_data_and_root(GetAndroidData().c_str(), GetAndroidRoot().c_str())) {
251 LOG(ERROR) << "Could not initialize globals; exiting.";
252 return false;
253 }
254
255 // This is different from the normal installd. We only do the base
256 // directory, the rest will be created on demand when each app is compiled.
257 if (access(GetOtaDirectoryPrefix().c_str(), R_OK) < 0) {
258 LOG(ERROR) << "Could not access " << GetOtaDirectoryPrefix();
259 return false;
Andreas Gampe1842af32016-03-16 14:28:50 -0700260 }
Andreas Gampe73dae112015-11-19 14:12:14 -0800261
262 return true;
263 }
264
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700265 bool ParseUInt(const char* in, uint32_t* out) {
266 char* end;
267 long long int result = strtoll(in, &end, 0);
268 if (in == end || *end != '\0') {
269 return false;
270 }
271 if (result < std::numeric_limits<uint32_t>::min() ||
272 std::numeric_limits<uint32_t>::max() < result) {
273 return false;
274 }
275 *out = static_cast<uint32_t>(result);
276 return true;
277 }
Andreas Gamped089ca12016-06-27 14:25:30 -0700278
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700279 bool ReadArguments(int argc, char** argv) {
280 // Expected command line:
281 // target-slot [version] dexopt {DEXOPT_PARAMETERS}
Andreas Gamped089ca12016-06-27 14:25:30 -0700282
283 const char* target_slot_arg = argv[1];
284 if (target_slot_arg == nullptr) {
285 LOG(ERROR) << "Missing parameters";
286 return false;
287 }
288 // Sanitize value. Only allow (a-zA-Z0-9_)+.
289 target_slot_ = target_slot_arg;
Andreas Gampefd12eda2016-07-12 09:47:17 -0700290 if (!ValidateTargetSlotSuffix(target_slot_)) {
291 LOG(ERROR) << "Target slot suffix not legal: " << target_slot_;
292 return false;
Andreas Gamped089ca12016-06-27 14:25:30 -0700293 }
294
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700295 // Check for version or "dexopt" next.
296 if (argv[2] == nullptr) {
297 LOG(ERROR) << "Missing parameters";
298 return false;
299 }
300
301 if (std::string("dexopt").compare(argv[2]) == 0) {
302 // This is version 1 (N) or pre-versioning version 2.
303 constexpr int kV2ArgCount = 1 // "otapreopt"
304 + 1 // slot
305 + 1 // "dexopt"
306 + 1 // apk_path
307 + 1 // uid
308 + 1 // pkg
309 + 1 // isa
310 + 1 // dexopt_needed
311 + 1 // oat_dir
312 + 1 // dexopt_flags
313 + 1 // filter
314 + 1 // volume
315 + 1 // libs
316 + 1 // seinfo
317 + 1; // null
318 if (argc == kV2ArgCount) {
319 return ReadArgumentsV2(argc, argv, false);
320 } else {
321 return ReadArgumentsV1(argc, argv);
322 }
323 }
324
325 uint32_t version;
326 if (!ParseUInt(argv[2], &version)) {
327 LOG(ERROR) << "Could not parse version: " << argv[2];
328 return false;
329 }
330
331 switch (version) {
332 case 2:
333 return ReadArgumentsV2(argc, argv, true);
334
335 default:
336 LOG(ERROR) << "Unsupported version " << version;
337 return false;
338 }
339 }
340
341 bool ReadArgumentsV2(int argc ATTRIBUTE_UNUSED, char** argv, bool versioned) {
342 size_t dexopt_index = versioned ? 3 : 2;
343
344 // Check for "dexopt".
345 if (argv[dexopt_index] == nullptr) {
346 LOG(ERROR) << "Missing parameters";
347 return false;
348 }
349 if (std::string("dexopt").compare(argv[dexopt_index]) != 0) {
350 LOG(ERROR) << "Expected \"dexopt\"";
351 return false;
352 }
353
354 size_t param_index = 0;
355 for (;; ++param_index) {
356 const char* param = argv[dexopt_index + 1 + param_index];
357 if (param == nullptr) {
358 break;
359 }
360
361 switch (param_index) {
362 case 0:
363 package_parameters_.apk_path = param;
364 break;
365
366 case 1:
367 package_parameters_.uid = atoi(param);
368 break;
369
370 case 2:
371 package_parameters_.pkgName = param;
372 break;
373
374 case 3:
375 package_parameters_.instruction_set = param;
376 break;
377
378 case 4:
379 package_parameters_.dexopt_needed = atoi(param);
380 break;
381
382 case 5:
383 package_parameters_.oat_dir = param;
384 break;
385
386 case 6:
387 package_parameters_.dexopt_flags = atoi(param);
388 break;
389
390 case 7:
391 package_parameters_.compiler_filter = param;
392 break;
393
394 case 8:
395 package_parameters_.volume_uuid = ParseNull(param);
396 break;
397
398 case 9:
399 package_parameters_.shared_libraries = ParseNull(param);
400 break;
401
402 case 10:
403 package_parameters_.se_info = ParseNull(param);
404 break;
405
406 default:
407 LOG(ERROR) << "Too many arguments, got " << param;
408 return false;
409 }
410 }
411
412 if (param_index != 11) {
413 LOG(ERROR) << "Not enough parameters";
414 return false;
415 }
416
417 return true;
418 }
419
420 static int ReplaceMask(int input, int old_mask, int new_mask) {
421 return (input & old_mask) != 0 ? new_mask : 0;
422 }
423
424 bool ReadArgumentsV1(int argc ATTRIBUTE_UNUSED, char** argv) {
425 // Check for "dexopt".
Andreas Gamped089ca12016-06-27 14:25:30 -0700426 if (argv[2] == nullptr) {
427 LOG(ERROR) << "Missing parameters";
428 return false;
429 }
430 if (std::string("dexopt").compare(argv[2]) != 0) {
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700431 LOG(ERROR) << "Expected \"dexopt\"";
Andreas Gamped089ca12016-06-27 14:25:30 -0700432 return false;
433 }
434
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700435 size_t param_index = 0;
436 for (;; ++param_index) {
437 const char* param = argv[3 + param_index];
438 if (param == nullptr) {
439 break;
440 }
441
442 switch (param_index) {
443 case 0:
444 package_parameters_.apk_path = param;
445 break;
446
447 case 1:
448 package_parameters_.uid = atoi(param);
449 break;
450
451 case 2:
452 package_parameters_.pkgName = param;
453 break;
454
455 case 3:
456 package_parameters_.instruction_set = param;
457 break;
458
459 case 4: {
460 // Version 1 had:
461 // DEXOPT_DEX2OAT_NEEDED = 1
462 // DEXOPT_PATCHOAT_NEEDED = 2
463 // DEXOPT_SELF_PATCHOAT_NEEDED = 3
464 // We will simply use DEX2OAT_FROM_SCRATCH.
465 package_parameters_.dexopt_needed = DEX2OAT_FROM_SCRATCH;
466 break;
467 }
468
469 case 5:
470 package_parameters_.oat_dir = param;
471 break;
472
473 case 6: {
474 // Version 1 had:
475 constexpr int OLD_DEXOPT_PUBLIC = 1 << 1;
476 constexpr int OLD_DEXOPT_SAFEMODE = 1 << 2;
477 constexpr int OLD_DEXOPT_DEBUGGABLE = 1 << 3;
478 constexpr int OLD_DEXOPT_BOOTCOMPLETE = 1 << 4;
479 constexpr int OLD_DEXOPT_PROFILE_GUIDED = 1 << 5;
480 constexpr int OLD_DEXOPT_OTA = 1 << 6;
481 int input = atoi(param);
482 package_parameters_.dexopt_flags =
483 ReplaceMask(input, OLD_DEXOPT_PUBLIC, DEXOPT_PUBLIC) |
484 ReplaceMask(input, OLD_DEXOPT_SAFEMODE, DEXOPT_SAFEMODE) |
485 ReplaceMask(input, OLD_DEXOPT_DEBUGGABLE, DEXOPT_DEBUGGABLE) |
486 ReplaceMask(input, OLD_DEXOPT_BOOTCOMPLETE, DEXOPT_BOOTCOMPLETE) |
487 ReplaceMask(input, OLD_DEXOPT_PROFILE_GUIDED, DEXOPT_PROFILE_GUIDED) |
488 ReplaceMask(input, OLD_DEXOPT_OTA, 0);
489 break;
490 }
491
492 case 7:
493 package_parameters_.compiler_filter = param;
494 break;
495
496 case 8:
497 package_parameters_.volume_uuid = ParseNull(param);
498 break;
499
500 case 9:
501 package_parameters_.shared_libraries = ParseNull(param);
502 break;
503
504 default:
505 LOG(ERROR) << "Too many arguments, got " << param;
506 return false;
507 }
Andreas Gampe73dae112015-11-19 14:12:14 -0800508 }
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700509
510 if (param_index != 10) {
511 LOG(ERROR) << "Not enough parameters";
Andreas Gampe73dae112015-11-19 14:12:14 -0800512 return false;
513 }
514
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700515 // Set se_info to null. It is only relevant for secondary dex files, which we won't
516 // receive from a v1 A side.
517 package_parameters_.se_info = nullptr;
518
Andreas Gampe73dae112015-11-19 14:12:14 -0800519 return true;
520 }
521
522 void PrepareEnvironment() {
Andreas Gamped089ca12016-06-27 14:25:30 -0700523 environ_.push_back(StringPrintf("BOOTCLASSPATH=%s", boot_classpath_.c_str()));
524 environ_.push_back(StringPrintf("ANDROID_DATA=%s", GetOTADataDirectory().c_str()));
525 environ_.push_back(StringPrintf("ANDROID_ROOT=%s", android_root_.c_str()));
Andreas Gampe73dae112015-11-19 14:12:14 -0800526
527 for (const std::string& e : environ_) {
528 putenv(const_cast<char*>(e.c_str()));
529 }
530 }
531
532 // Ensure that we have the right boot image. The first time any app is
533 // compiled, we'll try to generate it.
Andreas Gamped089ca12016-06-27 14:25:30 -0700534 bool PrepareBootImage(bool force) const {
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700535 if (package_parameters_.instruction_set == nullptr) {
Andreas Gampe73dae112015-11-19 14:12:14 -0800536 LOG(ERROR) << "Instruction set missing.";
537 return false;
538 }
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700539 const char* isa = package_parameters_.instruction_set;
Andreas Gampe73dae112015-11-19 14:12:14 -0800540
541 // Check whether the file exists where expected.
Andreas Gamped089ca12016-06-27 14:25:30 -0700542 std::string dalvik_cache = GetOTADataDirectory() + "/" + DALVIK_CACHE;
Andreas Gampe73dae112015-11-19 14:12:14 -0800543 std::string isa_path = dalvik_cache + "/" + isa;
544 std::string art_path = isa_path + "/system@framework@boot.art";
545 std::string oat_path = isa_path + "/system@framework@boot.oat";
Andreas Gamped089ca12016-06-27 14:25:30 -0700546 bool cleared = false;
547 if (access(art_path.c_str(), F_OK) == 0 && access(oat_path.c_str(), F_OK) == 0) {
548 // Files exist, assume everything is alright if not forced. Otherwise clean up.
549 if (!force) {
550 return true;
551 }
552 ClearDirectory(isa_path);
553 cleared = true;
Andreas Gampe73dae112015-11-19 14:12:14 -0800554 }
555
Andreas Gamped089ca12016-06-27 14:25:30 -0700556 // Reset umask in otapreopt, so that we control the the access for the files we create.
557 umask(0);
558
Andreas Gampe73dae112015-11-19 14:12:14 -0800559 // Create the directories, if necessary.
560 if (access(dalvik_cache.c_str(), F_OK) != 0) {
Andreas Gamped089ca12016-06-27 14:25:30 -0700561 if (!CreatePath(dalvik_cache)) {
562 PLOG(ERROR) << "Could not create dalvik-cache dir " << dalvik_cache;
Andreas Gampe73dae112015-11-19 14:12:14 -0800563 return false;
564 }
565 }
566 if (access(isa_path.c_str(), F_OK) != 0) {
Andreas Gamped089ca12016-06-27 14:25:30 -0700567 if (!CreatePath(isa_path)) {
Andreas Gampe73dae112015-11-19 14:12:14 -0800568 PLOG(ERROR) << "Could not create dalvik-cache isa dir";
569 return false;
570 }
571 }
572
Andreas Gampe5709b572016-02-12 17:42:59 -0800573 // Prepare to create.
Andreas Gamped089ca12016-06-27 14:25:30 -0700574 if (!cleared) {
575 ClearDirectory(isa_path);
576 }
Andreas Gampe73dae112015-11-19 14:12:14 -0800577
Andreas Gampe9fb85b02016-03-16 10:09:29 -0700578 std::string preopted_boot_art_path = StringPrintf("/system/framework/%s/boot.art", isa);
Andreas Gampe5709b572016-02-12 17:42:59 -0800579 if (access(preopted_boot_art_path.c_str(), F_OK) == 0) {
580 return PatchoatBootImage(art_path, isa);
581 } else {
582 // No preopted boot image. Try to compile.
Andreas Gamped089ca12016-06-27 14:25:30 -0700583 return Dex2oatBootImage(boot_classpath_, art_path, oat_path, isa);
Andreas Gampe5709b572016-02-12 17:42:59 -0800584 }
585 }
586
Andreas Gamped089ca12016-06-27 14:25:30 -0700587 static bool CreatePath(const std::string& path) {
588 // Create the given path. Use string processing instead of dirname, as dirname's need for
589 // a writable char buffer is painful.
590
591 // First, try to use the full path.
592 if (mkdir(path.c_str(), 0711) == 0) {
593 return true;
594 }
595 if (errno != ENOENT) {
596 PLOG(ERROR) << "Could not create path " << path;
597 return false;
598 }
599
600 // Now find the parent and try that first.
601 size_t last_slash = path.find_last_of('/');
602 if (last_slash == std::string::npos || last_slash == 0) {
603 PLOG(ERROR) << "Could not create " << path;
604 return false;
605 }
606
607 if (!CreatePath(path.substr(0, last_slash))) {
608 return false;
609 }
610
611 if (mkdir(path.c_str(), 0711) == 0) {
612 return true;
613 }
614 PLOG(ERROR) << "Could not create " << path;
615 return false;
616 }
617
618 static void ClearDirectory(const std::string& dir) {
619 DIR* c_dir = opendir(dir.c_str());
620 if (c_dir == nullptr) {
621 PLOG(WARNING) << "Unable to open " << dir << " to delete it's contents";
622 return;
623 }
624
625 for (struct dirent* de = readdir(c_dir); de != nullptr; de = readdir(c_dir)) {
626 const char* name = de->d_name;
627 if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
628 continue;
629 }
630 // We only want to delete regular files and symbolic links.
631 std::string file = StringPrintf("%s/%s", dir.c_str(), name);
632 if (de->d_type != DT_REG && de->d_type != DT_LNK) {
633 LOG(WARNING) << "Unexpected file "
634 << file
635 << " of type "
636 << std::hex
637 << de->d_type
638 << " encountered.";
639 } else {
640 // Try to unlink the file.
641 if (unlink(file.c_str()) != 0) {
642 PLOG(ERROR) << "Unable to unlink " << file;
643 }
644 }
645 }
646 CHECK_EQ(0, closedir(c_dir)) << "Unable to close directory.";
647 }
648
649 bool PatchoatBootImage(const std::string& art_path, const char* isa) const {
Andreas Gampe5709b572016-02-12 17:42:59 -0800650 // This needs to be kept in sync with ART, see art/runtime/gc/space/image_space.cc.
651
652 std::vector<std::string> cmd;
Andreas Gampe9fb85b02016-03-16 10:09:29 -0700653 cmd.push_back("/system/bin/patchoat");
Andreas Gampe5709b572016-02-12 17:42:59 -0800654
655 cmd.push_back("--input-image-location=/system/framework/boot.art");
656 cmd.push_back(StringPrintf("--output-image-file=%s", art_path.c_str()));
657
658 cmd.push_back(StringPrintf("--instruction-set=%s", isa));
659
660 int32_t base_offset = ChooseRelocationOffsetDelta(ART_BASE_ADDRESS_MIN_DELTA,
661 ART_BASE_ADDRESS_MAX_DELTA);
Andreas Gampefebf0bf2016-02-29 18:04:17 -0800662 cmd.push_back(StringPrintf("--base-offset-delta=%d", base_offset));
Andreas Gampe5709b572016-02-12 17:42:59 -0800663
664 std::string error_msg;
665 bool result = Exec(cmd, &error_msg);
666 if (!result) {
667 LOG(ERROR) << "Could not generate boot image: " << error_msg;
668 }
669 return result;
670 }
671
672 bool Dex2oatBootImage(const std::string& boot_cp,
673 const std::string& art_path,
674 const std::string& oat_path,
Andreas Gamped089ca12016-06-27 14:25:30 -0700675 const char* isa) const {
Andreas Gampe73dae112015-11-19 14:12:14 -0800676 // This needs to be kept in sync with ART, see art/runtime/gc/space/image_space.cc.
677 std::vector<std::string> cmd;
Andreas Gampe9fb85b02016-03-16 10:09:29 -0700678 cmd.push_back("/system/bin/dex2oat");
Andreas Gampe73dae112015-11-19 14:12:14 -0800679 cmd.push_back(StringPrintf("--image=%s", art_path.c_str()));
Andreas Gampe6db8db92016-06-03 10:22:19 -0700680 for (const std::string& boot_part : Split(boot_cp, ":")) {
Andreas Gampe73dae112015-11-19 14:12:14 -0800681 cmd.push_back(StringPrintf("--dex-file=%s", boot_part.c_str()));
682 }
683 cmd.push_back(StringPrintf("--oat-file=%s", oat_path.c_str()));
684
685 int32_t base_offset = ChooseRelocationOffsetDelta(ART_BASE_ADDRESS_MIN_DELTA,
686 ART_BASE_ADDRESS_MAX_DELTA);
687 cmd.push_back(StringPrintf("--base=0x%x", ART_BASE_ADDRESS + base_offset));
688
689 cmd.push_back(StringPrintf("--instruction-set=%s", isa));
690
691 // These things are pushed by AndroidRuntime, see frameworks/base/core/jni/AndroidRuntime.cpp.
692 AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-Xms",
693 "-Xms",
694 true,
695 cmd);
696 AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-Xmx",
697 "-Xmx",
698 true,
699 cmd);
700 AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-filter",
701 "--compiler-filter=",
702 false,
703 cmd);
Andreas Gampe9fb85b02016-03-16 10:09:29 -0700704 cmd.push_back("--image-classes=/system/etc/preloaded-classes");
Andreas Gampe73dae112015-11-19 14:12:14 -0800705 // TODO: Compiled-classes.
706 const std::string* extra_opts =
707 system_properties_.GetProperty("dalvik.vm.image-dex2oat-flags");
708 if (extra_opts != nullptr) {
Andreas Gampe6db8db92016-06-03 10:22:19 -0700709 std::vector<std::string> extra_vals = Split(*extra_opts, " ");
Andreas Gampe73dae112015-11-19 14:12:14 -0800710 cmd.insert(cmd.end(), extra_vals.begin(), extra_vals.end());
711 }
712 // TODO: Should we lower this? It's usually set close to max, because
713 // normally there's not much else going on at boot.
714 AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-threads",
715 "-j",
716 false,
717 cmd);
718 AddCompilerOptionFromSystemProperty(
719 StringPrintf("dalvik.vm.isa.%s.variant", isa).c_str(),
720 "--instruction-set-variant=",
721 false,
722 cmd);
723 AddCompilerOptionFromSystemProperty(
724 StringPrintf("dalvik.vm.isa.%s.features", isa).c_str(),
725 "--instruction-set-features=",
726 false,
727 cmd);
728
729 std::string error_msg;
730 bool result = Exec(cmd, &error_msg);
731 if (!result) {
732 LOG(ERROR) << "Could not generate boot image: " << error_msg;
733 }
734 return result;
735 }
736
737 static const char* ParseNull(const char* arg) {
738 return (strcmp(arg, "!") == 0) ? nullptr : arg;
739 }
740
Andreas Gamped089ca12016-06-27 14:25:30 -0700741 bool ShouldSkipPreopt() const {
Andreas Gampe56f79f92016-06-08 15:11:37 -0700742 // There's one thing we have to be careful about: we may/will be asked to compile an app
743 // living in the system image. This may be a valid request - if the app wasn't compiled,
744 // e.g., if the system image wasn't large enough to include preopted files. However, the
745 // data we have is from the old system, so the driver (the OTA service) can't actually
746 // know. Thus, we will get requests for apps that have preopted components. To avoid
747 // duplication (we'd generate files that are not used and are *not* cleaned up), do two
748 // simple checks:
749 //
750 // 1) Does the apk_path start with the value of ANDROID_ROOT? (~in the system image)
751 // (For simplicity, assume the value of ANDROID_ROOT does not contain a symlink.)
752 //
753 // 2) If you replace the name in the apk_path with "oat," does the path exist?
754 // (=have a subdirectory for preopted files)
755 //
756 // If the answer to both is yes, skip the dexopt.
757 //
758 // Note: while one may think it's OK to call dexopt and it will fail (because APKs should
759 // be stripped), that's not true for APKs signed outside the build system (so the
760 // jar content must be exactly the same).
761
762 // (This is ugly as it's the only thing where we need to understand the contents
763 // of package_parameters_, but it beats postponing the decision or using the call-
764 // backs to do weird things.)
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700765 const char* apk_path = package_parameters_.apk_path;
766 CHECK(apk_path != nullptr);
767 if (StartsWith(apk_path, android_root_.c_str())) {
768 const char* last_slash = strrchr(apk_path, '/');
Andreas Gampe56f79f92016-06-08 15:11:37 -0700769 if (last_slash != nullptr) {
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700770 std::string path(apk_path, last_slash - apk_path + 1);
Andreas Gampe56f79f92016-06-08 15:11:37 -0700771 CHECK(EndsWith(path, "/"));
772 path = path + "oat";
773 if (access(path.c_str(), F_OK) == 0) {
Andreas Gamped089ca12016-06-27 14:25:30 -0700774 return true;
Andreas Gampe56f79f92016-06-08 15:11:37 -0700775 }
776 }
777 }
778
Andreas Gamped089ca12016-06-27 14:25:30 -0700779 // Another issue is unavailability of files in the new system. If the partition
780 // layout changes, otapreopt_chroot may not know about this. Then files from that
781 // partition will not be available and fail to build. This is problematic, as
782 // this tool will wipe the OTA artifact cache and try again (for robustness after
783 // a failed OTA with remaining cache artifacts).
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700784 if (access(apk_path, F_OK) != 0) {
785 LOG(WARNING) << "Skipping preopt of non-existing package " << apk_path;
Andreas Gamped089ca12016-06-27 14:25:30 -0700786 return true;
787 }
788
789 return false;
790 }
791
792 int RunPreopt() {
793 if (ShouldSkipPreopt()) {
794 return 0;
795 }
796
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700797 int dexopt_result = dexopt(package_parameters_.apk_path,
798 package_parameters_.uid,
799 package_parameters_.pkgName,
800 package_parameters_.instruction_set,
801 package_parameters_.dexopt_needed,
802 package_parameters_.oat_dir,
803 package_parameters_.dexopt_flags,
804 package_parameters_.compiler_filter,
805 package_parameters_.volume_uuid,
806 package_parameters_.shared_libraries,
807 package_parameters_.se_info);
Andreas Gamped089ca12016-06-27 14:25:30 -0700808 if (dexopt_result == 0) {
809 return 0;
810 }
811
812 // If the dexopt failed, we may have a stale boot image from a previous OTA run.
Andreas Gampe54e1a402017-03-20 18:42:49 -0700813 // Then regenerate and retry.
814 if (WEXITSTATUS(dexopt_result) !=
815 static_cast<int>(art::dex2oat::ReturnCode::kCreateRuntime)) {
816 return dexopt_result;
817 }
Andreas Gamped089ca12016-06-27 14:25:30 -0700818
819 if (!PrepareBootImage(/* force */ true)) {
820 LOG(ERROR) << "Forced boot image creating failed. Original error return was "
821 << dexopt_result;
822 return dexopt_result;
823 }
824
825 LOG(WARNING) << "Original dexopt failed, re-trying after boot image was regenerated.";
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700826 return dexopt(package_parameters_.apk_path,
827 package_parameters_.uid,
828 package_parameters_.pkgName,
829 package_parameters_.instruction_set,
830 package_parameters_.dexopt_needed,
831 package_parameters_.oat_dir,
832 package_parameters_.dexopt_flags,
833 package_parameters_.compiler_filter,
834 package_parameters_.volume_uuid,
835 package_parameters_.shared_libraries,
836 package_parameters_.se_info);
Andreas Gampe73dae112015-11-19 14:12:14 -0800837 }
838
839 ////////////////////////////////////
840 // Helpers, mostly taken from ART //
841 ////////////////////////////////////
842
843 // Wrapper on fork/execv to run a command in a subprocess.
Andreas Gamped089ca12016-06-27 14:25:30 -0700844 static bool Exec(const std::vector<std::string>& arg_vector, std::string* error_msg) {
Andreas Gampe6db8db92016-06-03 10:22:19 -0700845 const std::string command_line = Join(arg_vector, ' ');
Andreas Gampe73dae112015-11-19 14:12:14 -0800846
847 CHECK_GE(arg_vector.size(), 1U) << command_line;
848
849 // Convert the args to char pointers.
850 const char* program = arg_vector[0].c_str();
851 std::vector<char*> args;
852 for (size_t i = 0; i < arg_vector.size(); ++i) {
853 const std::string& arg = arg_vector[i];
854 char* arg_str = const_cast<char*>(arg.c_str());
855 CHECK(arg_str != nullptr) << i;
856 args.push_back(arg_str);
857 }
858 args.push_back(nullptr);
859
860 // Fork and exec.
861 pid_t pid = fork();
862 if (pid == 0) {
863 // No allocation allowed between fork and exec.
864
865 // Change process groups, so we don't get reaped by ProcessManager.
866 setpgid(0, 0);
867
868 execv(program, &args[0]);
869
870 PLOG(ERROR) << "Failed to execv(" << command_line << ")";
871 // _exit to avoid atexit handlers in child.
872 _exit(1);
873 } else {
874 if (pid == -1) {
875 *error_msg = StringPrintf("Failed to execv(%s) because fork failed: %s",
876 command_line.c_str(), strerror(errno));
877 return false;
878 }
879
880 // wait for subprocess to finish
881 int status;
882 pid_t got_pid = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0));
883 if (got_pid != pid) {
884 *error_msg = StringPrintf("Failed after fork for execv(%s) because waitpid failed: "
885 "wanted %d, got %d: %s",
886 command_line.c_str(), pid, got_pid, strerror(errno));
887 return false;
888 }
889 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
890 *error_msg = StringPrintf("Failed execv(%s) because non-0 exit status",
891 command_line.c_str());
892 return false;
893 }
894 }
895 return true;
896 }
897
898 // Choose a random relocation offset. Taken from art/runtime/gc/image_space.cc.
899 static int32_t ChooseRelocationOffsetDelta(int32_t min_delta, int32_t max_delta) {
900 constexpr size_t kPageSize = PAGE_SIZE;
901 CHECK_EQ(min_delta % kPageSize, 0u);
902 CHECK_EQ(max_delta % kPageSize, 0u);
903 CHECK_LT(min_delta, max_delta);
904
905 std::default_random_engine generator;
906 generator.seed(GetSeed());
907 std::uniform_int_distribution<int32_t> distribution(min_delta, max_delta);
908 int32_t r = distribution(generator);
909 if (r % 2 == 0) {
910 r = RoundUp(r, kPageSize);
911 } else {
912 r = RoundDown(r, kPageSize);
913 }
914 CHECK_LE(min_delta, r);
915 CHECK_GE(max_delta, r);
916 CHECK_EQ(r % kPageSize, 0u);
917 return r;
918 }
919
920 static uint64_t GetSeed() {
921#ifdef __BIONIC__
922 // Bionic exposes arc4random, use it.
923 uint64_t random_data;
924 arc4random_buf(&random_data, sizeof(random_data));
925 return random_data;
926#else
927#error "This is only supposed to run with bionic. Otherwise, implement..."
928#endif
929 }
930
931 void AddCompilerOptionFromSystemProperty(const char* system_property,
932 const char* prefix,
933 bool runtime,
Andreas Gamped089ca12016-06-27 14:25:30 -0700934 std::vector<std::string>& out) const {
935 const std::string* value = system_properties_.GetProperty(system_property);
Andreas Gampe73dae112015-11-19 14:12:14 -0800936 if (value != nullptr) {
937 if (runtime) {
938 out.push_back("--runtime-arg");
939 }
940 if (prefix != nullptr) {
941 out.push_back(StringPrintf("%s%s", prefix, value->c_str()));
942 } else {
943 out.push_back(*value);
944 }
945 }
946 }
947
Andreas Gamped089ca12016-06-27 14:25:30 -0700948 static constexpr const char* kBootClassPathPropertyName = "BOOTCLASSPATH";
949 static constexpr const char* kAndroidRootPathPropertyName = "ANDROID_ROOT";
950 static constexpr const char* kAndroidDataPathPropertyName = "ANDROID_DATA";
951 // The index of the instruction-set string inside the package parameters. Needed for
952 // some special-casing that requires knowledge of the instruction-set.
953 static constexpr size_t kISAIndex = 3;
954
Andreas Gampe73dae112015-11-19 14:12:14 -0800955 // Stores the system properties read out of the B partition. We need to use these properties
956 // to compile, instead of the A properties we could get from init/get_property.
957 SystemProperties system_properties_;
958
Andreas Gamped089ca12016-06-27 14:25:30 -0700959 // Some select properties that are always needed.
960 std::string target_slot_;
961 std::string android_root_;
962 std::string android_data_;
963 std::string boot_classpath_;
964 std::string asec_mountpoint_;
965
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700966 Parameters package_parameters_;
Andreas Gampe73dae112015-11-19 14:12:14 -0800967
968 // Store environment values we need to set.
969 std::vector<std::string> environ_;
970};
971
972OTAPreoptService gOps;
973
974////////////////////////
975// Plug-in functions. //
976////////////////////////
977
978int get_property(const char *key, char *value, const char *default_value) {
Andreas Gampe73dae112015-11-19 14:12:14 -0800979 return gOps.GetProperty(key, value, default_value);
980}
981
982// Compute the output path of
983bool calculate_oat_file_path(char path[PKG_PATH_MAX], const char *oat_dir,
984 const char *apk_path,
985 const char *instruction_set) {
Dan Austin9c8f93a2016-06-03 16:15:54 -0700986 const char *file_name_start;
987 const char *file_name_end;
Andreas Gampe73dae112015-11-19 14:12:14 -0800988
989 file_name_start = strrchr(apk_path, '/');
990 if (file_name_start == nullptr) {
991 ALOGE("apk_path '%s' has no '/'s in it\n", apk_path);
992 return false;
993 }
994 file_name_end = strrchr(file_name_start, '.');
995 if (file_name_end == nullptr) {
996 ALOGE("apk_path '%s' has no extension\n", apk_path);
997 return false;
998 }
999
1000 // Calculate file_name
1001 file_name_start++; // Move past '/', is valid as file_name_end is valid.
1002 size_t file_name_len = file_name_end - file_name_start;
1003 std::string file_name(file_name_start, file_name_len);
1004
1005 // <apk_parent_dir>/oat/<isa>/<file_name>.odex.b
Andreas Gamped089ca12016-06-27 14:25:30 -07001006 snprintf(path,
1007 PKG_PATH_MAX,
1008 "%s/%s/%s.odex.%s",
1009 oat_dir,
1010 instruction_set,
1011 file_name.c_str(),
1012 gOps.GetTargetSlot().c_str());
Andreas Gampe73dae112015-11-19 14:12:14 -08001013 return true;
1014}
1015
1016/*
1017 * Computes the odex file for the given apk_path and instruction_set.
1018 * /system/framework/whatever.jar -> /system/framework/oat/<isa>/whatever.odex
1019 *
1020 * Returns false if it failed to determine the odex file path.
1021 */
1022bool calculate_odex_file_path(char path[PKG_PATH_MAX], const char *apk_path,
1023 const char *instruction_set) {
Andreas Gampe73dae112015-11-19 14:12:14 -08001024 const char *path_end = strrchr(apk_path, '/');
1025 if (path_end == nullptr) {
1026 ALOGE("apk_path '%s' has no '/'s in it?!\n", apk_path);
1027 return false;
1028 }
1029 std::string path_component(apk_path, path_end - apk_path);
1030
1031 const char *name_begin = path_end + 1;
1032 const char *extension_start = strrchr(name_begin, '.');
1033 if (extension_start == nullptr) {
1034 ALOGE("apk_path '%s' has no extension.\n", apk_path);
1035 return false;
1036 }
1037 std::string name_component(name_begin, extension_start - name_begin);
1038
Andreas Gamped089ca12016-06-27 14:25:30 -07001039 std::string new_path = StringPrintf("%s/oat/%s/%s.odex.%s",
Andreas Gampe73dae112015-11-19 14:12:14 -08001040 path_component.c_str(),
1041 instruction_set,
Andreas Gamped089ca12016-06-27 14:25:30 -07001042 name_component.c_str(),
1043 gOps.GetTargetSlot().c_str());
1044 if (new_path.length() >= PKG_PATH_MAX) {
1045 LOG(ERROR) << "apk_path of " << apk_path << " is too long: " << new_path;
1046 return false;
1047 }
Andreas Gampe73dae112015-11-19 14:12:14 -08001048 strcpy(path, new_path.c_str());
1049 return true;
1050}
1051
1052bool create_cache_path(char path[PKG_PATH_MAX],
1053 const char *src,
1054 const char *instruction_set) {
1055 size_t srclen = strlen(src);
1056
1057 /* demand that we are an absolute path */
1058 if ((src == 0) || (src[0] != '/') || strstr(src,"..")) {
1059 return false;
1060 }
1061
1062 if (srclen > PKG_PATH_MAX) { // XXX: PKG_NAME_MAX?
1063 return false;
1064 }
1065
1066 std::string from_src = std::string(src + 1);
1067 std::replace(from_src.begin(), from_src.end(), '/', '@');
1068
1069 std::string assembled_path = StringPrintf("%s/%s/%s/%s%s",
Andreas Gamped089ca12016-06-27 14:25:30 -07001070 gOps.GetOTADataDirectory().c_str(),
Andreas Gampe73dae112015-11-19 14:12:14 -08001071 DALVIK_CACHE,
1072 instruction_set,
1073 from_src.c_str(),
David Brazdil249c1792016-09-06 15:35:28 +01001074 DALVIK_CACHE_POSTFIX);
Andreas Gampe73dae112015-11-19 14:12:14 -08001075
1076 if (assembled_path.length() + 1 > PKG_PATH_MAX) {
1077 return false;
1078 }
1079 strcpy(path, assembled_path.c_str());
1080
1081 return true;
1082}
1083
Andreas Gampe73dae112015-11-19 14:12:14 -08001084static int log_callback(int type, const char *fmt, ...) {
1085 va_list ap;
1086 int priority;
1087
1088 switch (type) {
1089 case SELINUX_WARNING:
1090 priority = ANDROID_LOG_WARN;
1091 break;
1092 case SELINUX_INFO:
1093 priority = ANDROID_LOG_INFO;
1094 break;
1095 default:
1096 priority = ANDROID_LOG_ERROR;
1097 break;
1098 }
1099 va_start(ap, fmt);
1100 LOG_PRI_VA(priority, "SELinux", fmt, ap);
1101 va_end(ap);
1102 return 0;
1103}
1104
1105static int otapreopt_main(const int argc, char *argv[]) {
1106 int selinux_enabled = (is_selinux_enabled() > 0);
1107
1108 setenv("ANDROID_LOG_TAGS", "*:v", 1);
1109 android::base::InitLogging(argv);
1110
Andreas Gampe73dae112015-11-19 14:12:14 -08001111 if (argc < 2) {
1112 ALOGE("Expecting parameters");
1113 exit(1);
1114 }
1115
1116 union selinux_callback cb;
1117 cb.func_log = log_callback;
1118 selinux_set_callback(SELINUX_CB_LOG, cb);
1119
Andreas Gampe73dae112015-11-19 14:12:14 -08001120 if (selinux_enabled && selinux_status_open(true) < 0) {
1121 ALOGE("Could not open selinux status; exiting.\n");
1122 exit(1);
1123 }
1124
1125 int ret = android::installd::gOps.Main(argc, argv);
1126
1127 return ret;
1128}
1129
1130} // namespace installd
1131} // namespace android
1132
1133int main(const int argc, char *argv[]) {
1134 return android::installd::otapreopt_main(argc, argv);
1135}