3.2. onStatusUpdate和onPayloadApplicationComplete接口函数
- 升级状态码见
frameworks/base/core/java/android/os/UpdateEngine.java - UpdateStatusConstants
(抽取system/update_engine/client_library/include/update_engine/update_status.h
数据) - 升级错误码见
frameworks/base/core/java/android/os/UpdateEngine.java - ErrorCodeConstants
(抽取system/update_engine/common/error_code.h
部分)
//UpdateLayoutFragment.java
public class CarUpdateEngineCallback extends UpdateEngineCallback {
@Override
//升级状态码和进度接收
public void onStatusUpdate(int status, float percent) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, String.format("onStatusUpdate %d, Percent %.2f", status, percent));
}
switch (status) {
//UpdateStatusConstants升级状态码见frameworks/base/core/java/android/os/UpdateEngine.java
case UpdateEngine.UpdateStatusConstants.UPDATED_NEED_REBOOT:
rebootNow();
break;
case UpdateEngine.UpdateStatusConstants.DOWNLOADING:
mProgressBar.setProgress((int) (percent * 100));
break;
default:
// noop
}
}
@Override
//升级结果接收
public void onPayloadApplicationComplete(int errorCode) {
Log.w(TAG, String.format("onPayloadApplicationComplete %d", errorCode));
mInstallationInProgress = false;
//错误码见frameworks/base/core/java/android/os/UpdateEngine.java的ErrorCodeConstants集合定义
showStatus(errorCode == UpdateEngine.ErrorCodeConstants.SUCCESS
? R.string.install_success
: R.string.install_failed);
mProgressBar.setVisibility(View.GONE);
mSystemUpdateToolbarAction.setVisibility(View.GONE);
}
}
重启接口调用:
private void rebootNow() {
if (Log.isLoggable(TAG, Log.INFO)) {
Log.i(TAG, "Rebooting Now.");
}
mPowerManager.reboot(REBOOT_REASON);
}
3.3. 升级状态码解释
//frameworks/base/core/java/android/os/UpdateEngine.java
/**
* Status codes for update engine. Values must agree with the ones in
* {@code system/update_engine/client_library/include/update_engine/update_status.h}.
*/
public static final class UpdateStatusConstants {
//IDLE状态
public static final int IDLE = 0;
//update engine服务检查升级
public static final int CHECKING_FOR_UPDATE = 1;
//存在可获取的升级
public static final int UPDATE_AVAILABLE = 2;
//downloading下载步骤状态
public static final int DOWNLOADING = 3;
//update engine正在校验状态
public static final int VERIFYING = 4;
//update engine正在完成一个升级
public static final int FINALIZING = 5;
//请求重启(一般是升级成功)
public static final int UPDATED_NEED_REBOOT = 6;
//update egnine上报一个错误事件
public static final int REPORTING_ERROR_EVENT = 7;
//update engine试图恢复一个升级(可能升级被中断过)
public static final int ATTEMPTING_ROLLBACK = 8;
//update engine处于被禁止状态
public static final int DISABLED = 9;
}
3.4. 升级错误码解释
//frameworks/base/core/java/android/os/UpdateEngine.java
/**
* Error codes from update engine upon finishing a call to
* {@link applyPayload}. Values will be passed via the callback function
* {@link UpdateEngineCallback#onPayloadApplicationComplete}. Values must
* agree with the ones in {@code system/update_engine/common/error_code.h}.
*/
public static final class ErrorCodeConstants {
//升级成功
public static final int SUCCESS = 0;
//升级失败
public static final int ERROR = 1;
//文件系统拷贝失败
public static final int FILESYSTEM_COPIER_ERROR = 4;
/**
* Error code: an update failed to apply due to an error in running
* post-install hooks.
*/
//post-install运行时报错
public static final int POST_INSTALL_RUNNER_ERROR = 5;
/**
* Error code: an update failed to apply due to a mismatching payload.
*
* <p>For example, the given payload uses a feature that's not
* supported by the current update engine.
*/
public static final int PAYLOAD_MISMATCHED_TYPE_ERROR = 6;
/**
* Error code: an update failed to apply due to an error in opening
* devices.
*/
public static final int INSTALL_DEVICE_OPEN_ERROR = 7;
/**
* Error code: an update failed to apply due to an error in opening
* kernel device.
*/
public static final int KERNEL_DEVICE_OPEN_ERROR = 8;
/**
* Error code: an update failed to apply due to an error in fetching
* the payload.
*
* <p>For example, this could be a result of bad network connection
* when streaming an update.
*/
//download传输报错,比如U盘升级download时拔出U盘
public static final int DOWNLOAD_TRANSFER_ERROR = 9;
/**
* Error code: an update failed to apply due to a mismatch in payload
* hash.
*
* <p>Update engine does sanity checks for the given payload and its
* metadata.
*/
public static final int PAYLOAD_HASH_MISMATCH_ERROR = 10;
/**
* Error code: an update failed to apply due to a mismatch in payload
* size.
*/
public static final int PAYLOAD_SIZE_MISMATCH_ERROR = 11;
/**
* Error code: an update failed to apply due to failing to verify
* payload signatures.
*/
public static final int DOWNLOAD_PAYLOAD_VERIFICATION_ERROR = 12;
/**
* Error code: an update failed to apply due to a downgrade in payload
* timestamp.
*
* <p>The timestamp of a build is encoded into the payload, which will
* be enforced during install to prevent downgrading a device.
*/
//版本时间戳校验,如果不支持回滚,则回滚升级会报错
public static final int PAYLOAD_TIMESTAMP_ERROR = 51;
/**
* Error code: an update has been applied successfully but the new slot
* hasn't been set to active.
*
* <p>It indicates a successful finish of calling {@link #applyPayload} with
* {@code SWITCH_SLOT_ON_REBOOT=0}. See {@link #applyPayload}.
*/
public static final int UPDATED_BUT_NOT_ACTIVE = 52;
}