Skip to content

Commit 1042eb2

Browse files
timvpGoogleAndroid (Google) Code Review
authored andcommitted
Merge "Make FeatureOverrides/FeatureConfig Parcelable" into main
2 parents 6812b08 + 4a5fd7e commit 1042eb2

2 files changed

Lines changed: 126 additions & 3 deletions

File tree

libs/graphicsenv/FeatureOverrides.cpp

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,46 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include <graphicsenv/FeatureOverrides.h>
17+
#include <cinttypes>
1818

1919
#include <android-base/stringprintf.h>
20+
#include <binder/Parcel.h>
21+
#include <graphicsenv/FeatureOverrides.h>
2022

2123
namespace android {
2224

2325
using base::StringAppendF;
2426

27+
status_t FeatureConfig::writeToParcel(Parcel* parcel) const {
28+
status_t status;
29+
30+
status = parcel->writeUtf8AsUtf16(mFeatureName);
31+
if (status != OK) {
32+
return status;
33+
}
34+
status = parcel->writeBool(mEnabled);
35+
if (status != OK) {
36+
return status;
37+
}
38+
39+
return OK;
40+
}
41+
42+
status_t FeatureConfig::readFromParcel(const Parcel* parcel) {
43+
status_t status;
44+
45+
status = parcel->readUtf8FromUtf16(&mFeatureName);
46+
if (status != OK) {
47+
return status;
48+
}
49+
status = parcel->readBool(&mEnabled);
50+
if (status != OK) {
51+
return status;
52+
}
53+
54+
return OK;
55+
}
56+
2557
std::string FeatureConfig::toString() const {
2658
std::string result;
2759
StringAppendF(&result, "Feature: %s\n", mFeatureName.c_str());
@@ -30,6 +62,91 @@ std::string FeatureConfig::toString() const {
3062
return result;
3163
}
3264

65+
status_t FeatureOverrides::writeToParcel(Parcel* parcel) const {
66+
status_t status;
67+
// Number of global feature configs.
68+
status = parcel->writeVectorSize(mGlobalFeatures);
69+
if (status != OK) {
70+
return status;
71+
}
72+
// Global feature configs.
73+
for (const auto& cfg : mGlobalFeatures) {
74+
status = cfg.writeToParcel(parcel);
75+
if (status != OK) {
76+
return status;
77+
}
78+
}
79+
// Number of package feature overrides.
80+
status = parcel->writeInt32(static_cast<int32_t>(mPackageFeatures.size()));
81+
if (status != OK) {
82+
return status;
83+
}
84+
for (const auto& feature : mPackageFeatures) {
85+
// Package name.
86+
status = parcel->writeUtf8AsUtf16(feature.first);
87+
if (status != OK) {
88+
return status;
89+
}
90+
// Number of package feature configs.
91+
status = parcel->writeVectorSize(feature.second);
92+
if (status != OK) {
93+
return status;
94+
}
95+
// Package feature configs.
96+
for (const auto& cfg : feature.second) {
97+
status = cfg.writeToParcel(parcel);
98+
if (status != OK) {
99+
return status;
100+
}
101+
}
102+
}
103+
104+
return OK;
105+
}
106+
107+
status_t FeatureOverrides::readFromParcel(const Parcel* parcel) {
108+
status_t status;
109+
110+
// Number of global feature configs.
111+
status = parcel->resizeOutVector(&mGlobalFeatures);
112+
if (status != OK) {
113+
return status;
114+
}
115+
// Global feature configs.
116+
for (FeatureConfig& cfg : mGlobalFeatures) {
117+
status = cfg.readFromParcel(parcel);
118+
if (status != OK) {
119+
return status;
120+
}
121+
}
122+
123+
// Number of package feature overrides.
124+
int numPkgOverrides = parcel->readInt32();
125+
for (int i = 0; i < numPkgOverrides; i++) {
126+
// Package name.
127+
std::string name;
128+
status = parcel->readUtf8FromUtf16(&name);
129+
if (status != OK) {
130+
return status;
131+
}
132+
std::vector<FeatureConfig> cfgs;
133+
// Number of package feature configs.
134+
int numCfgs = parcel->readInt32();
135+
// Package feature configs.
136+
for (int j = 0; j < numCfgs; j++) {
137+
FeatureConfig cfg;
138+
status = cfg.readFromParcel(parcel);
139+
if (status != OK) {
140+
return status;
141+
}
142+
cfgs.emplace_back(cfg);
143+
}
144+
mPackageFeatures[name] = cfgs;
145+
}
146+
147+
return OK;
148+
}
149+
33150
std::string FeatureOverrides::toString() const {
34151
std::string result;
35152
result.append("Global Features:\n");

libs/graphicsenv/include/graphicsenv/FeatureOverrides.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@
2020
#include <string>
2121
#include <vector>
2222

23+
#include <binder/Parcelable.h>
24+
2325
namespace android {
2426

25-
class FeatureConfig {
27+
class FeatureConfig : public Parcelable {
2628
public:
2729
FeatureConfig() = default;
2830
FeatureConfig(const FeatureConfig&) = default;
2931
virtual ~FeatureConfig() = default;
32+
virtual status_t writeToParcel(Parcel* parcel) const;
33+
virtual status_t readFromParcel(const Parcel* parcel);
3034
std::string toString() const;
3135

3236
std::string mFeatureName;
@@ -37,11 +41,13 @@ class FeatureConfig {
3741
* Class for transporting OpenGL ES Feature configurations from GpuService to authorized
3842
* recipients.
3943
*/
40-
class FeatureOverrides {
44+
class FeatureOverrides : public Parcelable {
4145
public:
4246
FeatureOverrides() = default;
4347
FeatureOverrides(const FeatureOverrides&) = default;
4448
virtual ~FeatureOverrides() = default;
49+
virtual status_t writeToParcel(Parcel* parcel) const;
50+
virtual status_t readFromParcel(const Parcel* parcel);
4551
std::string toString() const;
4652

4753
std::vector<FeatureConfig> mGlobalFeatures;

0 commit comments

Comments
 (0)