1 /* 2 * Copyright (C) 2018 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 #ifndef _OTAUTIL_PATHS_H_ 18 #define _OTAUTIL_PATHS_H_ 19 20 #include <string> 21 22 #include <android-base/macros.h> 23 24 // A singleton class to maintain the update related paths. The paths should be only set once at the 25 // start of the program. 26 class Paths { 27 public: 28 static Paths& Get(); 29 cache_log_directory()30 std::string cache_log_directory() const { 31 return cache_log_directory_; 32 } set_cache_log_directory(const std::string & log_dir)33 void set_cache_log_directory(const std::string& log_dir) { 34 cache_log_directory_ = log_dir; 35 } 36 cache_temp_source()37 std::string cache_temp_source() const { 38 return cache_temp_source_; 39 } set_cache_temp_source(const std::string & temp_source)40 void set_cache_temp_source(const std::string& temp_source) { 41 cache_temp_source_ = temp_source; 42 } 43 last_command_file()44 std::string last_command_file() const { 45 return last_command_file_; 46 } set_last_command_file(const std::string & last_command_file)47 void set_last_command_file(const std::string& last_command_file) { 48 last_command_file_ = last_command_file; 49 } 50 resource_dir()51 std::string resource_dir() const { 52 return resource_dir_; 53 } set_resource_dir(const std::string & resource_dir)54 void set_resource_dir(const std::string& resource_dir) { 55 resource_dir_ = resource_dir; 56 } 57 stash_directory_base()58 std::string stash_directory_base() const { 59 return stash_directory_base_; 60 } set_stash_directory_base(const std::string & base)61 void set_stash_directory_base(const std::string& base) { 62 stash_directory_base_ = base; 63 } 64 temporary_install_file()65 std::string temporary_install_file() const { 66 return temporary_install_file_; 67 } set_temporary_install_file(const std::string & install_file)68 void set_temporary_install_file(const std::string& install_file) { 69 temporary_install_file_ = install_file; 70 } 71 temporary_log_file()72 std::string temporary_log_file() const { 73 return temporary_log_file_; 74 } set_temporary_log_file(const std::string & log_file)75 void set_temporary_log_file(const std::string& log_file) { 76 temporary_log_file_ = log_file; 77 } 78 temporary_update_binary()79 std::string temporary_update_binary() const { 80 return temporary_update_binary_; 81 } set_temporary_update_binary(const std::string & update_binary)82 void set_temporary_update_binary(const std::string& update_binary) { 83 temporary_update_binary_ = update_binary; 84 } 85 86 private: 87 Paths(); 88 DISALLOW_COPY_AND_ASSIGN(Paths); 89 90 // Path to the directory that contains last_log and last_kmsg log files. 91 std::string cache_log_directory_; 92 93 // Path to the temporary source file on /cache. When there isn't enough room on the target 94 // filesystem to hold the patched version of the file, we copy the original here and delete it to 95 // free up space. If the expected source file doesn't exist, or is corrupted, we look to see if 96 // the cached file contains the bits we want and use it as the source instead. 97 std::string cache_temp_source_; 98 99 // Path to the last command file. 100 std::string last_command_file_; 101 102 // Path to the resource dir; 103 std::string resource_dir_; 104 105 // Path to the base directory to write stashes during update. 106 std::string stash_directory_base_; 107 108 // Path to the temporary file that contains the install result. 109 std::string temporary_install_file_; 110 111 // Path to the temporary log file while under recovery. 112 std::string temporary_log_file_; 113 114 // Path to the temporary update binary while installing a non-A/B package. 115 std::string temporary_update_binary_; 116 }; 117 118 #endif // _OTAUTIL_PATHS_H_ 119