diff options
Diffstat (limited to 'toolbox')
-rw-r--r-- | toolbox/Android.bp | 9 | ||||
-rw-r--r-- | toolbox/getprop.cpp | 126 |
2 files changed, 1 insertions, 134 deletions
diff --git a/toolbox/Android.bp b/toolbox/Android.bp index de8324af3..b5d16b80f 100644 --- a/toolbox/Android.bp +++ b/toolbox/Android.bp | |||
@@ -34,7 +34,7 @@ cc_library_static { | |||
34 | 34 | ||
35 | genrule { | 35 | genrule { |
36 | name: "toolbox_tools", | 36 | name: "toolbox_tools", |
37 | cmd: "echo '/* file generated automatically */' >$(out) && for t in toolbox dd getevent newfs_msdos getprop; do echo \"TOOL($$t)\" >>$(out); done", | 37 | cmd: "echo '/* file generated automatically */' >$(out) && for t in toolbox dd getevent newfs_msdos; do echo \"TOOL($$t)\" >>$(out); done", |
38 | out: ["tools.h"], | 38 | out: ["tools.h"], |
39 | } | 39 | } |
40 | 40 | ||
@@ -52,7 +52,6 @@ cc_binary { | |||
52 | srcs: [ | 52 | srcs: [ |
53 | "toolbox.c", | 53 | "toolbox.c", |
54 | "getevent.c", | 54 | "getevent.c", |
55 | "getprop.cpp", | ||
56 | "newfs_msdos.c", | 55 | "newfs_msdos.c", |
57 | ], | 56 | ], |
58 | generated_headers: [ | 57 | generated_headers: [ |
@@ -61,18 +60,12 @@ cc_binary { | |||
61 | ], | 60 | ], |
62 | whole_static_libs: ["libtoolbox_dd"], | 61 | whole_static_libs: ["libtoolbox_dd"], |
63 | shared_libs: [ | 62 | shared_libs: [ |
64 | "libbase", | ||
65 | "libcutils", | 63 | "libcutils", |
66 | ], | 64 | ], |
67 | static_libs: [ | ||
68 | "libpropertyinfoparser", | ||
69 | ], | ||
70 | cpp_std: "gnu++1z", | ||
71 | 65 | ||
72 | symlinks: [ | 66 | symlinks: [ |
73 | "dd", | 67 | "dd", |
74 | "getevent", | 68 | "getevent", |
75 | "getprop", | ||
76 | "newfs_msdos", | 69 | "newfs_msdos", |
77 | ], | 70 | ], |
78 | } | 71 | } |
diff --git a/toolbox/getprop.cpp b/toolbox/getprop.cpp deleted file mode 100644 index 7818ff222..000000000 --- a/toolbox/getprop.cpp +++ /dev/null | |||
@@ -1,126 +0,0 @@ | |||
1 | // | ||
2 | // Copyright (C) 2017 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 <getopt.h> | ||
18 | #include <sys/system_properties.h> | ||
19 | |||
20 | #include <iostream> | ||
21 | #include <string> | ||
22 | #include <vector> | ||
23 | |||
24 | #include <android-base/properties.h> | ||
25 | #include <property_info_parser/property_info_parser.h> | ||
26 | |||
27 | using android::base::GetProperty; | ||
28 | using android::properties::PropertyInfoAreaFile; | ||
29 | |||
30 | PropertyInfoAreaFile property_info_file; | ||
31 | |||
32 | void PrintAllProperties(bool print_property_context) { | ||
33 | std::vector<std::pair<std::string, std::string>> properties; | ||
34 | __system_property_foreach( | ||
35 | [](const prop_info* pi, void* cookie) { | ||
36 | __system_property_read_callback( | ||
37 | pi, | ||
38 | [](void* cookie, const char* name, const char* value, unsigned) { | ||
39 | auto properties = | ||
40 | reinterpret_cast<std::vector<std::pair<std::string, std::string>>*>(cookie); | ||
41 | properties->emplace_back(name, value); | ||
42 | }, | ||
43 | cookie); | ||
44 | }, | ||
45 | &properties); | ||
46 | |||
47 | std::sort(properties.begin(), properties.end()); | ||
48 | |||
49 | if (print_property_context) { | ||
50 | for (auto& [name, value] : properties) { | ||
51 | const char* context = nullptr; | ||
52 | property_info_file->GetPropertyInfo(name.c_str(), &context, nullptr); | ||
53 | value = context; | ||
54 | } | ||
55 | } | ||
56 | |||
57 | for (const auto& [name, value] : properties) { | ||
58 | std::cout << "[" << name << "]: [" << value << "]" << std::endl; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | void PrintProperty(const char* name, const char* default_value, bool print_property_context) { | ||
63 | if (print_property_context) { | ||
64 | const char* context = nullptr; | ||
65 | property_info_file->GetPropertyInfo(name, &context, nullptr); | ||
66 | std::cout << context << std::endl; | ||
67 | } else { | ||
68 | std::cout << GetProperty(name, default_value) << std::endl; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | extern "C" int getprop_main(int argc, char** argv) { | ||
73 | bool print_property_context = false; | ||
74 | |||
75 | while (true) { | ||
76 | static const struct option long_options[] = { | ||
77 | {"help", no_argument, nullptr, 'h'}, | ||
78 | {nullptr, 0, nullptr, 0}, | ||
79 | }; | ||
80 | |||
81 | int arg = getopt_long(argc, argv, "Z", long_options, nullptr); | ||
82 | |||
83 | if (arg == -1) { | ||
84 | break; | ||
85 | } | ||
86 | |||
87 | switch (arg) { | ||
88 | case 'h': | ||
89 | std::cout << "usage: getprop [-Z] [NAME [DEFAULT]]\n\n" | ||
90 | "Gets an Android system property, or lists them all.\n" | ||
91 | "Use -Z to return the property context instead of the property value\n" | ||
92 | << std::endl; | ||
93 | return 0; | ||
94 | case 'Z': | ||
95 | print_property_context = true; | ||
96 | break; | ||
97 | case '?': | ||
98 | return -1; | ||
99 | default: | ||
100 | std::cerr << "getprop: getopt returned invalid result: " << arg << std::endl; | ||
101 | return -1; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | if (print_property_context) { | ||
106 | property_info_file.LoadDefaultPath(); | ||
107 | if (!property_info_file) { | ||
108 | std::cerr << "Unable to load property info file" << std::endl; | ||
109 | return -1; | ||
110 | } | ||
111 | } | ||
112 | |||
113 | if (optind >= argc) { | ||
114 | PrintAllProperties(print_property_context); | ||
115 | return 0; | ||
116 | } | ||
117 | |||
118 | if (optind < argc - 2) { | ||
119 | std::cerr << "getprop: Max 2 arguments (see \"getprop --help\")" << std::endl; | ||
120 | return -1; | ||
121 | } | ||
122 | |||
123 | PrintProperty(argv[optind], (optind == argc - 1) ? "" : argv[optind + 1], print_property_context); | ||
124 | |||
125 | return 0; | ||
126 | } | ||