blob: b3660ab378493b3f27bcf30fcd136014091b9819 [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
20#include <inttypes.h>
21
Yifan Hong40bb0d02020-02-24 17:33:14 -080022#include <memory>
Alex Deymof8bfcff2016-02-02 21:22:11 -080023#include <string>
24#include <vector>
25
26#include <brillo/errors/error.h>
27
28namespace chromeos_update_engine {
29
Yifan Hong40bb0d02020-02-24 17:33:14 -080030// See ServiceDelegateAndroidInterface.CleanupSuccessfulUpdate
31// Wraps a IUpdateEngineCallback binder object used specifically for
32// CleanupSuccessfulUpdate.
33class 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.
39 virtual void RegisterForDeathNotifications(base::Closure unbind) = 0;
40};
41
Alex Deymof8bfcff2016-02-02 21:22:11 -080042// This class defines the interface exposed by the Android version of the
43// daemon service. This interface only includes the method calls that such
44// daemon exposes. For asynchronous events initiated by a class implementing
45// this interface see the ServiceObserverInterface class.
46class ServiceDelegateAndroidInterface {
47 public:
48 virtual ~ServiceDelegateAndroidInterface() = default;
49
50 // Start an update attempt to download an apply the provided |payload_url| if
51 // no other update is running. The extra |key_value_pair_headers| will be
52 // included when fetching the payload. Returns whether the update was started
53 // successfully, which means that no other update was running and the passed
54 // parameters were correct, but not necessarily that the update finished
55 // correctly.
56 virtual bool ApplyPayload(
57 const std::string& payload_url,
58 int64_t payload_offset,
59 int64_t payload_size,
60 const std::vector<std::string>& key_value_pair_headers,
61 brillo::ErrorPtr* error) = 0;
62
Kyeongkab.Nam500ca132019-06-26 13:48:07 +090063 virtual bool ApplyPayload(
64 int fd,
65 int64_t payload_offset,
66 int64_t payload_size,
67 const std::vector<std::string>& key_value_pair_headers,
68 brillo::ErrorPtr* error) = 0;
69
Alex Deymof8bfcff2016-02-02 21:22:11 -080070 // Suspend an ongoing update. Returns true if there was an update ongoing and
71 // it was suspended. In case of failure, it returns false and sets |error|
72 // accordingly.
73 virtual bool SuspendUpdate(brillo::ErrorPtr* error) = 0;
74
75 // Resumes an update suspended with SuspendUpdate(). The update can't be
76 // suspended after it finished and this method will fail in that case.
77 // Returns whether the resume operation was successful, which only implies
78 // that there was a suspended update. In case of error, returns false and sets
79 // |error| accordingly.
80 virtual bool ResumeUpdate(brillo::ErrorPtr* error) = 0;
81
82 // Cancel the ongoing update. The update could be running or suspended, but it
83 // can't be canceled after it was done. In case of error, returns false and
84 // sets |error| accordingly.
85 virtual bool CancelUpdate(brillo::ErrorPtr* error) = 0;
86
Alex Deymo3b678db2016-02-09 11:50:06 -080087 // Reset the already applied update back to an idle state. This method can
88 // only be called when no update attempt is going on, and it will reset the
89 // status back to idle, deleting the currently applied update if any. In case
90 // of error, returns false and sets |error| accordingly.
91 virtual bool ResetStatus(brillo::ErrorPtr* error) = 0;
92
Sen Jiang8371c1c2018-02-01 13:46:39 -080093 // Verifies whether a payload (delegated by the payload metadata) can be
94 // applied to the current device. Returns whether the payload is applicable.
95 // In case of error, returns false and sets |error| accordingly.
96 virtual bool VerifyPayloadApplicable(const std::string& metadata_filename,
97 brillo::ErrorPtr* error) = 0;
Tianjie7f8f2ab2021-07-23 17:08:50 -070098 // Sets the A/B slot switch for the next boot after applying an ota update.
99 // If applyPayload hasn't switched the slot by itself, the client can call
100 // this API to switch the slot and apply the update on next boot. Returns
101 // true on success.
102 virtual bool setShouldSwitchSlotOnReboot(const std::string& metadata_filename,
103 brillo::ErrorPtr* error) = 0;
104
105 // Resets the boot slot to the source/current slot, without cancelling the
106 // update progress. This can be called after the update is installed, and to
107 // prevent the device from accidentally taking the update when it reboots.
108 virtual bool resetShouldSwitchSlotOnReboot(brillo::ErrorPtr* error) = 0;
Sen Jiang8371c1c2018-02-01 13:46:39 -0800109
Yifan Hong6f7e29f2019-12-13 14:41:06 -0800110 // Allocates space for a payload.
111 // Returns 0 if space is successfully preallocated.
112 // Return non-zero if not enough space is not available; returned value is
113 // the total space required (in bytes) to be free on the device for this
114 // update to be applied, and |error| is unset.
115 // In case of error, returns 0, and sets |error| accordingly.
116 //
117 // This function may block for several minutes in the worst case.
118 virtual uint64_t AllocateSpaceForPayload(
119 const std::string& metadata_filename,
120 const std::vector<std::string>& key_value_pair_headers,
121 brillo::ErrorPtr* error) = 0;
122
Yifan Hong2236ea02019-12-13 16:11:22 -0800123 // Wait for merge to complete, then clean up merge after an update has been
124 // successful.
125 //
Yifan Hong40bb0d02020-02-24 17:33:14 -0800126 // This function returns immediately. Progress updates are provided in
127 // |callback|.
128 virtual void CleanupSuccessfulUpdate(
129 std::unique_ptr<CleanupSuccessfulUpdateCallbackInterface> callback,
130 brillo::ErrorPtr* error) = 0;
Yifan Hong2236ea02019-12-13 16:11:22 -0800131
Alex Deymof8bfcff2016-02-02 21:22:11 -0800132 protected:
133 ServiceDelegateAndroidInterface() = default;
134};
135
136} // namespace chromeos_update_engine
137
Amin Hassaniec7bc112020-10-29 16:47:58 -0700138#endif // UPDATE_ENGINE_AOSP_SERVICE_DELEGATE_ANDROID_INTERFACE_H_