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

Commit 713a5cdb authored by Alan Viverette's avatar Alan Viverette
Browse files

Don't call public non-final getResources() from getAssets()

Refactors to getResourcesInternal() and calls that from both methods.
Adds documentation on Context.getResources() and getAssets() that the
instances returned should be consistent with each other.

Bug: 26228895
Change-Id: I41b09f1e9a3a0315bcdf1c08a7b431a9a697bb6f
parent eb2094ce
Loading
Loading
Loading
Loading
+22 −2
Original line number Original line Diff line number Diff line
@@ -326,10 +326,30 @@ public abstract class Context {
     */
     */
    public static final int BIND_NOT_VISIBLE = 0x40000000;
    public static final int BIND_NOT_VISIBLE = 0x40000000;


    /** Return an AssetManager instance for your application's package. */
    /**
     * Returns an AssetManager instance for the application's package.
     * <p>
     * <strong>Note:</strong> Implementations of this method should return
     * an AssetManager instance that is consistent with the Resources instance
     * returned by {@link #getResources()}. For example, they should share the
     * same {@link Configuration} object.
     *
     * @return an AssetManager instance for the application's package
     * @see #getResources()
     */
    public abstract AssetManager getAssets();
    public abstract AssetManager getAssets();


    /** Return a Resources instance for your application's package. */
    /**
     * Returns a Resources instance for the application's package.
     * <p>
     * <strong>Note:</strong> Implementations of this method should return
     * a Resources instance that is consistent with the AssetManager instance
     * returned by {@link #getAssets()}. For example, they should share the
     * same {@link Configuration} object.
     *
     * @return a Resources instance for the application's package
     * @see #getAssets()
     */
    public abstract Resources getResources();
    public abstract Resources getResources();


    /** Return PackageManager instance to find global package information. */
    /** Return PackageManager instance to find global package information. */
+1 −2
Original line number Original line Diff line number Diff line
@@ -82,8 +82,7 @@ public class ContextWrapper extends Context {
    }
    }


    @Override
    @Override
    public Resources getResources()
    public Resources getResources() {
    {
        return mBase.getResources();
        return mBase.getResources();
    }
    }


+5 −2
Original line number Original line Diff line number Diff line
@@ -104,11 +104,15 @@ public class ContextThemeWrapper extends ContextWrapper {
    @Override
    @Override
    public AssetManager getAssets() {
    public AssetManager getAssets() {
        // Ensure we're returning assets with the correct configuration.
        // Ensure we're returning assets with the correct configuration.
        return getResources().getAssets();
        return getResourcesInternal().getAssets();
    }
    }


    @Override
    @Override
    public Resources getResources() {
    public Resources getResources() {
        return getResourcesInternal();
    }

    private Resources getResourcesInternal() {
        if (mResources == null) {
        if (mResources == null) {
            if (mOverrideConfiguration == null) {
            if (mOverrideConfiguration == null) {
                mResources = super.getResources();
                mResources = super.getResources();
@@ -117,7 +121,6 @@ public class ContextThemeWrapper extends ContextWrapper {
                mResources = resContext.getResources();
                mResources = resContext.getResources();
            }
            }
        }
        }

        return mResources;
        return mResources;
    }
    }