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

Commit 359a7e78 authored by Marin Shalamanov's avatar Marin Shalamanov
Browse files

Use std::string in DeviceProductInfo and serialize it as Flattenable

Use std::string instead of fixed size char arrays. Serialize
DeviceProductInfo and DisplayInfo as Flattenable instead of using
memcpy().

Bug: 145299597
Test: 1. m
      2. adb shell dumpsys display
      3. check that DeviceProductInfo is correctly populated
Change-Id: Id21186138b39d7bb167c41ff7ee9387081ac6285
parent 1581d90e
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -371,10 +371,8 @@ public:
        data.writeStrongBinder(display);
        remote()->transact(BnSurfaceComposer::GET_DISPLAY_INFO, data, &reply);
        const status_t result = reply.readInt32();
        if (result == NO_ERROR) {
            memcpy(info, reply.readInplace(sizeof(DisplayInfo)), sizeof(DisplayInfo));
        }
        return result;
        if (result != NO_ERROR) return result;
        return reply.read(*info);
    }

    virtual status_t getDisplayConfigs(const sp<IBinder>& display, Vector<DisplayConfig>* configs) {
@@ -1377,10 +1375,8 @@ status_t BnSurfaceComposer::onTransact(
            const sp<IBinder> display = data.readStrongBinder();
            const status_t result = getDisplayInfo(display, &info);
            reply->writeInt32(result);
            if (result == NO_ERROR) {
                memcpy(reply->writeInplace(sizeof(DisplayInfo)), &info, sizeof(DisplayInfo));
            }
            return NO_ERROR;
            if (result != NO_ERROR) return result;
            return reply->write(info);
        }
        case GET_DISPLAY_CONFIGS: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
+3 −1
Original line number Diff line number Diff line
@@ -97,6 +97,8 @@ cc_library_shared {
        "BufferHubEventFd.cpp",
        "BufferHubMetadata.cpp",
        "DebugUtils.cpp",
        "DeviceProductInfo.cpp",
        "DisplayInfo.cpp",
        "Fence.cpp",
        "FenceTime.cpp",
        "FrameStats.cpp",
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 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.
 */

#include <ui/DeviceProductInfo.h>

#include <ui/FlattenableHelpers.h>

namespace android {

size_t DeviceProductInfo::getFlattenedSize() const {
    return FlattenableHelpers::getFlattenedSize(name) + sizeof(manufacturerPnpId) +
            FlattenableHelpers::getFlattenedSize(productId) + sizeof(manufactureOrModelDate);
}

status_t DeviceProductInfo::flatten(void* buffer, size_t size) const {
    if (size < getFlattenedSize()) {
        return NO_MEMORY;
    }
    FlattenableHelpers::write(buffer, size, name);
    FlattenableUtils::write(buffer, size, manufacturerPnpId);
    FlattenableHelpers::write(buffer, size, productId);
    FlattenableUtils::write(buffer, size, manufactureOrModelDate);
    return NO_ERROR;
}

status_t DeviceProductInfo::unflatten(void const* buffer, size_t size) {
    if (size < getFlattenedSize()) {
        return NO_MEMORY;
    }
    FlattenableHelpers::read(buffer, size, &name);
    FlattenableUtils::read(buffer, size, manufacturerPnpId);
    FlattenableHelpers::read(buffer, size, &productId);
    FlattenableUtils::read(buffer, size, manufactureOrModelDate);
    return NO_ERROR;
}

} // namespace android
+54 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 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.
 */

#include <ui/DisplayInfo.h>

#include <cstdint>

#include <ui/FlattenableHelpers.h>

namespace android {

size_t DisplayInfo::getFlattenedSize() const {
    return sizeof(connectionType) + sizeof(density) + sizeof(secure) +
            FlattenableHelpers::getFlattenedSize(deviceProductInfo);
}

status_t DisplayInfo::flatten(void* buffer, size_t size) const {
    if (size < getFlattenedSize()) {
        return NO_MEMORY;
    }
    FlattenableUtils::write(buffer, size, connectionType);
    FlattenableUtils::write(buffer, size, density);
    FlattenableUtils::write(buffer, size, secure);
    FlattenableHelpers::write(buffer, size, deviceProductInfo);

    return NO_ERROR;
}

status_t DisplayInfo::unflatten(void const* buffer, size_t size) {
    if (size < getFlattenedSize()) {
        return NO_MEMORY;
    }
    FlattenableUtils::read(buffer, size, connectionType);
    FlattenableUtils::read(buffer, size, density);
    FlattenableUtils::read(buffer, size, secure);
    FlattenableHelpers::read(buffer, size, &deviceProductInfo);

    return NO_ERROR;
}

} // namespace android
+13 −5
Original line number Diff line number Diff line
@@ -19,8 +19,12 @@
#include <array>
#include <cstdint>
#include <optional>
#include <string>
#include <type_traits>
#include <variant>

#include <utils/Flattenable.h>

namespace android {

// NUL-terminated plug and play ID.
@@ -29,9 +33,7 @@ using PnpId = std::array<char, 4>;
// Product-specific information about the display or the directly connected device on the
// display chain. For example, if the display is transitively connected, this field may contain
// product information about the intermediate device.
struct DeviceProductInfo {
    static constexpr size_t TEXT_BUFFER_SIZE = 20;

struct DeviceProductInfo : LightFlattenable<DeviceProductInfo> {
    struct ModelYear {
        uint32_t year;
    };
@@ -44,16 +46,22 @@ struct DeviceProductInfo {
    };

    // Display name.
    std::array<char, TEXT_BUFFER_SIZE> name;
    std::string name;

    // Manufacturer Plug and Play ID.
    PnpId manufacturerPnpId;

    // Manufacturer product ID.
    std::array<char, TEXT_BUFFER_SIZE> productId;
    std::string productId;

    using ManufactureOrModelDate = std::variant<ModelYear, ManufactureYear, ManufactureWeekAndYear>;
    static_assert(std::is_trivially_copyable_v<ManufactureOrModelDate>);
    ManufactureOrModelDate manufactureOrModelDate;

    bool isFixedSize() const { return false; }
    size_t getFlattenedSize() const;
    status_t flatten(void* buffer, size_t size) const;
    status_t unflatten(void const* buffer, size_t size);
};

} // namespace android
Loading