This adds support for shared resource libraries in the new ResTable/AssetManager implementation. The dynamic package map encoded in resources.arsc is parsed and stored with LoadedArsc, and combined to form a resolved table in AssetManager2. Benchmarks show that this implementation is an order of magnitude faster on angler-userdebug (make libandroidfw_benchmarks). Test: libandroidfw_tests Change-Id: I57c80248728b63b162bf8269ac9495b53c3e7fa0
54 lines
1.8 KiB
C++
54 lines
1.8 KiB
C++
/*
|
|
* Copyright (C) 2016 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include "androidfw/ApkAssets.h"
|
|
|
|
#include "TestHelpers.h"
|
|
#include "data/basic/R.h"
|
|
|
|
using com::android::basic::R;
|
|
|
|
namespace android {
|
|
|
|
TEST(ApkAssetsTest, LoadApk) {
|
|
std::unique_ptr<ApkAssets> loaded_apk = ApkAssets::Load(GetTestDataPath() + "/basic/basic.apk");
|
|
ASSERT_NE(nullptr, loaded_apk);
|
|
EXPECT_NE(nullptr, loaded_apk->GetLoadedArsc());
|
|
|
|
std::unique_ptr<Asset> asset = loaded_apk->Open("res/layout/main.xml");
|
|
ASSERT_NE(nullptr, asset);
|
|
}
|
|
|
|
TEST(ApkAssetsTest, LoadApkAsSharedLibrary) {
|
|
std::unique_ptr<ApkAssets> loaded_apk =
|
|
ApkAssets::Load(GetTestDataPath() + "/appaslib/appaslib.apk");
|
|
ASSERT_NE(nullptr, loaded_apk);
|
|
const LoadedArsc* loaded_arsc = loaded_apk->GetLoadedArsc();
|
|
ASSERT_NE(nullptr, loaded_arsc);
|
|
ASSERT_EQ(1u, loaded_arsc->GetPackages().size());
|
|
EXPECT_FALSE(loaded_arsc->GetPackages()[0]->IsDynamic());
|
|
|
|
loaded_apk = ApkAssets::LoadAsSharedLibrary(GetTestDataPath() + "/appaslib/appaslib.apk");
|
|
ASSERT_NE(nullptr, loaded_apk);
|
|
|
|
loaded_arsc = loaded_apk->GetLoadedArsc();
|
|
ASSERT_NE(nullptr, loaded_arsc);
|
|
ASSERT_EQ(1u, loaded_arsc->GetPackages().size());
|
|
EXPECT_TRUE(loaded_arsc->GetPackages()[0]->IsDynamic());
|
|
}
|
|
|
|
} // namespace android
|