• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2019 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 #pragma once
18 
19 #include <string>
20 
21 namespace android {
22 namespace gsi {
23 
24 static constexpr char kGsiServiceName[] = "gsiservice";
25 
26 #define DSU_METADATA_PREFIX "/metadata/gsi/dsu/"
27 
28 static constexpr char kGsiBootedIndicatorFile[] = DSU_METADATA_PREFIX "booted";
29 
30 static constexpr char kGsiLpNamesFile[] = DSU_METADATA_PREFIX "lp_names";
31 
32 static constexpr char kDsuActiveFile[] = DSU_METADATA_PREFIX "active";
33 
34 static constexpr char kDsuAvbKeyDir[] = DSU_METADATA_PREFIX "avb/";
35 
DsuLpMetadataFile(const std::string & dsu_slot)36 static inline std::string DsuLpMetadataFile(const std::string& dsu_slot) {
37     return DSU_METADATA_PREFIX + dsu_slot + "/lp_metadata";
38 }
39 
DsuInstallDirFile(const std::string & dsu_slot)40 static inline std::string DsuInstallDirFile(const std::string& dsu_slot) {
41     return DSU_METADATA_PREFIX + dsu_slot + "/install_dir";
42 }
43 
44 // install_dir "/data/gsi/dsu/dsu" has a slot name "dsu"
45 // install_dir "/data/gsi/dsu/dsu2" has a slot name "dsu2"
46 std::string GetDsuSlot(const std::string& install_dir);
47 
48 static constexpr char kGsiBootedProp[] = "ro.gsid.image_running";
49 
50 static constexpr char kGsiInstalledProp[] = "gsid.image_installed";
51 
52 static constexpr char kDsuPostfix[] = "_gsi";
53 
54 static constexpr int kMaxBootAttempts = 1;
55 
56 // Get the currently active dsu slot
57 // Return true on success
58 bool GetActiveDsu(std::string* active_dsu);
59 
60 // Returns true if the currently running system image is a live GSI.
61 bool IsGsiRunning();
62 
63 // Return true if a GSI is installed (but not necessarily running).
64 bool IsGsiInstalled();
65 
66 // Set the GSI as no longer bootable. This effectively removes the GSI. If no
67 // GSI was bootable, false is returned.
68 bool UninstallGsi();
69 
70 // Set the GSI as no longer bootable, without removing its installed files.
71 bool DisableGsi();
72 
73 // Returns true if init should attempt to boot into a live GSI image, false
74 // otherwise. If false, an error message is set.
75 //
76 // This is only called by first-stage init.
77 bool CanBootIntoGsi(std::string* error);
78 
79 // Called by first-stage init to indicate that we're about to boot into a
80 // GSI.
81 bool MarkSystemAsGsi();
82 
83 }  // namespace gsi
84 }  // namespace android
85