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

Commit 5d707816 authored by Xin Li's avatar Xin Li Committed by Gerrit Code Review
Browse files

Merge "Merge Android Pie into master"

parents 574533a6 fb973d34
Loading
Loading
Loading
Loading
+26 −17
Original line number Diff line number Diff line
@@ -132,8 +132,11 @@ int adf_get_device_data(struct adf_device *dev, struct adf_device_data *data)
void adf_free_device_data(struct adf_device_data *data)
{
    delete [] data->attachments;
    data->attachments = nullptr;
    delete [] data->allowed_attachments;
    data->allowed_attachments = nullptr;
    delete [] static_cast<char *>(data->custom_data);
    data->custom_data = nullptr;
}

int adf_device_post(struct adf_device *dev,
@@ -236,6 +239,7 @@ ssize_t adf_interfaces_for_overlay_engine(struct adf_device *dev,
        return err;

    std::vector<adf_id_t> ids;
    if (data.allowed_attachments != nullptr)
        for (size_t i = 0; i < data.n_allowed_attachments; i++)
            if (data.allowed_attachments[i].overlay_engine == overlay_engine)
              ids.push_back(data.allowed_attachments[i].interface);
@@ -450,6 +454,7 @@ ssize_t adf_overlay_engines_for_interface(struct adf_device *dev,
        return err;

    std::vector<adf_id_t> ids;
    if (data.allowed_attachments != nullptr)
        for (size_t i = 0; i < data.n_allowed_attachments; i++)
            if (data.allowed_attachments[i].interface == interface)
                ids.push_back(data.allowed_attachments[i].overlay_engine);
@@ -551,7 +556,9 @@ int adf_get_overlay_engine_data(int fd, struct adf_overlay_engine_data *data)
void adf_free_overlay_engine_data(struct adf_overlay_engine_data *data)
{
    delete [] data->supported_formats;
    data->supported_formats = nullptr;
    delete [] static_cast<char *>(data->custom_data);
    data->custom_data = nullptr;
}

bool adf_overlay_engine_supports_format(int fd, __u32 format)
@@ -564,12 +571,14 @@ bool adf_overlay_engine_supports_format(int fd, __u32 format)
    if (err < 0)
        return false;

    if (data.supported_formats != nullptr) {
        for (i = 0; i < data.n_supported_formats; i++) {
            if (data.supported_formats[i] == format) {
                ret = true;
                break;
            }
        }
    }

    adf_free_overlay_engine_data(&data);
    return ret;
@@ -638,18 +647,18 @@ static bool adf_find_simple_post_overlay_engine(struct adf_device *dev,
        const __u32 *formats, size_t n_formats,
        adf_id_t interface, adf_id_t *overlay_engine)
{
    adf_id_t *engs;
    adf_id_t *engs = nullptr;
    ssize_t n_engs = adf_overlay_engines_for_interface(dev, interface, &engs);

    if (n_engs <= 0)
    if (engs == nullptr)
        return false;

    adf_id_t *filtered_engs;
    adf_id_t *filtered_engs = nullptr;
    ssize_t n_filtered_engs = adf_overlay_engines_filter_by_format(dev,
            formats, n_formats, engs, n_engs, &filtered_engs);
    free(engs);

    if (n_filtered_engs <= 0)
    if (filtered_engs == nullptr)
        return false;

    *overlay_engine = filtered_engs[0];
@@ -700,17 +709,17 @@ int adf_find_simple_post_configuration(struct adf_device *dev,

    if (n_intfs < 0)
        return n_intfs;
    else if (!n_intfs)
    else if (!intfs)
        return -ENODEV;

    adf_id_t *primary_intfs;
    adf_id_t *primary_intfs = nullptr;
    ssize_t n_primary_intfs = adf_interfaces_filter_by_flag(dev,
            ADF_INTF_FLAG_PRIMARY, intfs, n_intfs, &primary_intfs);
    free(intfs);

    if (n_primary_intfs < 0)
        return n_primary_intfs;
    else if (!n_primary_intfs)
    else if (!primary_intfs)
        return -ENODEV;

    if (!formats) {
+3 −0
Original line number Diff line number Diff line
@@ -63,6 +63,9 @@ cc_binary {
    name: "bootstat",
    defaults: ["bootstat_defaults"],
    static_libs: ["libbootstat"],
    shared_libs: [
        "libstatslog"
    ],
    init_rc: ["bootstat.rc"],
    product_variables: {
        pdk: {
+65 −19
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@
#include <cutils/android_reboot.h>
#include <cutils/properties.h>
#include <metricslogger/metrics_logger.h>
#include <statslog.h>

#include "boot_event_record_store.h"

@@ -1026,6 +1027,16 @@ const BootloaderTimingMap GetBootLoaderTimings() {
  return timings;
}

// Returns the total bootloader boot time from the ro.boot.boottime system property.
int32_t GetBootloaderTime(const BootloaderTimingMap& bootloader_timings) {
  int32_t total_time = 0;
  for (const auto& timing : bootloader_timings) {
    total_time += timing.second;
  }

  return total_time;
}

// Parses and records the set of bootloader stages and associated boot times
// from the ro.boot.boottime system property.
void RecordBootloaderTimings(BootEventRecordStore* boot_event_store,
@@ -1039,10 +1050,9 @@ void RecordBootloaderTimings(BootEventRecordStore* boot_event_store,
  boot_event_store->AddBootEventWithValue("boottime.bootloader.total", total_time);
}

// Records the closest estimation to the absolute device boot time, i.e.,
// Returns the closest estimation to the absolute device boot time, i.e.,
// from power on to boot_complete, including bootloader times.
void RecordAbsoluteBootTime(BootEventRecordStore* boot_event_store,
                            const BootloaderTimingMap& bootloader_timings,
std::chrono::milliseconds GetAbsoluteBootTime(const BootloaderTimingMap& bootloader_timings,
                                              std::chrono::milliseconds uptime) {
  int32_t bootloader_time_ms = 0;

@@ -1053,23 +1063,36 @@ void RecordAbsoluteBootTime(BootEventRecordStore* boot_event_store,
  }

  auto bootloader_duration = std::chrono::milliseconds(bootloader_time_ms);
  auto absolute_total =
      std::chrono::duration_cast<std::chrono::seconds>(bootloader_duration + uptime);
  boot_event_store->AddBootEventWithValue("absolute_boot_time", absolute_total.count());
  return bootloader_duration + uptime;
}

// Gets the boot time offset. This is useful when Android is running in a
// container, because the boot_clock is not reset when Android reboots.
std::chrono::nanoseconds GetBootTimeOffset() {
  static const int64_t boottime_offset =
      android::base::GetIntProperty<int64_t>("ro.boot.boottime_offset", 0);
  return std::chrono::nanoseconds(boottime_offset);
// Records the closest estimation to the absolute device boot time in seconds.
// i.e. from power on to boot_complete, including bootloader times.
void RecordAbsoluteBootTime(BootEventRecordStore* boot_event_store,
                            std::chrono::milliseconds absolute_total) {
  auto absolute_total_sec = std::chrono::duration_cast<std::chrono::seconds>(absolute_total);
  boot_event_store->AddBootEventWithValue("absolute_boot_time", absolute_total_sec.count());
}

// Returns the current uptime, accounting for any offset in the CLOCK_BOOTTIME
// clock.
android::base::boot_clock::duration GetUptime() {
  return android::base::boot_clock::now().time_since_epoch() - GetBootTimeOffset();
// Logs the total boot time and reason to statsd.
void LogBootInfoToStatsd(std::chrono::milliseconds end_time,
                         std::chrono::milliseconds total_duration, int32_t bootloader_duration_ms,
                         double time_since_last_boot_sec) {
  const std::string reason(GetProperty(bootloader_reboot_reason_property));

  if (reason.empty()) {
    android::util::stats_write(android::util::BOOT_SEQUENCE_REPORTED, "<EMPTY>", "<EMPTY>",
                               end_time.count(), total_duration.count(),
                               (int64_t)bootloader_duration_ms,
                               (int64_t)time_since_last_boot_sec * 1000);
    return;
  }

  const std::string system_reason(GetProperty(system_reboot_reason_property));
  android::util::stats_write(android::util::BOOT_SEQUENCE_REPORTED, reason.c_str(),
                             system_reason.c_str(), end_time.count(), total_duration.count(),
                             (int64_t)bootloader_duration_ms,
                             (int64_t)time_since_last_boot_sec * 1000);
}

void SetSystemBootReason() {
@@ -1088,6 +1111,20 @@ void SetSystemBootReason() {
  SetProperty(last_reboot_reason_property, "");
}

// Gets the boot time offset. This is useful when Android is running in a
// container, because the boot_clock is not reset when Android reboots.
std::chrono::nanoseconds GetBootTimeOffset() {
  static const int64_t boottime_offset =
      android::base::GetIntProperty<int64_t>("ro.boot.boottime_offset", 0);
  return std::chrono::nanoseconds(boottime_offset);
}

// Returns the current uptime, accounting for any offset in the CLOCK_BOOTTIME
// clock.
android::base::boot_clock::duration GetUptime() {
  return android::base::boot_clock::now().time_since_epoch() - GetBootTimeOffset();
}

// Records several metrics related to the time it takes to boot the device,
// including disambiguating boot time on encrypted or non-encrypted devices.
void RecordBootComplete() {
@@ -1097,10 +1134,11 @@ void RecordBootComplete() {
  auto uptime_ns = GetUptime();
  auto uptime_s = std::chrono::duration_cast<std::chrono::seconds>(uptime_ns);
  time_t current_time_utc = time(nullptr);
  time_t time_since_last_boot = 0;

  if (boot_event_store.GetBootEvent("last_boot_time_utc", &record)) {
    time_t last_boot_time_utc = record.second;
    time_t time_since_last_boot = difftime(current_time_utc, last_boot_time_utc);
    time_since_last_boot = difftime(current_time_utc, last_boot_time_utc);
    boot_event_store.AddBootEventWithValue("time_since_last_boot", time_since_last_boot);
  }

@@ -1140,10 +1178,18 @@ void RecordBootComplete() {
  RecordInitBootTimeProp(&boot_event_store, "ro.boottime.init.cold_boot_wait");

  const BootloaderTimingMap bootloader_timings = GetBootLoaderTimings();
  int32_t bootloader_boot_duration = GetBootloaderTime(bootloader_timings);
  RecordBootloaderTimings(&boot_event_store, bootloader_timings);

  auto uptime_ms = std::chrono::duration_cast<std::chrono::milliseconds>(uptime_ns);
  RecordAbsoluteBootTime(&boot_event_store, bootloader_timings, uptime_ms);
  auto absolute_boot_time = GetAbsoluteBootTime(bootloader_timings, uptime_ms);
  RecordAbsoluteBootTime(&boot_event_store, absolute_boot_time);

  auto boot_end_time_point = std::chrono::system_clock::now().time_since_epoch();
  auto boot_end_time = std::chrono::duration_cast<std::chrono::milliseconds>(boot_end_time_point);

  LogBootInfoToStatsd(boot_end_time, absolute_boot_time, bootloader_boot_duration,
                      time_since_last_boot);
}

// Records the boot_reason metric by querying the ro.boot.bootreason system
+2 −0
Original line number Diff line number Diff line
@@ -177,6 +177,8 @@ static int generate_f2fs_image(const char* fileName, long long partSize, const s
    mkf2fs_args.push_back("encrypt");
    mkf2fs_args.push_back("-O");
    mkf2fs_args.push_back("quota");
    mkf2fs_args.push_back("-O");
    mkf2fs_args.push_back("verity");
    mkf2fs_args.push_back(fileName);
    mkf2fs_args.push_back(nullptr);

+1 −0
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@ static int format_f2fs(char *fs_blkdev, uint64_t dev_sz, bool crypt_footer)
        "-f",
        "-O", "encrypt",
        "-O", "quota",
        "-O", "verity",
        "-w", "4096",
        fs_blkdev,
        size_str.c_str(),
Loading