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

Commit a473a80c authored by d34d's avatar d34d Committed by Clark Scheff
Browse files

CM11 Themes: Put overlays in their own group.

Overlays will now be added to their own group and the
target group will contain a pointer to the overlay
package to be used in getResource and getBagLocked.

Change-Id: Icc6c6eb791f04966e68dbc099eae8e7129546414
(cherry picked from commit 4c8a2c47)
parent fcb30b1b
Loading
Loading
Loading
Loading
+33 −11
Original line number Diff line number Diff line
@@ -2550,7 +2550,8 @@ struct ResTable::Package
struct ResTable::PackageGroup
{
    PackageGroup(ResTable* _owner, const String16& _name, uint32_t _id)
        : owner(_owner), name(_name), id(_id), typeCount(0), bags(NULL), overlayPkgId(0) { }
        : owner(_owner), name(_name), id(_id), typeCount(0), bags(NULL),
          overlayPkgId(0), overlayPackage(NULL) { }
    ~PackageGroup() {
        clearBagCache();
        const size_t N = packages.size();
@@ -2605,6 +2606,7 @@ struct ResTable::PackageGroup
    bag_set***                      bags;

    uint32_t                        overlayPkgId;
    Package*                        overlayPackage;
};

struct ResTable::bag_set
@@ -3242,12 +3244,17 @@ ssize_t ResTable::getResource(uint32_t resID, Res_value* outValue, bool mayBeBag

    ssize_t rc = BAD_VALUE;
    size_t ip = grp->packages.size();
    bool checkOverlay = grp->overlayPackage != NULL;
    while (ip > 0 && !bestFitOverride) {
        ip--;
        int T = t;
        int E = e;

        const Package* const package = grp->packages[ip];
        const Package* const package = checkOverlay ? grp->overlayPackage : grp->packages[ip];
        if (checkOverlay) {
            checkOverlay = false;
            ip++;
        }
        if (package->header->resourceIDMap) {
            uint32_t overlayResID = 0x0;
            status_t retval = idmapLookup(package->header->resourceIDMap,
@@ -3520,12 +3527,17 @@ ssize_t ResTable::getBagLocked(uint32_t resID, const bag_entry** outBag,

    // Now collect all bag attributes from all packages.
    size_t ip = grp->packages.size();
    bool checkOverlay = grp->overlayPackage != NULL;
    while (ip > 0) {
        ip--;
        int T = t;
        int E = e;

        const Package* const package = grp->packages[ip];
        const Package* const package = checkOverlay ? grp->overlayPackage : grp->packages[ip];
        if (checkOverlay) {
            checkOverlay = false;
            ip++;
        }
        if (package->header->resourceIDMap) {
            if (performMapping) {
                uint32_t overlayResID = 0x0;
@@ -5205,7 +5217,7 @@ status_t ResTable::parsePackage(const ResTable_package* const pkg,
    
    Package* package = NULL;
    PackageGroup* group = NULL;
    uint32_t id = idmap_id != 0 ? idmap_id : dtohl(pkg->id);
    uint32_t id = dtohl(pkg->id);
    // If at this point id == 0, pkg is an overlay package without a
    // corresponding idmap. During regular usage, overlay packages are
    // always loaded alongside their idmaps, but during idmap creation
@@ -5250,8 +5262,8 @@ status_t ResTable::parsePackage(const ResTable_package* const pkg,
                return (mError=err);
            }
            group->basePackage = package;

            mPackageMap[id] = (uint8_t)idx;
            group->overlayPkgId = pkg->id;
        } else {
            group = mPackageGroups.itemAt(idx-1);
            if (group == NULL) {
@@ -5263,10 +5275,11 @@ status_t ResTable::parsePackage(const ResTable_package* const pkg,
            return (mError=err);
        }
        if (idmap_id != 0) {
            // we need to add our overlay's package ID to this group so resources that
            // only exist in the overlay are accessed from the overlay correctly
            mPackageMap[pkg->id] = (uint8_t)idx;
            group->overlayPkgId = pkg->id;
            PackageGroup* targetGroup = mPackageGroups.itemAt(mPackageMap[idmap_id] - 1);
            if (targetGroup) {
                targetGroup->overlayPackage = package;
                targetGroup->overlayPkgId = pkg->id;
            }
        }
    } else {
        LOG_ALWAYS_FATAL("Package id out of range");
@@ -5634,8 +5647,9 @@ void ResTable::removeAssetsByCookie(const String8 &packageName, void* cookie)
        size_t index = pkgCount;
        for (size_t pkgIndex = 0; pkgIndex < pkgCount; pkgIndex++) {
            const Package* pkg = pg->packages[pkgIndex];
            ALOGV("Examining pkg: %s", String8(pkg->package->name).string());
            if (String8(String16(pkg->package->name)).compare(packageName) == 0) {
            ALOGV("Examining pkg: %s cookie: %d", String8(pkg->package->name).string(),
                    (size_t)pkg->header->cookie);
            if ((size_t)pkg->header->cookie == (size_t)cookie) {
                index = pkgIndex;
                ALOGV("Delete Package %d id=%d name=%s\n",
                     (int)pkgIndex, pkg->package->id,
@@ -5651,6 +5665,14 @@ void ResTable::removeAssetsByCookie(const String8 &packageName, void* cookie)
                ALOGV("Settings id:%d to zero in mPackageMap", id);
                mPackageMap[id] = 0;
            }
            // Check if this package is being reference in any other groups and remove it
            size_t N = mPackageGroups.size();
            for (int i = 0; i < N; i++) {
                PackageGroup* grp = mPackageGroups.itemAt(i);
                if (grp->overlayPackage == pkg) {
                    grp->overlayPackage = NULL;
                }
            }
            if (pkgCount == 1) {
                ALOGV("Delete Package Group %d id=%d packageCount=%d name=%s\n",
                      (int)pgIndex, pg->id, (int)pg->packages.size(),