blob: 13df88b1804c8c286cc66498a7ab0e70e9ebaf12 [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;
Zhomart Mukhamejanov8f4059d2018-05-18 10:15:31 -070039 public static final int USER_CANCELLED = 48;
Zhomart Mukhamejanovf4d280c2018-04-17 13:20:22 -070040
41 private static final SparseArray<String> CODE_TO_NAME_MAP = new SparseArray<>();
42
43 static {
44 CODE_TO_NAME_MAP.put(0, "SUCCESS");
45 CODE_TO_NAME_MAP.put(1, "ERROR");
46 CODE_TO_NAME_MAP.put(4, "FILESYSTEM_COPIER_ERROR");
47 CODE_TO_NAME_MAP.put(5, "POST_INSTALL_RUNNER_ERROR");
48 CODE_TO_NAME_MAP.put(6, "PAYLOAD_MISMATCHED_TYPE_ERROR");
49 CODE_TO_NAME_MAP.put(7, "INSTALL_DEVICE_OPEN_ERROR");
50 CODE_TO_NAME_MAP.put(8, "KERNEL_DEVICE_OPEN_ERROR");
51 CODE_TO_NAME_MAP.put(9, "DOWNLOAD_TRANSFER_ERROR");
52 CODE_TO_NAME_MAP.put(10, "PAYLOAD_HASH_MISMATCH_ERROR");
53 CODE_TO_NAME_MAP.put(11, "PAYLOAD_SIZE_MISMATCH_ERROR");
54 CODE_TO_NAME_MAP.put(12, "DOWNLOAD_PAYLOAD_VERIFICATION_ERROR");
Zhomart Mukhamejanovda7e2372018-05-01 12:50:55 -070055 CODE_TO_NAME_MAP.put(15, "NEW_ROOTFS_VERIFICATION_ERROR");
Zhomart Mukhamejanovf4d280c2018-04-17 13:20:22 -070056 CODE_TO_NAME_MAP.put(20, "DOWNLOAD_STATE_INITIALIZATION_ERROR");
Zhomart Mukhamejanovebee98d2018-06-13 16:18:38 -070057 CODE_TO_NAME_MAP.put(26, "DOWNLOAD_METADATA_SIGNATURE_MISMATCH");
Zhomart Mukhamejanovf4d280c2018-04-17 13:20:22 -070058 CODE_TO_NAME_MAP.put(48, "USER_CANCELLED");
59 CODE_TO_NAME_MAP.put(52, "UPDATED_BUT_NOT_ACTIVE");
60 }
61
62 /**
63 * Completion codes returned by update engine indicating that the update
64 * was successfully applied.
65 */
Zhomart Mukhamejanov8f4059d2018-05-18 10:15:31 -070066 private static final Set<Integer> SUCCEEDED_COMPLETION_CODES = new HashSet<>(
Zhomart Mukhamejanovf4d280c2018-04-17 13:20:22 -070067 Arrays.asList(UpdateEngine.ErrorCodeConstants.SUCCESS,
68 // UPDATED_BUT_NOT_ACTIVE is returned when the payload is
69 // successfully applied but the
70 // device won't switch to the new slot after the next boot.
71 UPDATED_BUT_NOT_ACTIVE));
72
73 /**
74 * checks if update succeeded using errorCode
75 */
76 public static boolean isUpdateSucceeded(int errorCode) {
77 return SUCCEEDED_COMPLETION_CODES.contains(errorCode);
78 }
79
80 /**
81 * converts error code to error name
82 */
83 public static String getCodeName(int errorCode) {
84 return CODE_TO_NAME_MAP.get(errorCode);
85 }
86
87 private UpdateEngineErrorCodes() {}
88}