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

Commit 355d7cd8 authored by Brandon Liu's avatar Brandon Liu
Browse files

Introduce a count for registered shared library on ResourcesImpl to

help to fix gmail crash.

Gmail crashes consistently while copy pasting texts into the body of
composing an email. This happened because previous design missed to
handle an edge case when after a shared library have its asset paths
registered, new created Resources could find an outdated ResourcesImpl
cache which does not have the proper lib asset paths appended and
reuse it. Introduced a count for shared library on ResourcesImpl to
fix it.

Bug: b/329915827
Test: Verified all affected tests pass and manually tested on device.
Change-Id: I3183e5c8c20ac8f86501846e6f6dd82e035402fc
parent 9ce824ca
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -736,7 +736,8 @@ public class ResourcesManager {
    private @Nullable ResourcesImpl findOrCreateResourcesImplForKeyLocked(
            @NonNull ResourcesKey key, @Nullable ApkAssetsSupplier apkSupplier) {
        ResourcesImpl impl = findResourcesImplForKeyLocked(key);
        if (impl == null) {
        // ResourcesImpl also need to be recreated if its shared library count is not up-to-date.
        if (impl == null || impl.getSharedLibCount() != mSharedLibAssetsMap.size()) {
            impl = createResourcesImpl(key, apkSupplier);
            if (impl != null) {
                mResourceImpls.put(key, new WeakReference<>(impl));
+10 −0
Original line number Diff line number Diff line
@@ -146,6 +146,11 @@ public class ResourcesImpl {

    // Cyclical cache used for recently-accessed XML files.
    private int mLastCachedXmlBlockIndex = -1;

    // The number of shared libraries registered within this ResourcesImpl, which is designed to
    // help to determine whether this ResourcesImpl is outdated on shared library information and
    // needs to be replaced.
    private int mSharedLibCount;
    private final int[] mCachedXmlBlockCookies = new int[XML_BLOCK_CACHE_SIZE];
    private final String[] mCachedXmlBlockFiles = new String[XML_BLOCK_CACHE_SIZE];
    private final XmlBlock[] mCachedXmlBlocks = new XmlBlock[XML_BLOCK_CACHE_SIZE];
@@ -206,6 +211,7 @@ public class ResourcesImpl {
            for (int i = 0; i < size; i++) {
                assets.addSharedLibraryPaths(sharedLibMap.valueAt(i).getAllAssetPaths());
            }
            mSharedLibCount = sharedLibMap.size();
        }
        mMetrics.setToDefaults();
        mDisplayAdjustments = displayAdjustments;
@@ -1602,4 +1608,8 @@ public class ResourcesImpl {
            mSize--;
        }
    }

    public int getSharedLibCount() {
        return mSharedLibCount;
    }
}