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

Commit cb2ebfc6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge changes I1d3e5e66,I86b869af,Iab4d3902,I645ee722 am: 72864d29 am: 968582e4

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1461087

Change-Id: Ice6233ff1de7e7e3112c4f4ba6f01c02468ab5bd
parents 1dd9fa36 968582e4
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,8 @@
#include <android-base/unique_fd.h>
#include <android-base/unique_fd.h>
#include <binder/BinderService.h>
#include <binder/BinderService.h>


#include <string>

#include "android/os/BnIdmap2.h"
#include "android/os/BnIdmap2.h"


namespace android::os {
namespace android::os {
+1 −2
Original line number Original line Diff line number Diff line
@@ -36,12 +36,11 @@ class BinaryStreamVisitor : public Visitor {
  void visit(const IdmapData::Header& header) override;
  void visit(const IdmapData::Header& header) override;


 private:
 private:
  void Write(const void* value, size_t length);
  void Write8(uint8_t value);
  void Write8(uint8_t value);
  void Write16(uint16_t value);
  void Write16(uint16_t value);
  void Write32(uint32_t value);
  void Write32(uint32_t value);
  void WriteString256(const StringPiece& value);
  void WriteString256(const StringPiece& value);
  void WriteString(const std::string& value);
  void WriteString(const StringPiece& value);
  std::ostream& stream_;
  std::ostream& stream_;
};
};


+64 −54
Original line number Original line Diff line number Diff line
@@ -18,47 +18,44 @@
 * # idmap file format (current version)
 * # idmap file format (current version)
 *
 *
 * idmap                      := header data*
 * idmap                      := header data*
 * header            := magic version target_crc overlay_crc target_path overlay_path debug_info
 * header                     := magic version target_crc overlay_crc fulfilled_policies
 * data              := data_header data_block*
 *                               enforce_overlayable target_path overlay_path debug_info
 * data_header       := target_package_id types_count
 * data                       := data_header target_entry* target_inline_entry* overlay_entry*
 * data_block        := target_type overlay_type entry_count entry_offset entry*
 *                               string_pool
 * overlay_path      := string256
 * data_header                := target_package_id overlay_package_id padding(2) target_entry_count
 * target_path       := string256
 *                               target_inline_entry_count overlay_entry_count string_pool_index
 * target_entry               := target_id overlay_id
 * target_inline_entry        := target_id Res_value::size padding(1) Res_value::type
 *                               Res_value::value
 * overlay_entry              := overlay_id target_id
 *
 * debug_info                 := string
 * debug_info                 := string
 * string            := <uint32_t> <uint8_t>+ '\0'+
 * enforce_overlayable        := <uint32_t>
 * entry             := <uint32_t>
 * fulfilled_policies         := <uint32_t>
 * entry_count       := <uint16_t>
 * entry_offset      := <uint16_t>
 * magic                      := <uint32_t>
 * magic                      := <uint32_t>
 * overlay_crc                := <uint32_t>
 * overlay_crc                := <uint32_t>
 * overlay_type      := <uint16_t>
 * overlay_entry_count        := <uint32_t>
 * overlay_id                 := <uint32_t>
 * overlay_package_id         := <uint8_t>
 * overlay_path               := string256
 * padding(n)                 := <uint8_t>[n]
 * Res_value::size            := <uint16_t>
 * Res_value::type            := <uint8_t>
 * Res_value::value           := <uint32_t>
 * string                     := <uint32_t> <uint8_t>+ padding(n)
 * string256                  := <uint8_t>[256]
 * string256                  := <uint8_t>[256]
 * string_pool                := string
 * string_pool_index          := <uint32_t>
 * string_pool_length         := <uint32_t>
 * target_crc                 := <uint32_t>
 * target_crc                 := <uint32_t>
 * target_package_id := <uint16_t>
 * target_entry_count         := <uint32_t>
 * target_type       := <uint16_t>
 * target_inline_entry_count  := <uint32_t>
 * types_count       := <uint16_t>
 * target_id                  := <uint32_t>
 * target_package_id          := <uint8_t>
 * target_path                := string256
 * value_type                 := <uint8_t>
 * value_data                 := <uint32_t>
 * version                    := <uint32_t>
 * version                    := <uint32_t>
 *
 *
 * # idmap file format changelog
 * ## v1
 * - Identical to idmap v1.
 *
 * ## v2
 * - Entries are no longer separated by type into type specific data blocks.
 * - Added overlay-indexed target resource id lookup capabilities.
 * - Target and overlay entries are stored as a sparse array in the data block. The target entries
 *   array maps from target resource id to overlay data type and value and the array is sorted by
 *   target resource id. The overlay entries array maps from overlay resource id to target resource
 *   id and the array is sorted by overlay resource id. It is important for both arrays to be sorted
 *   to allow for O(log(number_of_overlaid_resources)) performance when looking up resource
 *   mappings at runtime.
 * - Idmap can now encode a type and value to override a resource without needing a table entry.
 * - A string pool block is included to retrieve the value of strings that do not have a resource
 *   table entry.
 *
 * ## v3
 * - Add 'debug' block to IdmapHeader.
 */
 */


#ifndef IDMAP2_INCLUDE_IDMAP2_IDMAP_H_
#ifndef IDMAP2_INCLUDE_IDMAP2_IDMAP_H_
@@ -183,6 +180,10 @@ class IdmapData {
      return target_entry_count;
      return target_entry_count;
    }
    }


    inline uint32_t GetTargetInlineEntryCount() const {
      return target_entry_inline_count;
    }

    inline uint32_t GetOverlayEntryCount() const {
    inline uint32_t GetOverlayEntryCount() const {
      return overlay_entry_count;
      return overlay_entry_count;
    }
    }
