summaryrefslogtreecommitdiff
path: root/tools/art_boot.cc
blob: b55fc50dc6d691fd517c72ac64d265b3e5f358e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// This binary is run on boot as a oneshot service. It should not be run at any
// other point.

#include <string>

#include "android-base/logging.h"
#include "android-base/properties.h"

static void SetPropertyAndLog(const std::string& key,
                              const std::string& value,
                              const std::string& message = "") {
  if (android::base::SetProperty(key, value)) {
    LOG(INFO) << "Set property " << key << " to " << value << " " << message;
  } else {
    LOG(ERROR) << "Failed to set property " << key << " to " << value << " " << message;
  }
}

// Copies the value of one system property to another if it isn't empty and
// passes the predicate test_fn.
static void CopyPropertyIf(const char* src, const char* dst, bool (*test_fn)(const std::string&)) {
  std::string prop = android::base::GetProperty(src, "");
  if (prop.empty()) {
    LOG(INFO) << "Property " << src << " not set";
  } else if (!test_fn(prop)) {
    LOG(INFO) << "Property " << src << " has ignored value " << prop;
  } else {
    SetPropertyAndLog(dst, prop, std::string("from ") + src);
  }
}

int main(int, char** argv) {
  android::base::InitLogging(argv);

  // Copy properties that must only be set at boot and not change value later.
  // Note that P/H can change the properties in the experiment namespaces at any
  // time.
  CopyPropertyIf("persist.device_config.runtime_native_boot.useartservice",
                 "dalvik.vm.useartservice",
                 // If an OEM has set dalvik.vm.useartservice to false we
                 // shouldn't override it to true from the P/H property.
                 [](const std::string& prop) { return prop == "false"; });

  return 0;
}