blob: f06ddf7fc83052fafd7891aab142327e30d0ae02 [file] [log] [blame]
Zhomart Mukhamejanovf4d280c2018-04-17 13:20:22 -07001/*
2 * Copyright (C) 2018 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
17package com.example.android.systemupdatersample.util;
18
19import android.os.UpdateEngine;
20import android.util.SparseArray;
21
22import java.util.Arrays;
23import java.util.HashSet;
24import java.util.Set;
25
26/**
27 * Helper class to work with update_engine's error codes.
28 * Many error codes are defined in {@link UpdateEngine.ErrorCodeConstants},
29 * but you can find more in system/update_engine/common/error_code.h.
30 */
31public final class UpdateEngineErrorCodes {
32
33 /**
34 * Error code from the update engine. Values must agree with the ones in
35 * system/update_engine/common/error_code.h.
36 */
Zhomart Mukhamejanov6f26e712018-05-18 10:15:31 -070037 public static final int UNKNOWN = -1;
Zhomart Mukhamejanovf4d280c2018-04-17 13:20:22 -070038 public static final int UPDATED_BUT_NOT_ACTIVE = 52;
39
40 private static final SparseArray<String> CODE_TO_NAME_MAP = new SparseArray<>();
41
42 static {
43 CODE_TO_NAME_MAP.put(0, "SUCCESS");
44 CODE_TO_NAME_MAP.put(1, "ERROR");
45 CODE_TO_NAME_MAP.put(4, "FILESYSTEM_COPIER_ERROR");
46 CODE_TO_NAME_MAP.put(5, "POST_INSTALL_RUNNER_ERROR");
47 CODE_TO_NAME_MAP.put(6, "PAYLOAD_MISMATCHED_TYPE_ERROR");
48 CODE_TO_NAME_MAP.put(7, "INSTALL_DEVICE_OPEN_ERROR");
49 CODE_TO_NAME_MAP.put(8, "KERNEL_DEVICE_OPEN_ERROR");
50 CODE_TO_NAME_MAP.put(9, "DOWNLOAD_TRANSFER_ERROR");
51 CODE_TO_NAME_MAP.put(10, "PAYLOAD_HASH_MISMATCH_ERROR");
52 CODE_TO_NAME_MAP.put(11, "PAYLOAD_SIZE_MISMATCH_ERROR");
53 CODE_TO_NAME_MAP.put(12, "DOWNLOAD_PAYLOAD_VERIFICATION_ERROR");
Zhomart Mukhamejanovda7e2372018-05-01 12:50:55 -070054 CODE_TO_NAME_MAP.put(15, "NEW_ROOTFS_VERIFICATION_ERROR");
Zhomart Mukhamejanovf4d280c2018-04-17 13:20:22 -070055 CODE_TO_NAME_MAP.put(20, "DOWNLOAD_STATE_INITIALIZATION_ERROR");
56 CODE_TO_NAME_MAP.put(48, "USER_CANCELLED");
57 CODE_TO_NAME_MAP.put(52, "UPDATED_BUT_NOT_ACTIVE");
58 }
59
60 /**
61 * Completion codes returned by update engine indicating that the update
62 * was successfully applied.
63 */
64 private static final Set<Integer> SUCCEEDED_COMPLETION_CODES = new HashSet<Integer>(
65 Arrays.asList(UpdateEngine.ErrorCodeConstants.SUCCESS,
66 // UPDATED_BUT_NOT_ACTIVE is returned when the payload is
67 // successfully applied but the
68 // device won't switch to the new slot after the next boot.
69 UPDATED_BUT_NOT_ACTIVE));
70
71 /**
72 * checks if update succeeded using errorCode
73 */
74 public static boolean isUpdateSucceeded(int errorCode) {
75 return SUCCEEDED_COMPLETION_CODES.contains(errorCode);
76 }
77
78 /**
79 * converts error code to error name
80 */
81 public static String getCodeName(int errorCode) {
82 return CODE_TO_NAME_MAP.get(errorCode);
83 }
84
85 private UpdateEngineErrorCodes() {}
86}