Search in sources :

Example 1 with BundleClassLoader

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

the class BundleLifecycleHandler method started.

private void started(Bundle bundle) {
    BundleImpl b = (BundleImpl) bundle;
    if (b.getClassLoader() == null || !((BundleClassLoader) b.getClassLoader()).validateClasses()) {
        return;
    }
    long time = System.currentTimeMillis();
    // load application from AndroidManifest.xml
    //        PackageLite packageLite = DelegateComponent.getPackage(b.getLocation());
    BundleListing.BundleInfo info = AtlasBundleInfoManager.instance().getBundleInfo(b.getLocation());
    if (info != null) {
        String appClassName = info.getApplicationName();
        if (StringUtils.isNotEmpty(appClassName)) {
            try {
                Log.e("BundleLifeCycle", "start " + appClassName);
                Application app = newApplication(appClassName, b.getClassLoader());
                app.onCreate();
                Log.e("BundleLifeCycle", "start finish" + appClassName);
                ((BundleImpl) bundle).setActive();
            } catch (ApplicationInitException e) {
                if (b.getArchive() != null && b.getArchive().isDexOpted()) {
                    throw new RuntimeException(e);
                }
                AtlasMonitor.getInstance().trace(AtlasMonitor.BUNDLE_APPLICATION_FAIL, bundle.getLocation(), e.getMessage(), FileUtils.getAvailableDisk());
                Log.e("BundleLifeCycle", "started application crash | " + (Looper.getMainLooper().getThread().getId() == Thread.currentThread().getId()));
            }
        } else {
            ((BundleImpl) bundle).setActive();
            Log.e("BundleLifeCycle", "started with no application");
        }
    }
}
Also used : BundleImpl(android.taobao.atlas.framework.BundleImpl) BundleClassLoader(android.taobao.atlas.framework.BundleClassLoader) BundleListing(android.taobao.atlas.bundleInfo.BundleListing) Application(android.app.Application)

Example 2 with BundleClassLoader

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

the class InstrumentationHook method callActivityOnCreate.

@Override
public void callActivityOnCreate(Activity activity, Bundle icicle) {
    if (!RuntimeVariables.androidApplication.getPackageName().equals(activity.getPackageName())) {
        mBase.callActivityOnCreate(activity, icicle);
        return;
    }
    ContextImplHook hook = new ContextImplHook(activity.getBaseContext(), activity.getClass().getClassLoader());
    if (activity.getBaseContext().getResources() != RuntimeVariables.delegateResources) {
        if (Build.VERSION.SDK_INT < 21) {
            try {
                AtlasHacks.ContextImpl_mResources.set(activity.getBaseContext(), RuntimeVariables.delegateResources);
            } catch (Throwable e) {
            }
        }
    }
    if (AtlasHacks.ContextThemeWrapper_mBase != null && AtlasHacks.ContextThemeWrapper_mBase.getField() != null) {
        //AtlasHacks.ContextThemeWrapper_mBase.on(activity).set(hook);
        AtlasHacks.ContextThemeWrapper_mBase.set(activity, hook);
    }
    AtlasHacks.ContextWrapper_mBase.set(activity, hook);
    String Location = null;
    if (activity.getClass().getClassLoader() instanceof BundleClassLoader) {
        BundleClassLoader bundleClassLoader = (BundleClassLoader) activity.getClass().getClassLoader();
        BundleImpl bundle = bundleClassLoader.getBundle();
        bundle.startBundle();
    } else if ((Location = AtlasBundleInfoManager.instance().getBundleForComponet(activity.getClass().getName())) != null) {
        //yunos, get the bundle from bundleInfoList and Frameworks
        BundleImpl bundle = (BundleImpl) Framework.getBundle(Location);
        if (bundle != null)
            bundle.startBundle();
    }
    String welcomeClassName = Framework.getProperty("android.taobao.atlas.welcome", "com.taobao.tao.welcome.Welcome");
    if (TextUtils.isEmpty(welcomeClassName)) {
        welcomeClassName = "com.taobao.tao.welcome.Welcome";
    }
    if (activity.getIntent() != null) {
        activity.getIntent().setExtrasClassLoader(RuntimeVariables.delegateClassLoader);
    }
    //        ensureResourcesInjected(activity);
    if (activity.getClass().getName().equals(welcomeClassName)) {
        mBase.callActivityOnCreate(activity, null);
    } else {
        try {
            if (isAppFirstStartAfterUpdated()) {
                mBase.callActivityOnCreate(activity, null);
            } else {
                mBase.callActivityOnCreate(activity, icicle);
            }
        } catch (RuntimeException e) {
            if ((e.toString().contains("android.content.res.Resources") || e.toString().contains("Error inflating class") || e.toString().contains("java.lang.ArrayIndexOutOfBoundsException")) && !e.toString().contains("OutOfMemoryError")) {
                HandleResourceNotFound(activity, icicle, e);
            } else {
                throw e;
            }
        }
    }
}
Also used : BundleImpl(android.taobao.atlas.framework.BundleImpl) BundleClassLoader(android.taobao.atlas.framework.BundleClassLoader)

Aggregations

BundleClassLoader (android.taobao.atlas.framework.BundleClassLoader)2 BundleImpl (android.taobao.atlas.framework.BundleImpl)2 Application (android.app.Application)1 BundleListing (android.taobao.atlas.bundleInfo.BundleListing)1