summaryrefslogtreecommitdiffstats
path: root/core/java/android/content
diff options
context:
space:
mode:
authord34d <clark@cyngn.com>2015-01-19 08:13:59 -0800
committerClark Scheff <clark@cyngn.com>2015-10-27 10:38:48 -0700
commit75ab08fd9c9c1645335d12eeef734ff493bd0070 (patch)
tree60d7173f54cc7e38a125a7315d9cd3e6a26eecdf /core/java/android/content
parent607f76114ba5665c9ac7866da1a42cb89ccac6f2 (diff)
downloadframeworks_base-75ab08fd9c9c1645335d12eeef734ff493bd0070.zip
frameworks_base-75ab08fd9c9c1645335d12eeef734ff493bd0070.tar.gz
frameworks_base-75ab08fd9c9c1645335d12eeef734ff493bd0070.tar.bz2
Themes: Restructure resource cache [1/2]
The new structure is as follows: /data/resource-cache/ ├─ theme1_pkg_name | ├─ target1_pkg_name | | ├─ idmap | | └─ resources.apk | ├─ target2_pkg_name | · | · | · | ├─ targetN_pkg_name | └─ icons | ├─ hash | └─ resources.apk ├─ theme2_pkg_name · · · └─ themeN_pkg_name Change-Id: Id39688c88929733b42368c1f20ef0e25848a3390
Diffstat (limited to 'core/java/android/content')
-rw-r--r--core/java/android/content/pm/ThemeUtils.java83
-rw-r--r--core/java/android/content/res/AssetManager.java15
2 files changed, 41 insertions, 57 deletions
diff --git a/core/java/android/content/pm/ThemeUtils.java b/core/java/android/content/pm/ThemeUtils.java
index 7cb2216..38391d4 100644
--- a/core/java/android/content/pm/ThemeUtils.java
+++ b/core/java/android/content/pm/ThemeUtils.java
@@ -15,7 +15,6 @@
*/
package android.content.pm;
-import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.ContentValues;
@@ -27,7 +26,6 @@ import android.content.res.Configuration;
import android.content.res.ThemeConfig;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteException;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.FileUtils;
@@ -73,8 +71,7 @@ public class ThemeUtils {
public static final String ICONS_PATH = "assets/icons/";
public static final String COMMON_RES_PATH = "assets/overlays/common/";
public static final String FONT_XML = "fonts.xml";
- public static final String RESTABLE_EXTENSION = ".arsc";
- public static final String IDMAP_PREFIX = "/data/resource-cache/";
+ public static final String RESOURCE_CACHE_DIR = "/data/resource-cache/";
public static final String IDMAP_SUFFIX = "@idmap";
public static final String COMMON_RES_SUFFIX = ".common";
public static final String COMMON_RES_TARGET = "common";
@@ -128,47 +125,40 @@ public class ThemeUtils {
};
- /*
- * Retrieve the path to a resource table (ie resource.arsc)
- * Themes have a resources.arsc for every overlay package targeted. These are compiled
- * at install time and stored in the data partition.
- *
+ /**
+ * Get the root path of the resource cache for the given theme
+ * @param themePkgName
+ * @return Root resource cache path for the given theme
*/
- public static String getResTablePath(String targetPkgName, PackageInfo overlayPkg) {
- return getResTablePath(targetPkgName, overlayPkg.applicationInfo.publicSourceDir);
+ public static String getOverlayResourceCacheDir(String themePkgName) {
+ return RESOURCE_CACHE_DIR + themePkgName;
}
- public static String getResTablePath(String targetPkgName, PackageParser.Package overlayPkg) {
- return getResTablePath(targetPkgName, overlayPkg.applicationInfo.publicSourceDir);
- }
-
- public static String getResTablePath(String targetPkgName, String overlayApkPath) {
- String restablePath = getResDir(targetPkgName, overlayApkPath) + "/resources.arsc";
- return restablePath;
- }
-
- /*
- * Retrieve the path to the directory where resource table (ie resource.arsc) resides
- * Themes have a resources.arsc for every overlay package targeted. These are compiled
- * at install time and stored in the data partition.
- *
+ /**
+ * Get the path of the resource cache for the given target and theme
+ * @param targetPkgName
+ * @param themePkg
+ * @return Path to the resource cache for this target and theme
*/
- public static String getResDir(String targetPkgName, PackageInfo overlayPkg) {
- return getResDir(targetPkgName, overlayPkg.applicationInfo.publicSourceDir);
+ public static String getTargetCacheDir(String targetPkgName, PackageInfo themePkg) {
+ return getTargetCacheDir(targetPkgName, themePkg.packageName);
}
- public static String getResDir(String targetPkgName, PackageParser.Package overlayPkg) {
- return getResDir(targetPkgName, overlayPkg.applicationInfo.publicSourceDir);
+ public static String getTargetCacheDir(String targetPkgName, PackageParser.Package themePkg) {
+ return getTargetCacheDir(targetPkgName, themePkg.packageName);
}
- public static String getResDir(String targetPkgName, String overlayApkPath) {
- String restableName = overlayApkPath.replaceAll("/", "@") + "@" + targetPkgName;
- if (restableName.startsWith("@")) restableName = restableName.substring(1);
- return IDMAP_PREFIX + restableName;
+ public static String getTargetCacheDir(String targetPkgName, String themePkgName) {
+ return getOverlayResourceCacheDir(themePkgName) + File.separator + targetPkgName;
}
+ /**
+ * Get the path to the icons for the given theme
+ * @param pkgName
+ * @return
+ */
public static String getIconPackDir(String pkgName) {
- return IDMAP_PREFIX + pkgName;
+ return getOverlayResourceCacheDir(pkgName) + File.separator + "icons";
}
public static String getIconHashFile(String pkgName) {
@@ -183,6 +173,10 @@ public class ThemeUtils {
return getIconPackDir(pkgName) + "/resources.arsc";
}
+ public static String getIdmapPath(String targetPkgName, String overlayPkgName) {
+ return getTargetCacheDir(targetPkgName, overlayPkgName) + File.separator + "idmap";
+ }
+
public static String getOverlayPathToTarget(String targetPkgName) {
StringBuilder sb = new StringBuilder();
sb.append(OVERLAY_PATH);
@@ -198,7 +192,7 @@ public class ThemeUtils {
}
public static void createCacheDirIfNotExists() throws IOException {
- File file = new File(IDMAP_PREFIX);
+ File file = new File(RESOURCE_CACHE_DIR);
if (!file.exists() && !file.mkdir()) {
throw new IOException("Could not create dir: " + file.toString());
}
@@ -206,9 +200,10 @@ public class ThemeUtils {
| FileUtils.S_IRWXG | FileUtils.S_IROTH | FileUtils.S_IXOTH, -1, -1);
}
- public static void createResourcesDirIfNotExists(String targetPkgName, String overlayApkPath)
+ public static void createResourcesDirIfNotExists(String targetPkgName, String overlayPkgName)
throws IOException {
- File file = new File(getResDir(targetPkgName, overlayApkPath));
+ createDirIfNotExists(getOverlayResourceCacheDir(overlayPkgName));
+ File file = new File(getTargetCacheDir(targetPkgName, overlayPkgName));
if (!file.exists() && !file.mkdir()) {
throw new IOException("Could not create dir: " + file.toString());
}
@@ -217,6 +212,7 @@ public class ThemeUtils {
}
public static void createIconDirIfNotExists(String pkgName) throws IOException {
+ createDirIfNotExists(getOverlayResourceCacheDir(pkgName));
File file = new File(getIconPackDir(pkgName));
if (!file.exists() && !file.mkdir()) {
throw new IOException("Could not create dir: " + file.toString());
@@ -283,18 +279,7 @@ public class ThemeUtils {
}
public static void clearIconCache() {
- deleteFilesInDir(SYSTEM_THEME_ICON_CACHE_DIR);
- }
-
- //Note: will not delete populated subdirs
- public static void deleteFilesInDir(String dirPath) {
- File fontDir = new File(dirPath);
- File[] files = fontDir.listFiles();
- if (files != null) {
- for(File file : fontDir.listFiles()) {
- file.delete();
- }
- }
+ FileUtils.deleteContents(new File(SYSTEM_THEME_ICON_CACHE_DIR));
}
public static InputStream getInputStreamFromAsset(Context ctx, String path) throws IOException {
diff --git a/core/java/android/content/res/AssetManager.java b/core/java/android/content/res/AssetManager.java
index f663c50..421701a 100644
--- a/core/java/android/content/res/AssetManager.java
+++ b/core/java/android/content/res/AssetManager.java
@@ -644,11 +644,10 @@ public final class AssetManager implements AutoCloseable {
*
* {@hide}
*/
-
- public final int addOverlayPath(String idmapPath, String resApkPath, String targetPkgPath,
- String prefixPath) {
+ public final int addOverlayPath(String idmapPath, String themeApkPath,
+ String resApkPath, String targetPkgPath, String prefixPath) {
synchronized (this) {
- int res = addOverlayPathNative(idmapPath, resApkPath, targetPkgPath,
+ int res = addOverlayPathNative(idmapPath, themeApkPath, resApkPath, targetPkgPath,
prefixPath);
makeStringBlocks(mStringBlocks);
return res;
@@ -660,7 +659,7 @@ public final class AssetManager implements AutoCloseable {
*
* {@hide}
*/
- private native final int addOverlayPathNative(String idmapPath,
+ private native final int addOverlayPathNative(String idmapPath, String themeApkPath,
String resApkPath, String targetPkgPath, String prefixPath);
/**
@@ -668,14 +667,14 @@ public final class AssetManager implements AutoCloseable {
*
* {@hide}
*/
- public final int addCommonOverlayPath(String idmapPath,
+ public final int addCommonOverlayPath(String themeApkPath,
String resApkPath, String prefixPath) {
synchronized (this) {
- return addCommonOverlayPathNative(idmapPath, resApkPath, prefixPath);
+ return addCommonOverlayPathNative(themeApkPath, resApkPath, prefixPath);
}
}
- private native final int addCommonOverlayPathNative(String idmapPath,
+ private native final int addCommonOverlayPathNative(String themeApkPath,
String resApkPath, String prefixPath);
/**