Loading tools/aapt2/Resources.proto +5 −2 Original line number Diff line number Diff line Loading @@ -306,6 +306,7 @@ message FileReference { } // A value that represents a primitive data type (float, int, boolean, etc.). // Refer to Res_value in ResourceTypes.h for info on types and formatting message Primitive { message NullType { } Loading @@ -315,8 +316,8 @@ message Primitive { NullType null_value = 1; EmptyType empty_value = 2; float float_value = 3; float dimension_value = 4; float fraction_value = 5; uint32 dimension_value = 13; uint32 fraction_value = 14; int32 int_decimal_value = 6; uint32 int_hexadecimal_value = 7; bool boolean_value = 8; Loading @@ -324,6 +325,8 @@ message Primitive { uint32 color_rgb8_value = 10; uint32 color_argb4_value = 11; uint32 color_rgb4_value = 12; float dimension_value_deprecated = 4 [deprecated=true]; float fraction_value_deprecated = 5 [deprecated=true]; } } Loading tools/aapt2/format/proto/ProtoDeserialize.cpp +12 −4 Original line number Diff line number Diff line Loading @@ -780,13 +780,11 @@ std::unique_ptr<Item> DeserializeItemFromPb(const pb::Item& pb_item, } break; case pb::Primitive::kDimensionValue: { val.dataType = android::Res_value::TYPE_DIMENSION; float dimen_val = pb_prim.dimension_value(); val.data = *(uint32_t*)&dimen_val; val.data = pb_prim.dimension_value(); } break; case pb::Primitive::kFractionValue: { val.dataType = android::Res_value::TYPE_FRACTION; float fraction_val = pb_prim.fraction_value(); val.data = *(uint32_t*)&fraction_val; val.data = pb_prim.fraction_value(); } break; case pb::Primitive::kIntDecimalValue: { val.dataType = android::Res_value::TYPE_INT_DEC; Loading Loading @@ -816,6 +814,16 @@ std::unique_ptr<Item> DeserializeItemFromPb(const pb::Item& pb_item, val.dataType = android::Res_value::TYPE_INT_COLOR_RGB4; val.data = pb_prim.color_rgb4_value(); } break; case pb::Primitive::kDimensionValueDeprecated: { // DEPRECATED val.dataType = android::Res_value::TYPE_DIMENSION; float dimen_val = pb_prim.dimension_value_deprecated(); val.data = *(uint32_t*)&dimen_val; } break; case pb::Primitive::kFractionValueDeprecated: { // DEPRECATED val.dataType = android::Res_value::TYPE_FRACTION; float fraction_val = pb_prim.fraction_value_deprecated(); val.data = *(uint32_t*)&fraction_val; } break; default: { LOG(FATAL) << "Unexpected Primitive type: " << static_cast<uint32_t>(pb_prim.oneof_value_case()); Loading tools/aapt2/format/proto/ProtoSerialize.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -452,10 +452,10 @@ class ValueSerializer : public ConstValueVisitor { pb_prim->set_float_value(*(float*)&val.data); } break; case android::Res_value::TYPE_DIMENSION: { pb_prim->set_dimension_value(*(float*)&val.data); pb_prim->set_dimension_value(val.data); } break; case android::Res_value::TYPE_FRACTION: { pb_prim->set_fraction_value(*(float*)&val.data); pb_prim->set_fraction_value(val.data); } break; case android::Res_value::TYPE_INT_DEC: { pb_prim->set_int_decimal_value(static_cast<int32_t>(val.data)); Loading tools/aapt2/format/proto/ProtoSerialize_test.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -271,6 +271,7 @@ TEST(ProtoSerializeTest, SerializeAndDeserializePrimitives) { .AddValue("android:integer/hex_int_abcd", ResourceUtils::TryParseInt("0xABCD")) .AddValue("android:dimen/dimen_1.39mm", ResourceUtils::TryParseFloat("1.39mm")) .AddValue("android:fraction/fraction_27", ResourceUtils::TryParseFloat("27%")) .AddValue("android:dimen/neg_2.3in", ResourceUtils::TryParseFloat("-2.3in")) .AddValue("android:integer/null", ResourceUtils::MakeEmpty()) .Build(); Loading Loading @@ -353,6 +354,12 @@ TEST(ProtoSerializeTest, SerializeAndDeserializePrimitives) { EXPECT_THAT(bp->value.dataType, Eq(android::Res_value::TYPE_FRACTION)); EXPECT_THAT(bp->value.data, Eq(ResourceUtils::TryParseFloat("27%")->value.data)); bp = test::GetValueForConfigAndProduct<BinaryPrimitive>(&new_table, "android:dimen/neg_2.3in", ConfigDescription::DefaultConfig(), ""); ASSERT_THAT(bp, NotNull()); EXPECT_THAT(bp->value.dataType, Eq(android::Res_value::TYPE_DIMENSION)); EXPECT_THAT(bp->value.data, Eq(ResourceUtils::TryParseFloat("-2.3in")->value.data)); bp = test::GetValueForConfigAndProduct<BinaryPrimitive>(&new_table, "android:integer/null", ConfigDescription::DefaultConfig(), ""); ASSERT_THAT(bp, NotNull()); Loading Loading
tools/aapt2/Resources.proto +5 −2 Original line number Diff line number Diff line Loading @@ -306,6 +306,7 @@ message FileReference { } // A value that represents a primitive data type (float, int, boolean, etc.). // Refer to Res_value in ResourceTypes.h for info on types and formatting message Primitive { message NullType { } Loading @@ -315,8 +316,8 @@ message Primitive { NullType null_value = 1; EmptyType empty_value = 2; float float_value = 3; float dimension_value = 4; float fraction_value = 5; uint32 dimension_value = 13; uint32 fraction_value = 14; int32 int_decimal_value = 6; uint32 int_hexadecimal_value = 7; bool boolean_value = 8; Loading @@ -324,6 +325,8 @@ message Primitive { uint32 color_rgb8_value = 10; uint32 color_argb4_value = 11; uint32 color_rgb4_value = 12; float dimension_value_deprecated = 4 [deprecated=true]; float fraction_value_deprecated = 5 [deprecated=true]; } } Loading
tools/aapt2/format/proto/ProtoDeserialize.cpp +12 −4 Original line number Diff line number Diff line Loading @@ -780,13 +780,11 @@ std::unique_ptr<Item> DeserializeItemFromPb(const pb::Item& pb_item, } break; case pb::Primitive::kDimensionValue: { val.dataType = android::Res_value::TYPE_DIMENSION; float dimen_val = pb_prim.dimension_value(); val.data = *(uint32_t*)&dimen_val; val.data = pb_prim.dimension_value(); } break; case pb::Primitive::kFractionValue: { val.dataType = android::Res_value::TYPE_FRACTION; float fraction_val = pb_prim.fraction_value(); val.data = *(uint32_t*)&fraction_val; val.data = pb_prim.fraction_value(); } break; case pb::Primitive::kIntDecimalValue: { val.dataType = android::Res_value::TYPE_INT_DEC; Loading Loading @@ -816,6 +814,16 @@ std::unique_ptr<Item> DeserializeItemFromPb(const pb::Item& pb_item, val.dataType = android::Res_value::TYPE_INT_COLOR_RGB4; val.data = pb_prim.color_rgb4_value(); } break; case pb::Primitive::kDimensionValueDeprecated: { // DEPRECATED val.dataType = android::Res_value::TYPE_DIMENSION; float dimen_val = pb_prim.dimension_value_deprecated(); val.data = *(uint32_t*)&dimen_val; } break; case pb::Primitive::kFractionValueDeprecated: { // DEPRECATED val.dataType = android::Res_value::TYPE_FRACTION; float fraction_val = pb_prim.fraction_value_deprecated(); val.data = *(uint32_t*)&fraction_val; } break; default: { LOG(FATAL) << "Unexpected Primitive type: " << static_cast<uint32_t>(pb_prim.oneof_value_case()); Loading
tools/aapt2/format/proto/ProtoSerialize.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -452,10 +452,10 @@ class ValueSerializer : public ConstValueVisitor { pb_prim->set_float_value(*(float*)&val.data); } break; case android::Res_value::TYPE_DIMENSION: { pb_prim->set_dimension_value(*(float*)&val.data); pb_prim->set_dimension_value(val.data); } break; case android::Res_value::TYPE_FRACTION: { pb_prim->set_fraction_value(*(float*)&val.data); pb_prim->set_fraction_value(val.data); } break; case android::Res_value::TYPE_INT_DEC: { pb_prim->set_int_decimal_value(static_cast<int32_t>(val.data)); Loading
tools/aapt2/format/proto/ProtoSerialize_test.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -271,6 +271,7 @@ TEST(ProtoSerializeTest, SerializeAndDeserializePrimitives) { .AddValue("android:integer/hex_int_abcd", ResourceUtils::TryParseInt("0xABCD")) .AddValue("android:dimen/dimen_1.39mm", ResourceUtils::TryParseFloat("1.39mm")) .AddValue("android:fraction/fraction_27", ResourceUtils::TryParseFloat("27%")) .AddValue("android:dimen/neg_2.3in", ResourceUtils::TryParseFloat("-2.3in")) .AddValue("android:integer/null", ResourceUtils::MakeEmpty()) .Build(); Loading Loading @@ -353,6 +354,12 @@ TEST(ProtoSerializeTest, SerializeAndDeserializePrimitives) { EXPECT_THAT(bp->value.dataType, Eq(android::Res_value::TYPE_FRACTION)); EXPECT_THAT(bp->value.data, Eq(ResourceUtils::TryParseFloat("27%")->value.data)); bp = test::GetValueForConfigAndProduct<BinaryPrimitive>(&new_table, "android:dimen/neg_2.3in", ConfigDescription::DefaultConfig(), ""); ASSERT_THAT(bp, NotNull()); EXPECT_THAT(bp->value.dataType, Eq(android::Res_value::TYPE_DIMENSION)); EXPECT_THAT(bp->value.data, Eq(ResourceUtils::TryParseFloat("-2.3in")->value.data)); bp = test::GetValueForConfigAndProduct<BinaryPrimitive>(&new_table, "android:integer/null", ConfigDescription::DefaultConfig(), ""); ASSERT_THAT(bp, NotNull()); Loading