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

Commit 578087e3 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Gerrit Code Review
Browse files

Merge "New command line tool 'idmap'"

parents 3aeb629d 65a05fd5
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -69,6 +69,7 @@ struct ResTable_config;
 */
 */
class AssetManager : public AAssetManager {
class AssetManager : public AAssetManager {
public:
public:
    static const char* RESOURCES_FILENAME;
    typedef enum CacheMode {
    typedef enum CacheMode {
        CACHE_UNKNOWN = 0,
        CACHE_UNKNOWN = 0,
        CACHE_OFF,          // don't try to cache file locations
        CACHE_OFF,          // don't try to cache file locations
@@ -218,6 +219,13 @@ public:
     */
     */
    void getLocales(Vector<String8>* locales) const;
    void getLocales(Vector<String8>* locales) const;


    /**
     * Generate idmap data to translate resources IDs between a package and a
     * corresponding overlay package.
     */
    bool createIdmap(const char* targetApkPath, const char* overlayApkPath,
        uint32_t targetCrc, uint32_t overlayCrc, uint32_t** outData, uint32_t* outSize);

private:
private:
    struct asset_path
    struct asset_path
    {
    {
+23 −2
Original line number Original line Diff line number Diff line
@@ -1545,9 +1545,19 @@ public:
    // Return value: on success: NO_ERROR; caller is responsible for free-ing
    // Return value: on success: NO_ERROR; caller is responsible for free-ing
    // outData (using free(3)). On failure, any status_t value other than
    // outData (using free(3)). On failure, any status_t value other than
    // NO_ERROR; the caller should not free outData.
    // NO_ERROR; the caller should not free outData.
    status_t createIdmap(const ResTable& overlay, uint32_t originalCrc, uint32_t overlayCrc,
    status_t createIdmap(const ResTable& overlay, uint32_t targetCrc, uint32_t overlayCrc,
                         void** outData, size_t* outSize) const;
                         void** outData, size_t* outSize) const;


    status_t createIdmap(const ResTable& overlay,
            uint32_t targetCrc, uint32_t overlayCrc,
            const char* targetPath, const char* overlayPath,
            void** outData, uint32_t* outSize) const
    {
        (void)targetPath;
        (void)overlayPath;
        return createIdmap(overlay, targetCrc, overlayCrc, outData, outSize);
    }

    enum {
    enum {
        IDMAP_HEADER_SIZE_BYTES = 3 * sizeof(uint32_t),
        IDMAP_HEADER_SIZE_BYTES = 3 * sizeof(uint32_t),
    };
    };
@@ -1556,7 +1566,18 @@ public:
    // This function only requires the idmap header (the first
    // This function only requires the idmap header (the first
    // IDMAP_HEADER_SIZE_BYTES) bytes of an idmap file.
    // IDMAP_HEADER_SIZE_BYTES) bytes of an idmap file.
    static bool getIdmapInfo(const void* idmap, size_t size,
    static bool getIdmapInfo(const void* idmap, size_t size,
                             uint32_t* pOriginalCrc, uint32_t* pOverlayCrc);
                             uint32_t* pTargetCrc, uint32_t* pOverlayCrc);

    static bool getIdmapInfo(const void* idmap, size_t size,
            uint32_t* pTargetCrc, uint32_t* pOverlayCrc,
            String8* pTargetPath, String8* pOverlayPath)
    {
        if (*pTargetPath)
            *pTargetPath = String8();
        if (*pOverlayPath)
            *pOverlayPath = String8();
        return getIdmapInfo(idmap, size, pTargetCrc, pOverlayCrc);
    }


    void print(bool inclValues) const;
    void print(bool inclValues) const;
    static String8 normalizeForOutput(const char* input);
    static String8 normalizeForOutput(const char* input);
+25 −0
Original line number Original line Diff line number Diff line
@@ -83,6 +83,8 @@ static Asset* const kExcludedAsset = (Asset*) 0xd000000d;


static volatile int32_t gCount = 0;
static volatile int32_t gCount = 0;


const char* AssetManager::RESOURCES_FILENAME = "resources.arsc";

namespace {
namespace {
    // Transform string /a/b/c.apk to /data/resource-cache/a@b@c.apk@idmap
    // Transform string /a/b/c.apk to /data/resource-cache/a@b@c.apk@idmap
    String8 idmapPathForPackagePath(const String8& pkgPath)
    String8 idmapPathForPackagePath(const String8& pkgPath)
@@ -239,6 +241,29 @@ bool AssetManager::addAssetPath(const String8& path, int32_t* cookie)
    return true;
    return true;
}
}


bool AssetManager::createIdmap(const char* targetApkPath, const char* overlayApkPath,
        uint32_t targetCrc, uint32_t overlayCrc, uint32_t** outData, uint32_t* outSize)
{
    AutoMutex _l(mLock);
    const String8 paths[2] = { String8(targetApkPath), String8(overlayApkPath) };
    ResTable tables[2];

    for (int i = 0; i < 2; ++i) {
        asset_path ap;
        ap.type = kFileTypeRegular;
        ap.path = paths[i];
        Asset* ass = openNonAssetInPathLocked("resources.arsc", Asset::ACCESS_BUFFER, ap);
        if (ass == NULL) {
            ALOGW("failed to find resources.arsc in %s\n", ap.path.string());
            return false;
        }
        tables[i].add(ass, (void*)1, false);
    }

    return tables[0].createIdmap(tables[1], targetCrc, overlayCrc,
            targetApkPath, overlayApkPath, (void**)outData, outSize) == NO_ERROR;
}

bool AssetManager::isIdmapStaleLocked(const String8& originalPath, const String8& overlayPath,
bool AssetManager::isIdmapStaleLocked(const String8& originalPath, const String8& overlayPath,
                                      const String8& idmapPath)
                                      const String8& idmapPath)
{
{
+1 −1
Original line number Original line Diff line number Diff line
@@ -5368,7 +5368,7 @@ status_t ResTable::createIdmap(const ResTable& overlay, uint32_t originalCrc, ui
                | (0x00ff0000 & ((typeIndex+1)<<16))
                | (0x00ff0000 & ((typeIndex+1)<<16))
                | (0x0000ffff & (entryIndex));
                | (0x0000ffff & (entryIndex));
            resource_name resName;
            resource_name resName;
            if (!this->getResourceName(resID, true, &resName)) {
            if (!this->getResourceName(resID, false, &resName)) {
                ALOGW("idmap: resource 0x%08x has spec but lacks values, skipping\n", resID);
                ALOGW("idmap: resource 0x%08x has spec but lacks values, skipping\n", resID);
                // add dummy value, or trimming leading/trailing zeroes later will fail
                // add dummy value, or trimming leading/trailing zeroes later will fail
                vector.push(0);
                vector.push(0);