Search in sources :

Example 21 with BundleImpl

use of android.taobao.atlas.framework.BundleImpl in project atlas by alibaba.

the class ResourceIdFetcher method getIdentifierWithRefection.

private int getIdentifierWithRefection(String name, String defType, String defPackage) {
    if (defType == null && defPackage == null) {
        String rawName = name;
        name = rawName.substring(name.indexOf("/") + 1);
        defType = rawName.substring(rawName.indexOf(":") + 1, rawName.indexOf("/"));
    }
    if (TextUtils.isEmpty(name) || TextUtils.isEmpty(defType)) {
        return 0;
    }
    List<Bundle> bundles = Framework.getBundles();
    if (bundles != null && !bundles.isEmpty()) {
        for (Bundle b : Framework.getBundles()) {
            String pkgName = b.getLocation();
            final String searchKey = pkgName + ":" + name;
            if (!resIdentifierMap.isEmpty() && resIdentifierMap.containsKey(searchKey)) {
                ResInfo info = resIdentifierMap.get(searchKey);
                if (info != null && info.type != null && defType != null && info.type.equals(defType)) {
                    return info.resId;
                }
            }
            BundleImpl bundle = (BundleImpl) b;
            if (bundle.getArchive().isDexOpted()) {
                ClassLoader classloader = bundle.getClassLoader();
                try {
                    if (classloader != null) {
                        StringBuilder resClass = new StringBuilder(pkgName);
                        resClass.append(".R$");
                        resClass.append(defType);
                        Class clazz = classloader.loadClass(resClass.toString());
                        int tmpResID = getFieldValueOfR(clazz, name);
                        if (tmpResID != 0) {
                            resIdentifierMap.put(searchKey, new ResInfo(defType, tmpResID));
                            return tmpResID;
                        }
                    }
                } catch (ClassNotFoundException e) {
                }
            }
        }
    }
    return 0;
}
Also used : BundleImpl(android.taobao.atlas.framework.BundleImpl) Bundle(org.osgi.framework.Bundle)

Aggregations

BundleImpl (android.taobao.atlas.framework.BundleImpl)21 ResolveInfo (android.content.pm.ResolveInfo)5 Bundle (org.osgi.framework.Bundle)5 ArrayList (java.util.ArrayList)4 ComponentName (android.content.ComponentName)3 Resources (android.content.res.Resources)3 BundleClassLoader (android.taobao.atlas.framework.BundleClassLoader)3 Field (java.lang.reflect.Field)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Intent (android.content.Intent)2 Activity (android.app.Activity)1 Application (android.app.Application)1 BroadcastReceiver (android.content.BroadcastReceiver)1 ComponentCallbacks (android.content.ComponentCallbacks)1 ActivityInfo (android.content.pm.ActivityInfo)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 ServiceInfo (android.content.pm.ServiceInfo)1 AssetManager (android.content.res.AssetManager)1 Configuration (android.content.res.Configuration)1 XmlResourceParser (android.content.res.XmlResourceParser)1