Search in sources :

Example 1 with BundlePackageManager

use of android.taobao.atlas.runtime.newcomponent.BundlePackageManager in project atlas by alibaba.

the class InstrumentationHook method execStartActivityInternal.

private ActivityResult execStartActivityInternal(final Context context, final Intent intent, final int requestCode, ExecStartActivityCallback callback) {
    //intent.putExtra("atlas_wrapper",true);
    /**
         * bundle update后可能需要预处理
         */
    Log.e("InsturmentationHook", "patch execStartActivity start");
    if (BundlePackageManager.isNeedCheck(intent)) {
        List<org.osgi.framework.Bundle> bundles = Atlas.getInstance().getBundles();
        for (org.osgi.framework.Bundle bundle : bundles) {
            if (((BundleImpl) bundle).isUpdated()) {
                BundlePackageManager packageManager = ((BundleImpl) bundle).getPackageManager();
                if (null != packageManager && packageManager.wrapperActivityIntentIfNeed(intent) != null) {
                    break;
                }
            }
        }
    }
    if (intent != null) {
        Atlas.getInstance().checkDownGradeToH5(intent);
    }
    // Get package name and component name
    String packageName = null;
    String componentName = null;
    if (intent.getComponent() != null) {
        packageName = intent.getComponent().getPackageName();
        componentName = intent.getComponent().getClassName();
    } else {
        ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent, 0);
        if (resolveInfo != null && resolveInfo.activityInfo != null) {
            packageName = resolveInfo.activityInfo.packageName;
            componentName = resolveInfo.activityInfo.name;
        }
    }
    if (componentName == null) {
        ActivityResult result = null;
        try {
            // Just invoke callback since component is null
            result = callback.execStartActivity();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
    // Taobao may start a component not exist in com.taobao.taobao package.
    if (!StringUtils.equals(context.getPackageName(), packageName)) {
        if (sOnIntentRedirectListener != null) {
            Activity sourceActivity = ActivityTaskMgr.getInstance().peekTopActivity();
            if (!sOnIntentRedirectListener.onExternalRedirect(intent, packageName, componentName, sourceActivity)) {
                Log.e("InstrumentationHook", "fiter app" + packageName);
                return null;
            }
        }
        return callback.execStartActivity();
    }
    String bundleName = AtlasBundleInfoManager.instance().getBundleForComponet(componentName);
    if (!TextUtils.isEmpty(bundleName)) {
        BundleImpl impl = (BundleImpl) Atlas.getInstance().getBundle(bundleName);
        if (impl != null && impl.checkValidate()) {
            return callback.execStartActivity();
        } else {
            if (ActivityTaskMgr.getInstance().peekTopActivity() != null && Looper.getMainLooper().getThread().getId() == Thread.currentThread().getId()) {
                final String component = componentName;
                asyncStartActivity(context, bundleName, intent, requestCode, component, callback);
            } else {
                callback.execStartActivity();
                Log.e("InsturmentationHook", "patch execStartActivity finish");
            }
        }
        return null;
    }
    // Try to get class from system Classloader
    try {
        Class<?> clazz = null;
        clazz = Framework.getSystemClassLoader().loadClass(componentName);
        if (clazz != null) {
            return callback.execStartActivity();
        }
    } catch (ClassNotFoundException e) {
        fallBackToClassNotFoundCallback(context, intent, componentName);
    }
    return null;
}
Also used : BundleImpl(android.taobao.atlas.framework.BundleImpl) Bundle(android.os.Bundle) BundlePackageManager(android.taobao.atlas.runtime.newcomponent.BundlePackageManager) Activity(android.app.Activity) ResolveInfo(android.content.pm.ResolveInfo)

Aggregations

Activity (android.app.Activity)1 ResolveInfo (android.content.pm.ResolveInfo)1 Bundle (android.os.Bundle)1 BundleImpl (android.taobao.atlas.framework.BundleImpl)1 BundlePackageManager (android.taobao.atlas.runtime.newcomponent.BundlePackageManager)1