androidfw: Squash of declare and load omnirom sdk resource package w/ id

Author: Adnan Begovic <adnan@cyngn.com>
Date:   Mon Jul 6 20:06:36 2015 -0700
    androidfw: Declare and load cmsdk resource package w/ id.
    Change-Id: I63b8f3e4a938896dd21999c5b4470573a1da2e52

Author: Steve Kondik <steve@cyngn.com>
Date:   Wed Aug 31 01:32:13 2016 -0700
    androidfw: Fix CMSDK resource handling on N
     * Consider the CMSDK package identifier in the new dynamic resource
       conditions.
    Change-Id: I3e84d12ac86a6eb1d3407aa64234f80a0e945e70

Author: Sam Mortimer <sam@mortimer.me.uk>
Date:   Wed Aug 15 21:58:12 2018 -0700
    fw/b AssetManager: Load lineage resources in constructor
    *) AssetManager was refactored here:
    https://android.googlesource.com/platform/frameworks/base/+/bebfcc46a249a70af04bc18490a897888a142fb8
    *) Lineage resources are no longer accessible as a result.  For example, LineageParts crashes from:
       08-15 16:22:04.850  2599  2599 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity
       ComponentInfo{org.lineageos.lineageparts/org.lineageos.lineageparts.PartsActivity}:
       android.content.res.Resources$NotFoundException: Resource ID #0x3f080008
    *) When framework-res.apk is loaded, load org.linageos.platform-res.apk too.  Fixes resource loading.
    Change-Id: I8e3408a1031c0b8e000d78ab59cbcabc860d8b57

Copied system resources apk loading order from lineage-15.1 commit:

Author: Ethan Chen <intervigil@gmail.com>
Date:   Sun Oct 15 23:09:36 2017 -0700
    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

Author: Luca Stefani <luca.stefani.ge1@gmail.com>
Date:   Fri Oct 8 16:40:09 2021 +0200
    AssetManager: Mark lineage res as system
    Another case of "How did it ever work before?"
    Change-Id: I06e800170c51afd1e5575cc0b3b381e5fbceee3d

Change-Id: I383ff3eb35cd8d94bd1aebc5b811948d63da621d

Add omnirom sdk resource APK to Zygote FD whitelist

Change-Id: Ica91b23e467db61f142b183316db4afee2a2a283

services: Keep sdk classes

Change-Id: Ic22d58a8c791905e5943f9ed8bc0322f0187ea65

androidfw: Add OmniRom res to default assets

Change-Id: I815a78e645a2eaf65667fea3789d0a68149ee075

idmap2: Cache OmniRom resources

Change-Id: I212e029be783657fec738031db44fdf2aa5f3cdd

Allow omnirom resources package to be overlayed by RRO packages

Change-Id: I152ef9a87b16338e14af508e0f1f42830688c5ea
diff --git a/libs/androidfw/AssetManager.cpp b/libs/androidfw/AssetManager.cpp
index e618245..f4a77ec 100644
--- a/libs/androidfw/AssetManager.cpp
+++ b/libs/androidfw/AssetManager.cpp
@@ -63,6 +63,7 @@
 static const char* kAssetsRoot = "assets";
 static const char* kAppZipName = NULL; //"classes.jar";
 static const char* kSystemAssets = "framework/framework-res.apk";
+static const char* kOmniRomAssets = "framework/omnirom-res.apk";
 static const char* kResourceCache = "resource-cache";
 
 static const char* kExcludeExtension = ".EXCLUDE";
@@ -367,10 +368,19 @@
     const char* root = getenv("ANDROID_ROOT");
     LOG_ALWAYS_FATAL_IF(root == NULL, "ANDROID_ROOT not set");
 
-    String8 path(root);
-    appendPath(path, kSystemAssets);
+    bool success = true;
+    {
+       String8 path(root);
+       appendPath(path, kSystemAssets);
+       success &= addAssetPath(path, NULL, false /* appAsLib */, true /* isSystemAsset */);
+    }
+    {
+       String8 path(root);
+       appendPath(path, kOmniRomAssets);
+       success &= addAssetPath(path, NULL, false /* appAsLib */, true /* isSystemAsset */);
+    }
 
-    return addAssetPath(path, NULL, false /* appAsLib */, true /* isSystemAsset */);
+    return success;
 }
 
 int32_t AssetManager::nextAssetPath(const int32_t cookie) const