1 /*
2  * Copyright (C) 2020 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 #ifndef ART_ODREFRESH_INCLUDE_ODREFRESH_ODREFRESH_H_
18 #define ART_ODREFRESH_INCLUDE_ODREFRESH_ODREFRESH_H_
19 
20 #include <sysexits.h>
21 
22 namespace art {
23 namespace odrefresh {
24 
25 static constexpr const char* kOdrefreshArtifactDirectory =
26     "/data/misc/apexdata/com.android.art/dalvik-cache";
27 
28 //
29 // Exit codes from the odrefresh process (in addition to standard exit codes in sysexits.h).
30 //
31 // NB if odrefresh crashes, then the caller should not sign any artifacts and should remove any
32 // unsigned artifacts under `kOdrefreshArtifactDirectory`.
33 //
34 enum ExitCode : int {
35   // No compilation required, all artifacts look good or there is insufficient space to compile.
36   // For ART APEX in the system image, there may be no artifacts present under
37   // `kOdrefreshArtifactDirectory`.
38   kOkay = EX_OK,
39 
40   // Compilation required (only returned for --check). Re-run program with --compile on the
41   // command-line to generate + new artifacts under `kOdrefreshArtifactDirectory`.
42   kCompilationRequired = EX__MAX + 1,
43 
44   // New artifacts successfully generated under `kOdrefreshArtifactDirectory`.
45   kCompilationSuccess = EX__MAX + 2,
46 
47   // Compilation failed. Any artifacts under `kOdrefreshArtifactDirectory` are valid and should not
48   // be removed. This may happen, for example, if compilation of boot extensions succeeds, but the
49   // compilation of the system_server jars fails due to lack of storage space.
50   kCompilationFailed = EX__MAX + 3,
51 
52   // Removal of existing artifacts (or files under `kOdrefreshArtifactDirectory`) failed. Artifacts
53   // should be treated as invalid and should be removed if possible.
54   kCleanupFailed = EX__MAX + 4,
55 
56   // Last exit code defined.
57   kLastExitCode = kCleanupFailed,
58 };
59 
60 static_assert(EX_OK == 0);
61 static_assert(ExitCode::kOkay < EX__BASE);
62 static_assert(ExitCode::kLastExitCode < 0xff);  // The `exit()` man page discusses the mask value.
63 
64 }  // namespace odrefresh
65 }  // namespace art
66 
67 #endif  // ART_ODREFRESH_INCLUDE_ODREFRESH_ODREFRESH_H_
68