Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame^] | 1 | // |
| 2 | // Copyright (C) 2010 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 | // |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 16 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_DBUS_SERVICE_H_ |
| 18 | #define UPDATE_ENGINE_DBUS_SERVICE_H_ |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 19 | |
| 20 | #include <inttypes.h> |
Alex Vakulenko | 44cab30 | 2014-07-23 13:12:15 -0700 | [diff] [blame] | 21 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 22 | #include <string> |
| 23 | |
| 24 | #include <base/memory/ref_counted.h> |
| 25 | #include <chromeos/errors/error.h> |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 26 | |
| 27 | #include "update_engine/update_attempter.h" |
| 28 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 29 | #include "update_engine/dbus_adaptor/org.chromium.UpdateEngineInterface.h" |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 30 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 31 | namespace chromeos { |
| 32 | namespace dbus { |
| 33 | class Bus; |
| 34 | } // namespace dbus |
| 35 | } // namespace chromeos |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 36 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 37 | namespace chromeos_update_engine { |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 38 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 39 | class UpdateEngineService |
| 40 | : public org::chromium::UpdateEngineInterfaceInterface { |
| 41 | public: |
| 42 | explicit UpdateEngineService(SystemState* system_state); |
| 43 | virtual ~UpdateEngineService() = default; |
| 44 | |
| 45 | // Implementation of org::chromium::UpdateEngineInterfaceInterface. |
| 46 | bool AttemptUpdate(chromeos::ErrorPtr* error, |
| 47 | const std::string& in_app_version, |
| 48 | const std::string& in_omaha_url) override; |
| 49 | |
| 50 | bool AttemptUpdateWithFlags(chromeos::ErrorPtr* error, |
| 51 | const std::string& in_app_version, |
| 52 | const std::string& in_omaha_url, |
| 53 | int32_t in_flags_as_int) override; |
| 54 | |
| 55 | bool AttemptRollback(chromeos::ErrorPtr* error, bool in_powerwash) override; |
| 56 | |
| 57 | // Checks if the system rollback is available by verifying if the secondary |
| 58 | // system partition is valid and bootable. |
| 59 | bool CanRollback(chromeos::ErrorPtr* error, bool* out_can_rollback) override; |
| 60 | |
| 61 | // Resets the status of the update_engine to idle, ignoring any applied |
| 62 | // update. This is used for development only. |
| 63 | bool ResetStatus(chromeos::ErrorPtr* error) override; |
| 64 | |
| 65 | // Returns the current status of the Update Engine. If an update is in |
| 66 | // progress, the number of operations, size to download and overall progress |
| 67 | // is reported. |
| 68 | bool GetStatus(chromeos::ErrorPtr* error, |
| 69 | int64_t* out_last_checked_time, |
| 70 | double* out_progress, |
| 71 | std::string* out_current_operation, |
| 72 | std::string* out_new_version, |
| 73 | int64_t* out_new_size) override; |
| 74 | |
| 75 | // Reboots the device if an update is applied and a reboot is required. |
| 76 | bool RebootIfNeeded(chromeos::ErrorPtr* error) override; |
| 77 | |
| 78 | // Changes the current channel of the device to the target channel. If the |
| 79 | // target channel is a less stable channel than the current channel, then the |
| 80 | // channel change happens immediately (at the next update check). If the |
| 81 | // target channel is a more stable channel, then if is_powerwash_allowed is |
| 82 | // set to true, then also the change happens immediately but with a powerwash |
| 83 | // if required. Otherwise, the change takes effect eventually (when the |
| 84 | // version on the target channel goes above the version number of what the |
| 85 | // device currently has). |
| 86 | bool SetChannel(chromeos::ErrorPtr* error, |
| 87 | const std::string& in_target_channel, |
| 88 | bool in_is_powerwash_allowed) override; |
| 89 | |
| 90 | // If get_current_channel is set to true, populates |channel| with the name of |
| 91 | // the channel that the device is currently on. Otherwise, it populates it |
| 92 | // with the name of the channel the device is supposed to be (in case of a |
| 93 | // pending channel change). |
| 94 | bool GetChannel(chromeos::ErrorPtr* error, |
| 95 | bool in_get_current_channel, |
| 96 | std::string* out_channel) override; |
| 97 | |
| 98 | // Enables or disables the sharing and consuming updates over P2P feature |
| 99 | // according to the |enabled| argument passed. |
| 100 | bool SetP2PUpdatePermission(chromeos::ErrorPtr* error, |
| 101 | bool in_enabled) override; |
| 102 | |
| 103 | // Returns the current value for the P2P enabled setting. This involves both |
| 104 | // sharing and consuming updates over P2P. |
| 105 | bool GetP2PUpdatePermission(chromeos::ErrorPtr* error, |
| 106 | bool* out_enabled) override; |
| 107 | |
| 108 | // If there's no device policy installed, sets the update over cellular |
| 109 | // networks permission to the |allowed| value. Otherwise, this method returns |
| 110 | // with an error since this setting is overridden by the applied policy. |
| 111 | bool SetUpdateOverCellularPermission(chromeos::ErrorPtr* error, |
| 112 | bool in_allowed) override; |
| 113 | |
| 114 | // Returns the current value of the update over cellular network setting, |
| 115 | // either forced by the device policy if the device is enrolled or the current |
| 116 | // user preference otherwise. |
| 117 | bool GetUpdateOverCellularPermission(chromeos::ErrorPtr* error, |
| 118 | bool* out_allowed) override; |
| 119 | |
| 120 | // Returns the duration since the last successful update, as the |
| 121 | // duration on the wallclock. Returns an error if the device has not |
| 122 | // updated. |
| 123 | bool GetDurationSinceUpdate(chromeos::ErrorPtr* error, |
| 124 | int64_t* out_usec_wallclock) override; |
| 125 | |
| 126 | // Returns the version string of OS that was used before the last reboot |
| 127 | // into an updated version. This is available only when rebooting into an |
| 128 | // update from previous version, otherwise an empty string is returned. |
| 129 | bool GetPrevVersion(chromeos::ErrorPtr* error, |
| 130 | std::string* out_prev_version) override; |
| 131 | |
| 132 | // Returns a list of available kernel partitions and whether each of them |
| 133 | // can be booted from or not. |
| 134 | bool GetKernelDevices(chromeos::ErrorPtr* error, |
| 135 | std::string* out_kernel_devices) override; |
| 136 | |
| 137 | // Returns the name of kernel partition that can be rolled back into. |
| 138 | bool GetRollbackPartition(chromeos::ErrorPtr* error, |
| 139 | std::string* out_rollback_partition_name) override; |
| 140 | |
| 141 | private: |
| 142 | SystemState* system_state_; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 143 | }; |
| 144 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 145 | // The UpdateEngineAdaptor class runs the UpdateEngineInterface in the fixed |
| 146 | // object path, without an ObjectManager notifying the interfaces, since it is |
| 147 | // all static and clients don't expect it to be implemented. |
| 148 | class UpdateEngineAdaptor : public org::chromium::UpdateEngineInterfaceAdaptor { |
| 149 | public: |
| 150 | UpdateEngineAdaptor(SystemState* system_state, |
| 151 | const scoped_refptr<dbus::Bus>& bus); |
| 152 | ~UpdateEngineAdaptor() = default; |
| 153 | |
| 154 | // Register the DBus object with the update engine service asynchronously. |
| 155 | // Calls |copmletion_callback| when done passing a boolean indicating if the |
| 156 | // registration succeeded. |
| 157 | void RegisterAsync(const base::Callback<void(bool)>& completion_callback); |
| 158 | |
| 159 | // Takes ownership of the well-known DBus name and returns whether it |
| 160 | // succeeded. |
| 161 | bool RequestOwnership(); |
| 162 | |
| 163 | private: |
| 164 | scoped_refptr<dbus::Bus> bus_; |
| 165 | UpdateEngineService dbus_service_; |
| 166 | chromeos::dbus_utils::DBusObject dbus_object_; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 169 | } // namespace chromeos_update_engine |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 170 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 171 | #endif // UPDATE_ENGINE_DBUS_SERVICE_H_ |