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

Commit c9c31508 authored by Mark Punzalan's avatar Mark Punzalan
Browse files

Always enable sparse encoding if minSdk >= 32

Sparse encoding has been enabled in the framework since T QPR2 with no major issues. It should be safe to enable by default for any app with minSdk >= 32 (S_V2) which is when the last fix for sparse encoding was made.

This CL makes the `--enable-sparse-encoding` flag a no-op. As such, we are also bumping the version to 2.20.

Bug: 302179337
Change-Id: Ia886a0da9d61175d00c24e30f4e263f7e5df511a
Test: build + boot on Pixel 6 Pro
Flag: EXEMPT command line tool
parent ca618d9f
Loading
Loading
Loading
Loading
+18 −6
Original line number Diff line number Diff line
@@ -54,7 +54,9 @@ std::string GetSafePath(StringPiece arg) {
void Command::AddRequiredFlag(StringPiece name, StringPiece description, std::string* value,
                              uint32_t flags) {
  auto func = [value, flags](StringPiece arg, std::ostream*) -> bool {
    if (value) {
      *value = (flags & Command::kPath) ? GetSafePath(arg) : std::string(arg);
    }
    return true;
  };

@@ -65,7 +67,9 @@ void Command::AddRequiredFlag(StringPiece name, StringPiece description, std::st
void Command::AddRequiredFlagList(StringPiece name, StringPiece description,
                                  std::vector<std::string>* value, uint32_t flags) {
  auto func = [value, flags](StringPiece arg, std::ostream*) -> bool {
    if (value) {
      value->push_back((flags & Command::kPath) ? GetSafePath(arg) : std::string(arg));
    }
    return true;
  };

@@ -76,7 +80,9 @@ void Command::AddRequiredFlagList(StringPiece name, StringPiece description,
void Command::AddOptionalFlag(StringPiece name, StringPiece description,
                              std::optional<std::string>* value, uint32_t flags) {
  auto func = [value, flags](StringPiece arg, std::ostream*) -> bool {
    if (value) {
      *value = (flags & Command::kPath) ? GetSafePath(arg) : std::string(arg);
    }
    return true;
  };

@@ -87,7 +93,9 @@ void Command::AddOptionalFlag(StringPiece name, StringPiece description,
void Command::AddOptionalFlagList(StringPiece name, StringPiece description,
                                  std::vector<std::string>* value, uint32_t flags) {
  auto func = [value, flags](StringPiece arg, std::ostream*) -> bool {
    if (value) {
      value->push_back((flags & Command::kPath) ? GetSafePath(arg) : std::string(arg));
    }
    return true;
  };

@@ -98,7 +106,9 @@ void Command::AddOptionalFlagList(StringPiece name, StringPiece description,
void Command::AddOptionalFlagList(StringPiece name, StringPiece description,
                                  std::unordered_set<std::string>* value) {
  auto func = [value](StringPiece arg, std::ostream* out_error) -> bool {
    if (value) {
      value->emplace(arg);
    }
    return true;
  };

@@ -108,7 +118,9 @@ void Command::AddOptionalFlagList(StringPiece name, StringPiece description,

void Command::AddOptionalSwitch(StringPiece name, StringPiece description, bool* value) {
  auto func = [value](StringPiece arg, std::ostream* out_error) -> bool {
    if (value) {
      *value = true;
    }
    return true;
  };

+18 −0
Original line number Diff line number Diff line
@@ -159,4 +159,22 @@ TEST(CommandTest, ShortOptions) {
  ASSERT_NE(0, command.Execute({"-w"s, "2"s}, &std::cerr));
}

TEST(CommandTest, OptionsWithNullptrToAcceptValues) {
  TestCommand command;
  command.AddRequiredFlag("--rflag", "", nullptr);
  command.AddRequiredFlagList("--rlflag", "", nullptr);
  command.AddOptionalFlag("--oflag", "", nullptr);
  command.AddOptionalFlagList("--olflag", "", (std::vector<std::string>*)nullptr);
  command.AddOptionalFlagList("--olflag2", "", (std::unordered_set<std::string>*)nullptr);
  command.AddOptionalSwitch("--switch", "", nullptr);

  ASSERT_EQ(0, command.Execute({
    "--rflag"s, "1"s,
    "--rlflag"s, "1"s,
    "--oflag"s, "1"s,
    "--olflag"s, "1"s,
    "--olflag2"s, "1"s,
    "--switch"s}, &std::cerr));
}

}  // namespace aapt
 No newline at end of file
+0 −3
Original line number Diff line number Diff line
@@ -425,9 +425,6 @@ int ConvertCommand::Action(const std::vector<std::string>& args) {
                                    << output_format_.value());
    return 1;
  }
  if (enable_sparse_encoding_) {
    table_flattener_options_.sparse_entries = SparseEntriesMode::Enabled;
  }
  if (force_sparse_encoding_) {
    table_flattener_options_.sparse_entries = SparseEntriesMode::Forced;
  }
+3 −6
Original line number Diff line number Diff line
@@ -36,11 +36,9 @@ class ConvertCommand : public Command {
        kOutputFormatProto, kOutputFormatBinary, kOutputFormatBinary), &output_format_);
    AddOptionalSwitch(
        "--enable-sparse-encoding",
        "Enables encoding sparse entries using a binary search tree.\n"
        "This decreases APK size at the cost of resource retrieval performance.\n"
        "Only applies sparse encoding to Android O+ resources or all resources if minSdk of "
        "the APK is O+",
        &enable_sparse_encoding_);
        "[DEPRECATED] This flag is a no-op as of aapt2 v2.20. Sparse encoding is always\n"
        "enabled if minSdk of the APK is >= 32.",
        nullptr);
    AddOptionalSwitch("--force-sparse-encoding",
                      "Enables encoding sparse entries using a binary search tree.\n"
                      "This decreases APK size at the cost of resource retrieval performance.\n"
@@ -87,7 +85,6 @@ class ConvertCommand : public Command {
  std::string output_path_;
  std::optional<std::string> output_format_;
  bool verbose_ = false;
  bool enable_sparse_encoding_ = false;
  bool force_sparse_encoding_ = false;
  bool enable_compact_entries_ = false;
  std::optional<std::string> resources_config_path_;
+0 −3
Original line number Diff line number Diff line
@@ -2504,9 +2504,6 @@ int LinkCommand::Action(const std::vector<std::string>& args) {
                << "the --merge-only flag can be only used when building a static library");
    return 1;
  }
  if (options_.use_sparse_encoding) {
    options_.table_flattener_options.sparse_entries = SparseEntriesMode::Enabled;
  }

  // The default build type.
  context.SetPackageType(PackageType::kApp);
Loading