1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2023 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker *
4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker *
8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker *
10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker */
16*795d594fSAndroid Build Coastguard Worker
17*795d594fSAndroid Build Coastguard Worker // This binary is run on boot as a oneshot service. It should not be run at any
18*795d594fSAndroid Build Coastguard Worker // other point.
19*795d594fSAndroid Build Coastguard Worker
20*795d594fSAndroid Build Coastguard Worker #include <string>
21*795d594fSAndroid Build Coastguard Worker
22*795d594fSAndroid Build Coastguard Worker #include "android-base/logging.h"
23*795d594fSAndroid Build Coastguard Worker #include "android-base/properties.h"
24*795d594fSAndroid Build Coastguard Worker
SetPropertyAndLog(const std::string & key,const std::string & value,const std::string & message="")25*795d594fSAndroid Build Coastguard Worker static void SetPropertyAndLog(const std::string& key,
26*795d594fSAndroid Build Coastguard Worker const std::string& value,
27*795d594fSAndroid Build Coastguard Worker const std::string& message = "") {
28*795d594fSAndroid Build Coastguard Worker if (android::base::SetProperty(key, value)) {
29*795d594fSAndroid Build Coastguard Worker LOG(INFO) << "Set property " << key << " to " << value << " " << message;
30*795d594fSAndroid Build Coastguard Worker } else {
31*795d594fSAndroid Build Coastguard Worker LOG(ERROR) << "Failed to set property " << key << " to " << value << " " << message;
32*795d594fSAndroid Build Coastguard Worker }
33*795d594fSAndroid Build Coastguard Worker }
34*795d594fSAndroid Build Coastguard Worker
35*795d594fSAndroid Build Coastguard Worker // Copies the value of one system property to another if it isn't empty and
36*795d594fSAndroid Build Coastguard Worker // passes the predicate test_fn.
CopyPropertyIf(const char * src,const char * dst,bool (* test_fn)(const std::string &))37*795d594fSAndroid Build Coastguard Worker static void CopyPropertyIf(const char* src, const char* dst, bool (*test_fn)(const std::string&)) {
38*795d594fSAndroid Build Coastguard Worker std::string prop = android::base::GetProperty(src, "");
39*795d594fSAndroid Build Coastguard Worker if (prop.empty()) {
40*795d594fSAndroid Build Coastguard Worker LOG(INFO) << "Property " << src << " not set";
41*795d594fSAndroid Build Coastguard Worker } else if (!test_fn(prop)) {
42*795d594fSAndroid Build Coastguard Worker LOG(INFO) << "Property " << src << " has ignored value " << prop;
43*795d594fSAndroid Build Coastguard Worker } else {
44*795d594fSAndroid Build Coastguard Worker SetPropertyAndLog(dst, prop, std::string("from ") + src);
45*795d594fSAndroid Build Coastguard Worker }
46*795d594fSAndroid Build Coastguard Worker }
47*795d594fSAndroid Build Coastguard Worker
main(int,char ** argv)48*795d594fSAndroid Build Coastguard Worker int main(int, char** argv) {
49*795d594fSAndroid Build Coastguard Worker android::base::InitLogging(argv);
50*795d594fSAndroid Build Coastguard Worker
51*795d594fSAndroid Build Coastguard Worker // Copy properties that must only be set at boot and not change value later.
52*795d594fSAndroid Build Coastguard Worker // Note that P/H can change the properties in the experiment namespaces at any
53*795d594fSAndroid Build Coastguard Worker // time.
54*795d594fSAndroid Build Coastguard Worker CopyPropertyIf("persist.device_config.runtime_native_boot.useartservice",
55*795d594fSAndroid Build Coastguard Worker "dalvik.vm.useartservice",
56*795d594fSAndroid Build Coastguard Worker // If an OEM has set dalvik.vm.useartservice to false we
57*795d594fSAndroid Build Coastguard Worker // shouldn't override it to true from the P/H property.
58*795d594fSAndroid Build Coastguard Worker [](const std::string& prop) { return prop == "false"; });
59*795d594fSAndroid Build Coastguard Worker
60*795d594fSAndroid Build Coastguard Worker return 0;
61*795d594fSAndroid Build Coastguard Worker }
62