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

Commit c2a3d7aa authored by Andreas Gampe's avatar Andreas Gampe Committed by Android (Google) Code Review
Browse files

Merge "Installd: Introduce otapreopt"

parents a275dd13 73dae111
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -43,6 +43,43 @@ LOCAL_INIT_RC := installd.rc
LOCAL_CLANG := true
include $(BUILD_EXECUTABLE)

#
# OTA Executable
#

include $(CLEAR_VARS)
LOCAL_MODULE := otapreopt
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS := $(common_cflags)

# Base & ASLR boundaries for boot image creation.
ifndef LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA
  LOCAL_LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA := -0x1000000
else
  LOCAL_LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA := $(LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA)
endif
ifndef LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA
  LOCAL_LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA := 0x1000000
else
  LOCAL_LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA := $(LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA)
endif
LOCAL_CFLAGS += -DART_BASE_ADDRESS=$(LIBART_IMG_HOST_BASE_ADDRESS)
LOCAL_CFLAGS += -DART_BASE_ADDRESS_MIN_DELTA=$(LOCAL_LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA)
LOCAL_CFLAGS += -DART_BASE_ADDRESS_MAX_DELTA=$(LOCAL_LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA)

LOCAL_SRC_FILES := otapreopt.cpp $(common_src_files)
LOCAL_SHARED_LIBRARIES := \
    libbase \
    libcutils \
    liblog \
    liblogwrap \
    libselinux \

LOCAL_STATIC_LIBRARIES := libdiskusage
LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
LOCAL_CLANG := true
include $(BUILD_EXECUTABLE)

# Tests.

include $(LOCAL_PATH)/tests/Android.mk
 No newline at end of file
+31 −2
Original line number Diff line number Diff line
@@ -211,12 +211,41 @@ static int do_destroy_app_data(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSE
    return destroy_app_data(parse_null(arg[0]), arg[1], atoi(arg[2]), atoi(arg[3]));
}

static int do_dexopt(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED)
static int do_ota_dexopt(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED) {
  // Time to fork and run otapreopt.
  pid_t pid = fork();
  if (pid == 0) {
    const char* argv[1 + 9 + 1];
    argv[0] = "/system/bin/otapreopt";
    for (size_t i = 1; i <= 9; ++i) {
      argv[i] = arg[i - 1];
    }
    argv[10] = nullptr;

    execv(argv[0], (char * const *)argv);
    ALOGE("execv(OTAPREOPT) failed: %s\n", strerror(errno));
    exit(99);
  } else {
    int res = wait_child(pid);
    if (res == 0) {
      ALOGV("DexInv: --- END OTAPREOPT (success) ---\n");
    } else {
      ALOGE("DexInv: --- END OTAPREOPT --- status=0x%04x, process failed\n", res);
    }
    return res;
  }
}

static int do_dexopt(char **arg, char reply[REPLY_MAX])
{
    int dexopt_flags = atoi(arg[6]);
    if ((dexopt_flags & DEXOPT_OTA) != 0) {
      return do_ota_dexopt(arg, reply);
    }
    /* apk_path, uid, pkgname, instruction_set, dexopt_needed, oat_dir, dexopt_flags, volume_uuid,
            use_profiles */
    return dexopt(arg[0], atoi(arg[1]), arg[2], arg[3], atoi(arg[4]),
                  arg[5], atoi(arg[6]), parse_null(arg[7]), (atoi(arg[8]) == 0 ? false : true));
                  arg[5], dexopt_flags, parse_null(arg[7]), (atoi(arg[8]) == 0 ? false : true));
}

static int do_mark_boot_complete(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED)
+4 −1
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ constexpr const char* PRIVATE_APP_SUBDIR = "app-private/"; // sub-directory unde
// This is used as a string literal, can't be constants. TODO: std::string...
#define DALVIK_CACHE "dalvik-cache"
constexpr const char* DALVIK_CACHE_POSTFIX = "/classes.dex";
constexpr const char* DALVIK_CACHE_POSTFIX2 = "@classes.dex";

constexpr const char* IDMAP_PREFIX = "/data/resource-cache/";
constexpr const char* IDMAP_SUFFIX = "@idmap";
@@ -74,6 +75,7 @@ constexpr int DEXOPT_SAFEMODE = 1 << 2;
constexpr int DEXOPT_DEBUGGABLE   = 1 << 3;
constexpr int DEXOPT_BOOTCOMPLETE = 1 << 4;
constexpr int DEXOPT_EXTRACTONLY  = 1 << 5;
constexpr int DEXOPT_OTA          = 1 << 6;

/* all known values for dexopt flags */
constexpr int DEXOPT_MASK =
@@ -81,7 +83,8 @@ constexpr int DEXOPT_MASK =
    | DEXOPT_SAFEMODE
    | DEXOPT_DEBUGGABLE
    | DEXOPT_BOOTCOMPLETE
    | DEXOPT_EXTRACTONLY;
    | DEXOPT_EXTRACTONLY
    | DEXOPT_OTA;

#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))

+641 −0

File added.

Preview size limit exceeded, changes collapsed.

+67 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 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 ART_OTAPREOPT_STRING_HELPERS_H_
#define ART_OTAPREOPT_STRING_HELPERS_H_

#include <sstream>
#include <string>

#include <android-base/macros.h>

namespace android {
namespace installd {

static inline bool StringStartsWith(const std::string& target,
                                    const char* prefix) {
    return target.compare(0, strlen(prefix), prefix) == 0;
}

// Split the input according to the separator character. Doesn't honor quotation.
static inline std::vector<std::string> Split(const std::string& in, const char separator) {
    if (in.empty()) {
        return std::vector<std::string>();
    }

    std::vector<std::string> ret;
    std::stringstream strstr(in);
    std::string token;

    while (std::getline(strstr, token, separator)) {
        ret.push_back(token);
    }

    return ret;
}

template <typename StringT>
static inline std::string Join(const std::vector<StringT>& strings, char separator) {
    if (strings.empty()) {
        return "";
    }

    std::string result(strings[0]);
    for (size_t i = 1; i < strings.size(); ++i) {
        result += separator;
        result += strings[i];
    }
    return result;
}

}  // namespace installd
}  // namespace android

#endif  // ART_OTAPREOPT_STRING_HELPERS_H_
Loading