...$wux.toast

“Every problem is a gift — without problems, we would not grow.” ― Anthony Robbins

“每个问题都是一份礼物,没有问题,我们就不会成长。” 安东尼·罗宾斯

When we have to display information for a short span of time in Android, we use Toast.

当我们不得不在Android中短时间显示信息时,可以使用Toast

Here are some key features:

以下是一些主要功能:

  • It provides simple feedback about an operation in a small popup.它在小弹出窗口中提供有关操作的简单反馈。
  • It is a view containing a quick little message for the user这是一个包含给用户的简短提示的视图
  • It only fills the amount of space required for the message and the current activity remains visible and interactive.它仅填充消息所需的空间量,并且当前活动保持可见且可交互。

Recently, I started getting a major number of crashes for Toast#handleShow() on Crashlytics. Here are the logs:

最近,我开始在Crashlytics上收到Toast#handleShow()的大量崩溃。 以下是日志:

Fatal Exception: android.view.WindowManager$BadTokenException
Unable to add window -- token android.os.BinderProxy@f839de9 is not valid; is your activity running?
android.view.ViewRootImpl.setView (ViewRootImpl.java:697)
android.view.WindowManagerGlobal.addView (WindowManagerGlobal.java:347)
android.view.WindowManagerImpl.addView (WindowManagerImpl.java:94)
android.widget.Toast$TN.handleShow (Toast.java:463)
android.widget.Toast$TN$2.handleMessage (Toast.java:346)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:163)
android.app.ActivityThread.main (ActivityThread.java:6377)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:904)

Before the analysis, it's important for you to know about WindowManager.BadTokenException.

在进行分析之前,对您而言重要的是要了解WindowManager.BadTokenException。

Exception that is thrown when trying to add view whose LayoutParams LayoutParams#token is invalid.

尝试添加其LayoutParams LayoutParams#token无效的视图时引发的异常。

Lets, Look at the WindowManagerService.java file.

让我们看一下WindowManagerService.java文件。

WindowManagerService (WMS) is a system service that manages the windows on Android.

WindowManagerService(WMS)是一项系统服务,用于管理Android上的窗口。

Window Tokens:

窗口令牌:

As the name suggest, a window token is a special type of Binder token used by window manager to uniquely identify a window in the system. Window tokens are important for security reasons because they make it impossible for malicious applications to draw on top of the windows of other applications. The window manager protects against this by requiring applications to pass their application’s window token as part of each request to add or remove a window. If the tokens don’t match, the window manager rejects the request and throws a BadTokenException. Without window tokens, this necessary identification step wouldn’t be possible and the window manager wouldn’t be able to protect itself from malicious applications.

顾名思义,窗口令牌是窗口管理器用来在系统中唯一标识窗口的一种特殊类型的Binder令牌。 出于安全考虑,窗口令牌很重要,因为它们使恶意应用程序无法在其他应用程序的窗口上绘制。 窗口管理器通过要求应用程序将其应用程序的窗口令牌作为每个添加或删除窗口的请求的一部分来传递,从而防止这种情况的发生。 如果令牌不匹配,则窗口管理器拒绝该请求并抛出 BadTokenException 没有窗口令牌,将无法执行此必要的识别步骤,并且窗口管理器将无法保护自己免受恶意应用程序的攻击。

A real-world scenario:

真实场景:

When an application starts up for the first time, the ActivityManagerService creates a special kind of window token called an application window token, which uniquely identifies the application’s top-level container window. The activity manager gives this token to both the (*application) and the window manager, and it sends the token to the window manager each time it wants to add a new window to the screen. This ensures secure interaction between the application and the window manager (by making it impossible to add windows on top of other applications), and also makes it easy for the activity manager to make direct requests to the window manager.

当应用程序首次启动时, ActivityManagerService将 创建一种特殊的窗口令牌,称为应用程序窗口令牌,它唯一地标识应用程序的顶级容器窗口。 活动管理器将此令牌同时提供给(* application)和窗口管理器,并且每次要将新窗口添加到屏幕时,活动管理器都会将该令牌发送给窗口管理器。 这样可以确保应用程序和窗口管理器之间的安全交互(通过使其无法在其他应用程序之上添加窗口),还可以使活动管理器轻松直接向窗口管理器发出请求。

And the code that throws “BadTokenException”

和引发“ BadTokenException”的代码

Return WindowManagerGlobal.ADD_BAD_APP_TOKEN

返回WindowManagerGlobal.ADD_BAD_APP_TOKEN

If returned the WindowManagerGlobal.ADD_BAD_APP_TOKEN, the exception occurs when the WMS.addWindow () function is called to check whether the window to be added is not in violation of the policy according to the android window policy.

如果返回WindowManagerGlobal.ADD_BAD_APP_TOKENT他当WMS.addWindow()函数被调用,以检查是否要添加的窗口不违反根据Android的窗口策略的策略发生异常。

So now, after all, my research and analysis on BadTokenException, what I noticed about all the crashes there on Crashltyics:

所以,毕竟,现在,我对BadTokenException的研究和分析,使我注意到Crashltyics上的所有崩溃:

All were on Android 7.1 (API level 25).

所有这些都在Android 7.1 (API级别25)上。

I compared the API level 25 Toast class and others for the difference and I found an interesting thing there:

我比较了API 25级Toast类和其他类的区别,发现那里很有趣:

From API 25, Android added a new param IBinder windowToken for Toast#handleShow(), and It brought an exception.

最新文章

  1. 学习一下国际巨头互联网公司的一些运营与管理思路!
  2. python支持的数据类型float_Python基本数据类型之int 、 float
  3. ROS知识【10】:ROS通信
  4. mysql 全文检索 教程_MySQL:详细说明MySQL全文检索图文详细教程
  5. SQL Server使用convert对datetime日期数据进行转换
  6. ASP.NET中使用C#文件下载四方法
  7. input 底线_社区建设如何帮助组织的底线
  8. C#获取周一、周日的日期 函数类
  9. 面试官:问点基础,说说Object类下面有几种方法呢?
  10. Java学习视频教程
  11. 关于win10安装CPC专利软件以及win10安装office2003
  12. 嵌入式行业技术思维导图
  13. oracle hot patch david,Hotpatch文件介绍
  14. 通过商品ID和区域ID及cookie插件获取商品快递费用接口,1688快递物流费用接口,1688商品物流费用API接口获取方案
  15. 那些令人发燥的JAVA虚引用
  16. 重生之我是赏金猎人-SRC漏洞挖掘(十三)-攻防对抗/梦中绝杀X脖代理商
  17. Android获取本机号码闪退,手机号码是移动的,现在手机已经停机,想充话费却不知道本机号码,肿么查询本机号码?()...
  18. 《银杏,银杏》原文小说
  19. excel计算二元线性回归_分享一个用用Excel做回归分析
  20. 榜首易主!在线票务大战胜负已定,透过中影这个小动作早已看穿一切

热门文章

  1. 职称计算机模块intern,职称计算机考试模块试题.pdf
  2. 皮尔森类似度(Pearson Similiarity)计算举例与数学特性和存在问题
  3. 2021年西式面点师(中级)复审考试及西式面点师(中级)模拟考试
  4. 注会 第三章 存货
  5. vivo平台化实践探索之旅-平台产品系列01
  6. 12个摄影发烧友必知的常识
  7. 管理经济学知识点汇总
  8. 英语零基础怎么学计算机,零基础学英语的步骤有哪些
  9. 精伦安全模块-身份证读卡器对接-Qt调用SDK
  10. 婚恋网站有风险,网上交友须谨慎