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

Commit f8d1840f authored by Tom Dobek's avatar Tom Dobek Committed by Android (Google) Code Review
Browse files

Merge "Aapt2 convert: skip processing resources when resource table is absent. Test: manual"

parents 7888d2f9 725fb12c
Loading
Loading
Loading
Loading
+36 −39
Original line number Original line Diff line number Diff line
@@ -57,19 +57,17 @@ std::unique_ptr<LoadedApk> LoadedApk::LoadApkFromPath(const StringPiece& path, I


std::unique_ptr<LoadedApk> LoadedApk::LoadProtoApkFromFileCollection(
std::unique_ptr<LoadedApk> LoadedApk::LoadProtoApkFromFileCollection(
    const Source& source, unique_ptr<io::IFileCollection> collection, IDiagnostics* diag) {
    const Source& source, unique_ptr<io::IFileCollection> collection, IDiagnostics* diag) {
  io::IFile* table_file = collection->FindFile(kProtoResourceTablePath);
  std::unique_ptr<ResourceTable> table;
  if (table_file == nullptr) {
    diag->Error(DiagMessage(source) << "failed to find " << kProtoResourceTablePath);
    return {};
  }


  io::IFile* table_file = collection->FindFile(kProtoResourceTablePath);
  if (table_file != nullptr) {
    pb::ResourceTable pb_table;
    std::unique_ptr<io::InputStream> in = table_file->OpenInputStream();
    std::unique_ptr<io::InputStream> in = table_file->OpenInputStream();
    if (in == nullptr) {
    if (in == nullptr) {
      diag->Error(DiagMessage(source) << "failed to open " << kProtoResourceTablePath);
      diag->Error(DiagMessage(source) << "failed to open " << kProtoResourceTablePath);
      return {};
      return {};
    }
    }


  pb::ResourceTable pb_table;
    io::ZeroCopyInputAdaptor adaptor(in.get());
    io::ZeroCopyInputAdaptor adaptor(in.get());
    if (!pb_table.ParseFromZeroCopyStream(&adaptor)) {
    if (!pb_table.ParseFromZeroCopyStream(&adaptor)) {
      diag->Error(DiagMessage(source) << "failed to read " << kProtoResourceTablePath);
      diag->Error(DiagMessage(source) << "failed to read " << kProtoResourceTablePath);
@@ -77,12 +75,13 @@ std::unique_ptr<LoadedApk> LoadedApk::LoadProtoApkFromFileCollection(
    }
    }


    std::string error;
    std::string error;
  std::unique_ptr<ResourceTable> table = util::make_unique<ResourceTable>();
    table = util::make_unique<ResourceTable>();
    if (!DeserializeTableFromPb(pb_table, collection.get(), table.get(), &error)) {
    if (!DeserializeTableFromPb(pb_table, collection.get(), table.get(), &error)) {
      diag->Error(DiagMessage(source)
      diag->Error(DiagMessage(source)
                  << "failed to deserialize " << kProtoResourceTablePath << ": " << error);
                  << "failed to deserialize " << kProtoResourceTablePath << ": " << error);
      return {};
      return {};
    }
    }
  }


  io::IFile* manifest_file = collection->FindFile(kAndroidManifestPath);
  io::IFile* manifest_file = collection->FindFile(kAndroidManifestPath);
  if (manifest_file == nullptr) {
  if (manifest_file == nullptr) {
@@ -103,6 +102,7 @@ std::unique_ptr<LoadedApk> LoadedApk::LoadProtoApkFromFileCollection(
    return {};
    return {};
  }
  }


  std::string error;
  std::unique_ptr<xml::XmlResource> manifest = DeserializeXmlResourceFromPb(pb_node, &error);
  std::unique_ptr<xml::XmlResource> manifest = DeserializeXmlResourceFromPb(pb_node, &error);
  if (manifest == nullptr) {
  if (manifest == nullptr) {
    diag->Error(DiagMessage(source)
    diag->Error(DiagMessage(source)
@@ -115,25 +115,22 @@ std::unique_ptr<LoadedApk> LoadedApk::LoadProtoApkFromFileCollection(


std::unique_ptr<LoadedApk> LoadedApk::LoadBinaryApkFromFileCollection(
std::unique_ptr<LoadedApk> LoadedApk::LoadBinaryApkFromFileCollection(
    const Source& source, unique_ptr<io::IFileCollection> collection, IDiagnostics* diag) {
    const Source& source, unique_ptr<io::IFileCollection> collection, IDiagnostics* diag) {
  io::IFile* table_file = collection->FindFile(kApkResourceTablePath);
  std::unique_ptr<ResourceTable> table;
  if (table_file == nullptr) {
    diag->Error(DiagMessage(source) << "failed to find " << kApkResourceTablePath);

    return {};
  }


  io::IFile* table_file = collection->FindFile(kApkResourceTablePath);
  if (table_file != nullptr) {
    table = util::make_unique<ResourceTable>();
    std::unique_ptr<io::IData> data = table_file->OpenAsData();
    std::unique_ptr<io::IData> data = table_file->OpenAsData();
    if (data == nullptr) {
    if (data == nullptr) {
      diag->Error(DiagMessage(source) << "failed to open " << kApkResourceTablePath);
      diag->Error(DiagMessage(source) << "failed to open " << kApkResourceTablePath);
      return {};
      return {};
    }
    }

  std::unique_ptr<ResourceTable> table = util::make_unique<ResourceTable>();
    BinaryResourceParser parser(diag, table.get(), source, data->data(), data->size(),
    BinaryResourceParser parser(diag, table.get(), source, data->data(), data->size(),
                                collection.get());
                                collection.get());
    if (!parser.Parse()) {
    if (!parser.Parse()) {
      return {};
      return {};
    }
    }
  }


  io::IFile* manifest_file = collection->FindFile(kAndroidManifestPath);
  io::IFile* manifest_file = collection->FindFile(kAndroidManifestPath);
  if (manifest_file == nullptr) {
  if (manifest_file == nullptr) {
+31 −29
Original line number Original line Diff line number Diff line
@@ -64,6 +64,7 @@ bool ConvertApk(IAaptContext* context, unique_ptr<LoadedApk> apk, IApkSerializer
    return false;
    return false;
  }
  }


  if (apk->GetResourceTable() != nullptr) {
    // Resource table
    // Resource table
    if (!serializer->SerializeTable(apk->GetResourceTable(), writer)) {
    if (!serializer->SerializeTable(apk->GetResourceTable(), writer)) {
      context->GetDiagnostics()->Error(DiagMessage(apk->GetSource())
      context->GetDiagnostics()->Error(DiagMessage(apk->GetSource())
@@ -94,6 +95,7 @@ bool ConvertApk(IAaptContext* context, unique_ptr<LoadedApk> apk, IApkSerializer
        } // entry
        } // entry
      } // type
      } // type
    } // package
    } // package
  }


  // Other files
  // Other files
  std::unique_ptr<io::IFileCollectionIterator> iterator = apk->GetFileCollection()->Iterator();
  std::unique_ptr<io::IFileCollectionIterator> iterator = apk->GetFileCollection()->Iterator();