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

Commit 6169a5e3 authored by Adnan Begovic's avatar Adnan Begovic Committed by Eamon Powell
Browse files

androidfw: Squash of declare and load lineage 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

Change-Id: I383ff3eb35cd8d94bd1aebc5b811948d63da621d
parent b73d099b
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -1222,7 +1222,7 @@ public final class LoadedApk {
                    false, false);
                    false, false);
            for (int i = 0, n = packageIdentifiers.size(); i < n; i++) {
            for (int i = 0, n = packageIdentifiers.size(); i < n; i++) {
                final int id = packageIdentifiers.keyAt(i);
                final int id = packageIdentifiers.keyAt(i);
                if (id == 0x01 || id == 0x7f) {
                if (id == 0x01 || id == 0x7f || id == 0x3f) {
                    continue;
                    continue;
                }
                }


+2 −0
Original line number Original line Diff line number Diff line
@@ -63,6 +63,7 @@ public final class AssetManager implements AutoCloseable {
    private static final boolean DEBUG_REFS = false;
    private static final boolean DEBUG_REFS = false;


    private static final String FRAMEWORK_APK_PATH = "/system/framework/framework-res.apk";
    private static final String FRAMEWORK_APK_PATH = "/system/framework/framework-res.apk";
    private static final String LINEAGE_APK_PATH = "/system/framework/org.lineageos.platform-res.apk";


    private static final Object sSync = new Object();
    private static final Object sSync = new Object();


@@ -243,6 +244,7 @@ public final class AssetManager implements AutoCloseable {
            for (String idmapPath : systemIdmapPaths) {
            for (String idmapPath : systemIdmapPaths) {
                apkAssets.add(ApkAssets.loadOverlayFromPath(idmapPath, ApkAssets.PROPERTY_SYSTEM));
                apkAssets.add(ApkAssets.loadOverlayFromPath(idmapPath, ApkAssets.PROPERTY_SYSTEM));
            }
            }
            apkAssets.add(ApkAssets.loadFromPath(LINEAGE_APK_PATH, 0));


            sSystemApkAssetsSet = new ArraySet<>(apkAssets);
            sSystemApkAssetsSet = new ArraySet<>(apkAssets);
            sSystemApkAssets = apkAssets.toArray(new ApkAssets[apkAssets.size()]);
            sSystemApkAssets = apkAssets.toArray(new ApkAssets[apkAssets.size()]);
+10 −4
Original line number Original line Diff line number Diff line
@@ -64,6 +64,7 @@ namespace android {
#define IDMAP_MAGIC             0x504D4449
#define IDMAP_MAGIC             0x504D4449


#define APP_PACKAGE_ID      0x7f
#define APP_PACKAGE_ID      0x7f
#define LINEAGESDK_PACKAGE_ID    0x3f
#define SYS_PACKAGE_ID      0x01
#define SYS_PACKAGE_ID      0x01


static const bool kDebugStringPoolNoisy = false;
static const bool kDebugStringPoolNoisy = false;
@@ -5535,7 +5536,8 @@ bool ResTable::stringToValue(Res_value* outValue, String16* outString,
                }
                }


                uint32_t packageId = Res_GETPACKAGE(rid) + 1;
                uint32_t packageId = Res_GETPACKAGE(rid) + 1;
                if (packageId != APP_PACKAGE_ID && packageId != SYS_PACKAGE_ID) {
                if (packageId != APP_PACKAGE_ID && packageId != SYS_PACKAGE_ID &&
                        packageId != LINEAGESDK_PACKAGE_ID) {
                    outValue->dataType = Res_value::TYPE_DYNAMIC_REFERENCE;
                    outValue->dataType = Res_value::TYPE_DYNAMIC_REFERENCE;
                }
                }
                outValue->data = rid;
                outValue->data = rid;
@@ -5556,7 +5558,8 @@ bool ResTable::stringToValue(Res_value* outValue, String16* outString,
                        outValue->data = rid;
                        outValue->data = rid;
                        outValue->dataType = Res_value::TYPE_DYNAMIC_REFERENCE;
                        outValue->dataType = Res_value::TYPE_DYNAMIC_REFERENCE;
                        return true;
                        return true;
                    } else if (packageId == APP_PACKAGE_ID || packageId == SYS_PACKAGE_ID) {
                    } else if (packageId == APP_PACKAGE_ID || packageId == SYS_PACKAGE_ID ||
                            packageId == LINEAGESDK_PACKAGE_ID) {
                        // We accept packageId's generated as 0x01 in order to support
                        // We accept packageId's generated as 0x01 in order to support
                        // building the android system resources
                        // building the android system resources
                        outValue->data = rid;
                        outValue->data = rid;
@@ -5702,7 +5705,8 @@ bool ResTable::stringToValue(Res_value* outValue, String16* outString,
            }
            }


            uint32_t packageId = Res_GETPACKAGE(rid) + 1;
            uint32_t packageId = Res_GETPACKAGE(rid) + 1;
            if (packageId != APP_PACKAGE_ID && packageId != SYS_PACKAGE_ID) {
            if (packageId != APP_PACKAGE_ID && packageId != SYS_PACKAGE_ID &&
                    packageId != LINEAGESDK_PACKAGE_ID) {
                outValue->dataType = Res_value::TYPE_DYNAMIC_ATTRIBUTE;
                outValue->dataType = Res_value::TYPE_DYNAMIC_ATTRIBUTE;
            }
            }
            outValue->data = rid;
            outValue->data = rid;
@@ -5717,7 +5721,8 @@ bool ResTable::stringToValue(Res_value* outValue, String16* outString,
                    outValue->data = rid;
                    outValue->data = rid;
                    outValue->dataType = Res_value::TYPE_DYNAMIC_ATTRIBUTE;
                    outValue->dataType = Res_value::TYPE_DYNAMIC_ATTRIBUTE;
                    return true;
                    return true;
                } else if (packageId == APP_PACKAGE_ID || packageId == SYS_PACKAGE_ID) {
                } else if (packageId == APP_PACKAGE_ID || packageId == SYS_PACKAGE_ID ||
                        packageId == LINEAGESDK_PACKAGE_ID) {
                    // We accept packageId's generated as 0x01 in order to support
                    // We accept packageId's generated as 0x01 in order to support
                    // building the android system resources
                    // building the android system resources
                    outValue->data = rid;
                    outValue->data = rid;
@@ -6893,6 +6898,7 @@ DynamicRefTable::DynamicRefTable(uint8_t packageId, bool appAsLib)
    // Reserved package ids
    // Reserved package ids
    mLookupTable[APP_PACKAGE_ID] = APP_PACKAGE_ID;
    mLookupTable[APP_PACKAGE_ID] = APP_PACKAGE_ID;
    mLookupTable[SYS_PACKAGE_ID] = SYS_PACKAGE_ID;
    mLookupTable[SYS_PACKAGE_ID] = SYS_PACKAGE_ID;
    mLookupTable[LINEAGESDK_PACKAGE_ID] = LINEAGESDK_PACKAGE_ID;
}
}


status_t DynamicRefTable::load(const ResTable_lib_header* const header)
status_t DynamicRefTable::load(const ResTable_lib_header* const header)
+7 −0
Original line number Original line Diff line number Diff line
@@ -74,6 +74,7 @@ class BackTrackingAttributeFinder {


  // Package offsets (best-case, fast look-up).
  // Package offsets (best-case, fast look-up).
  Iterator framework_start_;
  Iterator framework_start_;
  Iterator lineage_framework_start_;
  Iterator app_start_;
  Iterator app_start_;


  // Worst case, we have shared-library resources.
  // Worst case, we have shared-library resources.
@@ -100,6 +101,9 @@ void BackTrackingAttributeFinder<Derived, Iterator>::JumpToClosestAttribute(
    case 0x01u:
    case 0x01u:
      current_ = framework_start_;
      current_ = framework_start_;
      break;
      break;
    case 0x3fu:
      current_ = lineage_framework_start_;
      break;
    case 0x7fu:
    case 0x7fu:
      current_ = app_start_;
      current_ = app_start_;
      break;
      break;
@@ -134,6 +138,9 @@ void BackTrackingAttributeFinder<Derived, Iterator>::MarkCurrentPackageId(
    case 0x01u:
    case 0x01u:
      framework_start_ = current_;
      framework_start_ = current_;
      break;
      break;
    case 0x3fu:
      lineage_framework_start_ = current_;
      break;
    case 0x7fu:
    case 0x7fu:
      app_start_ = current_;
      app_start_ = current_;
      break;
      break;
+3 −2
Original line number Original line Diff line number Diff line
@@ -2893,8 +2893,9 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<const ResourceFilter>&
    for (size_t i = 0; i < basePackageCount; i++) {
    for (size_t i = 0; i < basePackageCount; i++) {
        size_t packageId = table.getBasePackageId(i);
        size_t packageId = table.getBasePackageId(i);
        String16 packageName(table.getBasePackageName(i));
        String16 packageName(table.getBasePackageName(i));
        if (packageId > 0x01 && packageId != 0x7f &&
        if (packageId > 0x01 && packageId != 0x7f && packageId != 0x3f &&
                packageName != String16("android")) {
                packageName != String16("android") &&
                packageName != String16("lineageos.platform")) {
            libraryPackages.add(sp<Package>(new Package(packageName, packageId)));
            libraryPackages.add(sp<Package>(new Package(packageName, packageId)));
        }
        }
    }
    }