use of android.content.res.PackageRedirectionMap in project android_frameworks_base by ParanoidAndroid.
the class ActivityThread method attachThemeAssets.
/**
* Attach the necessary theme asset paths and meta information to convert an
* AssetManager to being globally "theme-aware".
*
* @param assets
* @param theme
* @return true if the AssetManager is now theme-aware; false otherwise.
* This can fail, for example, if the theme package has been been
* removed and the theme manager has yet to revert formally back to
* the framework default.
*/
private boolean attachThemeAssets(AssetManager assets, CustomTheme theme) {
IAssetRedirectionManager rm = getAssetRedirectionManager();
if (rm == null) {
return false;
}
PackageInfo pi = null;
try {
pi = getPackageManager().getPackageInfo(theme.getThemePackageName(), 0, UserHandle.myUserId());
} catch (RemoteException e) {
}
if (pi != null && pi.applicationInfo != null && pi.themeInfos != null) {
String themeResDir = pi.applicationInfo.publicSourceDir;
int cookie = assets.attachThemePath(themeResDir);
if (cookie != 0) {
String themePackageName = theme.getThemePackageName();
String themeId = theme.getThemeId();
int N = assets.getBasePackageCount();
for (int i = 0; i < N; i++) {
String packageName = assets.getBasePackageName(i);
int packageId = assets.getBasePackageId(i);
/*
* For now, we only consider redirections coming from the
* framework or regular android packages. This excludes
* themes and other specialty APKs we are not aware of.
*/
if (packageId != 0x01 && packageId != 0x7f) {
continue;
}
try {
PackageRedirectionMap map = rm.getPackageRedirectionMap(themePackageName, themeId, packageName);
if (map != null) {
assets.addRedirections(map);
}
} catch (RemoteException e) {
Log.e(TAG, "Failure accessing package redirection map, removing theme support.");
assets.detachThemePath(themePackageName, cookie);
return false;
}
}
assets.setThemePackageName(theme.getThemePackageName());
assets.setThemeCookie(cookie);
return true;
} else {
Log.e(TAG, "Unable to attach theme assets at " + themeResDir);
}
}
return false;
}
use of android.content.res.PackageRedirectionMap in project android_frameworks_base by ParanoidAndroid.
the class AssetRedirectionManagerService method generatePackageRedirectionMap.
private PackageRedirectionMap generatePackageRedirectionMap(RedirectionKey key) {
AssetManager assets = new AssetManager();
boolean frameworkAssets = key.targetPackageName.equals("android");
if (!frameworkAssets) {
PackageInfo pi = getPackageInfo(mContext, key.targetPackageName);
if (pi == null || pi.applicationInfo == null || assets.addAssetPath(pi.applicationInfo.publicSourceDir) == 0) {
Log.w(TAG, "Unable to attach target package assets for " + key.targetPackageName);
return null;
}
}
PackageInfo pi = getPackageInfo(mContext, key.themePackageName);
if (pi == null || pi.applicationInfo == null || pi.themeInfos == null || assets.addAssetPath(pi.applicationInfo.publicSourceDir) == 0) {
Log.w(TAG, "Unable to attach theme package assets from " + key.themePackageName);
return null;
}
PackageRedirectionMap resMap = new PackageRedirectionMap();
/*
* Apply a special redirection hack for the highest level <style>
* replacing @android:style/Theme.
*/
if (frameworkAssets) {
int themeResourceId = findThemeResourceId(pi.themeInfos, key.themeId);
assets.generateStyleRedirections(resMap.getNativePointer(), android.R.style.Theme, themeResourceId);
}
Resources res = new Resources(assets, null, null);
generateExplicitRedirections(resMap, res, key.themePackageName, key.targetPackageName);
return resMap;
}
use of android.content.res.PackageRedirectionMap in project android_frameworks_base by ParanoidAndroid.
the class AssetRedirectionManagerService method getPackageRedirectionMap.
@Override
public PackageRedirectionMap getPackageRedirectionMap(String themePackageName, String themeId, String targetPackageName) throws RemoteException {
synchronized (mRedirections) {
RedirectionKey key = new RedirectionKey();
key.themePackageName = themePackageName;
key.themeId = themeId;
key.targetPackageName = targetPackageName;
PackageRedirectionMap map = mRedirections.get(key);
if (map != null) {
return map;
} else {
map = generatePackageRedirectionMap(key);
if (map != null) {
mRedirections.put(key, map);
}
return map;
}
}
}
use of android.content.res.PackageRedirectionMap in project android_frameworks_base by ParanoidAndroid.
the class AssetRedirectionManagerService method dump.
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
synchronized (mRedirections) {
final ArrayList<RedirectionKey> filteredKeySet = new ArrayList<RedirectionKey>();
for (Map.Entry<RedirectionKey, PackageRedirectionMap> entry : mRedirections.entrySet()) {
PackageRedirectionMap map = entry.getValue();
if (map != null && map.getPackageId() != -1) {
filteredKeySet.add(entry.getKey());
}
}
Collections.sort(filteredKeySet, new Comparator<RedirectionKey>() {
@Override
public int compare(RedirectionKey a, RedirectionKey b) {
int comp = a.themePackageName.compareTo(b.themePackageName);
if (comp != 0) {
return comp;
}
comp = a.themeId.compareTo(b.themeId);
if (comp != 0) {
return comp;
}
return a.targetPackageName.compareTo(b.targetPackageName);
}
});
pw.println("Theme asset redirections:");
String lastPackageName = null;
String lastId = null;
Resources themeRes = null;
for (RedirectionKey key : filteredKeySet) {
if (lastPackageName == null || !lastPackageName.equals(key.themePackageName)) {
pw.println("* Theme package " + key.themePackageName + ":");
lastPackageName = key.themePackageName;
themeRes = getUnredirectedResourcesForPackage(mContext, key.themePackageName);
}
if (lastId == null || !lastId.equals(key.themeId)) {
pw.println(" theme id #" + key.themeId + ":");
lastId = key.themeId;
}
pw.println(" " + key.targetPackageName + ":");
Resources targetRes = getUnredirectedResourcesForPackage(mContext, key.targetPackageName);
PackageRedirectionMap resMap = mRedirections.get(key);
int[] fromIdents = resMap.getRedirectionKeys();
int N = fromIdents.length;
for (int i = 0; i < N; i++) {
int fromIdent = fromIdents[i];
int toIdent = resMap.lookupRedirection(fromIdent);
String fromName = targetRes != null ? targetRes.getResourceName(fromIdent) : null;
String toName = themeRes != null ? themeRes.getResourceName(toIdent) : null;
pw.println(String.format(" %s (0x%08x) => %s (0x%08x)", fromName, fromIdent, toName, toIdent));
}
}
}
}
Aggregations