Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix: SplitDelegateClassloader inject is not compatible with Tinker #49

Merged
merged 2 commits into from
May 11, 2021
Merged

bug fix: SplitDelegateClassloader inject is not compatible with Tinker #49

merged 2 commits into from
May 11, 2021

Conversation

xiangtailiang
Copy link

@xiangtailiang xiangtailiang commented Apr 27, 2021

tinker的从1.9.14.9版本开始,还会替换掉mBase中的mClassLoader。
com.iqiyi.android.qigsaw.core.splitload.SplitDelegateClassloader#inject的hook不彻底,只替换了mBase中的mPackageInfo里的mClassLoader,没有把mBase的mClassLoader也替换掉。

Tencent/tinker@b658362
Tinker hook的具体方法:

com.tencent.tinker.loader.NewClassLoaderInjector#doInject
  final Context baseContext = (Context) findField(app.getClass(), "mBase").get(app);
        try {
            findField(baseContext.getClass(), "mClassLoader").set(baseContext, classLoader);
        } catch (Throwable ignored) {
            // There's no mClassLoader field in ContextImpl before Android O.
            // However we should try our best to replace this field in case some
            // customized system has one.
        }
        final Object basePackageInfo = findField(baseContext.getClass(), "mPackageInfo").get(baseContext);
        findField(basePackageInfo.getClass(), "mClassLoader").set(basePackageInfo, classLoader);

而当我们使用getApplicationContext().getClassLoader()获取ClassLoader,实际上是调用了Application中的mBase.getClassLoader()。而这个mBase是frameworks/base/core/java/android/app/ContextImpl.java,里面的getClassLoader实现:

@Override
    public ClassLoader getClassLoader() {
        return mClassLoader != null ? mClassLoader : (mPackageInfo != null ? mPackageInfo.getClassLoader() : ClassLoader.getSystemClassLoader());
    }

因为mClassLoader被tinker注入了新的ClassLoader,所以会优先返回,而Qigsaw注入在mPackageInfo的ClassLoader,是无法被调用的。

@kissonchan kissonchan merged commit 78a55a8 into iqiyi:master May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants