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

Commit 725fb12c authored by Tom Dobek's avatar Tom Dobek
Browse files

Aapt2 convert: skip processing resources when resource table is absent.

Test: manual

Change-Id: Iafe20f98857a29d625e7a57a9201db6279d43e45
parent 3a1e51ab
Loading
Loading
Loading
Loading
+36 −39
Original line number 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(
    const Source& source, unique_ptr<io::IFileCollection> collection, IDiagnostics* diag) {
  io::IFile* table_file = collection->FindFile(kProtoResourceTablePath);
  if (table_file == nullptr) {
    diag->Error(DiagMessage(source) << "failed to find " << kProtoResourceTablePath);
    return {};
  }
  std::unique_ptr<ResourceTable> table;

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

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

    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)) {
      diag->Error(DiagMessage(source)
                  << "failed to deserialize " << kProtoResourceTablePath << ": " << error);
      return {};
    }
  }

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

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

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

    return {};
  }
  std::unique_ptr<ResourceTable> table;

  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();
    if (data == nullptr) {
      diag->Error(DiagMessage(source) << "failed to open " << kApkResourceTablePath);
      return {};
    }

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

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

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

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