blob: ff838ce0b229077418690da230d4e799f9a0f82c [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
Andreas Gampe645e79c2017-04-19 13:58:49 -0700316 + 1; // seinfo
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700317 if (argc == kV2ArgCount) {
318 return ReadArgumentsV2(argc, argv, false);
319 } else {
320 return ReadArgumentsV1(argc, argv);
321 }
322 }
323
324 uint32_t version;
325 if (!ParseUInt(argv[2], &version)) {
326 LOG(ERROR) << "Could not parse version: " << argv[2];
327 return false;
328 }
329
330 switch (version) {
331 case 2:
332 return ReadArgumentsV2(argc, argv, true);
333
334 default:
335 LOG(ERROR) << "Unsupported version " << version;
336 return false;
337 }
338 }
339
340 bool ReadArgumentsV2(int argc ATTRIBUTE_UNUSED, char** argv, bool versioned) {
341 size_t dexopt_index = versioned ? 3 : 2;
342
343 // Check for "dexopt".
344 if (argv[dexopt_index] == nullptr) {
345 LOG(ERROR) << "Missing parameters";
346 return false;
347 }
348 if (std::string("dexopt").compare(argv[dexopt_index]) != 0) {
349 LOG(ERROR) << "Expected \"dexopt\"";
350 return false;
351 }
352
353 size_t param_index = 0;
354 for (;; ++param_index) {
355 const char* param = argv[dexopt_index + 1 + param_index];
356 if (param == nullptr) {
357 break;
358 }
359
360 switch (param_index) {
361 case 0:
362 package_parameters_.apk_path = param;
363 break;
364
365 case 1:
366 package_parameters_.uid = atoi(param);
367 break;
368
369 case 2:
370 package_parameters_.pkgName = param;
371 break;
372
373 case 3:
374 package_parameters_.instruction_set = param;
375 break;
376
377 case 4:
378 package_parameters_.dexopt_needed = atoi(param);
379 break;
380
381 case 5:
382 package_parameters_.oat_dir = param;
383 break;
384
385 case 6:
386 package_parameters_.dexopt_flags = atoi(param);
387 break;
388
389 case 7:
390 package_parameters_.compiler_filter = param;
391 break;
392
393 case 8:
394 package_parameters_.volume_uuid = ParseNull(param);
395 break;
396
397 case 9:
398 package_parameters_.shared_libraries = ParseNull(param);
399 break;
400
401 case 10:
402 package_parameters_.se_info = ParseNull(param);
403 break;
404
405 default:
406 LOG(ERROR) << "Too many arguments, got " << param;
407 return false;
408 }
409 }
410
411 if (param_index != 11) {
412 LOG(ERROR) << "Not enough parameters";
413 return false;
414 }
415
416 return true;
417 }
418
419 static int ReplaceMask(int input, int old_mask, int new_mask) {
420 return (input & old_mask) != 0 ? new_mask : 0;
421 }
422
423 bool ReadArgumentsV1(int argc ATTRIBUTE_UNUSED, char** argv) {
424 // Check for "dexopt".
Andreas Gamped089ca12016-06-27 14:25:30 -0700425 if (argv[2] == nullptr) {
426 LOG(ERROR) << "Missing parameters";
427 return false;
428 }
429 if (std::string("dexopt").compare(argv[2]) != 0) {
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700430 LOG(ERROR) << "Expected \"dexopt\"";
Andreas Gamped089ca12016-06-27 14:25:30 -0700431 return false;
432 }
433
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700434 size_t param_index = 0;
435 for (;; ++param_index) {
436 const char* param = argv[3 + param_index];
437 if (param == nullptr) {
438 break;
439 }
440
441 switch (param_index) {
442 case 0:
443 package_parameters_.apk_path = param;
444 break;
445
446 case 1:
447 package_parameters_.uid = atoi(param);
448 break;
449
450 case 2:
451 package_parameters_.pkgName = param;
452 break;
453
454 case 3:
455 package_parameters_.instruction_set = param;
456 break;
457
458 case 4: {
459 // Version 1 had:
460 // DEXOPT_DEX2OAT_NEEDED = 1
461 // DEXOPT_PATCHOAT_NEEDED = 2
462 // DEXOPT_SELF_PATCHOAT_NEEDED = 3
463 // We will simply use DEX2OAT_FROM_SCRATCH.
464 package_parameters_.dexopt_needed = DEX2OAT_FROM_SCRATCH;
465 break;
466 }
467
468 case 5:
469 package_parameters_.oat_dir = param;
470 break;
471
472 case 6: {
473 // Version 1 had:
474 constexpr int OLD_DEXOPT_PUBLIC = 1 << 1;
475 constexpr int OLD_DEXOPT_SAFEMODE = 1 << 2;
476 constexpr int OLD_DEXOPT_DEBUGGABLE = 1 << 3;
477 constexpr int OLD_DEXOPT_BOOTCOMPLETE = 1 << 4;
478 constexpr int OLD_DEXOPT_PROFILE_GUIDED = 1 << 5;
479 constexpr int OLD_DEXOPT_OTA = 1 << 6;
480 int input = atoi(param);
481 package_parameters_.dexopt_flags =
482 ReplaceMask(input, OLD_DEXOPT_PUBLIC, DEXOPT_PUBLIC) |
483 ReplaceMask(input, OLD_DEXOPT_SAFEMODE, DEXOPT_SAFEMODE) |
484 ReplaceMask(input, OLD_DEXOPT_DEBUGGABLE, DEXOPT_DEBUGGABLE) |
485 ReplaceMask(input, OLD_DEXOPT_BOOTCOMPLETE, DEXOPT_BOOTCOMPLETE) |
486 ReplaceMask(input, OLD_DEXOPT_PROFILE_GUIDED, DEXOPT_PROFILE_GUIDED) |
487 ReplaceMask(input, OLD_DEXOPT_OTA, 0);
488 break;
489 }
490
491 case 7:
492 package_parameters_.compiler_filter = param;
493 break;
494
495 case 8:
496 package_parameters_.volume_uuid = ParseNull(param);
497 break;
498
499 case 9:
500 package_parameters_.shared_libraries = ParseNull(param);
501 break;
502
503 default:
504 LOG(ERROR) << "Too many arguments, got " << param;
505 return false;
506 }
Andreas Gampe73dae112015-11-19 14:12:14 -0800507 }
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700508
509 if (param_index != 10) {
510 LOG(ERROR) << "Not enough parameters";
Andreas Gampe73dae112015-11-19 14:12:14 -0800511 return false;
512 }
513
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700514 // Set se_info to null. It is only relevant for secondary dex files, which we won't
515 // receive from a v1 A side.
516 package_parameters_.se_info = nullptr;
517
Andreas Gampe73dae112015-11-19 14:12:14 -0800518 return true;
519 }
520
521 void PrepareEnvironment() {
Andreas Gamped089ca12016-06-27 14:25:30 -0700522 environ_.push_back(StringPrintf("BOOTCLASSPATH=%s", boot_classpath_.c_str()));
523 environ_.push_back(StringPrintf("ANDROID_DATA=%s", GetOTADataDirectory().c_str()));
524 environ_.push_back(StringPrintf("ANDROID_ROOT=%s", android_root_.c_str()));
Andreas Gampe73dae112015-11-19 14:12:14 -0800525
526 for (const std::string& e : environ_) {
527 putenv(const_cast<char*>(e.c_str()));
528 }
529 }
530
531 // Ensure that we have the right boot image. The first time any app is
532 // compiled, we'll try to generate it.
Andreas Gamped089ca12016-06-27 14:25:30 -0700533 bool PrepareBootImage(bool force) const {
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700534 if (package_parameters_.instruction_set == nullptr) {
Andreas Gampe73dae112015-11-19 14:12:14 -0800535 LOG(ERROR) << "Instruction set missing.";
536 return false;
537 }
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700538 const char* isa = package_parameters_.instruction_set;
Andreas Gampe73dae112015-11-19 14:12:14 -0800539
540 // Check whether the file exists where expected.
Andreas Gamped089ca12016-06-27 14:25:30 -0700541 std::string dalvik_cache = GetOTADataDirectory() + "/" + DALVIK_CACHE;
Andreas Gampe73dae112015-11-19 14:12:14 -0800542 std::string isa_path = dalvik_cache + "/" + isa;
543 std::string art_path = isa_path + "/system@framework@boot.art";
544 std::string oat_path = isa_path + "/system@framework@boot.oat";
Andreas Gamped089ca12016-06-27 14:25:30 -0700545 bool cleared = false;
546 if (access(art_path.c_str(), F_OK) == 0 && access(oat_path.c_str(), F_OK) == 0) {
547 // Files exist, assume everything is alright if not forced. Otherwise clean up.
548 if (!force) {
549 return true;
550 }
551 ClearDirectory(isa_path);
552 cleared = true;
Andreas Gampe73dae112015-11-19 14:12:14 -0800553 }
554
Andreas Gamped089ca12016-06-27 14:25:30 -0700555 // Reset umask in otapreopt, so that we control the the access for the files we create.
556 umask(0);
557
Andreas Gampe73dae112015-11-19 14:12:14 -0800558 // Create the directories, if necessary.
559 if (access(dalvik_cache.c_str(), F_OK) != 0) {
Andreas Gamped089ca12016-06-27 14:25:30 -0700560 if (!CreatePath(dalvik_cache)) {
561 PLOG(ERROR) << "Could not create dalvik-cache dir " << dalvik_cache;
Andreas Gampe73dae112015-11-19 14:12:14 -0800562 return false;
563 }
564 }
565 if (access(isa_path.c_str(), F_OK) != 0) {
Andreas Gamped089ca12016-06-27 14:25:30 -0700566 if (!CreatePath(isa_path)) {
Andreas Gampe73dae112015-11-19 14:12:14 -0800567 PLOG(ERROR) << "Could not create dalvik-cache isa dir";
568 return false;
569 }
570 }
571
Andreas Gampe5709b572016-02-12 17:42:59 -0800572 // Prepare to create.
Andreas Gamped089ca12016-06-27 14:25:30 -0700573 if (!cleared) {
574 ClearDirectory(isa_path);
575 }
Andreas Gampe73dae112015-11-19 14:12:14 -0800576
Andreas Gampe9fb85b02016-03-16 10:09:29 -0700577 std::string preopted_boot_art_path = StringPrintf("/system/framework/%s/boot.art", isa);
Andreas Gampe5709b572016-02-12 17:42:59 -0800578 if (access(preopted_boot_art_path.c_str(), F_OK) == 0) {
579 return PatchoatBootImage(art_path, isa);
580 } else {
581 // No preopted boot image. Try to compile.
Andreas Gamped089ca12016-06-27 14:25:30 -0700582 return Dex2oatBootImage(boot_classpath_, art_path, oat_path, isa);
Andreas Gampe5709b572016-02-12 17:42:59 -0800583 }
584 }
585
Andreas Gamped089ca12016-06-27 14:25:30 -0700586 static bool CreatePath(const std::string& path) {
587 // Create the given path. Use string processing instead of dirname, as dirname's need for
588 // a writable char buffer is painful.
589
590 // First, try to use the full path.
591 if (mkdir(path.c_str(), 0711) == 0) {
592 return true;
593 }
594 if (errno != ENOENT) {
595 PLOG(ERROR) << "Could not create path " << path;
596 return false;
597 }
598
599 // Now find the parent and try that first.
600 size_t last_slash = path.find_last_of('/');
601 if (last_slash == std::string::npos || last_slash == 0) {
602 PLOG(ERROR) << "Could not create " << path;
603 return false;
604 }
605
606 if (!CreatePath(path.substr(0, last_slash))) {
607 return false;
608 }
609
610 if (mkdir(path.c_str(), 0711) == 0) {
611 return true;
612 }
613 PLOG(ERROR) << "Could not create " << path;
614 return false;
615 }
616
617 static void ClearDirectory(const std::string& dir) {
618 DIR* c_dir = opendir(dir.c_str());
619 if (c_dir == nullptr) {
620 PLOG(WARNING) << "Unable to open " << dir << " to delete it's contents";
621 return;
622 }
623
624 for (struct dirent* de = readdir(c_dir); de != nullptr; de = readdir(c_dir)) {
625 const char* name = de->d_name;
626 if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
627 continue;
628 }
629 // We only want to delete regular files and symbolic links.
630 std::string file = StringPrintf("%s/%s", dir.c_str(), name);
631 if (de->d_type != DT_REG && de->d_type != DT_LNK) {
632 LOG(WARNING) << "Unexpected file "
633 << file
634 << " of type "
635 << std::hex
636 << de->d_type
637 << " encountered.";
638 } else {
639 // Try to unlink the file.
640 if (unlink(file.c_str()) != 0) {
641 PLOG(ERROR) << "Unable to unlink " << file;
642 }
643 }
644 }
645 CHECK_EQ(0, closedir(c_dir)) << "Unable to close directory.";
646 }
647
648 bool PatchoatBootImage(const std::string& art_path, const char* isa) const {
Andreas Gampe5709b572016-02-12 17:42:59 -0800649 // This needs to be kept in sync with ART, see art/runtime/gc/space/image_space.cc.
650
651 std::vector<std::string> cmd;
Andreas Gampe9fb85b02016-03-16 10:09:29 -0700652 cmd.push_back("/system/bin/patchoat");
Andreas Gampe5709b572016-02-12 17:42:59 -0800653
654 cmd.push_back("--input-image-location=/system/framework/boot.art");
655 cmd.push_back(StringPrintf("--output-image-file=%s", art_path.c_str()));
656
657 cmd.push_back(StringPrintf("--instruction-set=%s", isa));
658
659 int32_t base_offset = ChooseRelocationOffsetDelta(ART_BASE_ADDRESS_MIN_DELTA,
660 ART_BASE_ADDRESS_MAX_DELTA);
Andreas Gampefebf0bf2016-02-29 18:04:17 -0800661 cmd.push_back(StringPrintf("--base-offset-delta=%d", base_offset));
Andreas Gampe5709b572016-02-12 17:42:59 -0800662
663 std::string error_msg;
664 bool result = Exec(cmd, &error_msg);
665 if (!result) {
666 LOG(ERROR) << "Could not generate boot image: " << error_msg;
667 }
668 return result;
669 }
670
671 bool Dex2oatBootImage(const std::string& boot_cp,
672 const std::string& art_path,
673 const std::string& oat_path,
Andreas Gamped089ca12016-06-27 14:25:30 -0700674 const char* isa) const {
Andreas Gampe73dae112015-11-19 14:12:14 -0800675 // This needs to be kept in sync with ART, see art/runtime/gc/space/image_space.cc.
676 std::vector<std::string> cmd;
Andreas Gampe9fb85b02016-03-16 10:09:29 -0700677 cmd.push_back("/system/bin/dex2oat");
Andreas Gampe73dae112015-11-19 14:12:14 -0800678 cmd.push_back(StringPrintf("--image=%s", art_path.c_str()));
Andreas Gampe6db8db92016-06-03 10:22:19 -0700679 for (const std::string& boot_part : Split(boot_cp, ":")) {
Andreas Gampe73dae112015-11-19 14:12:14 -0800680 cmd.push_back(StringPrintf("--dex-file=%s", boot_part.c_str()));
681 }
682 cmd.push_back(StringPrintf("--oat-file=%s", oat_path.c_str()));
683
684 int32_t base_offset = ChooseRelocationOffsetDelta(ART_BASE_ADDRESS_MIN_DELTA,
685 ART_BASE_ADDRESS_MAX_DELTA);
686 cmd.push_back(StringPrintf("--base=0x%x", ART_BASE_ADDRESS + base_offset));
687
688 cmd.push_back(StringPrintf("--instruction-set=%s", isa));
689
690 // These things are pushed by AndroidRuntime, see frameworks/base/core/jni/AndroidRuntime.cpp.
691 AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-Xms",
692 "-Xms",
693 true,
694 cmd);
695 AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-Xmx",
696 "-Xmx",
697 true,
698 cmd);
699 AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-filter",
700 "--compiler-filter=",
701 false,
702 cmd);
Andreas Gampe9fb85b02016-03-16 10:09:29 -0700703 cmd.push_back("--image-classes=/system/etc/preloaded-classes");
Andreas Gampe73dae112015-11-19 14:12:14 -0800704 // TODO: Compiled-classes.
705 const std::string* extra_opts =
706 system_properties_.GetProperty("dalvik.vm.image-dex2oat-flags");
707 if (extra_opts != nullptr) {
Andreas Gampe6db8db92016-06-03 10:22:19 -0700708 std::vector<std::string> extra_vals = Split(*extra_opts, " ");
Andreas Gampe73dae112015-11-19 14:12:14 -0800709 cmd.insert(cmd.end(), extra_vals.begin(), extra_vals.end());
710 }
711 // TODO: Should we lower this? It's usually set close to max, because
712 // normally there's not much else going on at boot.
713 AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-threads",
714 "-j",
715 false,
716 cmd);
717 AddCompilerOptionFromSystemProperty(
718 StringPrintf("dalvik.vm.isa.%s.variant", isa).c_str(),
719 "--instruction-set-variant=",
720 false,
721 cmd);
722 AddCompilerOptionFromSystemProperty(
723 StringPrintf("dalvik.vm.isa.%s.features", isa).c_str(),
724 "--instruction-set-features=",
725 false,
726 cmd);
727
728 std::string error_msg;
729 bool result = Exec(cmd, &error_msg);
730 if (!result) {
731 LOG(ERROR) << "Could not generate boot image: " << error_msg;
732 }
733 return result;
734 }
735
736 static const char* ParseNull(const char* arg) {
737 return (strcmp(arg, "!") == 0) ? nullptr : arg;
738 }
739
Andreas Gamped089ca12016-06-27 14:25:30 -0700740 bool ShouldSkipPreopt() const {
Andreas Gampe56f79f92016-06-08 15:11:37 -0700741 // There's one thing we have to be careful about: we may/will be asked to compile an app
742 // living in the system image. This may be a valid request - if the app wasn't compiled,
743 // e.g., if the system image wasn't large enough to include preopted files. However, the
744 // data we have is from the old system, so the driver (the OTA service) can't actually
745 // know. Thus, we will get requests for apps that have preopted components. To avoid
746 // duplication (we'd generate files that are not used and are *not* cleaned up), do two
747 // simple checks:
748 //
749 // 1) Does the apk_path start with the value of ANDROID_ROOT? (~in the system image)
750 // (For simplicity, assume the value of ANDROID_ROOT does not contain a symlink.)
751 //
752 // 2) If you replace the name in the apk_path with "oat," does the path exist?
753 // (=have a subdirectory for preopted files)
754 //
755 // If the answer to both is yes, skip the dexopt.
756 //
757 // Note: while one may think it's OK to call dexopt and it will fail (because APKs should
758 // be stripped), that's not true for APKs signed outside the build system (so the
759 // jar content must be exactly the same).
760
761 // (This is ugly as it's the only thing where we need to understand the contents
762 // of package_parameters_, but it beats postponing the decision or using the call-
763 // backs to do weird things.)
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700764 const char* apk_path = package_parameters_.apk_path;
765 CHECK(apk_path != nullptr);
766 if (StartsWith(apk_path, android_root_.c_str())) {
767 const char* last_slash = strrchr(apk_path, '/');
Andreas Gampe56f79f92016-06-08 15:11:37 -0700768 if (last_slash != nullptr) {
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700769 std::string path(apk_path, last_slash - apk_path + 1);
Andreas Gampe56f79f92016-06-08 15:11:37 -0700770 CHECK(EndsWith(path, "/"));
771 path = path + "oat";
772 if (access(path.c_str(), F_OK) == 0) {
Andreas Gamped089ca12016-06-27 14:25:30 -0700773 return true;
Andreas Gampe56f79f92016-06-08 15:11:37 -0700774 }
775 }
776 }
777
Andreas Gamped089ca12016-06-27 14:25:30 -0700778 // Another issue is unavailability of files in the new system. If the partition
779 // layout changes, otapreopt_chroot may not know about this. Then files from that
780 // partition will not be available and fail to build. This is problematic, as
781 // this tool will wipe the OTA artifact cache and try again (for robustness after
782 // a failed OTA with remaining cache artifacts).
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700783 if (access(apk_path, F_OK) != 0) {
784 LOG(WARNING) << "Skipping preopt of non-existing package " << apk_path;
Andreas Gamped089ca12016-06-27 14:25:30 -0700785 return true;
786 }
787
788 return false;
789 }
790
Andreas Gampeb39d2f02017-04-17 20:04:02 -0700791 // Run dexopt with the parameters of package_parameters_.
792 int Dexopt() {
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700793 return dexopt(package_parameters_.apk_path,
794 package_parameters_.uid,
795 package_parameters_.pkgName,
796 package_parameters_.instruction_set,
797 package_parameters_.dexopt_needed,
798 package_parameters_.oat_dir,
799 package_parameters_.dexopt_flags,
800 package_parameters_.compiler_filter,
801 package_parameters_.volume_uuid,
802 package_parameters_.shared_libraries,
803 package_parameters_.se_info);
Andreas Gampe73dae112015-11-19 14:12:14 -0800804 }
805
Andreas Gampeb39d2f02017-04-17 20:04:02 -0700806 int RunPreopt() {
807 if (ShouldSkipPreopt()) {
808 return 0;
809 }
810
811 int dexopt_result = Dexopt();
812 if (dexopt_result == 0) {
813 return 0;
814 }
815
816 // If the dexopt failed, we may have a stale boot image from a previous OTA run.
817 // Then regenerate and retry.
818 if (WEXITSTATUS(dexopt_result) ==
819 static_cast<int>(art::dex2oat::ReturnCode::kCreateRuntime)) {
820 if (!PrepareBootImage(/* force */ true)) {
821 LOG(ERROR) << "Forced boot image creating failed. Original error return was "
822 << dexopt_result;
823 return dexopt_result;
824 }
825
826 int dexopt_result_boot_image_retry = Dexopt();
827 if (dexopt_result_boot_image_retry == 0) {
828 return 0;
829 }
830 }
831
832 // If this was a profile-guided run, we may have profile version issues. Try to downgrade,
833 // if possible.
834 if ((package_parameters_.dexopt_flags & DEXOPT_PROFILE_GUIDED) == 0) {
835 return dexopt_result;
836 }
837
838 LOG(WARNING) << "Downgrading compiler filter in an attempt to progress compilation";
839 package_parameters_.dexopt_flags &= ~DEXOPT_PROFILE_GUIDED;
840 return Dexopt();
841 }
842
Andreas Gampe73dae112015-11-19 14:12:14 -0800843 ////////////////////////////////////
844 // Helpers, mostly taken from ART //
845 ////////////////////////////////////
846
847 // Wrapper on fork/execv to run a command in a subprocess.
Andreas Gamped089ca12016-06-27 14:25:30 -0700848 static bool Exec(const std::vector<std::string>& arg_vector, std::string* error_msg) {
Andreas Gampe6db8db92016-06-03 10:22:19 -0700849 const std::string command_line = Join(arg_vector, ' ');
Andreas Gampe73dae112015-11-19 14:12:14 -0800850
851 CHECK_GE(arg_vector.size(), 1U) << command_line;
852
853 // Convert the args to char pointers.
854 const char* program = arg_vector[0].c_str();
855 std::vector<char*> args;
856 for (size_t i = 0; i < arg_vector.size(); ++i) {
857 const std::string& arg = arg_vector[i];
858 char* arg_str = const_cast<char*>(arg.c_str());
859 CHECK(arg_str != nullptr) << i;
860 args.push_back(arg_str);
861 }
862 args.push_back(nullptr);
863
864 // Fork and exec.
865 pid_t pid = fork();
866 if (pid == 0) {
867 // No allocation allowed between fork and exec.
868
869 // Change process groups, so we don't get reaped by ProcessManager.
870 setpgid(0, 0);
871
872 execv(program, &args[0]);
873
874 PLOG(ERROR) << "Failed to execv(" << command_line << ")";
875 // _exit to avoid atexit handlers in child.
876 _exit(1);
877 } else {
878 if (pid == -1) {
879 *error_msg = StringPrintf("Failed to execv(%s) because fork failed: %s",
880 command_line.c_str(), strerror(errno));
881 return false;
882 }
883
884 // wait for subprocess to finish
885 int status;
886 pid_t got_pid = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0));
887 if (got_pid != pid) {
888 *error_msg = StringPrintf("Failed after fork for execv(%s) because waitpid failed: "
889 "wanted %d, got %d: %s",
890 command_line.c_str(), pid, got_pid, strerror(errno));
891 return false;
892 }
893 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
894 *error_msg = StringPrintf("Failed execv(%s) because non-0 exit status",
895 command_line.c_str());
896 return false;
897 }
898 }
899 return true;
900 }
901
902 // Choose a random relocation offset. Taken from art/runtime/gc/image_space.cc.
903 static int32_t ChooseRelocationOffsetDelta(int32_t min_delta, int32_t max_delta) {
904 constexpr size_t kPageSize = PAGE_SIZE;
905 CHECK_EQ(min_delta % kPageSize, 0u);
906 CHECK_EQ(max_delta % kPageSize, 0u);
907 CHECK_LT(min_delta, max_delta);
908
909 std::default_random_engine generator;
910 generator.seed(GetSeed());
911 std::uniform_int_distribution<int32_t> distribution(min_delta, max_delta);
912 int32_t r = distribution(generator);
913 if (r % 2 == 0) {
914 r = RoundUp(r, kPageSize);
915 } else {
916 r = RoundDown(r, kPageSize);
917 }
918 CHECK_LE(min_delta, r);
919 CHECK_GE(max_delta, r);
920 CHECK_EQ(r % kPageSize, 0u);
921 return r;
922 }
923
924 static uint64_t GetSeed() {
925#ifdef __BIONIC__
926 // Bionic exposes arc4random, use it.
927 uint64_t random_data;
928 arc4random_buf(&random_data, sizeof(random_data));
929 return random_data;
930#else
931#error "This is only supposed to run with bionic. Otherwise, implement..."
932#endif
933 }
934
935 void AddCompilerOptionFromSystemProperty(const char* system_property,
936 const char* prefix,
937 bool runtime,
Andreas Gamped089ca12016-06-27 14:25:30 -0700938 std::vector<std::string>& out) const {
939 const std::string* value = system_properties_.GetProperty(system_property);
Andreas Gampe73dae112015-11-19 14:12:14 -0800940 if (value != nullptr) {
941 if (runtime) {
942 out.push_back("--runtime-arg");
943 }
944 if (prefix != nullptr) {
945 out.push_back(StringPrintf("%s%s", prefix, value->c_str()));
946 } else {
947 out.push_back(*value);
948 }
949 }
950 }
951
Andreas Gamped089ca12016-06-27 14:25:30 -0700952 static constexpr const char* kBootClassPathPropertyName = "BOOTCLASSPATH";
953 static constexpr const char* kAndroidRootPathPropertyName = "ANDROID_ROOT";
954 static constexpr const char* kAndroidDataPathPropertyName = "ANDROID_DATA";
955 // The index of the instruction-set string inside the package parameters. Needed for
956 // some special-casing that requires knowledge of the instruction-set.
957 static constexpr size_t kISAIndex = 3;
958
Andreas Gampe73dae112015-11-19 14:12:14 -0800959 // Stores the system properties read out of the B partition. We need to use these properties
960 // to compile, instead of the A properties we could get from init/get_property.
961 SystemProperties system_properties_;
962
Andreas Gamped089ca12016-06-27 14:25:30 -0700963 // Some select properties that are always needed.
964 std::string target_slot_;
965 std::string android_root_;
966 std::string android_data_;
967 std::string boot_classpath_;
968 std::string asec_mountpoint_;
969
Andreas Gampec4ced4f2017-04-14 20:39:56 -0700970 Parameters package_parameters_;
Andreas Gampe73dae112015-11-19 14:12:14 -0800971
972 // Store environment values we need to set.
973 std::vector<std::string> environ_;
974};
975
976OTAPreoptService gOps;
977
978////////////////////////
979// Plug-in functions. //
980////////////////////////
981
982int get_property(const char *key, char *value, const char *default_value) {
Andreas Gampe73dae112015-11-19 14:12:14 -0800983 return gOps.GetProperty(key, value, default_value);
984}
985
986// Compute the output path of
987bool calculate_oat_file_path(char path[PKG_PATH_MAX], const char *oat_dir,
988 const char *apk_path,
989 const char *instruction_set) {
Dan Austin9c8f93a2016-06-03 16:15:54 -0700990 const char *file_name_start;
991 const char *file_name_end;
Andreas Gampe73dae112015-11-19 14:12:14 -0800992
993 file_name_start = strrchr(apk_path, '/');
994 if (file_name_start == nullptr) {
995 ALOGE("apk_path '%s' has no '/'s in it\n", apk_path);
996 return false;
997 }
998 file_name_end = strrchr(file_name_start, '.');
999 if (file_name_end == nullptr) {
1000 ALOGE("apk_path '%s' has no extension\n", apk_path);
1001 return false;
1002 }
1003
1004 // Calculate file_name
1005 file_name_start++; // Move past '/', is valid as file_name_end is valid.
1006 size_t file_name_len = file_name_end - file_name_start;
1007 std::string file_name(file_name_start, file_name_len);
1008
1009 // <apk_parent_dir>/oat/<isa>/<file_name>.odex.b
Andreas Gamped089ca12016-06-27 14:25:30 -07001010 snprintf(path,
1011 PKG_PATH_MAX,
1012 "%s/%s/%s.odex.%s",
1013 oat_dir,
1014 instruction_set,
1015 file_name.c_str(),
1016 gOps.GetTargetSlot().c_str());
Andreas Gampe73dae112015-11-19 14:12:14 -08001017 return true;
1018}
1019
1020/*
1021 * Computes the odex file for the given apk_path and instruction_set.
1022 * /system/framework/whatever.jar -> /system/framework/oat/<isa>/whatever.odex
1023 *
1024 * Returns false if it failed to determine the odex file path.
1025 */
1026bool calculate_odex_file_path(char path[PKG_PATH_MAX], const char *apk_path,
1027 const char *instruction_set) {
Andreas Gampe73dae112015-11-19 14:12:14 -08001028 const char *path_end = strrchr(apk_path, '/');
1029 if (path_end == nullptr) {
1030 ALOGE("apk_path '%s' has no '/'s in it?!\n", apk_path);
1031 return false;
1032 }
1033 std::string path_component(apk_path, path_end - apk_path);
1034
1035 const char *name_begin = path_end + 1;
1036 const char *extension_start = strrchr(name_begin, '.');
1037 if (extension_start == nullptr) {
1038 ALOGE("apk_path '%s' has no extension.\n", apk_path);
1039 return false;
1040 }
1041 std::string name_component(name_begin, extension_start - name_begin);
1042
Andreas Gamped089ca12016-06-27 14:25:30 -07001043 std::string new_path = StringPrintf("%s/oat/%s/%s.odex.%s",
Andreas Gampe73dae112015-11-19 14:12:14 -08001044 path_component.c_str(),
1045 instruction_set,
Andreas Gamped089ca12016-06-27 14:25:30 -07001046 name_component.c_str(),
1047 gOps.GetTargetSlot().c_str());
1048 if (new_path.length() >= PKG_PATH_MAX) {
1049 LOG(ERROR) << "apk_path of " << apk_path << " is too long: " << new_path;
1050 return false;
1051 }
Andreas Gampe73dae112015-11-19 14:12:14 -08001052 strcpy(path, new_path.c_str());
1053 return true;
1054}
1055
1056bool create_cache_path(char path[PKG_PATH_MAX],
1057 const char *src,
1058 const char *instruction_set) {
1059 size_t srclen = strlen(src);
1060
1061 /* demand that we are an absolute path */
1062 if ((src == 0) || (src[0] != '/') || strstr(src,"..")) {
1063 return false;
1064 }
1065
1066 if (srclen > PKG_PATH_MAX) { // XXX: PKG_NAME_MAX?
1067 return false;
1068 }
1069
1070 std::string from_src = std::string(src + 1);
1071 std::replace(from_src.begin(), from_src.end(), '/', '@');
1072
1073 std::string assembled_path = StringPrintf("%s/%s/%s/%s%s",
Andreas Gamped089ca12016-06-27 14:25:30 -07001074 gOps.GetOTADataDirectory().c_str(),
Andreas Gampe73dae112015-11-19 14:12:14 -08001075 DALVIK_CACHE,
1076 instruction_set,
1077 from_src.c_str(),
David Brazdil249c1792016-09-06 15:35:28 +01001078 DALVIK_CACHE_POSTFIX);
Andreas Gampe73dae112015-11-19 14:12:14 -08001079
1080 if (assembled_path.length() + 1 > PKG_PATH_MAX) {
1081 return false;
1082 }
1083 strcpy(path, assembled_path.c_str());
1084
1085 return true;
1086}
1087
Andreas Gampe73dae112015-11-19 14:12:14 -08001088static int log_callback(int type, const char *fmt, ...) {
1089 va_list ap;
1090 int priority;
1091
1092 switch (type) {
1093 case SELINUX_WARNING:
1094 priority = ANDROID_LOG_WARN;
1095 break;
1096 case SELINUX_INFO:
1097 priority = ANDROID_LOG_INFO;
1098 break;
1099 default:
1100 priority = ANDROID_LOG_ERROR;
1101 break;
1102 }
1103 va_start(ap, fmt);
1104 LOG_PRI_VA(priority, "SELinux", fmt, ap);
1105 va_end(ap);
1106 return 0;
1107}
1108
1109static int otapreopt_main(const int argc, char *argv[]) {
1110 int selinux_enabled = (is_selinux_enabled() > 0);
1111
1112 setenv("ANDROID_LOG_TAGS", "*:v", 1);
1113 android::base::InitLogging(argv);
1114
Andreas Gampe73dae112015-11-19 14:12:14 -08001115 if (argc < 2) {
1116 ALOGE("Expecting parameters");
1117 exit(1);
1118 }
1119
1120 union selinux_callback cb;
1121 cb.func_log = log_callback;
1122 selinux_set_callback(SELINUX_CB_LOG, cb);
1123
Andreas Gampe73dae112015-11-19 14:12:14 -08001124 if (selinux_enabled && selinux_status_open(true) < 0) {
1125 ALOGE("Could not open selinux status; exiting.\n");
1126 exit(1);
1127 }
1128
1129 int ret = android::installd::gOps.Main(argc, argv);
1130
1131 return ret;
1132}
1133
1134} // namespace installd
1135} // namespace android
1136
1137int main(const int argc, char *argv[]) {
1138 return android::installd::otapreopt_main(argc, argv);
1139}