@@ -191,19 +192,15 @@ class IdmapData {
      return string_pool_index_offset;
      return string_pool_index_offset;
    }
    }


    inline uint32_t GetStringPoolLength() const {
      return string_pool_len;
    }

    void accept(Visitor* v) const;
    void accept(Visitor* v) const;


   private:
   private:
    PackageId target_package_id_;
    PackageId target_package_id_;
    PackageId overlay_package_id_;
    PackageId overlay_package_id_;
    uint32_t target_entry_count;
    uint32_t target_entry_count;
    uint32_t target_entry_inline_count;
    uint32_t overlay_entry_count;
    uint32_t overlay_entry_count;
    uint32_t string_pool_index_offset;
    uint32_t string_pool_index_offset;
    uint32_t string_pool_len;
    Header() = default;
    Header() = default;


    friend Idmap;
    friend Idmap;
@@ -213,8 +210,12 @@ class IdmapData {


  struct TargetEntry {
  struct TargetEntry {
    ResourceId target_id;
    ResourceId target_id;
    TargetValue::DataType data_type;
    ResourceId overlay_id;
    TargetValue::DataValue data_value;
  };

  struct TargetInlineEntry {
    ResourceId target_id;
    TargetValue value;
  };
  };


  struct OverlayEntry {
  struct OverlayEntry {
@@ -227,20 +228,24 @@ class IdmapData {
  static Result<std::unique_ptr<const IdmapData>> FromResourceMapping(
  static Result<std::unique_ptr<const IdmapData>> FromResourceMapping(
      const ResourceMapping& resource_mapping);
      const ResourceMapping& resource_mapping);


  inline const std::unique_ptr<const Header>& GetHeader() const {
  const std::unique_ptr<const Header>& GetHeader() const {
    return header_;
    return header_;
  }
  }


  inline const std::vector<TargetEntry>& GetTargetEntries() const {
  const std::vector<TargetEntry>& GetTargetEntries() const {
    return target_entries_;
    return target_entries_;
  }
  }


  inline const std::vector<OverlayEntry>& GetOverlayEntries() const {
  const std::vector<TargetInlineEntry>& GetTargetInlineEntries() const {
    return target_inline_entries_;
  }

  const std::vector<OverlayEntry>& GetOverlayEntries() const {
    return overlay_entries_;
    return overlay_entries_;
  }
  }


  inline const void* GetStringPoolData() const {
  const std::string& GetStringPoolData() const {
    return string_pool_.get();
    return string_pool_data_;
  }
  }


  void accept(Visitor* v) const;
  void accept(Visitor* v) const;
@@ -251,8 +256,9 @@ class IdmapData {


  std::unique_ptr<const Header> header_;
  std::unique_ptr<const Header> header_;
  std::vector<TargetEntry> target_entries_;
  std::vector<TargetEntry> target_entries_;
  std::vector<TargetInlineEntry> target_inline_entries_;
  std::vector<OverlayEntry> overlay_entries_;
  std::vector<OverlayEntry> overlay_entries_;
  std::unique_ptr<uint8_t[]> string_pool_;
  std::string string_pool_data_;


  friend Idmap;
  friend Idmap;
  DISALLOW_COPY_AND_ASSIGN(IdmapData);
  DISALLOW_COPY_AND_ASSIGN(IdmapData);
@@ -304,6 +310,10 @@ class Visitor {
  virtual void visit(const IdmapData::Header& header) = 0;
  virtual void visit(const IdmapData::Header& header) = 0;
};
};


inline size_t CalculatePadding(size_t data_length) {
  return (4 - (data_length % 4)) % 4;
}

}  // namespace android::idmap2
}  // namespace android::idmap2


#endif  // IDMAP2_INCLUDE_IDMAP2_IDMAP_H_
#endif  // IDMAP2_INCLUDE_IDMAP2_IDMAP_H_
+2 −1
Original line number Original line Diff line number Diff line
@@ -41,8 +41,9 @@ class PrettyPrintVisitor : public Visitor {


 private:
 private:
  std::ostream& stream_;
  std::ostream& stream_;
  std::unique_ptr<const ApkAssets> target_apk_;
  AssetManager2 target_am_;
  AssetManager2 target_am_;
  AssetManager2 overlay_am_;
  std::vector<std::unique_ptr<const ApkAssets>> apk_assets_;
};
};


}  // namespace idmap2
}  // namespace idmap2
+1 −3
Original line number Original line Diff line number Diff line
@@ -45,11 +45,9 @@ class RawPrintVisitor : public Visitor {
  void print(uint16_t value, const char* fmt, ...);
  void print(uint16_t value, const char* fmt, ...);
  void print(uint32_t value, const char* fmt, ...);
  void print(uint32_t value, const char* fmt, ...);
  void print(const std::string& value, size_t encoded_size, const char* fmt, ...);
  void print(const std::string& value, size_t encoded_size, const char* fmt, ...);
  void print_raw(uint32_t length, const char* fmt, ...);


  std::ostream& stream_;
  std::ostream& stream_;
  std::unique_ptr<const ApkAssets> target_apk_;
  std::vector<std::unique_ptr<const ApkAssets>> apk_assets_;
  std::unique_ptr<const ApkAssets> overlay_apk_;
  AssetManager2 target_am_;
  AssetManager2 target_am_;
  AssetManager2 overlay_am_;
  AssetManager2 overlay_am_;
  size_t offset_;
  size_t offset_;
Loading