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
2123namespace android {
2224
2325using 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+
2557std::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+
33150std::string FeatureOverrides::toString () const {
34151 std::string result;
35152 result.append (" Global Features:\n " );
0 commit comments