Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -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 | |
| 17 | package android.os; |
| 18 | |
Kyeongkab.Nam | 77f1aac | 2019-09-12 11:33:39 +0900 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 20 | import android.annotation.SystemApi; |
| 21 | import android.os.IUpdateEngine; |
| 22 | import android.os.IUpdateEngineCallback; |
| 23 | import android.os.RemoteException; |
| 24 | |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 25 | /** |
| 26 | * UpdateEngine handles calls to the update engine which takes care of A/B OTA |
| 27 | * updates. It wraps up the update engine Binder APIs and exposes them as |
Elliott Hughes | e3ce3e8b | 2017-02-27 09:37:02 -0800 | [diff] [blame] | 28 | * SystemApis, which will be called by the system app responsible for OTAs. |
| 29 | * On a Google device, this will be GmsCore. |
| 30 | * |
| 31 | * The minimal flow is: |
| 32 | * <ol> |
| 33 | * <li>Create a new UpdateEngine instance. |
| 34 | * <li>Call {@link #bind}, optionally providing callbacks. |
| 35 | * <li>Call {@link #applyPayload}. |
| 36 | * </ol> |
| 37 | * |
| 38 | * In addition, methods are provided to {@link #cancel} or |
| 39 | * {@link #suspend}/{@link #resume} application of an update. |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 40 | * |
| 41 | * The APIs defined in this class and UpdateEngineCallback class must be in |
| 42 | * sync with the ones in |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 43 | * {@code system/update_engine/binder_bindings/android/os/IUpdateEngine.aidl} |
| 44 | * and |
| 45 | * {@code system/update_engine/binder_bindings/android/os/IUpdateEngineCallback.aidl}. |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 46 | * |
| 47 | * {@hide} |
| 48 | */ |
| 49 | @SystemApi |
| 50 | public class UpdateEngine { |
| 51 | private static final String TAG = "UpdateEngine"; |
| 52 | |
| 53 | private static final String UPDATE_ENGINE_SERVICE = "android.os.UpdateEngineService"; |
| 54 | |
| 55 | /** |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 56 | * Error codes from update engine upon finishing a call to |
| 57 | * {@link applyPayload}. Values will be passed via the callback function |
| 58 | * {@link UpdateEngineCallback#onPayloadApplicationComplete}. Values must |
| 59 | * agree with the ones in {@code system/update_engine/common/error_code.h}. |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 60 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 61 | public static final class ErrorCodeConstants { |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 62 | /** |
| 63 | * Error code: a request finished successfully. |
| 64 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 65 | public static final int SUCCESS = 0; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 66 | /** |
| 67 | * Error code: a request failed due to a generic error. |
| 68 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 69 | public static final int ERROR = 1; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 70 | /** |
| 71 | * Error code: an update failed to apply due to filesystem copier |
| 72 | * error. |
| 73 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 74 | public static final int FILESYSTEM_COPIER_ERROR = 4; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 75 | /** |
| 76 | * Error code: an update failed to apply due to an error in running |
| 77 | * post-install hooks. |
| 78 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 79 | public static final int POST_INSTALL_RUNNER_ERROR = 5; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 80 | /** |
| 81 | * Error code: an update failed to apply due to a mismatching payload. |
| 82 | * |
| 83 | * <p>For example, the given payload uses a feature that's not |
| 84 | * supported by the current update engine. |
| 85 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 86 | public static final int PAYLOAD_MISMATCHED_TYPE_ERROR = 6; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 87 | /** |
| 88 | * Error code: an update failed to apply due to an error in opening |
| 89 | * devices. |
| 90 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 91 | public static final int INSTALL_DEVICE_OPEN_ERROR = 7; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 92 | /** |
| 93 | * Error code: an update failed to apply due to an error in opening |
| 94 | * kernel device. |
| 95 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 96 | public static final int KERNEL_DEVICE_OPEN_ERROR = 8; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 97 | /** |
| 98 | * Error code: an update failed to apply due to an error in fetching |
| 99 | * the payload. |
| 100 | * |
| 101 | * <p>For example, this could be a result of bad network connection |
| 102 | * when streaming an update. |
| 103 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 104 | public static final int DOWNLOAD_TRANSFER_ERROR = 9; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 105 | /** |
| 106 | * Error code: an update failed to apply due to a mismatch in payload |
| 107 | * hash. |
| 108 | * |
| 109 | * <p>Update engine does sanity checks for the given payload and its |
| 110 | * metadata. |
| 111 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 112 | public static final int PAYLOAD_HASH_MISMATCH_ERROR = 10; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 113 | |
| 114 | /** |
| 115 | * Error code: an update failed to apply due to a mismatch in payload |
| 116 | * size. |
| 117 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 118 | public static final int PAYLOAD_SIZE_MISMATCH_ERROR = 11; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * Error code: an update failed to apply due to failing to verify |
| 122 | * payload signatures. |
| 123 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 124 | public static final int DOWNLOAD_PAYLOAD_VERIFICATION_ERROR = 12; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 125 | |
| 126 | /** |
| 127 | * Error code: an update failed to apply due to a downgrade in payload |
| 128 | * timestamp. |
| 129 | * |
| 130 | * <p>The timestamp of a build is encoded into the payload, which will |
| 131 | * be enforced during install to prevent downgrading a device. |
| 132 | */ |
Alex Kershaw | 7bcb2fa | 2019-01-04 15:17:39 +0000 | [diff] [blame] | 133 | public static final int PAYLOAD_TIMESTAMP_ERROR = 51; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * Error code: an update has been applied successfully but the new slot |
| 137 | * hasn't been set to active. |
| 138 | * |
| 139 | * <p>It indicates a successful finish of calling {@link #applyPayload} with |
| 140 | * {@code SWITCH_SLOT_ON_REBOOT=0}. See {@link #applyPayload}. |
| 141 | */ |
scypher | f5a5365 | 2017-11-06 14:45:12 -0800 | [diff] [blame] | 142 | public static final int UPDATED_BUT_NOT_ACTIVE = 52; |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /** |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 146 | * Status codes for update engine. Values must agree with the ones in |
| 147 | * {@code system/update_engine/client_library/include/update_engine/update_status.h}. |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 148 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 149 | public static final class UpdateStatusConstants { |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 150 | /** |
| 151 | * Update status code: update engine is in idle state. |
| 152 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 153 | public static final int IDLE = 0; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 154 | |
| 155 | /** |
| 156 | * Update status code: update engine is checking for update. |
| 157 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 158 | public static final int CHECKING_FOR_UPDATE = 1; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 159 | |
| 160 | /** |
| 161 | * Update status code: an update is available. |
| 162 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 163 | public static final int UPDATE_AVAILABLE = 2; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 164 | |
| 165 | /** |
| 166 | * Update status code: update engine is downloading an update. |
| 167 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 168 | public static final int DOWNLOADING = 3; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 169 | |
| 170 | /** |
| 171 | * Update status code: update engine is verifying an update. |
| 172 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 173 | public static final int VERIFYING = 4; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 174 | |
| 175 | /** |
| 176 | * Update status code: update engine is finalizing an update. |
| 177 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 178 | public static final int FINALIZING = 5; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 179 | |
| 180 | /** |
| 181 | * Update status code: an update has been applied and is pending for |
| 182 | * reboot. |
| 183 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 184 | public static final int UPDATED_NEED_REBOOT = 6; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 185 | |
| 186 | /** |
| 187 | * Update status code: update engine is reporting an error event. |
| 188 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 189 | public static final int REPORTING_ERROR_EVENT = 7; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 190 | |
| 191 | /** |
| 192 | * Update status code: update engine is attempting to rollback an |
| 193 | * update. |
| 194 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 195 | public static final int ATTEMPTING_ROLLBACK = 8; |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 196 | |
| 197 | /** |
| 198 | * Update status code: update engine is in disabled state. |
| 199 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 200 | public static final int DISABLED = 9; |
| 201 | } |
| 202 | |
| 203 | private IUpdateEngine mUpdateEngine; |
Tao Bao | 445c304 | 2017-07-16 11:21:03 -0700 | [diff] [blame] | 204 | private IUpdateEngineCallback mUpdateEngineCallback = null; |
| 205 | private final Object mUpdateEngineCallbackLock = new Object(); |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 206 | |
Elliott Hughes | e3ce3e8b | 2017-02-27 09:37:02 -0800 | [diff] [blame] | 207 | /** |
| 208 | * Creates a new instance. |
| 209 | */ |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 210 | public UpdateEngine() { |
| 211 | mUpdateEngine = IUpdateEngine.Stub.asInterface( |
| 212 | ServiceManager.getService(UPDATE_ENGINE_SERVICE)); |
| 213 | } |
| 214 | |
Elliott Hughes | e3ce3e8b | 2017-02-27 09:37:02 -0800 | [diff] [blame] | 215 | /** |
| 216 | * Prepares this instance for use. The callback will be notified on any |
| 217 | * status change, and when the update completes. A handler can be supplied |
| 218 | * to control which thread runs the callback, or null. |
| 219 | */ |
Tao Bao | b7e47ae | 2016-03-22 12:30:23 -0700 | [diff] [blame] | 220 | public boolean bind(final UpdateEngineCallback callback, final Handler handler) { |
Tao Bao | 445c304 | 2017-07-16 11:21:03 -0700 | [diff] [blame] | 221 | synchronized (mUpdateEngineCallbackLock) { |
| 222 | mUpdateEngineCallback = new IUpdateEngineCallback.Stub() { |
| 223 | @Override |
| 224 | public void onStatusUpdate(final int status, final float percent) { |
| 225 | if (handler != null) { |
| 226 | handler.post(new Runnable() { |
| 227 | @Override |
| 228 | public void run() { |
| 229 | callback.onStatusUpdate(status, percent); |
| 230 | } |
| 231 | }); |
| 232 | } else { |
| 233 | callback.onStatusUpdate(status, percent); |
| 234 | } |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 235 | } |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 236 | |
Tao Bao | 445c304 | 2017-07-16 11:21:03 -0700 | [diff] [blame] | 237 | @Override |
| 238 | public void onPayloadApplicationComplete(final int errorCode) { |
| 239 | if (handler != null) { |
| 240 | handler.post(new Runnable() { |
| 241 | @Override |
| 242 | public void run() { |
| 243 | callback.onPayloadApplicationComplete(errorCode); |
| 244 | } |
| 245 | }); |
| 246 | } else { |
| 247 | callback.onPayloadApplicationComplete(errorCode); |
| 248 | } |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 249 | } |
Tao Bao | 445c304 | 2017-07-16 11:21:03 -0700 | [diff] [blame] | 250 | }; |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 251 | |
Tao Bao | 445c304 | 2017-07-16 11:21:03 -0700 | [diff] [blame] | 252 | try { |
| 253 | return mUpdateEngine.bind(mUpdateEngineCallback); |
| 254 | } catch (RemoteException e) { |
| 255 | throw e.rethrowFromSystemServer(); |
| 256 | } |
Tao Bao | b7e47ae | 2016-03-22 12:30:23 -0700 | [diff] [blame] | 257 | } |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Elliott Hughes | e3ce3e8b | 2017-02-27 09:37:02 -0800 | [diff] [blame] | 260 | /** |
| 261 | * Equivalent to {@code bind(callback, null)}. |
| 262 | */ |
Tao Bao | b7e47ae | 2016-03-22 12:30:23 -0700 | [diff] [blame] | 263 | public boolean bind(final UpdateEngineCallback callback) { |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 264 | return bind(callback, null); |
| 265 | } |
| 266 | |
Elliott Hughes | e3ce3e8b | 2017-02-27 09:37:02 -0800 | [diff] [blame] | 267 | /** |
| 268 | * Applies the payload found at the given {@code url}. For non-streaming |
| 269 | * updates, the URL can be a local file using the {@code file://} scheme. |
| 270 | * |
| 271 | * <p>The {@code offset} and {@code size} parameters specify the location |
| 272 | * of the payload within the file represented by the URL. This is useful |
| 273 | * if the downloadable package at the URL contains more than just the |
| 274 | * update_engine payload (such as extra metadata). This is true for |
| 275 | * Google's OTA system, where the URL points to a zip file in which the |
| 276 | * payload is stored uncompressed within the zip file alongside other |
| 277 | * data. |
| 278 | * |
| 279 | * <p>The {@code headerKeyValuePairs} parameter is used to pass metadata |
| 280 | * to update_engine. In Google's implementation, this is stored as |
| 281 | * {@code payload_properties.txt} in the zip file. It's generated by the |
| 282 | * script {@code system/update_engine/scripts/brillo_update_payload}. |
| 283 | * The complete list of keys and their documentation is in |
| 284 | * {@code system/update_engine/common/constants.cc}, but an example |
| 285 | * might be: |
| 286 | * <pre> |
| 287 | * String[] pairs = { |
| 288 | * "FILE_HASH=lURPCIkIAjtMOyB/EjQcl8zDzqtD6Ta3tJef6G/+z2k=", |
| 289 | * "FILE_SIZE=871903868", |
| 290 | * "METADATA_HASH=tBvj43QOB0Jn++JojcpVdbRLz0qdAuL+uTkSy7hokaw=", |
| 291 | * "METADATA_SIZE=70604" |
| 292 | * }; |
| 293 | * </pre> |
Tao Bao | aa028f0 | 2019-03-08 13:37:57 -0800 | [diff] [blame] | 294 | * |
| 295 | * <p>The callback functions registered via {@code #bind} will be called |
| 296 | * during and at the end of the payload application. |
| 297 | * |
| 298 | * <p>By default the newly updated slot will be set active upon |
| 299 | * successfully finishing an update. Device will attempt to boot into the |
| 300 | * new slot on next reboot. This behavior can be customized by specifying |
| 301 | * {@code SWITCH_SLOT_ON_REBOOT=0} in {@code headerKeyValuePairs}, which |
| 302 | * allows the caller to later determine a good time to boot into the new |
| 303 | * slot. Calling {@code applyPayload} again with the same payload but with |
| 304 | * {@code SWITCH_SLOT_ON_REBOOT=1} will do the minimal work to set the new |
| 305 | * slot active, after verifying its integrity. |
Elliott Hughes | e3ce3e8b | 2017-02-27 09:37:02 -0800 | [diff] [blame] | 306 | */ |
Tao Bao | b7e47ae | 2016-03-22 12:30:23 -0700 | [diff] [blame] | 307 | public void applyPayload(String url, long offset, long size, String[] headerKeyValuePairs) { |
| 308 | try { |
| 309 | mUpdateEngine.applyPayload(url, offset, size, headerKeyValuePairs); |
| 310 | } catch (RemoteException e) { |
| 311 | throw e.rethrowFromSystemServer(); |
| 312 | } |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Elliott Hughes | e3ce3e8b | 2017-02-27 09:37:02 -0800 | [diff] [blame] | 315 | /** |
Kyeongkab.Nam | 73fde38 | 2019-09-26 10:44:32 +0900 | [diff] [blame] | 316 | * Applies the payload passed as ParcelFileDescriptor {@code pfd} instead of |
Kyeongkab.Nam | bcc5633 | 2019-04-09 12:07:37 +0900 | [diff] [blame] | 317 | * using the {@code file://} scheme. |
| 318 | * |
| 319 | * <p>See {@link #applyPayload(String)} for {@code offset}, {@code size} and |
| 320 | * {@code headerKeyValuePairs} parameters. |
| 321 | */ |
Kyeongkab.Nam | 73fde38 | 2019-09-26 10:44:32 +0900 | [diff] [blame] | 322 | public void applyPayload(@NonNull ParcelFileDescriptor pfd, long offset, long size, |
Kyeongkab.Nam | 77f1aac | 2019-09-12 11:33:39 +0900 | [diff] [blame] | 323 | @NonNull String[] headerKeyValuePairs) { |
Kyeongkab.Nam | bcc5633 | 2019-04-09 12:07:37 +0900 | [diff] [blame] | 324 | try { |
Kyeongkab.Nam | 73fde38 | 2019-09-26 10:44:32 +0900 | [diff] [blame] | 325 | mUpdateEngine.applyPayloadFd(pfd, offset, size, headerKeyValuePairs); |
Kyeongkab.Nam | bcc5633 | 2019-04-09 12:07:37 +0900 | [diff] [blame] | 326 | } catch (RemoteException e) { |
| 327 | throw e.rethrowFromSystemServer(); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | /** |
Elliott Hughes | e3ce3e8b | 2017-02-27 09:37:02 -0800 | [diff] [blame] | 332 | * Permanently cancels an in-progress update. |
| 333 | * |
| 334 | * <p>See {@link #resetStatus} to undo a finshed update (only available |
| 335 | * before the updated system has been rebooted). |
| 336 | * |
| 337 | * <p>See {@link #suspend} for a way to temporarily stop an in-progress |
| 338 | * update with the ability to resume it later. |
| 339 | */ |
Tao Bao | b7e47ae | 2016-03-22 12:30:23 -0700 | [diff] [blame] | 340 | public void cancel() { |
| 341 | try { |
| 342 | mUpdateEngine.cancel(); |
| 343 | } catch (RemoteException e) { |
| 344 | throw e.rethrowFromSystemServer(); |
| 345 | } |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 346 | } |
| 347 | |
Elliott Hughes | e3ce3e8b | 2017-02-27 09:37:02 -0800 | [diff] [blame] | 348 | /** |
| 349 | * Suspends an in-progress update. This can be undone by calling |
| 350 | * {@link #resume}. |
| 351 | */ |
Tao Bao | b7e47ae | 2016-03-22 12:30:23 -0700 | [diff] [blame] | 352 | public void suspend() { |
| 353 | try { |
| 354 | mUpdateEngine.suspend(); |
| 355 | } catch (RemoteException e) { |
| 356 | throw e.rethrowFromSystemServer(); |
| 357 | } |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 358 | } |
| 359 | |
Elliott Hughes | e3ce3e8b | 2017-02-27 09:37:02 -0800 | [diff] [blame] | 360 | /** |
| 361 | * Resumes a suspended update. |
| 362 | */ |
Tao Bao | b7e47ae | 2016-03-22 12:30:23 -0700 | [diff] [blame] | 363 | public void resume() { |
| 364 | try { |
| 365 | mUpdateEngine.resume(); |
| 366 | } catch (RemoteException e) { |
| 367 | throw e.rethrowFromSystemServer(); |
| 368 | } |
| 369 | } |
| 370 | |
Elliott Hughes | e3ce3e8b | 2017-02-27 09:37:02 -0800 | [diff] [blame] | 371 | /** |
| 372 | * Resets the bootable flag on the non-current partition and all internal |
| 373 | * update_engine state. This can be used after an unwanted payload has been |
| 374 | * successfully applied and the device has not yet been rebooted to signal |
| 375 | * that we no longer want to boot into that updated system. After this call |
| 376 | * completes, update_engine will no longer report |
| 377 | * {@code UPDATED_NEED_REBOOT}, so your callback can remove any outstanding |
| 378 | * notification that rebooting into the new system is possible. |
| 379 | */ |
Tao Bao | b7e47ae | 2016-03-22 12:30:23 -0700 | [diff] [blame] | 380 | public void resetStatus() { |
| 381 | try { |
| 382 | mUpdateEngine.resetStatus(); |
| 383 | } catch (RemoteException e) { |
| 384 | throw e.rethrowFromSystemServer(); |
| 385 | } |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 386 | } |
Tao Bao | 445c304 | 2017-07-16 11:21:03 -0700 | [diff] [blame] | 387 | |
| 388 | /** |
| 389 | * Unbinds the last bound callback function. |
| 390 | */ |
Tao Bao | 445c304 | 2017-07-16 11:21:03 -0700 | [diff] [blame] | 391 | public boolean unbind() { |
| 392 | synchronized (mUpdateEngineCallbackLock) { |
| 393 | if (mUpdateEngineCallback == null) { |
| 394 | return true; |
| 395 | } |
| 396 | try { |
| 397 | boolean result = mUpdateEngine.unbind(mUpdateEngineCallback); |
| 398 | mUpdateEngineCallback = null; |
| 399 | return result; |
| 400 | } catch (RemoteException e) { |
| 401 | throw e.rethrowFromSystemServer(); |
| 402 | } |
| 403 | } |
| 404 | } |
Tao Bao | d27be34 | 2018-01-10 11:40:19 -0800 | [diff] [blame] | 405 | |
| 406 | /** |
| 407 | * Verifies that a payload associated with the given payload metadata |
| 408 | * {@code payloadMetadataFilename} can be safely applied to ths device. |
| 409 | * Returns {@code true} if the update can successfully be applied and |
| 410 | * returns {@code false} otherwise. |
| 411 | * |
| 412 | * @param payloadMetadataFilename the location of the metadata without the |
| 413 | * {@code file://} prefix. |
| 414 | */ |
Tao Bao | d27be34 | 2018-01-10 11:40:19 -0800 | [diff] [blame] | 415 | public boolean verifyPayloadMetadata(String payloadMetadataFilename) { |
| 416 | try { |
| 417 | return mUpdateEngine.verifyPayloadApplicable(payloadMetadataFilename); |
| 418 | } catch (RemoteException e) { |
| 419 | throw e.rethrowFromSystemServer(); |
| 420 | } |
| 421 | } |
Tao Bao | 43cd1bc | 2016-02-08 09:51:38 -0800 | [diff] [blame] | 422 | } |