Revert "AssetManager2: Fix list function"
This reverts commit adc0b87ec2.
Bug:73134570
Change-Id: I9e652245e7661eb7a34dadb5f363a08bc8c9e57e
This commit is contained in:
@@ -403,30 +403,38 @@ static jobjectArray NativeList(JNIEnv* env, jclass /*clazz*/, jlong ptr, jstring
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ScopedLock<AssetManager2> assetmanager(AssetManagerFromLong(ptr));
|
||||
std::unique_ptr<AssetDir> asset_dir =
|
||||
assetmanager->OpenDir(path_utf8.c_str());
|
||||
if (asset_dir == nullptr) {
|
||||
jniThrowException(env, "java/io/FileNotFoundException", path_utf8.c_str());
|
||||
return nullptr;
|
||||
std::vector<std::string> all_file_paths;
|
||||
{
|
||||
StringPiece normalized_path = path_utf8.c_str();
|
||||
if (normalized_path.data()[0] == '/') {
|
||||
normalized_path = normalized_path.substr(1);
|
||||
}
|
||||
std::string root_path = StringPrintf("assets/%s", normalized_path.data());
|
||||
ScopedLock<AssetManager2> assetmanager(AssetManagerFromLong(ptr));
|
||||
for (const ApkAssets* assets : assetmanager->GetApkAssets()) {
|
||||
assets->ForEachFile(root_path, [&](const StringPiece& file_path, FileType type) {
|
||||
if (type == FileType::kFileTypeRegular) {
|
||||
all_file_paths.push_back(file_path.to_string());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const size_t file_count = asset_dir->getFileCount();
|
||||
|
||||
jobjectArray array = env->NewObjectArray(file_count, g_stringClass, nullptr);
|
||||
jobjectArray array = env->NewObjectArray(all_file_paths.size(), g_stringClass, nullptr);
|
||||
if (array == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < file_count; i++) {
|
||||
jstring java_string = env->NewStringUTF(asset_dir->getFileName(i).string());
|
||||
jsize index = 0;
|
||||
for (const std::string& file_path : all_file_paths) {
|
||||
jstring java_string = env->NewStringUTF(file_path.c_str());
|
||||
|
||||
// Check for errors creating the strings (if malformed or no memory).
|
||||
if (env->ExceptionCheck()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
env->SetObjectArrayElement(array, i, java_string);
|
||||
env->SetObjectArrayElement(array, index++, java_string);
|
||||
|
||||
// If we have a large amount of string in our array, we might overflow the
|
||||
// local reference table of the VM.
|
||||
|
||||
@@ -231,16 +231,12 @@ bool ApkAssets::ForEachFile(const std::string& root_path,
|
||||
while ((result = ::Next(cookie, &entry, &name)) == 0) {
|
||||
StringPiece full_file_path(reinterpret_cast<const char*>(name.name), name.name_length);
|
||||
StringPiece leaf_file_path = full_file_path.substr(root_path_full.size());
|
||||
|
||||
if (!leaf_file_path.empty()) {
|
||||
auto iter = std::find(leaf_file_path.begin(), leaf_file_path.end(), '/');
|
||||
if (iter != leaf_file_path.end()) {
|
||||
std::string dir =
|
||||
leaf_file_path.substr(0, std::distance(leaf_file_path.begin(), iter)).to_string();
|
||||
dirs.insert(std::move(dir));
|
||||
} else {
|
||||
f(leaf_file_path, kFileTypeRegular);
|
||||
}
|
||||
auto iter = std::find(leaf_file_path.begin(), leaf_file_path.end(), '/');
|
||||
if (iter != leaf_file_path.end()) {
|
||||
dirs.insert(
|
||||
leaf_file_path.substr(0, std::distance(leaf_file_path.begin(), iter)).to_string());
|
||||
} else if (!leaf_file_path.empty()) {
|
||||
f(leaf_file_path, kFileTypeRegular);
|
||||
}
|
||||
}
|
||||
::EndIteration(cookie);
|
||||
|
||||
@@ -36,10 +36,6 @@ namespace lib_one = com::android::lib_one;
|
||||
namespace lib_two = com::android::lib_two;
|
||||
namespace libclient = com::android::libclient;
|
||||
|
||||
using ::testing::Eq;
|
||||
using ::testing::NotNull;
|
||||
using ::testing::StrEq;
|
||||
|
||||
namespace android {
|
||||
|
||||
class AssetManager2Test : public ::testing::Test {
|
||||
@@ -68,9 +64,6 @@ class AssetManager2Test : public ::testing::Test {
|
||||
|
||||
system_assets_ = ApkAssets::Load(GetTestDataPath() + "/system/system.apk", true /*system*/);
|
||||
ASSERT_NE(nullptr, system_assets_);
|
||||
|
||||
app_assets_ = ApkAssets::Load(GetTestDataPath() + "/app/app.apk");
|
||||
ASSERT_THAT(app_assets_, NotNull());
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -82,7 +75,6 @@ class AssetManager2Test : public ::testing::Test {
|
||||
std::unique_ptr<const ApkAssets> libclient_assets_;
|
||||
std::unique_ptr<const ApkAssets> appaslib_assets_;
|
||||
std::unique_ptr<const ApkAssets> system_assets_;
|
||||
std::unique_ptr<const ApkAssets> app_assets_;
|
||||
};
|
||||
|
||||
TEST_F(AssetManager2Test, FindsResourceFromSingleApkAssets) {
|
||||
@@ -473,68 +465,8 @@ TEST_F(AssetManager2Test, GetResourceId) {
|
||||
assetmanager.GetResourceId("main", "layout", "com.android.basic"));
|
||||
}
|
||||
|
||||
TEST_F(AssetManager2Test, OpensFileFromSingleApkAssets) {
|
||||
AssetManager2 assetmanager;
|
||||
assetmanager.SetApkAssets({system_assets_.get()});
|
||||
TEST_F(AssetManager2Test, OpensFileFromSingleApkAssets) {}
|
||||
|
||||
std::unique_ptr<Asset> asset = assetmanager.Open("file.txt", Asset::ACCESS_BUFFER);
|
||||
ASSERT_THAT(asset, NotNull());
|
||||
|
||||
const char* data = reinterpret_cast<const char*>(asset->getBuffer(false /*wordAligned*/));
|
||||
ASSERT_THAT(data, NotNull());
|
||||
EXPECT_THAT(std::string(data, asset->getLength()), StrEq("file\n"));
|
||||
}
|
||||
|
||||
TEST_F(AssetManager2Test, OpensFileFromMultipleApkAssets) {
|
||||
AssetManager2 assetmanager;
|
||||
assetmanager.SetApkAssets({system_assets_.get(), app_assets_.get()});
|
||||
|
||||
std::unique_ptr<Asset> asset = assetmanager.Open("file.txt", Asset::ACCESS_BUFFER);
|
||||
ASSERT_THAT(asset, NotNull());
|
||||
|
||||
const char* data = reinterpret_cast<const char*>(asset->getBuffer(false /*wordAligned*/));
|
||||
ASSERT_THAT(data, NotNull());
|
||||
EXPECT_THAT(std::string(data, asset->getLength()), StrEq("app override file\n"));
|
||||
}
|
||||
|
||||
TEST_F(AssetManager2Test, OpenDir) {
|
||||
AssetManager2 assetmanager;
|
||||
assetmanager.SetApkAssets({system_assets_.get()});
|
||||
|
||||
std::unique_ptr<AssetDir> asset_dir = assetmanager.OpenDir("");
|
||||
ASSERT_THAT(asset_dir, NotNull());
|
||||
ASSERT_THAT(asset_dir->getFileCount(), Eq(2u));
|
||||
|
||||
EXPECT_THAT(asset_dir->getFileName(0), Eq(String8("file.txt")));
|
||||
EXPECT_THAT(asset_dir->getFileType(0), Eq(FileType::kFileTypeRegular));
|
||||
|
||||
EXPECT_THAT(asset_dir->getFileName(1), Eq(String8("subdir")));
|
||||
EXPECT_THAT(asset_dir->getFileType(1), Eq(FileType::kFileTypeDirectory));
|
||||
|
||||
asset_dir = assetmanager.OpenDir("subdir");
|
||||
ASSERT_THAT(asset_dir, NotNull());
|
||||
ASSERT_THAT(asset_dir->getFileCount(), Eq(1u));
|
||||
|
||||
EXPECT_THAT(asset_dir->getFileName(0), Eq(String8("subdir_file.txt")));
|
||||
EXPECT_THAT(asset_dir->getFileType(0), Eq(FileType::kFileTypeRegular));
|
||||
}
|
||||
|
||||
TEST_F(AssetManager2Test, OpenDirFromManyApks) {
|
||||
AssetManager2 assetmanager;
|
||||
assetmanager.SetApkAssets({system_assets_.get(), app_assets_.get()});
|
||||
|
||||
std::unique_ptr<AssetDir> asset_dir = assetmanager.OpenDir("");
|
||||
ASSERT_THAT(asset_dir, NotNull());
|
||||
ASSERT_THAT(asset_dir->getFileCount(), Eq(3u));
|
||||
|
||||
EXPECT_THAT(asset_dir->getFileName(0), Eq(String8("app_file.txt")));
|
||||
EXPECT_THAT(asset_dir->getFileType(0), Eq(FileType::kFileTypeRegular));
|
||||
|
||||
EXPECT_THAT(asset_dir->getFileName(1), Eq(String8("file.txt")));
|
||||
EXPECT_THAT(asset_dir->getFileType(1), Eq(FileType::kFileTypeRegular));
|
||||
|
||||
EXPECT_THAT(asset_dir->getFileName(2), Eq(String8("subdir")));
|
||||
EXPECT_THAT(asset_dir->getFileType(2), Eq(FileType::kFileTypeDirectory));
|
||||
}
|
||||
TEST_F(AssetManager2Test, OpensFileFromMultipleApkAssets) {}
|
||||
|
||||
} // namespace android
|
||||
|
||||
Binary file not shown.
@@ -1 +0,0 @@
|
||||
app file
|
||||
@@ -1 +0,0 @@
|
||||
app override file
|
||||
@@ -17,11 +17,4 @@
|
||||
|
||||
set -e
|
||||
|
||||
aapt2 compile --dir res -o compiled.flata
|
||||
aapt2 link \
|
||||
--manifest AndroidManifest.xml \
|
||||
-I ../system/system.apk \
|
||||
-A assets \
|
||||
-o app.apk \
|
||||
compiled.flata
|
||||
rm compiled.flata
|
||||
aapt package -I ../system/system.apk -M AndroidManifest.xml -S res -F app.apk -f
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
file
|
||||
@@ -1 +0,0 @@
|
||||
subdir file
|
||||
@@ -17,6 +17,4 @@
|
||||
|
||||
set -e
|
||||
|
||||
aapt2 compile --dir res -o compiled.flata
|
||||
aapt2 link --manifest AndroidManifest.xml -A assets -o system.apk compiled.flata
|
||||
rm compiled.flata
|
||||
aapt package -x -M AndroidManifest.xml -S res -F system.apk -f
|
||||
|
||||
@@ -15,5 +15,6 @@
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<public type="integer" name="number" id="0x01030000" />
|
||||
<integer name="number">1</integer>
|
||||
</resources>
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
<public name="background" type="attr" id="0x01010000"/>
|
||||
<public name="foreground" type="attr" id="0x01010001"/>
|
||||
<public name="Theme.One" type="style" id="0x01020000"/>
|
||||
<public type="integer" name="number" id="0x01030000" />
|
||||
|
||||
<attr name="background" format="color|reference"/>
|
||||
<attr name="foreground" format="color|reference"/>
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user