Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50f64173 authored by Tianjie Xu's avatar Tianjie Xu Committed by Android (Google) Code Review
Browse files

Merge "Allow recovery to return error codes" into nyc-dev

parents 75dea9ca 16255838
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -113,7 +113,7 @@ apply_from_adb(RecoveryUI* ui_, bool* wipe_cache, const char* install_file) {
                break;
            }
        }
        result = install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, install_file, false);
        result = install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, install_file, false, 0);
        break;
    }

+4 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ LOCAL_YACCFLAGS := -v
LOCAL_CPPFLAGS += -Wno-unused-parameter
LOCAL_CPPFLAGS += -Wno-deprecated-register
LOCAL_CLANG := true
LOCAL_C_INCLUDES += $(LOCAL_PATH)/..
LOCAL_STATIC_LIBRARIES += libbase

include $(BUILD_HOST_EXECUTABLE)

@@ -36,5 +38,7 @@ LOCAL_CPPFLAGS := -Wno-unused-parameter
LOCAL_CPPFLAGS += -Wno-deprecated-register
LOCAL_MODULE := libedify
LOCAL_CLANG := true
LOCAL_C_INCLUDES += $(LOCAL_PATH)/..
LOCAL_STATIC_LIBRARIES += libbase

include $(BUILD_STATIC_LIBRARY)
+29 −10
Original line number Diff line number Diff line
@@ -21,6 +21,11 @@
#include <stdarg.h>
#include <unistd.h>

#include <string>

#include <android-base/stringprintf.h>
#include <android-base/strings.h>

#include "expr.h"

// Functions should:
@@ -36,7 +41,7 @@ char* Evaluate(State* state, Expr* expr) {
    Value* v = expr->fn(expr->name, state, expr->argc, expr->argv);
    if (v == NULL) return NULL;
    if (v->type != VAL_STRING) {
        ErrorAbort(state, "expecting string, got value type %d", v->type);
        ErrorAbort(state, kArgsParsingFailure, "expecting string, got value type %d", v->type);
        FreeValue(v);
        return NULL;
    }
@@ -493,15 +498,29 @@ Value** ReadValueVarArgs(State* state, int argc, Expr* argv[]) {
    return args;
}

static void ErrorAbortV(State* state, const char* format, va_list ap) {
    std::string buffer;
    android::base::StringAppendV(&buffer, format, ap);
    free(state->errmsg);
    state->errmsg = strdup(buffer.c_str());
    return;
}

// Use printf-style arguments to compose an error message to put into
// *state.  Returns NULL.
// *state.  Returns nullptr.
Value* ErrorAbort(State* state, const char* format, ...) {
    char* buffer = reinterpret_cast<char*>(malloc(4096));
    va_list v;
    va_start(v, format);
    vsnprintf(buffer, 4096, format, v);
    va_end(v);
    free(state->errmsg);
    state->errmsg = buffer;
    return NULL;
    va_list ap;
    va_start(ap, format);
    ErrorAbortV(state, format, ap);
    va_end(ap);
    return nullptr;
}

Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...) {
    va_list ap;
    va_start(ap, format);
    ErrorAbortV(state, format, ap);
    va_end(ap);
    state->cause_code = cause_code;
    return nullptr;
}
+17 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

#include <unistd.h>

#include "error_code.h"
#include "yydefs.h"

#define MAX_STRING_LEN 1024
@@ -39,6 +40,15 @@ typedef struct {
    // Should be NULL initially, will be either NULL or a malloc'd
    // pointer after Evaluate() returns.
    char* errmsg;

    // error code indicates the type of failure (e.g. failure to update system image)
    // during the OTA process.
    ErrorCode error_code = kNoError;

    // cause code provides more detailed reason of an OTA failure (e.g. fsync error)
    // in addition to the error code.
    CauseCode cause_code = kNoCause;

} State;

#define VAL_STRING  1  // data will be NULL-terminated; size doesn't count null
@@ -152,7 +162,13 @@ Value** ReadValueVarArgs(State* state, int argc, Expr* argv[]);

// Use printf-style arguments to compose an error message to put into
// *state.  Returns NULL.
Value* ErrorAbort(State* state, const char* format, ...) __attribute__((format(printf, 2, 3)));
Value* ErrorAbort(State* state, const char* format, ...)
    __attribute__((format(printf, 2, 3), deprecated));

// ErrorAbort has an optional (but recommended) argument 'cause_code'. If the cause code
// is set, it will be logged into last_install and provides reason of OTA failures.
Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...)
    __attribute__((format(printf, 3, 4)));

// Wrap a string into a Value, taking ownership of the string.
Value* StringValue(char* str);

error_code.h

0 → 100644
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 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.
 */

#ifndef _ERROR_CODE_H_
#define _ERROR_CODE_H_

enum ErrorCode {
    kNoError = -1,
    kLowBattery = 20,
    kZipVerificationFailure,
    kZipOpenFailure
};

enum CauseCode {
    kNoCause = -1,
    kArgsParsingFailure = 100,
    kStashCreationFailure,
    kFileOpenFailure,
    kLseekFailure,
    kFreadFailure,
    kFwriteFailure,
    kFsyncFailure,
    kLibfecFailure,
    kFileGetPropFailure,
    kFileRenameFailure,
    kSymlinkFailure,
    kSetMetadataFailure,
    kTune2FsFailure,
    kRebootFailure,
    kVendorFailure = 200
};

#endif
Loading