本文主要是介绍关于monkey测试通过不同入口Intent启动app引起的anr分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题的根本原因是monkey测试时,com.android.quicksearchbox 应用查找FileExplorer应用并启动FileExploreActivity,创建对应的 task root activity,后续在发生问题期间并未有该token的activity finish及task id 被remove行为;在这个期间monkey测试大量启动了uid 0的FileExploreActivity,由于两者的启动Intent不一样,AMS处理将会创建多个FileExploreActivity实例对象,均建立在roottask activity的task id上,因此,就出现了大量的FileExploreActivity窗口及WIN DEATH,导致filedescriptor打开过多或其他问题,引起应用crash或anr等行为。
分析log如下:
第一步: 确认发生anr时的dum win问题FileExplorerActivity ,有大量的dup win taskid 78 的FileExploreActivity
01-01 13:34:05.136 759 833 I WindowManager: Input event dispatching timed out sendingto Prompt.
01-01 13:34:05.136 759 833 I WindowManager: Dump Display#0 windows:
01-01 13:34:05.138 759 833 I WindowManager: Dump Win No.275 = Window{81a08a6 u0com.xx.fileexplorer/com.xx.fileexplorer.activities.FileExploreActivity} =AppWindowToken{483d10b token=Token{5138da ActivityRecord{d3d3285 u0 com.xx.fileexplorer/.activities.FileExploreActivityt78}}}
01-01 13:34:05.215 759 833 I WindowManager: Dump Win No.35 = Window{557c393 u0com.xx.fileexplorer/com.xx.fileexplorer.activities.FileExploreActivity} =AppWindowToken{9f2eaf6 token=Token{6c42b91 ActivityRecord{5a3f1b8 u0com.xx.fileexplorer/.activities.FileExploreActivity t78}}}
第二步: 查找该task78 id最初创建者,确认是由quicksearchbox
01-01 08:03:33.381 759 824 I ActivityManager: START u0 {act=android.intent.action.MAINdat=content://applications/applications/com.xx.fileexplorer/com.xx.fileexplorer.activities.FileExploreActivityflg=0x14000000 cmp=com.android.quicksearchbox/.providers.ApplicationLauncher (has extras)} fromuid 10073 on display 0
// 查询 am_create_task task id 78
01-01 08:03:33.470 759 774 I ActivityManager: START u0 {act=android.intent.action.MAINflg=0x10200000 cmp=com.xx.fileexplorer/.activities.FileExploreActivity} fromuid 10073 on display 0
01-01 08:03:33.480 759 774 I am_create_task: [0,78]
// token 231695252
01-01 08:03:33.480 759 774 I am_create_activity: [0,231695252,78,com.xx.fileexplorer/.activities.FileExploreActivity,android.intent.action.MAIN,NULL,NULL,270532608]
第三步: 确认问题发生期间,这个task 78是否有被remove过
结论: 从01-01 08:03:33.381到发生问题 01-01 13:34:05,并未有 wm_task_removed 该task id 78
第四步: 确认发生问题期间,是否token 231695252 的Activity被finish
结论: 未被finish
第五步: 确认从taskroot Activity建立,到发生问题期间,monkey大量启动 FileExploreActivity,taskid 78
01-01 08:03:39.536 759 997 I ActivityManager: START u0 {act=android.intent.action.MAINcat=[android.intent.category.LAUNCHER] flg=0x10200000cmp=com.xx.fileexplorer/.activities.FileExploreActivity} from uid 0 ondisplay 0
01-01 08:03:39.563 759 997 I am_create_activity: [0,217736970,78,com.xx.fileexplorer/.activities.FileExploreActivity,android.intent.action.MAIN,NULL,NULL,274726912]
//…
01-0110:08:40.496 759 773 I ActivityManager: START u0{act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]flg=0x10200000 cmp=com.xx.fileexplorer/.activities.FileExploreActivity} fromuid 0 on display 0
01-0110:08:40.572 759 773 I am_create_activity:[0,186726681,78,com.xx.fileexplorer/.activities.FileExploreActivity,android.intent.action.MAIN,NULL,NULL,274726912]
// …
01-0113:32:24.161 759 773 I ActivityManager: START u0{act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]flg=0x10200000 cmp=com.xx.fileexplorer/.activities.FileExploreActivity} fromuid 0 on display 0
01-0113:32:24.266 759 773 I am_create_activity:[0,124159793,78,com.xx.fileexplorer/.activities.FileExploreActivity,android.intent.action.MAIN,NULL,NULL,274726912]
第六步:对比确认quicksearchbox、monkey、launcher启动的Intent
1) Quicksearchbox
01-01 08:03:33.470 759 774 IActivityManager: START u0 {act=android.intent.action.MAINflg=0x10200000 cmp=com.xx.fileexplorer/.activities.FileExploreActivity}from uid 10073 on display 0
2) Monkey
01-01 08:03:39.536 759 997 IActivityManager: START u0 {act=android.intent.action.MAINcat=[android.intent.category.LAUNCHER] flg=0x10200000cmp=com.xx.fileexplorer/.activities.FileExploreActivity} from uid 0 ondisplay 0
3) launcher
03-2117:22:57.937 739 754 I ActivityManager: START u0 {act=android.intent.action.MAINcat=[android.intent.category.LAUNCHER]flg=0x10200000cmp=com.xx.fileexplorer/.activities.FileExploreActivity (has extras)}from uid 10017 on display 0
结论:
根本原因是 quicksearchbox启动应用时,同monkey和launcher的Intent不一样,导致后续建立在该task上,monkey方式一直重复创建FileExplorerActivity实例,引起问题。
因此,是否quicksearchbox可以参考launcher启动应用方式添加cat标记使Intent一致,这样就不会创建多个实例对象;这篇关于关于monkey测试通过不同入口Intent启动app引起的anr分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!