blob: e63da6298102a9a0dc37e71ca8a76b8a24cc2bb1 [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 */
37 public static final int UPDATED_BUT_NOT_ACTIVE = 52;
38
39 private static final SparseArray<String> CODE_TO_NAME_MAP = new SparseArray<>();
40
41 static {
42 CODE_TO_NAME_MAP.put(0, "SUCCESS");
43 CODE_TO_NAME_MAP.put(1, "ERROR");
44 CODE_TO_NAME_MAP.put(4, "FILESYSTEM_COPIER_ERROR");
45 CODE_TO_NAME_MAP.put(5, "POST_INSTALL_RUNNER_ERROR");
46 CODE_TO_NAME_MAP.put(6, "PAYLOAD_MISMATCHED_TYPE_ERROR");
47 CODE_TO_NAME_MAP.put(7, "INSTALL_DEVICE_OPEN_ERROR");
48 CODE_TO_NAME_MAP.put(8, "KERNEL_DEVICE_OPEN_ERROR");
49 CODE_TO_NAME_MAP.put(9, "DOWNLOAD_TRANSFER_ERROR");
50 CODE_TO_NAME_MAP.put(10, "PAYLOAD_HASH_MISMATCH_ERROR");
51 CODE_TO_NAME_MAP.put(11, "PAYLOAD_SIZE_MISMATCH_ERROR");
52 CODE_TO_NAME_MAP.put(12, "DOWNLOAD_PAYLOAD_VERIFICATION_ERROR");
53 CODE_TO_NAME_MAP.put(20, "DOWNLOAD_STATE_INITIALIZATION_ERROR");
54 CODE_TO_NAME_MAP.put(48, "USER_CANCELLED");
55 CODE_TO_NAME_MAP.put(52, "UPDATED_BUT_NOT_ACTIVE");
56 }
57
58 /**
59 * Completion codes returned by update engine indicating that the update
60 * was successfully applied.
61 */
62 private static final Set<Integer> SUCCEEDED_COMPLETION_CODES = new HashSet<Integer>(
63 Arrays.asList(UpdateEngine.ErrorCodeConstants.SUCCESS,
64 // UPDATED_BUT_NOT_ACTIVE is returned when the payload is
65 // successfully applied but the
66 // device won't switch to the new slot after the next boot.
67 UPDATED_BUT_NOT_ACTIVE));
68
69 /**
70 * checks if update succeeded using errorCode
71 */
72 public static boolean isUpdateSucceeded(int errorCode) {
73 return SUCCEEDED_COMPLETION_CODES.contains(errorCode);
74 }
75
76 /**
77 * converts error code to error name
78 */
79 public static String getCodeName(int errorCode) {
80 return CODE_TO_NAME_MAP.get(errorCode);
81 }
82
83 private UpdateEngineErrorCodes() {}
84}