• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 namespace android {
18 namespace installd {
19 
20 // Constants for exit codes that installd code emits. These are failure situations before calling
21 // any tools, e.g., in validation, and must not overlap with the exit codes of tools, so they
22 // can be distinguished.
23 enum DexoptReturnCodes : int {
24     kSetGid = 64,
25     kSetUid = 65,
26     kCapSet = 66,
27     kFlock = 67,
28     kProfmanExec = 68,
29     kSetSchedPolicy = 70,
30     kSetPriority = 71,
31     kDex2oatExec = 72,
32     kInstructionSetLength = 73,
33     kHashValidatePath = 74,
34     kHashOpenPath = 75,
35     kHashReadDex = 76,
36     kHashWrite = 77,
37 };
38 
get_installd_return_code_name(DexoptReturnCodes code)39 inline const char* get_installd_return_code_name(DexoptReturnCodes code) {
40     switch (code) {
41         case kSetGid:
42             return "setgid";
43         case kSetUid:
44             return "setuid";
45         case kCapSet:
46             return "capset";
47         case kFlock:
48             return "flock";
49         case kProfmanExec:
50             return "exec(profman)";
51         case kSetSchedPolicy:
52             return "setschedpolicy";
53         case kSetPriority:
54             return "setpriority";
55         case kDex2oatExec:
56             return "exec(dex2oat)";
57         case kInstructionSetLength:
58             return "instruction-set-length";
59         case kHashValidatePath:
60             return "hash(validate-path)";
61         case kHashOpenPath:
62             return "hash(open-path)";
63         case kHashReadDex:
64             return "hash(read-dex)";
65         case kHashWrite:
66             return "hash(write)";
67     }
68     return nullptr;
69 }
70 
get_dex2oat_return_code_name(int code)71 inline const char* get_dex2oat_return_code_name(int code) {
72     if (code == 0) {
73         return "dex2oat success";
74     } else {
75         return "dex2oat error";
76     }
77 }
78 
79 // Get some slightly descriptive string for the return code.
get_return_code_name(int code)80 inline const char* get_return_code_name(int code) {
81     const char* value = get_installd_return_code_name(static_cast<DexoptReturnCodes>(code));
82     if (value != nullptr) {
83         return value;
84     }
85     value = get_dex2oat_return_code_name(code);
86     return value;
87 }
88 
89 }  // namespace installd
90 }  // namespace android
91