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

Commit 1a123114 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix fraction and dimension type in Resource.proto" into pi-dev

parents 686fab14 8b74927e
Loading
Loading
Loading
Loading
+5 −2
Original line number Original line Diff line number Diff line
@@ -306,6 +306,7 @@ message FileReference {
}
}


// A value that represents a primitive data type (float, int, boolean, etc.).
// 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 Primitive {
  message NullType {
  message NullType {
  }
  }
@@ -315,8 +316,8 @@ message Primitive {
    NullType null_value = 1;
    NullType null_value = 1;
    EmptyType empty_value = 2;
    EmptyType empty_value = 2;
    float float_value = 3;
    float float_value = 3;
    float dimension_value = 4;
    uint32 dimension_value = 13;
    float fraction_value = 5;
    uint32 fraction_value = 14;
    int32 int_decimal_value = 6;
    int32 int_decimal_value = 6;
    uint32 int_hexadecimal_value = 7;
    uint32 int_hexadecimal_value = 7;
    bool boolean_value = 8;
    bool boolean_value = 8;
@@ -324,6 +325,8 @@ message Primitive {
    uint32 color_rgb8_value = 10;
    uint32 color_rgb8_value = 10;
    uint32 color_argb4_value = 11;
    uint32 color_argb4_value = 11;
    uint32 color_rgb4_value = 12;
    uint32 color_rgb4_value = 12;
    float dimension_value_deprecated = 4 [deprecated=true];
    float fraction_value_deprecated = 5 [deprecated=true];
  }
  }
}
}


+12 −4
Original line number Original line Diff line number Diff line
@@ -780,13 +780,11 @@ std::unique_ptr<Item> DeserializeItemFromPb(const pb::Item& pb_item,
        } break;
        } break;
        case pb::Primitive::kDimensionValue: {
        case pb::Primitive::kDimensionValue: {
          val.dataType = android::Res_value::TYPE_DIMENSION;
          val.dataType = android::Res_value::TYPE_DIMENSION;
          float dimen_val = pb_prim.dimension_value();
          val.data  = pb_prim.dimension_value();
          val.data = *(uint32_t*)&dimen_val;
        } break;
        } break;
        case pb::Primitive::kFractionValue: {
        case pb::Primitive::kFractionValue: {
          val.dataType = android::Res_value::TYPE_FRACTION;
          val.dataType = android::Res_value::TYPE_FRACTION;
          float fraction_val = pb_prim.fraction_value();
          val.data  = pb_prim.fraction_value();
          val.data = *(uint32_t*)&fraction_val;
        } break;
        } break;
        case pb::Primitive::kIntDecimalValue: {
        case pb::Primitive::kIntDecimalValue: {
          val.dataType = android::Res_value::TYPE_INT_DEC;
          val.dataType = android::Res_value::TYPE_INT_DEC;
@@ -816,6 +814,16 @@ std::unique_ptr<Item> DeserializeItemFromPb(const pb::Item& pb_item,
          val.dataType = android::Res_value::TYPE_INT_COLOR_RGB4;
          val.dataType = android::Res_value::TYPE_INT_COLOR_RGB4;
          val.data = pb_prim.color_rgb4_value();
          val.data = pb_prim.color_rgb4_value();
        } break;
        } 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: {
        default: {
          LOG(FATAL) << "Unexpected Primitive type: "
          LOG(FATAL) << "Unexpected Primitive type: "
                     << static_cast<uint32_t>(pb_prim.oneof_value_case());
                     << static_cast<uint32_t>(pb_prim.oneof_value_case());
+2 −2
Original line number Original line Diff line number Diff line
@@ -452,10 +452,10 @@ class ValueSerializer : public ConstValueVisitor {
        pb_prim->set_float_value(*(float*)&val.data);
        pb_prim->set_float_value(*(float*)&val.data);
      } break;
      } break;
      case android::Res_value::TYPE_DIMENSION: {
      case android::Res_value::TYPE_DIMENSION: {
        pb_prim->set_dimension_value(*(float*)&val.data);
        pb_prim->set_dimension_value(val.data);
      } break;
      } break;
      case android::Res_value::TYPE_FRACTION: {
      case android::Res_value::TYPE_FRACTION: {
        pb_prim->set_fraction_value(*(float*)&val.data);
        pb_prim->set_fraction_value(val.data);
      } break;
      } break;
      case android::Res_value::TYPE_INT_DEC: {
      case android::Res_value::TYPE_INT_DEC: {
        pb_prim->set_int_decimal_value(static_cast<int32_t>(val.data));
        pb_prim->set_int_decimal_value(static_cast<int32_t>(val.data));
+7 −0
Original line number Original line Diff line number Diff line
@@ -271,6 +271,7 @@ TEST(ProtoSerializeTest, SerializeAndDeserializePrimitives) {
          .AddValue("android:integer/hex_int_abcd", ResourceUtils::TryParseInt("0xABCD"))
          .AddValue("android:integer/hex_int_abcd", ResourceUtils::TryParseInt("0xABCD"))
          .AddValue("android:dimen/dimen_1.39mm", ResourceUtils::TryParseFloat("1.39mm"))
          .AddValue("android:dimen/dimen_1.39mm", ResourceUtils::TryParseFloat("1.39mm"))
          .AddValue("android:fraction/fraction_27", ResourceUtils::TryParseFloat("27%"))
          .AddValue("android:fraction/fraction_27", ResourceUtils::TryParseFloat("27%"))
          .AddValue("android:dimen/neg_2.3in", ResourceUtils::TryParseFloat("-2.3in"))
          .AddValue("android:integer/null", ResourceUtils::MakeEmpty())
          .AddValue("android:integer/null", ResourceUtils::MakeEmpty())
          .Build();
          .Build();


@@ -353,6 +354,12 @@ TEST(ProtoSerializeTest, SerializeAndDeserializePrimitives) {
  EXPECT_THAT(bp->value.dataType, Eq(android::Res_value::TYPE_FRACTION));
  EXPECT_THAT(bp->value.dataType, Eq(android::Res_value::TYPE_FRACTION));
  EXPECT_THAT(bp->value.data, Eq(ResourceUtils::TryParseFloat("27%")->value.data));
  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",
  bp = test::GetValueForConfigAndProduct<BinaryPrimitive>(&new_table, "android:integer/null",
                                                          ConfigDescription::DefaultConfig(), "");
                                                          ConfigDescription::DefaultConfig(), "");
  ASSERT_THAT(bp, NotNull());
  ASSERT_THAT(bp, NotNull());