summaryrefslogtreecommitdiff
path: root/libs/androidfw/include
diff options
context:
space:
mode:
author Adam Lesinski <adamlesinski@google.com> 2017-01-23 12:58:11 -0800
committer Adam Lesinski <adamlesinski@google.com> 2017-02-15 10:50:23 -0800
commitd1ecd7af687bcad0f87c37fe33515ff6c5ea0f1d (patch)
tree63822987507c52532481ca86333751e4fb329953 /libs/androidfw/include
parentc535d122c6a58a152ff2581f936070c2695c45ba (diff)
AssetManager2: Various fixes
- Use FileMaps to open Assets (prevents closing of ApkAssets underlying zip) - Implement OpenDir and List methods - Fix issue where DynamicRefTable wasn't properly constructed Test: make libandroidfw_tests Change-Id: Ib21a84e1114d028120744aa3bc1c6eb9d9399fa8
Diffstat (limited to 'libs/androidfw/include')
-rw-r--r--libs/androidfw/include/androidfw/ApkAssets.h5
-rw-r--r--libs/androidfw/include/androidfw/Asset.h9
-rw-r--r--libs/androidfw/include/androidfw/AssetDir.h1
-rw-r--r--libs/androidfw/include/androidfw/AssetManager2.h18
-rw-r--r--libs/androidfw/include/androidfw/ResourceTypes.h6
-rw-r--r--libs/androidfw/include/androidfw/Util.h8
6 files changed, 40 insertions, 7 deletions
diff --git a/libs/androidfw/include/androidfw/ApkAssets.h b/libs/androidfw/include/androidfw/ApkAssets.h
index 6d1578c2d50e..b7e66fb68be5 100644
--- a/libs/androidfw/include/androidfw/ApkAssets.h
+++ b/libs/androidfw/include/androidfw/ApkAssets.h
@@ -25,6 +25,7 @@
#include "androidfw/Asset.h"
#include "androidfw/LoadedArsc.h"
+#include "androidfw/misc.h"
namespace android {
@@ -38,6 +39,9 @@ class ApkAssets {
std::unique_ptr<Asset> Open(const std::string& path,
Asset::AccessMode mode = Asset::AccessMode::ACCESS_RANDOM) const;
+ bool ForEachFile(const std::string& path,
+ const std::function<void(const StringPiece&, FileType)>& f) const;
+
inline const std::string& GetPath() const { return path_; }
inline const LoadedArsc* GetLoadedArsc() const { return loaded_arsc_.get(); }
@@ -56,6 +60,7 @@ class ApkAssets {
using ZipArchivePtr =
std::unique_ptr<typename std::remove_pointer<::ZipArchiveHandle>::type, ZipArchivePtrCloser>;
+
ZipArchivePtr zip_handle_;
std::string path_;
std::unique_ptr<Asset> resources_asset_;
diff --git a/libs/androidfw/include/androidfw/Asset.h b/libs/androidfw/include/androidfw/Asset.h
index 461e773e5818..9d12a35395c9 100644
--- a/libs/androidfw/include/androidfw/Asset.h
+++ b/libs/androidfw/include/androidfw/Asset.h
@@ -24,6 +24,8 @@
#include <stdio.h>
#include <sys/types.h>
+#include <memory>
+
#include <utils/Compat.h>
#include <utils/Errors.h>
#include <utils/String8.h>
@@ -150,6 +152,7 @@ private:
/* AssetManager needs access to our "create" functions */
friend class AssetManager;
+ friend class ApkAssets;
/*
* Create the asset from a named file on disk.
@@ -194,6 +197,9 @@ private:
*/
static Asset* createFromUncompressedMap(FileMap* dataMap, AccessMode mode);
+ static std::unique_ptr<Asset> createFromUncompressedMap(std::unique_ptr<FileMap> dataMap,
+ AccessMode mode);
+
/*
* Create the asset from a memory-mapped file segment with compressed
* data.
@@ -203,6 +209,9 @@ private:
static Asset* createFromCompressedMap(FileMap* dataMap,
size_t uncompressedLen, AccessMode mode);
+ static std::unique_ptr<Asset> createFromCompressedMap(std::unique_ptr<FileMap> dataMap,
+ size_t uncompressedLen, AccessMode mode);
+
/*
* Create from a reference-counted chunk of shared memory.
diff --git a/libs/androidfw/include/androidfw/AssetDir.h b/libs/androidfw/include/androidfw/AssetDir.h
index bd89d7d34b97..7aef02dc4133 100644
--- a/libs/androidfw/include/androidfw/AssetDir.h
+++ b/libs/androidfw/include/androidfw/AssetDir.h
@@ -70,6 +70,7 @@ private:
const AssetDir& operator=(const AssetDir& src);
friend class AssetManager;
+ friend class AssetManager2;
/*
* This holds information about files in the asset hierarchy.
diff --git a/libs/androidfw/include/androidfw/AssetManager2.h b/libs/androidfw/include/androidfw/AssetManager2.h
index 81cdc46be0b4..d2bc6ee45576 100644
--- a/libs/androidfw/include/androidfw/AssetManager2.h
+++ b/libs/androidfw/include/androidfw/AssetManager2.h
@@ -107,6 +107,9 @@ class AssetManager2 : public ::AAssetManager {
// Returns the DynamicRefTable for the given package ID.
const DynamicRefTable* GetDynamicRefTableForPackage(uint32_t package_id) const;
+ // Returns the DynamicRefTable for the ApkAssets represented by the cookie.
+ const DynamicRefTable* GetDynamicRefTableForCookie(ApkAssetsCookie cookie) const;
+
// Sets/resets the configuration for this AssetManager. This will cause all
// caches that are related to the configuration change to be invalidated.
void SetConfiguration(const ResTable_config& configuration);
@@ -143,6 +146,11 @@ class AssetManager2 : public ::AAssetManager {
std::unique_ptr<Asset> Open(const std::string& filename, ApkAssetsCookie cookie,
Asset::AccessMode mode);
+ // Opens the directory specified by `dirname`. The result is an AssetDir that is the combination
+ // of all directories matching `dirname` under the assets/ directory of every ApkAssets loaded.
+ // The entries are sorted by their ASCII name.
+ std::unique_ptr<AssetDir> OpenDir(const std::string& dirname);
+
// Searches the set of APKs loaded by this AssetManager and opens the first one found.
// `mode` controls how the file is opened.
// `out_cookie` is populated with the cookie of the APK this file was found in.
@@ -203,7 +211,7 @@ class AssetManager2 : public ::AAssetManager {
// it was not found.
ApkAssetsCookie ResolveReference(ApkAssetsCookie cookie, Res_value* in_out_value,
ResTable_config* in_out_selected_config, uint32_t* in_out_flags,
- ResTable_ref* out_last_reference);
+ uint32_t* out_last_reference);
// Retrieves the best matching bag/map resource with ID `resid`.
// This method will resolve all parent references for this bag and merge keys with the child.
@@ -298,6 +306,8 @@ class Theme {
inline const AssetManager2* GetAssetManager() const { return asset_manager_; }
+ inline AssetManager2* GetAssetManager() { return asset_manager_; }
+
// Returns a bit mask of configuration changes that will impact this
// theme (and thus require completely reloading it).
inline uint32_t GetChangingConfigurations() const { return type_spec_flags_; }
@@ -318,10 +328,10 @@ class Theme {
// This is like AssetManager2::ResolveReference(), but also takes
// care of resolving attribute references to the theme.
- ApkAssetsCookie ResolveAttributeReference(Res_value* in_out_value, ApkAssetsCookie src_cookie,
- uint32_t* out_last_ref = nullptr,
+ ApkAssetsCookie ResolveAttributeReference(ApkAssetsCookie cookie, Res_value* in_out_value,
+ ResTable_config* in_out_selected_config = nullptr,
uint32_t* in_out_type_spec_flags = nullptr,
- ResTable_config* out_selected_config = nullptr) const;
+ uint32_t* out_last_ref = nullptr);
private:
DISALLOW_COPY_AND_ASSIGN(Theme);
diff --git a/libs/androidfw/include/androidfw/ResourceTypes.h b/libs/androidfw/include/androidfw/ResourceTypes.h
index 04a5d958c614..cfe2652a0d17 100644
--- a/libs/androidfw/include/androidfw/ResourceTypes.h
+++ b/libs/androidfw/include/androidfw/ResourceTypes.h
@@ -1554,7 +1554,7 @@ class DynamicRefTable
{
friend class AssetManager2;
public:
- DynamicRefTable() = default;
+ DynamicRefTable();
DynamicRefTable(uint8_t packageId, bool appAsLib);
// Loads an unmapped reference table from the package.
@@ -1577,10 +1577,10 @@ public:
}
private:
- uint8_t mAssignedPackageId = 0;
+ uint8_t mAssignedPackageId;
uint8_t mLookupTable[256];
KeyedVector<String16, uint8_t> mEntries;
- bool mAppAsLib = false;
+ bool mAppAsLib;
};
bool U16StringToInt(const char16_t* s, size_t len, Res_value* outValue);
diff --git a/libs/androidfw/include/androidfw/Util.h b/libs/androidfw/include/androidfw/Util.h
index 3950cf240a9e..e4cd6a8ab6b8 100644
--- a/libs/androidfw/include/androidfw/Util.h
+++ b/libs/androidfw/include/androidfw/Util.h
@@ -22,6 +22,8 @@
#include "android-base/macros.h"
+#include "androidfw/StringPiece.h"
+
namespace android {
namespace util {
@@ -108,6 +110,12 @@ class unique_cptr {
void ReadUtf16StringFromDevice(const uint16_t* src, size_t len, std::string* out);
+// Converts a UTF-8 string to a UTF-16 string.
+std::u16string Utf8ToUtf16(const StringPiece& utf8);
+
+// Converts a UTF-16 string to a UTF-8 string.
+std::string Utf16ToUtf8(const StringPiece16& utf16);
+
} // namespace util
} // namespace android