1856166594771c61973856f563e622ccb7dd48aa1Alex Deymo//
2856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// Copyright (C) 2015 The Android Open Source Project
3856166594771c61973856f563e622ccb7dd48aa1Alex Deymo//
4856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// Licensed under the Apache License, Version 2.0 (the "License");
5856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// you may not use this file except in compliance with the License.
6856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// You may obtain a copy of the License at
7856166594771c61973856f563e622ccb7dd48aa1Alex Deymo//
8856166594771c61973856f563e622ccb7dd48aa1Alex Deymo//      http://www.apache.org/licenses/LICENSE-2.0
9856166594771c61973856f563e622ccb7dd48aa1Alex Deymo//
10856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// Unless required by applicable law or agreed to in writing, software
11856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// distributed under the License is distributed on an "AS IS" BASIS,
12856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// See the License for the specific language governing permissions and
14856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// limitations under the License.
15856166594771c61973856f563e622ccb7dd48aa1Alex Deymo//
16856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
17856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// This module abstracts the properties tied to the current running image. These
18856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// properties are meant to be constant during the life of this daemon, but can
19856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// be modified in dev-move or non-official builds.
20856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
21856166594771c61973856f563e622ccb7dd48aa1Alex Deymo#ifndef UPDATE_ENGINE_IMAGE_PROPERTIES_H_
22856166594771c61973856f563e622ccb7dd48aa1Alex Deymo#define UPDATE_ENGINE_IMAGE_PROPERTIES_H_
23856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
24856166594771c61973856f563e622ccb7dd48aa1Alex Deymo#include <string>
25856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
26856166594771c61973856f563e622ccb7dd48aa1Alex Deymonamespace chromeos_update_engine {
27856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
28856166594771c61973856f563e622ccb7dd48aa1Alex Deymoclass SystemState;
29856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
30856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// The read-only system properties of the running image.
31856166594771c61973856f563e622ccb7dd48aa1Alex Deymostruct ImageProperties {
32856166594771c61973856f563e622ccb7dd48aa1Alex Deymo  // The product id of the image used for all channels, except canary.
33856166594771c61973856f563e622ccb7dd48aa1Alex Deymo  std::string product_id;
34856166594771c61973856f563e622ccb7dd48aa1Alex Deymo  // The canary-channel product id.
35856166594771c61973856f563e622ccb7dd48aa1Alex Deymo  std::string canary_product_id;
36856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
37856166594771c61973856f563e622ccb7dd48aa1Alex Deymo  // The product version of this image.
38856166594771c61973856f563e622ccb7dd48aa1Alex Deymo  std::string version;
39856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
40ebf6e1228e6e42c19334bb8b3da62f4aef105deaAlex Deymo  // A unique string that identifies this build. Normally a combination of the
41ebf6e1228e6e42c19334bb8b3da62f4aef105deaAlex Deymo  // the version, signing keys and build target.
42ebf6e1228e6e42c19334bb8b3da62f4aef105deaAlex Deymo  std::string build_fingerprint;
43ebf6e1228e6e42c19334bb8b3da62f4aef105deaAlex Deymo
44856166594771c61973856f563e622ccb7dd48aa1Alex Deymo  // The board name this image was built for.
45856166594771c61973856f563e622ccb7dd48aa1Alex Deymo  std::string board;
46856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
47856166594771c61973856f563e622ccb7dd48aa1Alex Deymo  // The release channel this image was obtained from.
48856166594771c61973856f563e622ccb7dd48aa1Alex Deymo  std::string current_channel;
49856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
50856166594771c61973856f563e622ccb7dd48aa1Alex Deymo  // The Omaha URL this image should get updates from.
51856166594771c61973856f563e622ccb7dd48aa1Alex Deymo  std::string omaha_url;
52856166594771c61973856f563e622ccb7dd48aa1Alex Deymo};
53856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
54856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// The mutable image properties are read-write image properties, initialized
55856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// with values from the image but can be modified by storing them in the
56856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// stateful partition.
57856166594771c61973856f563e622ccb7dd48aa1Alex Deymostruct MutableImageProperties {
58856166594771c61973856f563e622ccb7dd48aa1Alex Deymo  // The release channel we are tracking.
59856166594771c61973856f563e622ccb7dd48aa1Alex Deymo  std::string target_channel;
60856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
61856166594771c61973856f563e622ccb7dd48aa1Alex Deymo  // Whether powerwash is allowed when downloading an update for the selected
62856166594771c61973856f563e622ccb7dd48aa1Alex Deymo  // target_channel.
63856166594771c61973856f563e622ccb7dd48aa1Alex Deymo  bool is_powerwash_allowed{false};
64856166594771c61973856f563e622ccb7dd48aa1Alex Deymo};
65856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
66856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// Loads all the image properties from the running system. In case of error
67856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// loading any of these properties from the read-only system image a default
68856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// value may be returned instead.
69856166594771c61973856f563e622ccb7dd48aa1Alex DeymoImageProperties LoadImageProperties(SystemState* system_state);
70856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
71856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// Loads the mutable image properties from the stateful partition if found or the
72856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// system image otherwise.
73856166594771c61973856f563e622ccb7dd48aa1Alex DeymoMutableImageProperties LoadMutableImageProperties(SystemState* system_state);
74856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
75856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// Stores the mutable image properties in the stateful partition. Returns
76856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// whether the operation succeeded.
77856166594771c61973856f563e622ccb7dd48aa1Alex Deymobool StoreMutableImageProperties(SystemState* system_state,
78856166594771c61973856f563e622ccb7dd48aa1Alex Deymo                                 const MutableImageProperties& properties);
79856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
80856166594771c61973856f563e622ccb7dd48aa1Alex Deymo// Sets the root_prefix used to load files from during unittests to
813be05c82442b2fbab693b6399f64610e8542462bAlex Deymo// |test_root_prefix|. Passing a nullptr value resets it to the default.
82856166594771c61973856f563e622ccb7dd48aa1Alex Deymonamespace test {
83856166594771c61973856f563e622ccb7dd48aa1Alex Deymovoid SetImagePropertiesRootPrefix(const char* test_root_prefix);
84856166594771c61973856f563e622ccb7dd48aa1Alex Deymo}  // namespace test
85856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
86856166594771c61973856f563e622ccb7dd48aa1Alex Deymo}  // namespace chromeos_update_engine
87856166594771c61973856f563e622ccb7dd48aa1Alex Deymo
88856166594771c61973856f563e622ccb7dd48aa1Alex Deymo#endif  // UPDATE_ENGINE_IMAGE_PROPERTIES_H_
89