blob: 16ecdcda495c514014cf2e4088099bed376c4d05 [file] [log] [blame]
Tom Cherryfa0c21c2015-07-23 17:53:11 -07001/*
2 * Copyright (C) 2015 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 "action.h"
18
Tom Cherryede0d532017-07-06 14:20:11 -070019#include <android-base/chrono_utils.h>
Tom Cherry3f5eaae52017-04-06 16:30:22 -070020#include <android-base/logging.h>
Tom Cherryccf23532017-03-28 16:40:41 -070021#include <android-base/properties.h>
Tom Cherryccf23532017-03-28 16:40:41 -070022#include <android-base/strings.h>
Tom Cherryfa0c21c2015-07-23 17:53:11 -070023
Tom Cherryfa0c21c2015-07-23 17:53:11 -070024#include "util.h"
25
Tom Cherryb7349902015-08-26 11:43:36 -070026using android::base::Join;
Tom Cherrycb0f9bb2017-09-12 15:58:47 -070027using android::base::StartsWith;
Tom Cherryfa0c21c2015-07-23 17:53:11 -070028
Tom Cherry81f5d3e2017-06-22 12:53:17 -070029namespace android {
30namespace init {
31
Tom Cherrycb0f9bb2017-09-12 15:58:47 -070032Result<Success> RunBuiltinFunction(const BuiltinFunction& function,
33 const std::vector<std::string>& args,
34 const std::string& context) {
35 auto builtin_arguments = BuiltinArguments(context);
Tom Cherryfa0c21c2015-07-23 17:53:11 -070036
Tom Cherrycb0f9bb2017-09-12 15:58:47 -070037 builtin_arguments.args.resize(args.size());
38 builtin_arguments.args[0] = args[0];
39 for (std::size_t i = 1; i < args.size(); ++i) {
40 if (!expand_props(args[i], &builtin_arguments.args[i])) {
41 return Error() << "cannot expand '" << args[i] << "'";
Tom Cherryfa0c21c2015-07-23 17:53:11 -070042 }
43 }
44
Tom Cherrycb0f9bb2017-09-12 15:58:47 -070045 return function(builtin_arguments);
46}
47
48Command::Command(BuiltinFunction f, bool execute_in_subcontext,
49 const std::vector<std::string>& args, int line)
50 : func_(std::move(f)), execute_in_subcontext_(execute_in_subcontext), args_(args), line_(line) {}
51
52Result<Success> Command::InvokeFunc(Subcontext* subcontext) const {
Tom Cherryc49719f2018-01-10 11:04:34 -080053 if (subcontext) {
54 if (execute_in_subcontext_) {
55 return subcontext->Execute(args_);
56 }
57
58 auto expanded_args = subcontext->ExpandArgs(args_);
59 if (!expanded_args) {
60 return expanded_args.error();
61 }
62 return RunBuiltinFunction(func_, *expanded_args, subcontext->context());
Tom Cherrycb0f9bb2017-09-12 15:58:47 -070063 }
Tom Cherryc49719f2018-01-10 11:04:34 -080064
65 return RunBuiltinFunction(func_, args_, kInitContext);
Tom Cherryfa0c21c2015-07-23 17:53:11 -070066}
67
Tom Cherryb7349902015-08-26 11:43:36 -070068std::string Command::BuildCommandString() const {
69 return Join(args_, ' ');
Tom Cherryfa0c21c2015-07-23 17:53:11 -070070}
71
Tom Cherrycb0f9bb2017-09-12 15:58:47 -070072Action::Action(bool oneshot, Subcontext* subcontext, const std::string& filename, int line)
73 : oneshot_(oneshot), subcontext_(subcontext), filename_(filename), line_(line) {}
Tom Cherryfa0c21c2015-07-23 17:53:11 -070074
Tom Cherrycb0f9bb2017-09-12 15:58:47 -070075const KeywordFunctionMap* Action::function_map_ = nullptr;
Tom Cherryb7349902015-08-26 11:43:36 -070076
Tom Cherry89bcc852017-08-02 17:01:36 -070077Result<Success> Action::AddCommand(const std::vector<std::string>& args, int line) {
Tom Cherryb7349902015-08-26 11:43:36 -070078 if (!function_map_) {
Tom Cherry89bcc852017-08-02 17:01:36 -070079 return Error() << "no function map available";
Tom Cherryb7349902015-08-26 11:43:36 -070080 }
81
Tom Cherry89bcc852017-08-02 17:01:36 -070082 auto function = function_map_->FindFunction(args);
83 if (!function) return Error() << function.error();
Tom Cherryb7349902015-08-26 11:43:36 -070084
Tom Cherrycb0f9bb2017-09-12 15:58:47 -070085 commands_.emplace_back(function->second, function->first, args, line);
Tom Cherry89bcc852017-08-02 17:01:36 -070086 return Success();
Tom Cherryb7349902015-08-26 11:43:36 -070087}
88
Tom Cherry012c5732017-04-18 13:21:54 -070089void Action::AddCommand(BuiltinFunction f, const std::vector<std::string>& args, int line) {
Tom Cherrycb0f9bb2017-09-12 15:58:47 -070090 commands_.emplace_back(f, false, args, line);
Tom Cherryfa0c21c2015-07-23 17:53:11 -070091}
92
Tom Cherryb7349902015-08-26 11:43:36 -070093std::size_t Action::NumCommands() const {
94 return commands_.size();
95}
96
97void Action::ExecuteOneCommand(std::size_t command) const {
Wei Wangd67a4ab2016-11-16 12:08:30 -080098 // We need a copy here since some Command execution may result in
99 // changing commands_ vector by importing .rc files through parser
100 Command cmd = commands_[command];
101 ExecuteCommand(cmd);
Tom Cherryb7349902015-08-26 11:43:36 -0700102}
103
104void Action::ExecuteAllCommands() const {
105 for (const auto& c : commands_) {
106 ExecuteCommand(c);
107 }
108}
109
110void Action::ExecuteCommand(const Command& command) const {
Tom Cherryede0d532017-07-06 14:20:11 -0700111 android::base::Timer t;
Tom Cherrycb0f9bb2017-09-12 15:58:47 -0700112 auto result = command.InvokeFunc(subcontext_);
Tom Cherryede0d532017-07-06 14:20:11 -0700113 auto duration = t.duration();
Tom Cherry557946e2017-08-01 13:50:23 -0700114
Tom Cherry68f2a462017-08-22 16:15:26 -0700115 // There are many legacy paths in rootdir/init.rc that will virtually never exist on a new
116 // device, such as '/sys/class/leds/jogball-backlight/brightness'. As of this writing, there
117 // are 198 such failures on bullhead. Instead of spamming the log reporting them, we do not
118 // report such failures unless we're running at the DEBUG log level.
119 bool report_failure = !result.has_value();
120 if (report_failure && android::base::GetMinimumLogSeverity() > android::base::DEBUG &&
121 result.error_errno() == ENOENT) {
122 report_failure = false;
123 }
124
Wei Wang8b1d5262016-11-15 23:58:55 -0800125 // Any action longer than 50ms will be warned to user as slow operation
Tom Cherry68f2a462017-08-22 16:15:26 -0700126 if (report_failure || duration > 50ms ||
127 android::base::GetMinimumLogSeverity() <= android::base::DEBUG) {
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700128 std::string trigger_name = BuildTriggersString();
129 std::string cmd_str = command.BuildCommandString();
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700130
Tom Cherry1c3a53f2017-06-22 16:50:31 -0700131 LOG(INFO) << "Command '" << cmd_str << "' action=" << trigger_name << " (" << filename_
Tom Cherry557946e2017-08-01 13:50:23 -0700132 << ":" << command.line() << ") took " << duration.count() << "ms and "
Tom Cherry130e3d72017-08-22 16:07:15 -0700133 << (result ? "succeeded" : "failed: " + result.error_string());
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700134 }
135}
136
Tom Cherry89bcc852017-08-02 17:01:36 -0700137Result<Success> Action::ParsePropertyTrigger(const std::string& trigger) {
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700138 const static std::string prop_str("property:");
139 std::string prop_name(trigger.substr(prop_str.length()));
140 size_t equal_pos = prop_name.find('=');
141 if (equal_pos == std::string::npos) {
Tom Cherry89bcc852017-08-02 17:01:36 -0700142 return Error() << "property trigger found without matching '='";
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700143 }
144
145 std::string prop_value(prop_name.substr(equal_pos + 1));
146 prop_name.erase(equal_pos);
147
Tom Cherry2bc00142017-03-13 11:58:58 -0700148 if (auto [it, inserted] = property_triggers_.emplace(prop_name, prop_value); !inserted) {
Tom Cherry89bcc852017-08-02 17:01:36 -0700149 return Error() << "multiple property triggers found for same property";
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700150 }
Tom Cherry89bcc852017-08-02 17:01:36 -0700151 return Success();
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700152}
153
Tom Cherry89bcc852017-08-02 17:01:36 -0700154Result<Success> Action::InitTriggers(const std::vector<std::string>& args) {
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700155 const static std::string prop_str("property:");
156 for (std::size_t i = 0; i < args.size(); ++i) {
Wei Wang93df4e12016-11-16 19:19:49 -0800157 if (args[i].empty()) {
Tom Cherry89bcc852017-08-02 17:01:36 -0700158 return Error() << "empty trigger is not valid";
Wei Wang93df4e12016-11-16 19:19:49 -0800159 }
160
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700161 if (i % 2) {
Tom Cherrycb716f92015-08-11 12:34:22 -0700162 if (args[i] != "&&") {
Tom Cherry89bcc852017-08-02 17:01:36 -0700163 return Error() << "&& is the only symbol allowed to concatenate actions";
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700164 } else {
165 continue;
166 }
167 }
168
169 if (!args[i].compare(0, prop_str.length(), prop_str)) {
Tom Cherry89bcc852017-08-02 17:01:36 -0700170 if (auto result = ParsePropertyTrigger(args[i]); !result) {
171 return result;
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700172 }
173 } else {
174 if (!event_trigger_.empty()) {
Tom Cherry89bcc852017-08-02 17:01:36 -0700175 return Error() << "multiple event triggers are not allowed";
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700176 }
177
178 event_trigger_ = args[i];
179 }
180 }
181
Tom Cherry89bcc852017-08-02 17:01:36 -0700182 return Success();
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700183}
184
Tom Cherry89bcc852017-08-02 17:01:36 -0700185Result<Success> Action::InitSingleTrigger(const std::string& trigger) {
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700186 std::vector<std::string> name_vector{trigger};
Tom Cherry89bcc852017-08-02 17:01:36 -0700187 if (auto result = InitTriggers(name_vector); !result) {
188 return Error() << "InitTriggers() failed: " << result.error();
Wei Wang93df4e12016-11-16 19:19:49 -0800189 }
Tom Cherry89bcc852017-08-02 17:01:36 -0700190 return Success();
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700191}
192
Tom Cherryb7349902015-08-26 11:43:36 -0700193// This function checks that all property triggers are satisfied, that is
194// for each (name, value) in property_triggers_, check that the current
195// value of the property 'name' == value.
196//
197// It takes an optional (name, value) pair, which if provided must
198// be present in property_triggers_; it skips the check of the current
199// property value for this pair.
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700200bool Action::CheckPropertyTriggers(const std::string& name,
Tom Cherryb7349902015-08-26 11:43:36 -0700201 const std::string& value) const {
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700202 if (property_triggers_.empty()) {
203 return true;
204 }
205
Tom Cherryb7349902015-08-26 11:43:36 -0700206 bool found = name.empty();
Tom Cherry2bc00142017-03-13 11:58:58 -0700207 for (const auto& [trigger_name, trigger_value] : property_triggers_) {
Tom Cherrycb716f92015-08-11 12:34:22 -0700208 if (trigger_name == name) {
209 if (trigger_value != "*" && trigger_value != value) {
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700210 return false;
211 } else {
212 found = true;
213 }
214 } else {
Tom Cherryccf23532017-03-28 16:40:41 -0700215 std::string prop_val = android::base::GetProperty(trigger_name, "");
216 if (prop_val.empty() || (trigger_value != "*" && trigger_value != prop_val)) {
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700217 return false;
218 }
219 }
220 }
221 return found;
222}
223
Tom Cherry26ed9cb2017-04-17 13:25:29 -0700224bool Action::CheckEvent(const EventTrigger& event_trigger) const {
225 return event_trigger == event_trigger_ && CheckPropertyTriggers();
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700226}
227
Tom Cherry26ed9cb2017-04-17 13:25:29 -0700228bool Action::CheckEvent(const PropertyChange& property_change) const {
229 const auto& [name, value] = property_change;
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700230 return event_trigger_.empty() && CheckPropertyTriggers(name, value);
231}
232
Tom Cherry26ed9cb2017-04-17 13:25:29 -0700233bool Action::CheckEvent(const BuiltinAction& builtin_action) const {
234 return this == builtin_action;
235}
236
Tom Cherryb7349902015-08-26 11:43:36 -0700237std::string Action::BuildTriggersString() const {
Tom Cherryd8a72572017-03-13 12:24:49 -0700238 std::vector<std::string> triggers;
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700239
Tom Cherry2bc00142017-03-13 11:58:58 -0700240 for (const auto& [trigger_name, trigger_value] : property_triggers_) {
Tom Cherryd8a72572017-03-13 12:24:49 -0700241 triggers.emplace_back(trigger_name + '=' + trigger_value);
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700242 }
243 if (!event_trigger_.empty()) {
Tom Cherryd8a72572017-03-13 12:24:49 -0700244 triggers.emplace_back(event_trigger_);
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700245 }
Tom Cherryd8a72572017-03-13 12:24:49 -0700246
247 return Join(triggers, " && ");
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700248}
249
Tom Cherryb7349902015-08-26 11:43:36 -0700250void Action::DumpState() const {
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700251 std::string trigger_name = BuildTriggersString();
Elliott Hughesf86b5a62016-06-24 15:12:21 -0700252 LOG(INFO) << "on " << trigger_name;
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700253
254 for (const auto& c : commands_) {
Tom Cherryb7349902015-08-26 11:43:36 -0700255 std::string cmd_str = c.BuildCommandString();
Tom Cherryd8a72572017-03-13 12:24:49 -0700256 LOG(INFO) << " " << cmd_str;
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700257 }
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700258}
259
Tom Cherryb7349902015-08-26 11:43:36 -0700260ActionManager::ActionManager() : current_command_(0) {
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700261}
262
263ActionManager& ActionManager::GetInstance() {
264 static ActionManager instance;
265 return instance;
266}
267
Tom Cherryb7349902015-08-26 11:43:36 -0700268void ActionManager::AddAction(std::unique_ptr<Action> action) {
Tom Cherry012c5732017-04-18 13:21:54 -0700269 actions_.emplace_back(std::move(action));
Tom Cherryb7349902015-08-26 11:43:36 -0700270}
271
272void ActionManager::QueueEventTrigger(const std::string& trigger) {
Tom Cherry26ed9cb2017-04-17 13:25:29 -0700273 event_queue_.emplace(trigger);
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700274}
275
Tom Cherry26ed9cb2017-04-17 13:25:29 -0700276void ActionManager::QueuePropertyChange(const std::string& name, const std::string& value) {
277 event_queue_.emplace(std::make_pair(name, value));
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700278}
279
Tom Cherry26ed9cb2017-04-17 13:25:29 -0700280void ActionManager::QueueAllPropertyActions() {
281 QueuePropertyChange("", "");
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700282}
283
Tom Cherry012c5732017-04-18 13:21:54 -0700284void ActionManager::QueueBuiltinAction(BuiltinFunction func, const std::string& name) {
Tom Cherrycb0f9bb2017-09-12 15:58:47 -0700285 auto action = std::make_unique<Action>(true, nullptr, "<Builtin Action>", 0);
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700286 std::vector<std::string> name_vector{name};
287
Tom Cherry89bcc852017-08-02 17:01:36 -0700288 if (auto result = action->InitSingleTrigger(name); !result) {
289 LOG(ERROR) << "Cannot queue BuiltinAction for " << name << ": " << result.error();
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700290 return;
291 }
292
Tom Cherry012c5732017-04-18 13:21:54 -0700293 action->AddCommand(func, name_vector, 0);
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700294
Tom Cherry26ed9cb2017-04-17 13:25:29 -0700295 event_queue_.emplace(action.get());
Tom Cherryb7349902015-08-26 11:43:36 -0700296 actions_.emplace_back(std::move(action));
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700297}
298
299void ActionManager::ExecuteOneCommand() {
Tom Cherry26ed9cb2017-04-17 13:25:29 -0700300 // Loop through the event queue until we have an action to execute
301 while (current_executing_actions_.empty() && !event_queue_.empty()) {
Tom Cherryb7349902015-08-26 11:43:36 -0700302 for (const auto& action : actions_) {
Tom Cherry26ed9cb2017-04-17 13:25:29 -0700303 if (std::visit([&action](const auto& event) { return action->CheckEvent(event); },
304 event_queue_.front())) {
Tom Cherryb7349902015-08-26 11:43:36 -0700305 current_executing_actions_.emplace(action.get());
306 }
307 }
Tom Cherry26ed9cb2017-04-17 13:25:29 -0700308 event_queue_.pop();
Tom Cherrycb716f92015-08-11 12:34:22 -0700309 }
310
311 if (current_executing_actions_.empty()) {
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700312 return;
313 }
314
Tom Cherryb7349902015-08-26 11:43:36 -0700315 auto action = current_executing_actions_.front();
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700316
Tom Cherrycb716f92015-08-11 12:34:22 -0700317 if (current_command_ == 0) {
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700318 std::string trigger_name = action->BuildTriggersString();
Tom Cherry012c5732017-04-18 13:21:54 -0700319 LOG(INFO) << "processing action (" << trigger_name << ") from (" << action->filename()
320 << ":" << action->line() << ")";
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700321 }
322
Tom Cherryb7349902015-08-26 11:43:36 -0700323 action->ExecuteOneCommand(current_command_);
324
325 // If this was the last command in the current action, then remove
326 // the action from the executing list.
327 // If this action was oneshot, then also remove it from actions_.
328 ++current_command_;
Tom Cherrycb716f92015-08-11 12:34:22 -0700329 if (current_command_ == action->NumCommands()) {
Tom Cherryb7349902015-08-26 11:43:36 -0700330 current_executing_actions_.pop();
Tom Cherrycb716f92015-08-11 12:34:22 -0700331 current_command_ = 0;
Tom Cherryb7349902015-08-26 11:43:36 -0700332 if (action->oneshot()) {
333 auto eraser = [&action] (std::unique_ptr<Action>& a) {
334 return a.get() == action;
335 };
336 actions_.erase(std::remove_if(actions_.begin(), actions_.end(), eraser));
337 }
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700338 }
339}
340
Tom Cherryb7349902015-08-26 11:43:36 -0700341bool ActionManager::HasMoreCommands() const {
Tom Cherry26ed9cb2017-04-17 13:25:29 -0700342 return !current_executing_actions_.empty() || !event_queue_.empty();
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700343}
344
Tom Cherryb7349902015-08-26 11:43:36 -0700345void ActionManager::DumpState() const {
Tom Cherrycb716f92015-08-11 12:34:22 -0700346 for (const auto& a : actions_) {
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700347 a->DumpState();
348 }
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700349}
Tom Cherryb7349902015-08-26 11:43:36 -0700350
Wei Wangeeab4912017-06-27 22:08:45 -0700351void ActionManager::ClearQueue() {
352 // We are shutting down so don't claim the oneshot builtin actions back
353 current_executing_actions_ = {};
354 event_queue_ = {};
355 current_command_ = 0;
356}
357
Tom Cherry89bcc852017-08-02 17:01:36 -0700358Result<Success> ActionParser::ParseSection(std::vector<std::string>&& args,
359 const std::string& filename, int line) {
Tom Cherryb7349902015-08-26 11:43:36 -0700360 std::vector<std::string> triggers(args.begin() + 1, args.end());
361 if (triggers.size() < 1) {
Tom Cherry89bcc852017-08-02 17:01:36 -0700362 return Error() << "Actions must have a trigger";
Tom Cherryb7349902015-08-26 11:43:36 -0700363 }
364
Tom Cherrycb0f9bb2017-09-12 15:58:47 -0700365 Subcontext* action_subcontext = nullptr;
366 if (subcontexts_) {
367 for (auto& subcontext : *subcontexts_) {
Elliott Hughes579e6822017-12-20 09:41:00 -0800368 if (StartsWith(filename, subcontext.path_prefix())) {
Tom Cherrycb0f9bb2017-09-12 15:58:47 -0700369 action_subcontext = &subcontext;
370 break;
371 }
372 }
373 }
374
375 auto action = std::make_unique<Action>(false, action_subcontext, filename, line);
Tom Cherry89bcc852017-08-02 17:01:36 -0700376
377 if (auto result = action->InitTriggers(triggers); !result) {
378 return Error() << "InitTriggers() failed: " << result.error();
Tom Cherryb7349902015-08-26 11:43:36 -0700379 }
380
381 action_ = std::move(action);
Tom Cherry89bcc852017-08-02 17:01:36 -0700382 return Success();
Tom Cherryb7349902015-08-26 11:43:36 -0700383}
384
Tom Cherry89bcc852017-08-02 17:01:36 -0700385Result<Success> ActionParser::ParseLineSection(std::vector<std::string>&& args, int line) {
386 return action_ ? action_->AddCommand(std::move(args), line) : Success();
Tom Cherryb7349902015-08-26 11:43:36 -0700387}
388
Steven Moreland7d0a5c32017-11-10 14:20:47 -0800389Result<Success> ActionParser::EndSection() {
Tom Cherryb7349902015-08-26 11:43:36 -0700390 if (action_ && action_->NumCommands() > 0) {
Tom Cherry30a6f272017-04-19 15:31:58 -0700391 action_manager_->AddAction(std::move(action_));
Tom Cherryb7349902015-08-26 11:43:36 -0700392 }
Steven Moreland7d0a5c32017-11-10 14:20:47 -0800393
394 return Success();
Tom Cherryb7349902015-08-26 11:43:36 -0700395}
Tom Cherry81f5d3e2017-06-22 12:53:17 -0700396
397} // namespace init
398} // namespace android