diff options
| author | 2024-01-05 01:41:04 +0000 | |
|---|---|---|
| committer | 2024-01-05 01:41:04 +0000 | |
| commit | 378b126c9dfec9d5f44db4bd0362fc4948a9aee3 (patch) | |
| tree | 7ec259edf3c2e57928b08a7d14040af2e5f5e171 | |
| parent | cc0f2f0cebe312063c020f0226808819d9457f44 (diff) | |
| parent | 9ad1bc38f8ca314bb35077161cdc5dcca5d9023e (diff) | |
Merge "Added java wrapper for update engine stable" into main am: 5e4b9840fc am: 9ad1bc38f8
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2896745
Change-Id: I7e3ac06acfd4f1202ab5bda7fc1d75c2e893e962
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | Android.bp | 1 | ||||
| -rw-r--r-- | core/java/android/os/UpdateEngineStable.java | 192 | ||||
| -rw-r--r-- | core/java/android/os/UpdateEngineStableCallback.java | 46 |
3 files changed, 239 insertions, 0 deletions
diff --git a/Android.bp b/Android.bp index 316555f7391e..ebdb1a1a9082 100644 --- a/Android.bp +++ b/Android.bp @@ -127,6 +127,7 @@ filegroup { ":libcamera_client_aidl", ":libcamera_client_framework_aidl", ":libupdate_engine_aidl", + ":libupdate_engine_stable-V2-java-source", ":logd_aidl", ":resourcemanager_aidl", ":storaged_aidl", diff --git a/core/java/android/os/UpdateEngineStable.java b/core/java/android/os/UpdateEngineStable.java new file mode 100644 index 000000000000..9e2593e39e0e --- /dev/null +++ b/core/java/android/os/UpdateEngineStable.java @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2024 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.IntDef; + +/** + * UpdateEngineStable handles calls to the update engine stalbe which takes care of A/B OTA updates. + * This interface has lesser functionalities than UpdateEngine and doesn't allow cancel. + * + * <p>The minimal flow is: + * + * <ol> + * <li>Create a new UpdateEngineStable instance. + * <li>Call {@link #bind}, provide callback function. + * <li>Call {@link #applyPayloadFd}. + * </ol> + * + * The APIs defined in this class and UpdateEngineStableCallback class must be in sync with the ones + * in {@code system/update_engine/stable/android/os/IUpdateEngineStable.aidl} and {@code + * ssystem/update_engine/stable/android/os/IUpdateEngineStableCallback.aidl}. + * + * @hide + */ +public class UpdateEngineStable { + private static final String TAG = "UpdateEngineStable"; + + private static final String UPDATE_ENGINE_STABLE_SERVICE = + "android.os.UpdateEngineStableService"; + + /** + * Error codes from update engine upon finishing a call to {@link applyPayloadFd}. Values will + * be passed via the callback function {@link + * UpdateEngineStableCallback#onPayloadApplicationComplete}. Values must agree with the ones in + * {@code system/update_engine/common/error_code.h}. + */ + /** @hide */ + @IntDef( + value = { + UpdateEngine.ErrorCodeConstants.SUCCESS, + UpdateEngine.ErrorCodeConstants.ERROR, + UpdateEngine.ErrorCodeConstants.FILESYSTEM_COPIER_ERROR, + UpdateEngine.ErrorCodeConstants.POST_INSTALL_RUNNER_ERROR, + UpdateEngine.ErrorCodeConstants.PAYLOAD_MISMATCHED_TYPE_ERROR, + UpdateEngine.ErrorCodeConstants.INSTALL_DEVICE_OPEN_ERROR, + UpdateEngine.ErrorCodeConstants.KERNEL_DEVICE_OPEN_ERROR, + UpdateEngine.ErrorCodeConstants.DOWNLOAD_TRANSFER_ERROR, + UpdateEngine.ErrorCodeConstants.PAYLOAD_HASH_MISMATCH_ERROR, + UpdateEngine.ErrorCodeConstants.PAYLOAD_SIZE_MISMATCH_ERROR, + UpdateEngine.ErrorCodeConstants.DOWNLOAD_PAYLOAD_VERIFICATION_ERROR, + UpdateEngine.ErrorCodeConstants.PAYLOAD_TIMESTAMP_ERROR, + UpdateEngine.ErrorCodeConstants.UPDATED_BUT_NOT_ACTIVE, + UpdateEngine.ErrorCodeConstants.NOT_ENOUGH_SPACE, + UpdateEngine.ErrorCodeConstants.DEVICE_CORRUPTED, + }) + public @interface ErrorCode {} + + private final IUpdateEngineStable mUpdateEngineStable; + private IUpdateEngineStableCallback mUpdateEngineStableCallback = null; + private final Object mUpdateEngineStableCallbackLock = new Object(); + + /** + * Creates a new instance. + * + * @hide + */ + public UpdateEngineStable() { + mUpdateEngineStable = + IUpdateEngineStable.Stub.asInterface( + ServiceManager.getService(UPDATE_ENGINE_STABLE_SERVICE)); + if (mUpdateEngineStable == null) { + throw new IllegalStateException("Failed to find " + UPDATE_ENGINE_STABLE_SERVICE); + } + } + + /** + * Prepares this instance for use. The callback will be notified on any status change, and when + * the update completes. A handler can be supplied to control which thread runs the callback, or + * null. + * + * @hide + */ + public boolean bind(final UpdateEngineStableCallback callback, final Handler handler) { + synchronized (mUpdateEngineStableCallbackLock) { + mUpdateEngineStableCallback = + new IUpdateEngineStableCallback.Stub() { + @Override + public void onStatusUpdate(final int status, final float percent) { + if (handler != null) { + handler.post( + new Runnable() { + @Override + public void run() { + callback.onStatusUpdate(status, percent); + } + }); + } else { + callback.onStatusUpdate(status, percent); + } + } + + @Override + public void onPayloadApplicationComplete(final int errorCode) { + if (handler != null) { + handler.post( + new Runnable() { + @Override + public void run() { + callback.onPayloadApplicationComplete(errorCode); + } + }); + } else { + callback.onPayloadApplicationComplete(errorCode); + } + } + + @Override + public int getInterfaceVersion() { + return super.VERSION; + } + + @Override + public String getInterfaceHash() { + return super.HASH; + } + }; + + try { + return mUpdateEngineStable.bind(mUpdateEngineStableCallback); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + } + + /** + * Equivalent to {@code bind(callback, null)}. + * + * @hide + */ + public boolean bind(final UpdateEngineStableCallback callback) { + return bind(callback, null); + } + + /** + * Applies payload from given ParcelFileDescriptor. Usage is same as UpdateEngine#applyPayload + * + * @hide + */ + public void applyPayloadFd( + ParcelFileDescriptor fd, long offset, long size, String[] headerKeyValuePairs) { + try { + mUpdateEngineStable.applyPayloadFd(fd, offset, size, headerKeyValuePairs); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * Unbinds the last bound callback function. + * + * @hide + */ + public boolean unbind() { + synchronized (mUpdateEngineStableCallbackLock) { + if (mUpdateEngineStableCallback == null) { + return true; + } + try { + boolean result = mUpdateEngineStable.unbind(mUpdateEngineStableCallback); + mUpdateEngineStableCallback = null; + return result; + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + } +} diff --git a/core/java/android/os/UpdateEngineStableCallback.java b/core/java/android/os/UpdateEngineStableCallback.java new file mode 100644 index 000000000000..4bcfb4baae95 --- /dev/null +++ b/core/java/android/os/UpdateEngineStableCallback.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2024 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; + +/** + * Callback function for UpdateEngineStable. Used to keep the caller up to date with progress, so + * the UI (if any) can be updated. + * + * <p>The APIs defined in this class and UpdateEngineStable class must be in sync with the ones in + * system/update_engine/stable/android/os/IUpdateEngineStable.aidl and + * system/update_engine/stable/android/os/IUpdateEngineStableCallback.aidl. + * + * <p>{@hide} + */ +public abstract class UpdateEngineStableCallback { + + /** + * Invoked when anything changes. The value of {@code status} will be one of the values from + * {@link UpdateEngine.UpdateStatusConstants}, and {@code percent} will be valid + * + * @hide + */ + public abstract void onStatusUpdate(int status, float percent); + + /** + * Invoked when the payload has been applied, whether successfully or unsuccessfully. The value + * of {@code errorCode} will be one of the values from {@link UpdateEngine.ErrorCodeConstants}. + * + * @hide + */ + public abstract void onPayloadApplicationComplete(@UpdateEngineStable.ErrorCode int errorCode); +} |