diff options
author | 2025-01-13 11:32:23 -0700 | |
---|---|---|
committer | 2025-02-13 09:28:37 -0700 | |
commit | 4a5fd7e262df85180d9e6bd247cdb40c65f2ea85 (patch) | |
tree | 1da9552edb04c3110ec5bc45b837309e1da19a06 | |
parent | 1af4e87bbb262c3faeedc7262f75af389778a046 (diff) |
Make FeatureOverrides/FeatureConfig Parcelable
Implement Parcelable for FeatureOverrides and FeatureConfig. This allows
IGpuService to transmit the data via Binder.
Bug: 372694741
Test: CQ
Flag: com.android.graphics.graphicsenv.flags.feature_overrides
Change-Id: I7b095fcf2b396c8220ff72bed4ee2ef94741b70a
-rw-r--r-- | libs/graphicsenv/FeatureOverrides.cpp | 119 | ||||
-rw-r--r-- | libs/graphicsenv/include/graphicsenv/FeatureOverrides.h | 10 |
2 files changed, 126 insertions, 3 deletions
diff --git a/libs/graphicsenv/FeatureOverrides.cpp b/libs/graphicsenv/FeatureOverrides.cpp index 6974da9934..51afe285fb 100644 --- a/libs/graphicsenv/FeatureOverrides.cpp +++ b/libs/graphicsenv/FeatureOverrides.cpp @@ -14,14 +14,46 @@ * limitations under the License. */ -#include <graphicsenv/FeatureOverrides.h> +#include <cinttypes> #include <android-base/stringprintf.h> +#include <binder/Parcel.h> +#include <graphicsenv/FeatureOverrides.h> namespace android { using base::StringAppendF; +status_t FeatureConfig::writeToParcel(Parcel* parcel) const { + status_t status; + + status = parcel->writeUtf8AsUtf16(mFeatureName); + if (status != OK) { + return status; + } + status = parcel->writeBool(mEnabled); + if (status != OK) { + return status; + } + + return OK; +} + +status_t FeatureConfig::readFromParcel(const Parcel* parcel) { + status_t status; + + status = parcel->readUtf8FromUtf16(&mFeatureName); + if (status != OK) { + return status; + } + status = parcel->readBool(&mEnabled); + if (status != OK) { + return status; + } + + return OK; +} + std::string FeatureConfig::toString() const { std::string result; StringAppendF(&result, "Feature: %s\n", mFeatureName.c_str()); @@ -30,6 +62,91 @@ std::string FeatureConfig::toString() const { return result; } +status_t FeatureOverrides::writeToParcel(Parcel* parcel) const { + status_t status; + // Number of global feature configs. + status = parcel->writeVectorSize(mGlobalFeatures); + if (status != OK) { + return status; + } + // Global feature configs. + for (const auto& cfg : mGlobalFeatures) { + status = cfg.writeToParcel(parcel); + if (status != OK) { + return status; + } + } + // Number of package feature overrides. + status = parcel->writeInt32(static_cast<int32_t>(mPackageFeatures.size())); + if (status != OK) { + return status; + } + for (const auto& feature : mPackageFeatures) { + // Package name. + status = parcel->writeUtf8AsUtf16(feature.first); + if (status != OK) { + return status; + } + // Number of package feature configs. + status = parcel->writeVectorSize(feature.second); + if (status != OK) { + return status; + } + // Package feature configs. + for (const auto& cfg : feature.second) { + status = cfg.writeToParcel(parcel); + if (status != OK) { + return status; + } + } + } + + return OK; +} + +status_t FeatureOverrides::readFromParcel(const Parcel* parcel) { + status_t status; + + // Number of global feature configs. + status = parcel->resizeOutVector(&mGlobalFeatures); + if (status != OK) { + return status; + } + // Global feature configs. + for (FeatureConfig& cfg : mGlobalFeatures) { + status = cfg.readFromParcel(parcel); + if (status != OK) { + return status; + } + } + + // Number of package feature overrides. + int numPkgOverrides = parcel->readInt32(); + for (int i = 0; i < numPkgOverrides; i++) { + // Package name. + std::string name; + status = parcel->readUtf8FromUtf16(&name); + if (status != OK) { + return status; + } + std::vector<FeatureConfig> cfgs; + // Number of package feature configs. + int numCfgs = parcel->readInt32(); + // Package feature configs. + for (int j = 0; j < numCfgs; j++) { + FeatureConfig cfg; + status = cfg.readFromParcel(parcel); + if (status != OK) { + return status; + } + cfgs.emplace_back(cfg); + } + mPackageFeatures[name] = cfgs; + } + + return OK; +} + std::string FeatureOverrides::toString() const { std::string result; result.append("Global Features:\n"); diff --git a/libs/graphicsenv/include/graphicsenv/FeatureOverrides.h b/libs/graphicsenv/include/graphicsenv/FeatureOverrides.h index 2b9418733d..450eed2151 100644 --- a/libs/graphicsenv/include/graphicsenv/FeatureOverrides.h +++ b/libs/graphicsenv/include/graphicsenv/FeatureOverrides.h @@ -20,13 +20,17 @@ #include <string> #include <vector> +#include <binder/Parcelable.h> + namespace android { -class FeatureConfig { +class FeatureConfig : public Parcelable { public: FeatureConfig() = default; FeatureConfig(const FeatureConfig&) = default; virtual ~FeatureConfig() = default; + virtual status_t writeToParcel(Parcel* parcel) const; + virtual status_t readFromParcel(const Parcel* parcel); std::string toString() const; std::string mFeatureName; @@ -37,11 +41,13 @@ public: * Class for transporting OpenGL ES Feature configurations from GpuService to authorized * recipients. */ -class FeatureOverrides { +class FeatureOverrides : public Parcelable { public: FeatureOverrides() = default; FeatureOverrides(const FeatureOverrides&) = default; virtual ~FeatureOverrides() = default; + virtual status_t writeToParcel(Parcel* parcel) const; + virtual status_t readFromParcel(const Parcel* parcel); std::string toString() const; std::vector<FeatureConfig> mGlobalFeatures; |