blob: 5e139d794a8ce04b201c6386e27097d47ab6ea61 [file] [log] [blame]
Alex Deymof8bfcff2016-02-02 21:22:11 -08001//
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 Hassaniec7bc112020-10-29 16:47:58 -070017#ifndef UPDATE_ENGINE_AOSP_SERVICE_DELEGATE_ANDROID_INTERFACE_H_
18#define UPDATE_ENGINE_AOSP_SERVICE_DELEGATE_ANDROID_INTERFACE_H_
Alex Deymof8bfcff2016-02-02 21:22:11 -080019
Yifan Hong40bb0d02020-02-24 17:33:14 -080020#include <memory>
Alex Deymof8bfcff2016-02-02 21:22:11 -080021#include <string>
22#include <vector>
23
Kelvin Zhang2f6c25a2023-07-05 12:49:34 -070024#include "update_engine/common/error.h"
Alex Deymof8bfcff2016-02-02 21:22:11 -080025
26namespace chromeos_update_engine {
27
Yifan Hong40bb0d02020-02-24 17:33:14 -080028// See ServiceDelegateAndroidInterface.CleanupSuccessfulUpdate
29// Wraps a IUpdateEngineCallback binder object used specifically for
30// CleanupSuccessfulUpdate.
31class CleanupSuccessfulUpdateCallbackInterface {
32 public:
33 virtual ~CleanupSuccessfulUpdateCallbackInterface() {}
34 virtual void OnCleanupProgressUpdate(double progress) = 0;
35 virtual void OnCleanupComplete(int32_t error_code) = 0;
36 // Call RegisterForDeathNotifications on the internal binder object.
Kelvin Zhang2f6c25a2023-07-05 12:49:34 -070037 virtual void RegisterForDeathNotifications(
38 const std::function<void()>& unbind) = 0;
Yifan Hong40bb0d02020-02-24 17:33:14 -080039};
40
Alex Deymof8bfcff2016-02-02 21:22:11 -080041// This class defines the interface exposed by the Android version of the
42// daemon service. This interface only includes the method calls that such
43// daemon exposes. For asynchronous events initiated by a class implementing
44// this interface see the ServiceObserverInterface class.
45class ServiceDelegateAndroidInterface {
46 public:
47 virtual ~ServiceDelegateAndroidInterface() = default;
48
49 // Start an update attempt to download an apply the provided |payload_url| if
50 // no other update is running. The extra |key_value_pair_headers| will be
51 // included when fetching the payload. Returns whether the update was started
52 // successfully, which means that no other update was running and the passed
53 // parameters were correct, but not necessarily that the update finished
54 // correctly.
55 virtual bool ApplyPayload(
56 const std::string& payload_url,
57 int64_t payload_offset,
58 int64_t payload_size,
59 const std::vector<std::string>& key_value_pair_headers,
Daniel Zheng92f7d172023-06-22 14:31:37 -070060 Error* error) = 0;
Alex Deymof8bfcff2016-02-02 21:22:11 -080061
Kyeongkab.Nam500ca132019-06-26 13:48:07 +090062 virtual bool ApplyPayload(
63 int fd,
64 int64_t payload_offset,
65 int64_t payload_size,
66 const std::vector<std::string>& key_value_pair_headers,
Daniel Zheng92f7d172023-06-22 14:31:37 -070067 Error* error) = 0;
Kyeongkab.Nam500ca132019-06-26 13:48:07 +090068
Kelvin Zhang9c5baeb2024-11-05 13:42:32 -080069 virtual bool TriggerPostinstall(const std::string& partition,
70 Error* error) = 0;
71
Alex Deymof8bfcff2016-02-02 21:22:11 -080072 // Suspend an ongoing update. Returns true if there was an update ongoing and
73 // it was suspended. In case of failure, it returns false and sets |error|
74 // accordingly.
Daniel Zheng92f7d172023-06-22 14:31:37 -070075 virtual bool SuspendUpdate(Error* error) = 0;
Alex Deymof8bfcff2016-02-02 21:22:11 -080076
77 // Resumes an update suspended with SuspendUpdate(). The update can't be
78 // suspended after it finished and this method will fail in that case.
79 // Returns whether the resume operation was successful, which only implies
80 // that there was a suspended update. In case of error, returns false and sets
81 // |error| accordingly.
Daniel Zheng92f7d172023-06-22 14:31:37 -070082 virtual bool ResumeUpdate(Error* error) = 0;
Alex Deymof8bfcff2016-02-02 21:22:11 -080083
84 // Cancel the ongoing update. The update could be running or suspended, but it
85 // can't be canceled after it was done. In case of error, returns false and
86 // sets |error| accordingly.
Daniel Zheng92f7d172023-06-22 14:31:37 -070087 virtual bool CancelUpdate(Error* error) = 0;
Alex Deymof8bfcff2016-02-02 21:22:11 -080088
Alex Deymo3b678db2016-02-09 11:50:06 -080089 // Reset the already applied update back to an idle state. This method can
90 // only be called when no update attempt is going on, and it will reset the
91 // status back to idle, deleting the currently applied update if any. In case
92 // of error, returns false and sets |error| accordingly.
Daniel Zheng92f7d172023-06-22 14:31:37 -070093 virtual bool ResetStatus(Error* error) = 0;
Alex Deymo3b678db2016-02-09 11:50:06 -080094
Sen Jiang8371c1c2018-02-01 13:46:39 -080095 // Verifies whether a payload (delegated by the payload metadata) can be
96 // applied to the current device. Returns whether the payload is applicable.
97 // In case of error, returns false and sets |error| accordingly.
98 virtual bool VerifyPayloadApplicable(const std::string& metadata_filename,
Daniel Zheng92f7d172023-06-22 14:31:37 -070099 Error* error) = 0;
Tianjie7f8f2ab2021-07-23 17:08:50 -0700100 // Sets the A/B slot switch for the next boot after applying an ota update.
101 // If applyPayload hasn't switched the slot by itself, the client can call
102 // this API to switch the slot and apply the update on next boot. Returns
103 // true on success.
104 virtual bool setShouldSwitchSlotOnReboot(const std::string& metadata_filename,
Daniel Zheng92f7d172023-06-22 14:31:37 -0700105 Error* error) = 0;
Tianjie7f8f2ab2021-07-23 17:08:50 -0700106
107 // Resets the boot slot to the source/current slot, without cancelling the
108 // update progress. This can be called after the update is installed, and to
109 // prevent the device from accidentally taking the update when it reboots.
Daniel Zheng92f7d172023-06-22 14:31:37 -0700110 virtual bool resetShouldSwitchSlotOnReboot(Error* error) = 0;
Sen Jiang8371c1c2018-02-01 13:46:39 -0800111
Yifan Hong6f7e29f2019-12-13 14:41:06 -0800112 // Allocates space for a payload.
113 // Returns 0 if space is successfully preallocated.
114 // Return non-zero if not enough space is not available; returned value is
115 // the total space required (in bytes) to be free on the device for this
116 // update to be applied, and |error| is unset.
117 // In case of error, returns 0, and sets |error| accordingly.
118 //
119 // This function may block for several minutes in the worst case.
120 virtual uint64_t AllocateSpaceForPayload(
121 const std::string& metadata_filename,
122 const std::vector<std::string>& key_value_pair_headers,
Daniel Zheng92f7d172023-06-22 14:31:37 -0700123 Error* error) = 0;
Yifan Hong6f7e29f2019-12-13 14:41:06 -0800124
Yifan Hong2236ea02019-12-13 16:11:22 -0800125 // Wait for merge to complete, then clean up merge after an update has been
126 // successful.
127 //
Yifan Hong40bb0d02020-02-24 17:33:14 -0800128 // This function returns immediately. Progress updates are provided in
129 // |callback|.
130 virtual void CleanupSuccessfulUpdate(
131 std::unique_ptr<CleanupSuccessfulUpdateCallbackInterface> callback,
Daniel Zheng92f7d172023-06-22 14:31:37 -0700132 Error* error) = 0;
Yifan Hong2236ea02019-12-13 16:11:22 -0800133
Alex Deymof8bfcff2016-02-02 21:22:11 -0800134 protected:
135 ServiceDelegateAndroidInterface() = default;
136};
137
138} // namespace chromeos_update_engine
139
Amin Hassaniec7bc112020-10-29 16:47:58 -0700140#endif // UPDATE_ENGINE_AOSP_SERVICE_DELEGATE_ANDROID_INTERFACE_H_