summaryrefslogtreecommitdiffstats
path: root/include/androidfw
diff options
context:
space:
mode:
authorMÃ¥rten Kongstad <marten.kongstad@sonymobile.com>2014-01-31 14:43:27 +0100
committerZoran Jovanovic <zoran.jovanovic@sonymobile.com>2014-02-03 11:20:30 +0100
commit48d22323ce39f9aab003dce74456889b6414af55 (patch)
tree510aa964078d251874e2c0e7c8556f237b5710c4 /include/androidfw
parent65a05fd56dbc9fd9c2511a97f49c445a748fb3c5 (diff)
downloadframeworks_base-48d22323ce39f9aab003dce74456889b6414af55.zip
frameworks_base-48d22323ce39f9aab003dce74456889b6414af55.tar.gz
frameworks_base-48d22323ce39f9aab003dce74456889b6414af55.tar.bz2
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package. UPDATED PACKAGE MATCHING ------------------------ In Runtime resource overlay, iteration 1, only a single overlay package was considered. Package matching was based on file paths: /vendor/overlay/system/framework-res.apk corresponded to /system/framework-res.apk. Introduce a more flexible matching scheme where any package is an overlay package if its manifest includes <overlay targetPackage="com.target.package"/> For security reasons, an overlay package must fulfill certain criteria to take effect: see below. THE IDMAP TOOL AND IDMAP FILES ------------------------------ Idmap files are created by the 'idmap' binary; idmap files must be present when loading packages. For the Android system, Zygote calls 'idmap' as part of the resource pre-loading. For application packages, 'idmap' is invoked via 'installd' during package installation (similar to 'dexopt'). UPDATED FLOW ------------ The following is an outline of the start-up sequences for the Android system and Android apps. Steps marked with '+' are introduced by this commit. Zygote initialization Initial AssetManager object created + idmap --scan creates idmaps for overlays targeting 'android', \ stores list of overlays in /data/resource-cache/overlays.list AssetManager caches framework-res.apk + AssetManager caches overlay packages listed in overlays.list Android boot New AssetManager's ResTable acquired AssetManager re-uses cached framework-res.apk + AssetManager re-uses cached 'android' overlays (if any) App boot ActivityThread prepares AssetManager to load app.apk + ActivityThread prepares AssetManager to load app overlays (if any) New AssetManager's ResTable acquired as per Android boot SECURITY -------- Overlay packages are required to be pre-loaded (in /vendor/overlay). These packages are trusted by definition. A future iteration of runtime resource overlay may add support for downloaded overlays, which would likely require target and overlay signatures match for the overlay to be trusted. LOOKUP PRIORITY --------------- During resource lookup, packages are sequentially queried to provide a best match, given the constraints of the current configuration. If any package provide a better match than what has been found so far, it replaces the previous match. The target package is always queried last. When loading a package with more than one overlay, the order in which the overlays are added become significant if several packages overlay the same resource. Had downloaded overlays been supported, the install time could have been used to determine the load order. Regardless, for pre-installed overlays, the install time is randomly determined by the order in which the Package Manager locates the packages during initial boot. To support a well-defined order, pre-installed overlay packages are expected to define an additional 'priority' attribute in their <overlay> tags: <overlay targetPackage="com.target.package" priority="1234"/> Pre-installed overlays are loaded in order of their priority attributes, sorted in ascending order. Assigning the same priority to several overlays targeting the same base package leads to undefined behaviour. It is the responsibility of the vendor to avoid this. The following example shows the ResTable and PackageGroups after loading an application and two overlays. The resource lookup framework will query the packages in the order C, B, A. +------+------+- -+------+------+ | 0x01 | | ... | | 0x7f | +------+------+- -+------+------+ | | "android" Target package A | Pre-installed overlay B (priority 1) | Pre-installed overlay C (priority 2) Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
Diffstat (limited to 'include/androidfw')
-rw-r--r--include/androidfw/AssetManager.h26
-rw-r--r--include/androidfw/ResourceTypes.h24
2 files changed, 21 insertions, 29 deletions
diff --git a/include/androidfw/AssetManager.h b/include/androidfw/AssetManager.h
index e0c6183..ac47900 100644
--- a/include/androidfw/AssetManager.h
+++ b/include/androidfw/AssetManager.h
@@ -70,6 +70,12 @@ struct ResTable_config;
class AssetManager : public AAssetManager {
public:
static const char* RESOURCES_FILENAME;
+ static const char* IDMAP_BIN;
+ static const char* OVERLAY_DIR;
+ static const char* TARGET_PACKAGE_NAME;
+ static const char* TARGET_APK_PATH;
+ static const char* IDMAP_DIR;
+
typedef enum CacheMode {
CACHE_UNKNOWN = 0,
CACHE_OFF, // don't try to cache file locations
@@ -94,6 +100,7 @@ public:
* newly-added asset source.
*/
bool addAssetPath(const String8& path, int32_t* cookie);
+ bool addOverlayPath(const String8& path, int32_t* cookie);
/*
* Convenience for adding the standard system assets. Uses the
@@ -272,19 +279,14 @@ private:
void setLocaleLocked(const char* locale);
void updateResourceParamsLocked() const;
- bool createIdmapFileLocked(const String8& originalPath, const String8& overlayPath,
- const String8& idmapPath);
-
- bool isIdmapStaleLocked(const String8& originalPath, const String8& overlayPath,
- const String8& idmapPath);
-
Asset* openIdmapLocked(const struct asset_path& ap) const;
- bool getZipEntryCrcLocked(const String8& zipPath, const char* entryFilename, uint32_t* pCrc);
+ void addSystemOverlays(const char* pathOverlaysList, const String8& targetPackagePath,
+ ResTable* sharedRes, size_t offset) const;
class SharedZip : public RefBase {
public:
- static sp<SharedZip> get(const String8& path);
+ static sp<SharedZip> get(const String8& path, bool createIfNotPresent = true);
ZipFileRO* getZip();
@@ -295,6 +297,9 @@ private:
ResTable* setResourceTable(ResTable* res);
bool isUpToDate();
+
+ void addOverlay(const asset_path& ap);
+ bool getOverlay(size_t idx, asset_path* out) const;
protected:
~SharedZip();
@@ -310,6 +315,8 @@ private:
Asset* mResourceTableAsset;
ResTable* mResourceTable;
+ Vector<asset_path> mOverlays;
+
static Mutex gLock;
static DefaultKeyedVector<String8, wp<SharedZip> > gOpen;
};
@@ -342,6 +349,9 @@ private:
static String8 getPathName(const char* path);
bool isUpToDate();
+
+ void addOverlay(const String8& path, const asset_path& overlay);
+ bool getOverlay(const String8& path, size_t idx, asset_path* out) const;
private:
void closeZip(int idx);
diff --git a/include/androidfw/ResourceTypes.h b/include/androidfw/ResourceTypes.h
index 7779f7f..c022818 100644
--- a/include/androidfw/ResourceTypes.h
+++ b/include/androidfw/ResourceTypes.h
@@ -1545,39 +1545,21 @@ public:
// Return value: on success: NO_ERROR; caller is responsible for free-ing
// outData (using free(3)). On failure, any status_t value other than
// NO_ERROR; the caller should not free outData.
- status_t createIdmap(const ResTable& overlay, uint32_t targetCrc, uint32_t overlayCrc,
- 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);
- }
+ void** outData, uint32_t* outSize) const;
enum {
- IDMAP_HEADER_SIZE_BYTES = 3 * sizeof(uint32_t),
+ IDMAP_HEADER_SIZE_BYTES = 3 * sizeof(uint32_t) + 2 * 256,
};
// Retrieve idmap meta-data.
//
// This function only requires the idmap header (the first
// IDMAP_HEADER_SIZE_BYTES) bytes of an idmap file.
static bool getIdmapInfo(const void* idmap, size_t size,
- 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);
- }
+ String8* pTargetPath, String8* pOverlayPath);
void print(bool inclValues) const;
static String8 normalizeForOutput(const char* input);