From 8f004c85a0859b6fad16f26ac0fce7b2dc3db3b1 Mon Sep 17 00:00:00 2001 From: Aurimas Liutikas Date: Thu, 17 Jan 2019 17:20:10 -0800 Subject: Add helper methods for View attribute debugging Adding abilities to debug: - Attribute resolution stack (which resources are looked at when resolving an attribute) - Attribute value source (where did each attribute value get defined) - Get explicit style id (if a view had it set via style="...") This feature will be behind Settings.Global flag that Android Studio will set to the debugged application package ID. Bug: 111439551 Test: atest CtsViewTestCases:android.view.cts.ViewStyleTest Change-Id: Ib6f9fc81000bb867b5b94a68953c99b0bc802d6c --- libs/androidfw/AssetManager2.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'libs/androidfw/AssetManager2.cpp') diff --git a/libs/androidfw/AssetManager2.cpp b/libs/androidfw/AssetManager2.cpp index 20303eba6667..81afd937d85e 100644 --- a/libs/androidfw/AssetManager2.cpp +++ b/libs/androidfw/AssetManager2.cpp @@ -704,9 +704,29 @@ ApkAssetsCookie AssetManager2::ResolveReference(ApkAssetsCookie cookie, Res_valu return cookie; } +const std::vector AssetManager2::GetBagResIdStack(uint32_t resid) { + auto cached_iter = cached_bag_resid_stacks_.find(resid); + if (cached_iter != cached_bag_resid_stacks_.end()) { + return cached_iter->second; + } else { + auto found_resids = std::vector(); + GetBag(resid, found_resids); + // Cache style stacks if they are not already cached. + cached_bag_resid_stacks_[resid] = found_resids; + return found_resids; + } +} + const ResolvedBag* AssetManager2::GetBag(uint32_t resid) { auto found_resids = std::vector(); - return GetBag(resid, found_resids); + auto bag = GetBag(resid, found_resids); + + // Cache style stacks if they are not already cached. + auto cached_iter = cached_bag_resid_stacks_.find(resid); + if (cached_iter == cached_bag_resid_stacks_.end()) { + cached_bag_resid_stacks_[resid] = found_resids; + } + return bag; } const ResolvedBag* AssetManager2::GetBag(uint32_t resid, std::vector& child_resids) { -- cgit v1.2.3-59-g8ed1b