/* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.os; import android.annotation.SystemApi; import android.os.IUpdateEngine; import android.os.IUpdateEngineCallback; import android.os.RemoteException; import android.util.Log; /** * UpdateEngine handles calls to the update engine which takes care of A/B OTA * updates. It wraps up the update engine Binder APIs and exposes them as * SystemApis, which will be called by the system app responsible for OTAs. * On a Google device, this will be GmsCore. * * The minimal flow is: *
The {@code offset} and {@code size} parameters specify the location * of the payload within the file represented by the URL. This is useful * if the downloadable package at the URL contains more than just the * update_engine payload (such as extra metadata). This is true for * Google's OTA system, where the URL points to a zip file in which the * payload is stored uncompressed within the zip file alongside other * data. * *
The {@code headerKeyValuePairs} parameter is used to pass metadata * to update_engine. In Google's implementation, this is stored as * {@code payload_properties.txt} in the zip file. It's generated by the * script {@code system/update_engine/scripts/brillo_update_payload}. * The complete list of keys and their documentation is in * {@code system/update_engine/common/constants.cc}, but an example * might be: *
* String[] pairs = { * "FILE_HASH=lURPCIkIAjtMOyB/EjQcl8zDzqtD6Ta3tJef6G/+z2k=", * "FILE_SIZE=871903868", * "METADATA_HASH=tBvj43QOB0Jn++JojcpVdbRLz0qdAuL+uTkSy7hokaw=", * "METADATA_SIZE=70604" * }; **/ @SystemApi public void applyPayload(String url, long offset, long size, String[] headerKeyValuePairs) { try { mUpdateEngine.applyPayload(url, offset, size, headerKeyValuePairs); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Permanently cancels an in-progress update. * *
See {@link #resetStatus} to undo a finshed update (only available * before the updated system has been rebooted). * *
See {@link #suspend} for a way to temporarily stop an in-progress * update with the ability to resume it later. */ @SystemApi public void cancel() { try { mUpdateEngine.cancel(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Suspends an in-progress update. This can be undone by calling * {@link #resume}. */ @SystemApi public void suspend() { try { mUpdateEngine.suspend(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Resumes a suspended update. */ @SystemApi public void resume() { try { mUpdateEngine.resume(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Resets the bootable flag on the non-current partition and all internal * update_engine state. This can be used after an unwanted payload has been * successfully applied and the device has not yet been rebooted to signal * that we no longer want to boot into that updated system. After this call * completes, update_engine will no longer report * {@code UPDATED_NEED_REBOOT}, so your callback can remove any outstanding * notification that rebooting into the new system is possible. */ @SystemApi public void resetStatus() { try { mUpdateEngine.resetStatus(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } }