2 // Copyright 2015 Google, Inc.
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:
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "service/settings.h"
19 #include <base/base_switches.h>
20 #include <base/command_line.h>
21 #include <base/logging.h>
23 #include "service/switches.h"
27 Settings::Settings() : initialized_(false), enable_on_start_(false) {}
29 Settings::~Settings() {}
31 bool Settings::Init() {
33 auto command_line = base::CommandLine::ForCurrentProcess();
34 const auto& switches = command_line->GetSwitches();
36 for (const auto& iter : switches) {
37 if (iter.first == switches::kCreateIPCSocketPath) {
38 // kCreateIPCSocketPath: An optional argument that initializes an IPC
39 // socket path for IPC.
40 base::FilePath path(iter.second);
41 if (path.empty() || path.EndsWithSeparator()) {
42 LOG(ERROR) << "Invalid IPC create socket path";
46 create_ipc_socket_path_ = path;
47 } else if (iter.first == switches::kAndroidIPCSocketSuffix) {
48 // kAndroidIPCSocketSuffix: An optional argument used to express
49 // a socket that Android init created for us. We bind to this.
50 const std::string& suffix = iter.second;
52 LOG(ERROR) << "Invalid Android socket suffix";
56 android_ipc_socket_suffix_ = suffix;
57 } else if (iter.first == switches::kEnableOnStart) {
58 if (iter.second == "true") {
59 enable_on_start_ = true;
60 } else if (iter.second == "false") {
61 enable_on_start_ = false;
63 LOG(ERROR) << "Invalid value for " << switches::kEnableOnStart << ": "
64 << iter.second << ". Expect 'true' or 'false'";
68 // Check for libbase logging switches. These get processed by
69 // logging::InitLogging directly.
70 else if (iter.first != ::switches::kV) {
71 LOG(ERROR) << "Unexpected command-line switches found: " << iter.first;
76 // Two IPC methods/paths were provided.
77 if (!android_ipc_socket_suffix_.empty() && !create_ipc_socket_path_.empty()) {
78 LOG(ERROR) << "Too many IPC methods provided";
82 // The daemon has no arguments
83 if (command_line->GetArgs().size()) {
84 LOG(ERROR) << "Unexpected command-line arguments found";
92 } // namespace bluetooth