Skip to content

Commit

Permalink
fix(core): 插件Activity在getSystemService时默认委托给宿主Activity
Browse files Browse the repository at this point in the history
而不是像ShadowContext一样默认委托给baseContext。

baseContext可能不是一个Activity,导致Dialog等代码在
getSystemService(Context.WINDOW_SERVICE)时,
得到的WindowManager缺少mParentWindow。进而在
WindowManagerGlobal#addView时,依赖
mParentWindow.adjustLayoutParamsForSubWindow初始化
WindowManager.LayoutParams的token时失败。
从而导致Dialog.show会抛出"token is null"异常。

fix #640
  • Loading branch information
shifujun committed Oct 21, 2021
1 parent 5528372 commit 80bc328
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,13 @@ public void setTheme(int resid) {
hostActivityDelegator.setTheme(resid);
}

@Override
public Object getSystemService(String name) {
if (LAYOUT_INFLATER_SERVICE.equals(name)) {
return super.getSystemService(name);
} else {
return hostActivityDelegator.getHostActivity().getImplementActivity()
.getSystemService(name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

package com.tencent.shadow.test.plugin.general_cases.lib.usecases.dialog;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.ViewGroup;

Expand Down Expand Up @@ -48,4 +51,12 @@ protected void onCreate(Bundle savedInstanceState) {

dialog.show();
}

@SuppressLint("NewApi")
@Override
protected void attachBaseContext(Context newBase) {
Configuration configuration = new Configuration();
Context context = newBase.createConfigurationContext(configuration);
super.attachBaseContext(context);
}
}

0 comments on commit 80bc328

Please sign in to comment.