Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ce03276 authored by Yifan Hong's avatar Yifan Hong
Browse files

Add UpdateEngine.cleanupSuccessfulUpdate

This API cleans up the merge and free up space after the
device has boot successfully into the new build for a
Virtual A/B update.

Bug: 138808328
Test: pass
Change-Id: Id4543906b06e6a8487f91955af85024d8a50a464
parent 16d4554a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6088,6 +6088,7 @@ package android.os {
    method public boolean bind(android.os.UpdateEngineCallback, android.os.Handler);
    method public boolean bind(android.os.UpdateEngineCallback);
    method public void cancel();
    method public int cleanupAppliedPayload();
    method public void resetStatus();
    method public void resume();
    method public void suspend();
@@ -6102,6 +6103,7 @@ package android.os {
  public static final class UpdateEngine.ErrorCodeConstants {
    ctor public UpdateEngine.ErrorCodeConstants();
    field public static final int DEVICE_CORRUPTED = 61; // 0x3d
    field public static final int DOWNLOAD_PAYLOAD_VERIFICATION_ERROR = 12; // 0xc
    field public static final int DOWNLOAD_TRANSFER_ERROR = 9; // 0x9
    field public static final int ERROR = 1; // 0x1
+43 −0
Original line number Diff line number Diff line
@@ -148,6 +148,13 @@ public class UpdateEngine {
         * <p>See {@link UpdateEngine#allocateSpace}.
         */
        public static final int NOT_ENOUGH_SPACE = 60;

        /**
         * Error code: the device is corrupted and no further updates may be applied.
         *
         * <p>See {@link UpdateEngine#cleanupAppliedPayload}.
         */
        public static final int DEVICE_CORRUPTED = 61;
    }

    /**
@@ -523,4 +530,40 @@ public class UpdateEngine {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Cleanup files used by the previous update and free up space after the
     * device has been booted successfully into the new build.
     *
     * <p>In particular, this function waits until delta files for snapshots for
     * Virtual A/B update are merged to OS partitions, then delete these delta
     * files.
     *
     * <p>This function is synchronous and may take a non-trivial amount of
     * time. Callers should call this function in a background thread.
     *
     * <p>This function does not delete payload binaries downloaded for a
     * non-streaming OTA update.
     *
     * @return One of the following:
     * <ul>
     * <li>{@link ErrorCodeConstants#SUCCESS} if execution is successful.</li>
     * <li>{@link ErrorCodeConstants#ERROR} if a transient error has occurred.
     * The device should be able to recover after a reboot. The function should
     * be retried after the reboot.</li>
     * <li>{@link ErrorCodeConstants#DEVICE_CORRUPTED} if a permanent error is
     * encountered. Device is corrupted, and future updates must not be applied.
     * The device cannot recover without flashing and factory resets.
     * </ul>
     *
     * @throws ServiceSpecificException if other transient errors has occurred.
     * A reboot may or may not help resolving the issue.
     */
    public int cleanupAppliedPayload() {
        try {
            return mUpdateEngine.cleanupSuccessfulUpdate();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
}