Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2016 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 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_AOSP_SERVICE_DELEGATE_ANDROID_INTERFACE_H_ |
| 18 | #define UPDATE_ENGINE_AOSP_SERVICE_DELEGATE_ANDROID_INTERFACE_H_ |
Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 19 | |
| 20 | #include <inttypes.h> |
| 21 | |
Yifan Hong | 40bb0d0 | 2020-02-24 17:33:14 -0800 | [diff] [blame] | 22 | #include <memory> |
Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 23 | #include <string> |
| 24 | #include <vector> |
| 25 | |
Kelvin Zhang | 2f6c25a | 2023-07-05 12:49:34 -0700 | [diff] [blame] | 26 | #include "update_engine/common/error.h" |
Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 27 | |
| 28 | namespace chromeos_update_engine { |
| 29 | |
Yifan Hong | 40bb0d0 | 2020-02-24 17:33:14 -0800 | [diff] [blame] | 30 | // See ServiceDelegateAndroidInterface.CleanupSuccessfulUpdate |
| 31 | // Wraps a IUpdateEngineCallback binder object used specifically for |
| 32 | // CleanupSuccessfulUpdate. |
| 33 | class CleanupSuccessfulUpdateCallbackInterface { |
| 34 | public: |
| 35 | virtual ~CleanupSuccessfulUpdateCallbackInterface() {} |
| 36 | virtual void OnCleanupProgressUpdate(double progress) = 0; |
| 37 | virtual void OnCleanupComplete(int32_t error_code) = 0; |
| 38 | // Call RegisterForDeathNotifications on the internal binder object. |
Kelvin Zhang | 2f6c25a | 2023-07-05 12:49:34 -0700 | [diff] [blame] | 39 | virtual void RegisterForDeathNotifications( |
| 40 | const std::function<void()>& unbind) = 0; |
Yifan Hong | 40bb0d0 | 2020-02-24 17:33:14 -0800 | [diff] [blame] | 41 | }; |
| 42 | |
Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 43 | // This class defines the interface exposed by the Android version of the |
| 44 | // daemon service. This interface only includes the method calls that such |
| 45 | // daemon exposes. For asynchronous events initiated by a class implementing |
| 46 | // this interface see the ServiceObserverInterface class. |
| 47 | class ServiceDelegateAndroidInterface { |
| 48 | public: |
| 49 | virtual ~ServiceDelegateAndroidInterface() = default; |
| 50 | |
| 51 | // Start an update attempt to download an apply the provided |payload_url| if |
| 52 | // no other update is running. The extra |key_value_pair_headers| will be |
| 53 | // included when fetching the payload. Returns whether the update was started |
| 54 | // successfully, which means that no other update was running and the passed |
| 55 | // parameters were correct, but not necessarily that the update finished |
| 56 | // correctly. |
| 57 | virtual bool ApplyPayload( |
| 58 | const std::string& payload_url, |
| 59 | int64_t payload_offset, |
| 60 | int64_t payload_size, |
| 61 | const std::vector<std::string>& key_value_pair_headers, |
Daniel Zheng | 92f7d17 | 2023-06-22 14:31:37 -0700 | [diff] [blame] | 62 | Error* error) = 0; |
Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 63 | |
Kyeongkab.Nam | 500ca13 | 2019-06-26 13:48:07 +0900 | [diff] [blame] | 64 | virtual bool ApplyPayload( |
| 65 | int fd, |
| 66 | int64_t payload_offset, |
| 67 | int64_t payload_size, |
| 68 | const std::vector<std::string>& key_value_pair_headers, |
Daniel Zheng | 92f7d17 | 2023-06-22 14:31:37 -0700 | [diff] [blame] | 69 | Error* error) = 0; |
Kyeongkab.Nam | 500ca13 | 2019-06-26 13:48:07 +0900 | [diff] [blame] | 70 | |
Kelvin Zhang | 9c5baeb | 2024-11-05 13:42:32 -0800 | [diff] [blame^] | 71 | virtual bool TriggerPostinstall(const std::string& partition, |
| 72 | Error* error) = 0; |
| 73 | |
Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 74 | // Suspend an ongoing update. Returns true if there was an update ongoing and |
| 75 | // it was suspended. In case of failure, it returns false and sets |error| |
| 76 | // accordingly. |
Daniel Zheng | 92f7d17 | 2023-06-22 14:31:37 -0700 | [diff] [blame] | 77 | virtual bool SuspendUpdate(Error* error) = 0; |
Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 78 | |
| 79 | // Resumes an update suspended with SuspendUpdate(). The update can't be |
| 80 | // suspended after it finished and this method will fail in that case. |
| 81 | // Returns whether the resume operation was successful, which only implies |
| 82 | // that there was a suspended update. In case of error, returns false and sets |
| 83 | // |error| accordingly. |
Daniel Zheng | 92f7d17 | 2023-06-22 14:31:37 -0700 | [diff] [blame] | 84 | virtual bool ResumeUpdate(Error* error) = 0; |
Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 85 | |
| 86 | // Cancel the ongoing update. The update could be running or suspended, but it |
| 87 | // can't be canceled after it was done. In case of error, returns false and |
| 88 | // sets |error| accordingly. |
Daniel Zheng | 92f7d17 | 2023-06-22 14:31:37 -0700 | [diff] [blame] | 89 | virtual bool CancelUpdate(Error* error) = 0; |
Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 90 | |
Alex Deymo | 3b678db | 2016-02-09 11:50:06 -0800 | [diff] [blame] | 91 | // Reset the already applied update back to an idle state. This method can |
| 92 | // only be called when no update attempt is going on, and it will reset the |
| 93 | // status back to idle, deleting the currently applied update if any. In case |
| 94 | // of error, returns false and sets |error| accordingly. |
Daniel Zheng | 92f7d17 | 2023-06-22 14:31:37 -0700 | [diff] [blame] | 95 | virtual bool ResetStatus(Error* error) = 0; |
Alex Deymo | 3b678db | 2016-02-09 11:50:06 -0800 | [diff] [blame] | 96 | |
Sen Jiang | 8371c1c | 2018-02-01 13:46:39 -0800 | [diff] [blame] | 97 | // Verifies whether a payload (delegated by the payload metadata) can be |
| 98 | // applied to the current device. Returns whether the payload is applicable. |
| 99 | // In case of error, returns false and sets |error| accordingly. |
| 100 | virtual bool VerifyPayloadApplicable(const std::string& metadata_filename, |
Daniel Zheng | 92f7d17 | 2023-06-22 14:31:37 -0700 | [diff] [blame] | 101 | Error* error) = 0; |
Tianjie | 7f8f2ab | 2021-07-23 17:08:50 -0700 | [diff] [blame] | 102 | // Sets the A/B slot switch for the next boot after applying an ota update. |
| 103 | // If applyPayload hasn't switched the slot by itself, the client can call |
| 104 | // this API to switch the slot and apply the update on next boot. Returns |
| 105 | // true on success. |
| 106 | virtual bool setShouldSwitchSlotOnReboot(const std::string& metadata_filename, |
Daniel Zheng | 92f7d17 | 2023-06-22 14:31:37 -0700 | [diff] [blame] | 107 | Error* error) = 0; |
Tianjie | 7f8f2ab | 2021-07-23 17:08:50 -0700 | [diff] [blame] | 108 | |
| 109 | // Resets the boot slot to the source/current slot, without cancelling the |
| 110 | // update progress. This can be called after the update is installed, and to |
| 111 | // prevent the device from accidentally taking the update when it reboots. |
Daniel Zheng | 92f7d17 | 2023-06-22 14:31:37 -0700 | [diff] [blame] | 112 | virtual bool resetShouldSwitchSlotOnReboot(Error* error) = 0; |
Sen Jiang | 8371c1c | 2018-02-01 13:46:39 -0800 | [diff] [blame] | 113 | |
Yifan Hong | 6f7e29f | 2019-12-13 14:41:06 -0800 | [diff] [blame] | 114 | // Allocates space for a payload. |
| 115 | // Returns 0 if space is successfully preallocated. |
| 116 | // Return non-zero if not enough space is not available; returned value is |
| 117 | // the total space required (in bytes) to be free on the device for this |
| 118 | // update to be applied, and |error| is unset. |
| 119 | // In case of error, returns 0, and sets |error| accordingly. |
| 120 | // |
| 121 | // This function may block for several minutes in the worst case. |
| 122 | virtual uint64_t AllocateSpaceForPayload( |
| 123 | const std::string& metadata_filename, |
| 124 | const std::vector<std::string>& key_value_pair_headers, |
Daniel Zheng | 92f7d17 | 2023-06-22 14:31:37 -0700 | [diff] [blame] | 125 | Error* error) = 0; |
Yifan Hong | 6f7e29f | 2019-12-13 14:41:06 -0800 | [diff] [blame] | 126 | |
Yifan Hong | 2236ea0 | 2019-12-13 16:11:22 -0800 | [diff] [blame] | 127 | // Wait for merge to complete, then clean up merge after an update has been |
| 128 | // successful. |
| 129 | // |
Yifan Hong | 40bb0d0 | 2020-02-24 17:33:14 -0800 | [diff] [blame] | 130 | // This function returns immediately. Progress updates are provided in |
| 131 | // |callback|. |
| 132 | virtual void CleanupSuccessfulUpdate( |
| 133 | std::unique_ptr<CleanupSuccessfulUpdateCallbackInterface> callback, |
Daniel Zheng | 92f7d17 | 2023-06-22 14:31:37 -0700 | [diff] [blame] | 134 | Error* error) = 0; |
Yifan Hong | 2236ea0 | 2019-12-13 16:11:22 -0800 | [diff] [blame] | 135 | |
Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 136 | protected: |
| 137 | ServiceDelegateAndroidInterface() = default; |
| 138 | }; |
| 139 | |
| 140 | } // namespace chromeos_update_engine |
| 141 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 142 | #endif // UPDATE_ENGINE_AOSP_SERVICE_DELEGATE_ANDROID_INTERFACE_H_ |