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

Commit baeb3db3 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6424828 from 04083e2b to rvc-release

Change-Id: Ic1e74156dfdce21b4b903481958e93bc7779af34
parents 11c825b5 04083e2b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -617,7 +617,7 @@ class SyncConnection {
        }

        std::string path_and_mode = android::base::StringPrintf("%s,%d", path.c_str(), mode);
        if (!SendRequest(ID_SEND_V1, path_and_mode.c_str())) {
        if (!SendRequest(ID_SEND_V1, path_and_mode)) {
            Error("failed to send ID_SEND_V1 message '%s': %s", path_and_mode.c_str(),
                  strerror(errno));
            return false;
+7 −27
Original line number Diff line number Diff line
@@ -195,7 +195,6 @@ static std::mutex& LoggingLock() {
  return logging_lock;
}

// Only used for Q fallback.
static LogFunction& Logger() {
#ifdef __ANDROID__
  static auto& logger = *new LogFunction(LogdLogger());
@@ -205,7 +204,6 @@ static LogFunction& Logger() {
  return logger;
}

// Only used for Q fallback.
static AbortFunction& Aborter() {
  static auto& aborter = *new AbortFunction(DefaultAborter);
  return aborter;
@@ -416,45 +414,27 @@ void InitLogging(char* argv[], LogFunction&& logger, AbortFunction&& aborter) {
}

void SetLogger(LogFunction&& logger) {
  Logger() = std::move(logger);

  static auto& liblog_functions = GetLibLogFunctions();
  if (liblog_functions) {
    // We need to atomically swap the old and new pointers since other threads may be logging.
    // We know all threads will be using the new logger after __android_log_set_logger() returns,
    // so we can delete it then.
    // This leaks one std::function<> per instance of libbase if multiple copies of libbase within a
    // single process call SetLogger().  That is the same cost as having a static
    // std::function<>, which is the not-thread-safe alternative.
    static std::atomic<LogFunction*> logger_function(nullptr);
    auto* old_logger_function = logger_function.exchange(new LogFunction(logger));
    liblog_functions->__android_log_set_logger([](const struct __android_log_message* log_message) {
      auto log_id = log_id_tToLogId(log_message->buffer_id);
      auto severity = PriorityToLogSeverity(log_message->priority);

      auto& function = *logger_function.load(std::memory_order_acquire);
      function(log_id, severity, log_message->tag, log_message->file, log_message->line,
      Logger()(log_id, severity, log_message->tag, log_message->file, log_message->line,
               log_message->message);
    });
    delete old_logger_function;
  } else {
    std::lock_guard<std::mutex> lock(LoggingLock());
    Logger() = std::move(logger);
  }
}

void SetAborter(AbortFunction&& aborter) {
  Aborter() = std::move(aborter);

  static auto& liblog_functions = GetLibLogFunctions();
  if (liblog_functions) {
    // See the comment in SetLogger().
    static std::atomic<AbortFunction*> abort_function(nullptr);
    auto* old_abort_function = abort_function.exchange(new AbortFunction(aborter));
    liblog_functions->__android_log_set_aborter([](const char* abort_message) {
      auto& function = *abort_function.load(std::memory_order_acquire);
      function(abort_message);
    });
    delete old_abort_function;
  } else {
    std::lock_guard<std::mutex> lock(LoggingLock());
    Aborter() = std::move(aborter);
    liblog_functions->__android_log_set_aborter(
        [](const char* abort_message) { Aborter()(abort_message); });
  }
}

+17 −5
Original line number Diff line number Diff line
@@ -40,6 +40,20 @@ bool LinearExtent::AddTo(LpMetadata* out) const {
    return true;
}

bool LinearExtent::OverlapsWith(const LinearExtent& other) const {
    if (device_index_ != other.device_index()) {
        return false;
    }
    return physical_sector() < other.end_sector() && other.physical_sector() < end_sector();
}

bool LinearExtent::OverlapsWith(const Interval& interval) const {
    if (device_index_ != interval.device_index) {
        return false;
    }
    return physical_sector() < interval.end && interval.start < end_sector();
}

Interval LinearExtent::AsInterval() const {
    return Interval(device_index(), physical_sector(), end_sector());
}
@@ -774,8 +788,7 @@ std::unique_ptr<LinearExtent> MetadataBuilder::ExtendFinalExtent(
bool MetadataBuilder::IsAnyRegionCovered(const std::vector<Interval>& regions,
                                         const LinearExtent& candidate) const {
    for (const auto& region : regions) {
        if (region.device_index == candidate.device_index() &&
            (candidate.OwnsSector(region.start) || candidate.OwnsSector(region.end))) {
        if (candidate.OverlapsWith(region)) {
            return true;
        }
    }
@@ -786,11 +799,10 @@ bool MetadataBuilder::IsAnyRegionAllocated(const LinearExtent& candidate) const
    for (const auto& partition : partitions_) {
        for (const auto& extent : partition->extents()) {
            LinearExtent* linear = extent->AsLinearExtent();
            if (!linear || linear->device_index() != candidate.device_index()) {
            if (!linear) {
                continue;
            }
            if (linear->OwnsSector(candidate.physical_sector()) ||
                linear->OwnsSector(candidate.end_sector() - 1)) {
            if (linear->OverlapsWith(candidate)) {
                return true;
            }
        }
+82 −0
Original line number Diff line number Diff line
@@ -937,3 +937,85 @@ TEST_F(BuilderTest, ExpandedHeader) {
    EXPECT_EQ(exported->header.header_size, sizeof(LpMetadataHeaderV1_2));
    EXPECT_EQ(exported->header.flags, 0x5e5e5e5e);
}

static Interval ToInterval(const std::unique_ptr<Extent>& extent) {
    if (LinearExtent* le = extent->AsLinearExtent()) {
        return le->AsInterval();
    }
    return {0, 0, 0};
}

static void AddPartition(const std::unique_ptr<MetadataBuilder>& builder,
                         const std::string& partition_name, uint64_t num_sectors,
                         uint64_t start_sector, std::vector<Interval>* intervals) {
    Partition* p = builder->AddPartition(partition_name, "group", 0);
    ASSERT_NE(p, nullptr);
    ASSERT_TRUE(builder->AddLinearExtent(p, "super", num_sectors, start_sector));
    ASSERT_EQ(p->extents().size(), 1);

    if (!intervals) {
        return;
    }

    auto new_interval = ToInterval(p->extents().back());
    std::vector<Interval> new_intervals = {new_interval};

    auto overlap = Interval::Intersect(*intervals, new_intervals);
    ASSERT_TRUE(overlap.empty());

    intervals->push_back(new_interval);
}

TEST_F(BuilderTest, CollidedExtents) {
    BlockDeviceInfo super("super", 8_GiB, 786432, 229376, 4096);
    std::vector<BlockDeviceInfo> block_devices = {super};

    unique_ptr<MetadataBuilder> builder = MetadataBuilder::New(block_devices, "super", 65536, 2);
    ASSERT_NE(builder, nullptr);

    ASSERT_TRUE(builder->AddGroup("group", 0));

    std::vector<Interval> old_intervals;
    AddPartition(builder, "system", 10229008, 2048, &old_intervals);
    AddPartition(builder, "test_a", 648, 12709888, &old_intervals);
    AddPartition(builder, "test_b", 625184, 12711936, &old_intervals);
    AddPartition(builder, "test_c", 130912, 13338624, &old_intervals);
    AddPartition(builder, "test_d", 888, 13469696, &old_intervals);
    AddPartition(builder, "test_e", 888, 13471744, &old_intervals);
    AddPartition(builder, "test_f", 888, 13475840, &old_intervals);
    AddPartition(builder, "test_g", 888, 13477888, &old_intervals);

    // Don't track the first vendor interval, since it will get extended.
    AddPartition(builder, "vendor", 2477920, 10231808, nullptr);

    std::vector<Interval> new_intervals;

    Partition* p = builder->FindPartition("vendor");
    ASSERT_NE(p, nullptr);
    ASSERT_TRUE(builder->ResizePartition(p, 1282031616));
    ASSERT_GE(p->extents().size(), 1);
    for (const auto& extent : p->extents()) {
        new_intervals.push_back(ToInterval(extent));
    }

    std::vector<Interval> overlap = Interval::Intersect(old_intervals, new_intervals);
    ASSERT_TRUE(overlap.empty());
}

TEST_F(BuilderTest, LinearExtentOverlap) {
    LinearExtent extent(20, 0, 10);

    EXPECT_TRUE(extent.OverlapsWith(LinearExtent{20, 0, 10}));
    EXPECT_TRUE(extent.OverlapsWith(LinearExtent{50, 0, 10}));
    EXPECT_FALSE(extent.OverlapsWith(LinearExtent{20, 0, 30}));
    EXPECT_FALSE(extent.OverlapsWith(LinearExtent{10, 0, 0}));
    EXPECT_TRUE(extent.OverlapsWith(LinearExtent{20, 0, 0}));
    EXPECT_TRUE(extent.OverlapsWith(LinearExtent{40, 0, 0}));
    EXPECT_TRUE(extent.OverlapsWith(LinearExtent{20, 0, 15}));

    EXPECT_FALSE(extent.OverlapsWith(LinearExtent{20, 1, 0}));
    EXPECT_FALSE(extent.OverlapsWith(LinearExtent{50, 1, 10}));
    EXPECT_FALSE(extent.OverlapsWith(LinearExtent{40, 1, 0}));
    EXPECT_FALSE(extent.OverlapsWith(LinearExtent{20, 1, 15}));
    EXPECT_FALSE(extent.OverlapsWith(LinearExtent{20, 1, 10}));
}
+4 −0
Original line number Diff line number Diff line
@@ -56,6 +56,10 @@ TEST_F(DeviceTest, BlockDeviceInfo) {

    // Having an alignment offset > alignment doesn't really make sense.
    EXPECT_LT(device_info.alignment_offset, device_info.alignment);

    if (IPropertyFetcher::GetInstance()->GetBoolProperty("ro.virtual_ab.enabled", false)) {
        EXPECT_EQ(device_info.alignment_offset, 0);
    }
}

TEST_F(DeviceTest, ReadSuperPartitionCurrentSlot) {
Loading