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

Commit cfafa7a1 authored by Yurii Zubrytskyi's avatar Yurii Zubrytskyi Committed by Automerger Merge Worker
Browse files

[res] Better native pointer tracking in Java am: b9ef411d am: 5c9055a0 am: 23bb1e82

parents 8b680e6b 23bb1e82
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -528,6 +528,10 @@ public final class AssetManager implements AutoCloseable {
        if (!mOpen) {
        if (!mOpen) {
            throw new RuntimeException("AssetManager has been closed");
            throw new RuntimeException("AssetManager has been closed");
        }
        }
        // Let's still check if the native object exists, given all the memory corruptions.
        if (mObject == 0) {
            throw new RuntimeException("AssetManager is open but the native object is gone");
        }
    }
    }


    /**
    /**
@@ -1153,6 +1157,7 @@ public final class AssetManager implements AutoCloseable {
    int[] getAttributeResolutionStack(long themePtr, @AttrRes int defStyleAttr,
    int[] getAttributeResolutionStack(long themePtr, @AttrRes int defStyleAttr,
            @StyleRes int defStyleRes, @StyleRes int xmlStyle) {
            @StyleRes int defStyleRes, @StyleRes int xmlStyle) {
        synchronized (this) {
        synchronized (this) {
            ensureValidLocked();
            return nativeAttributeResolutionStack(
            return nativeAttributeResolutionStack(
                    mObject, themePtr, xmlStyle, defStyleAttr, defStyleRes);
                    mObject, themePtr, xmlStyle, defStyleAttr, defStyleRes);
        }
        }
+2 −1
Original line number Original line Diff line number Diff line
@@ -62,7 +62,7 @@ public final class StringBlock implements Closeable {
    private static final String TAG = "AssetManager";
    private static final String TAG = "AssetManager";
    private static final boolean localLOGV = false;
    private static final boolean localLOGV = false;


    private final long mNative;
    private long mNative;   // final, but gets modified when closed
    private final boolean mUseSparse;
    private final boolean mUseSparse;
    private final boolean mOwnsNative;
    private final boolean mOwnsNative;


@@ -207,6 +207,7 @@ public final class StringBlock implements Closeable {
                if (mOwnsNative) {
                if (mOwnsNative) {
                    nativeDestroy(mNative);
                    nativeDestroy(mNative);
                }
                }
                mNative = 0;
            }
            }
        }
        }
    }
    }
+3 −1
Original line number Original line Diff line number Diff line
@@ -73,7 +73,9 @@ public final class XmlBlock implements AutoCloseable {
    private void decOpenCountLocked() {
    private void decOpenCountLocked() {
        mOpenCount--;
        mOpenCount--;
        if (mOpenCount == 0) {
        if (mOpenCount == 0) {
            mStrings.close();
            nativeDestroy(mNative);
            nativeDestroy(mNative);
            mNative = 0;
            if (mAssets != null) {
            if (mAssets != null) {
                mAssets.xmlBlockGone(hashCode());
                mAssets.xmlBlockGone(hashCode());
            }
            }
@@ -621,7 +623,7 @@ public final class XmlBlock implements AutoCloseable {
    }
    }


    private @Nullable final AssetManager mAssets;
    private @Nullable final AssetManager mAssets;
    private final long mNative;
    private long mNative;   // final, but gets reset on close
    /*package*/ final StringBlock mStrings;
    /*package*/ final StringBlock mStrings;
    private boolean mOpen = true;
    private boolean mOpen = true;
    private int mOpenCount = 1;
    private int mOpenCount = 1;