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

Commit 0d930441 authored by Ethan Chen's avatar Ethan Chen Committed by Michael Bestas
Browse files

androidfw: Load SDK resources after initial system resources

* The existing AssetManager logic assumes a single system resource,
  as the RRO resource codepath expects to have the system AssetManager
  discover RRO overlay resources while the system resource is being
  added to the AssetManager's mAssetPaths. Having multiple system
  resources already present in the AssetManager's mAssetPaths breaks
  the expected ordering between the system AssetManager and the
  non-system AssetManager, as non-system AssetManagers will not need
  to discover system RRO overlay resources, and already have them
  in the it's mAssetPaths immediately following the system resource
  it is supposed to overlay.
* Resolve this issue by loading the SDK resources after the system
  RRO overlay resource is loaded to guarantee consistent ordering
  between the system AssetManager and non-system AssetManager instances.

Change-Id: I274cf9100fbb6215b840617993a7a6d9b7ff336d
parent 22635b87
Loading
Loading
Loading
Loading
+16 −1
Original line number Original line Diff line number Diff line
@@ -102,6 +102,7 @@ public final class AssetManager implements AutoCloseable {
            init(false);
            init(false);
            if (localLOGV) Log.v(TAG, "New asset manager: " + this);
            if (localLOGV) Log.v(TAG, "New asset manager: " + this);
            ensureSystemAssets();
            ensureSystemAssets();
            ensureExtraAssets(this);
        }
        }
    }
    }


@@ -111,10 +112,23 @@ public final class AssetManager implements AutoCloseable {
                AssetManager system = new AssetManager(true);
                AssetManager system = new AssetManager(true);
                system.makeStringBlocks(null);
                system.makeStringBlocks(null);
                sSystem = system;
                sSystem = system;
                ensureExtraAssets(sSystem);
            }
            }
        }
        }
    }
    }


    private static void ensureExtraAssets(AssetManager m) {
        // load extra assets after system assets, so
        // the ordering of asset paths is preserved for
        // RRO framework assets
        if (m == null) {
            Log.w(TAG, "ensureExtraAssets called on null AssetManager!");
            return;
        }
        m.initExtraAssets();
        m.makeStringBlocks(m.mStringBlocks);
    }

    private AssetManager(boolean isSystem) {
    private AssetManager(boolean isSystem) {
        if (DEBUG_REFS) {
        if (DEBUG_REFS) {
            synchronized (this) {
            synchronized (this) {
@@ -886,6 +900,7 @@ public final class AssetManager implements AutoCloseable {
    /*package*/ native final int[] getStyleAttributes(int themeRes);
    /*package*/ native final int[] getStyleAttributes(int themeRes);


    private native final void init(boolean isSystem);
    private native final void init(boolean isSystem);
    private native final void initExtraAssets();
    private native final void destroy();
    private native final void destroy();


    private final void incRefsLocked(long id) {
    private final void incRefsLocked(long id) {
+14 −0
Original line number Original line Diff line number Diff line
@@ -1608,6 +1608,18 @@ static void android_content_AssetManager_init(JNIEnv* env, jobject clazz, jboole
    env->SetLongField(clazz, gAssetManagerOffsets.mObject, reinterpret_cast<jlong>(am));
    env->SetLongField(clazz, gAssetManagerOffsets.mObject, reinterpret_cast<jlong>(am));
}
}


static void android_content_AssetManager_initExtraAssets(JNIEnv* env, jobject clazz)
{
    AssetManager* am = (AssetManager*)
        (env->GetLongField(clazz, gAssetManagerOffsets.mObject));
    if (am == NULL) {
        jniThrowNullPointerException(env, "asset");
        return;
    }

    am->addExtraAssets();
}

static void android_content_AssetManager_destroy(JNIEnv* env, jobject clazz)
static void android_content_AssetManager_destroy(JNIEnv* env, jobject clazz)
{
{
    AssetManager* am = (AssetManager*)
    AssetManager* am = (AssetManager*)
@@ -1755,6 +1767,8 @@ static const JNINativeMethod gAssetManagerMethods[] = {
    // Bookkeeping.
    // Bookkeeping.
    { "init",           "(Z)V",
    { "init",           "(Z)V",
        (void*) android_content_AssetManager_init },
        (void*) android_content_AssetManager_init },
    { "initExtraAssets", "()V",
        (void*) android_content_AssetManager_initExtraAssets },
    { "destroy",        "()V",
    { "destroy",        "()V",
        (void*) android_content_AssetManager_destroy },
        (void*) android_content_AssetManager_destroy },
    { "getGlobalAssetCount", "()I",
    { "getGlobalAssetCount", "()I",
+11 −9
Original line number Original line Diff line number Diff line
@@ -326,16 +326,18 @@ bool AssetManager::addDefaultAssets()
    String8 path(root);
    String8 path(root);
    path.appendPath(kSystemAssets);
    path.appendPath(kSystemAssets);


    bool ret = addAssetPath(path, NULL, false /* appAsLib */, true /* isSystemAsset */);
    return addAssetPath(path, NULL, false /* appAsLib */, true /* isSystemAsset */);
    if (ret) {
}

bool AssetManager::addExtraAssets()
{
    const char* root = getenv("ANDROID_ROOT");
    LOG_ALWAYS_FATAL_IF(root == NULL, "ANDROID_ROOT not set");

    String8 pathLineage(root);
    String8 pathLineage(root);
    pathLineage.appendPath(kLineageAssets);
    pathLineage.appendPath(kLineageAssets);


        if (!addAssetPath(pathLineage, NULL, false /* appAsLib */, false /* isSystemAsset */)) {
    return addAssetPath(pathLineage, NULL, false /* appAsLib */, false /* isSystemAsset */);
            ALOGE("Failed to load Lineage SDK resources!");
        }
    }
    return ret;
}
}


int32_t AssetManager::nextAssetPath(const int32_t cookie) const
int32_t AssetManager::nextAssetPath(const int32_t cookie) const
+6 −0
Original line number Original line Diff line number Diff line
@@ -97,6 +97,12 @@ public:
     */
     */
    bool addDefaultAssets();
    bool addDefaultAssets();


    /*
     * Convenience for adding the extra system assets.  Uses the
     * ANDROID_ROOT environment variable to find them.
     */
    bool addExtraAssets();

    /*
    /*
     * Iterate over the asset paths in this manager.  (Previously
     * Iterate over the asset paths in this manager.  (Previously
     * added via addAssetPath() and addDefaultAssets().)  On first call,
     * added via addAssetPath() and addDefaultAssets().)  On first call,