GMS ANR解决方案

摘要:
ANRLog如下:ANR避免方案如下:在BroadcastQueue类的processNextBroadcast方法中,当机器首次启动时,将跳过此操作。路径如下:/lps/frames/base/services/core/java.com/android/server/am/BroacastQueue.java/inimportandroid.provider.Settings//when firstboot,ingoreGoogleDuoanrhenreceivebroad:android.intent.action.LOCALE_CHANGEDif{intdeviceProvisioned=Settings.Global.getInt;if{Slog.e;skip=true;}}历史修改记录2。启动向导时的日历概率ANRANRLog如下:ANR规避方案如下:主要原因是android。内部动作。更改广播接收超时导致的LOCALE_ANR。请参见修改1历史修改记录3。启动启动向导时,ANR弹出窗口不会显示的解决方案是重新启动或恢复出厂设置。启动启动向导时,不应显示ANR。ANRLog如下:ANR避免方案如下:请参考修改1。2.当Google PlayStore下载apk概率闪回低内存时,使用PlayStore下载多个apk,PlayStore概率ANR。

GMS ANR解决方案第1张

GMS ANR解决方案第2张

极力推荐Android 开发大总结文章:欢迎收藏
程序员Android 力荐 ,Android 开发者需要的必备技能

GMS ANR解决方案第3张

GMS(GoogleMobile Service)包是出口国外手机中 Google 必须要预制,过 CTS 认证必须的。
GMS ANR解决方案第4张

极力推荐文章:欢迎收藏
Android 干货分享

GMS ANR解决方案第5张

阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android

本篇文章主要介绍 Android 开发中的部分GMS 包 相关APK ANR,闪退问题解决方案知识点,通过阅读本篇文章,您将收获以下内容:

  1. 开机向导时 Google DUO 概率ANR
  2. 开机向导时 Google Calendar 概率 ANR
  3. 开机向导时 ANR 弹框不show的解决方案
  4. 开机向导时 Google Music 概率 ANR
  5. 开机向导时 Google Play Store 概率 ANR
  6. Google play Store 下载apk 概率性闪退
1. 开机向导时 DUO 概率ANR

主要原因是 android.intent.action.LOCALE_CHANGED 广播接收超时导致的ANR。
ANR Log 如下:

ANR Log

ANR 规避方案如下:
BroadcastQueue类的 processNextBroadcast 方法中,当第一次开机时候,跳过此Action。路径如下:
/alps/frameworks/base/services/core/java/com/android/server/am/BroadcastQueue.java

         // import android.provider.Settings;
         //when frist boot , ingore Google Duo anr when receive broadcast : android.intent.action.LOCALE_CHANGED
            if (info.activityInfo.name.contains ("com.google.android.apps.tachyon") && 
                               r.intent.getAction().equals("android.intent.action.LOCALE_CHANGED")){
                 int deviceProvisioned = Settings.Global.getInt(mService.mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0);
                 if (deviceProvisioned == 0) {                  
                     Slog.e(TAG,"switch users or first boot google duo ANR ignore");
                     skip = true;
                 }
            }  

历史修改记录
git 修改记录

2. 开机向导时 Calendar 概率 ANR

ANR Log 如下:
Calendar ANR log

ANR 规避方案如下:
主要原因是 android.intent.action.LOCALE_CHANGED 广播接收超时导致的ANR。
请参考修改一
历史修改记录
git 修改记录

3. 开机向导时,ANR 弹框不show的解决方案

刷机或者恢复出厂设置是,开机向导过程中不应该显示ANR。
修改文件路径如下:
frameworks/base/services/core/java/com/android/server/am/AppErrors.java
修改AppErrors 类中 handleShowAnrUi方法,控制在开机向导时ANR弹窗。

解决方案

git 修改差别的

				// If we've created a crash dialog, show it without the lock held
       
				if (d != null) {
                     int deviceProvisioned = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED,0);
                         if(proc.userId == 0){
                             if(deviceProvisioned == 0 && !proc.processName.equals("com.google.android.setupwizard")){
                        
                                mService.killAppAtUsersRequest(proc, null);
                             }else{
                              d.show();
                            }
                         } else {
                           d.show();
                         }
				}
4. 开机向导时 Google Music 概率 ANR

开机向导时候 接收android.intent.action.LOCALE_CHANGED 广播超时导致的ANR。
ANR Log 如下:
ANR Log
ANR 规避方案如下:
请参考修改一

5.开机向导时 Google Play Store 概率 ANR

开机向导时候 接收android.intent.action.LOCALE_CHANGED 广播超时导致的ANR。
ANR Log 如下:
ANR Log
ANR 规避方案如下:
请参考修改一

2. Google play Store 下载apk 概率性闪退

低内存情况下,使用play Store 下载多个apk,playstore 概率性ANR。

闪退 Log 信息

Google Play Store 被kill Log信息

解决闪退问题方法
在ActivityManagerService 中的applyOomAdjLocked 方法中修改adj值,防止apk 低内存情况下被杀掉。

frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java 

解决闪退方案

			// add by wangjie for google play store was killed in sometime 
		    if(app.curAdj>3){
				if( app.processName.equals("com.android.vending") ||app.processName.equals("com.google.android.gms")){
                    app.curAdj = 3;
				}
			} 
			// add by wangjie for google play store was killed in sometime 

GMS ANR解决方案第5张

至此,本篇已结束,如有不对的地方,欢迎您的建议与指正。同时期待您的关注,感谢您的阅读,谢谢!

微信关注公众号: 程序员Android,领福利

本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以下内容:

  1. 多次刷机 开机向导过程中com.google.android.gms.ui Crash 解决方案
  2. 恢复出厂设置,com.google.android.gms.ui Crash 解决方案
  3. 恢复出厂,开机向导 com.google.android.setupwizard报错解决方案
  4. 恢复出厂设置或者第一次开机,先闪壁纸再显示开机向导
  5. 多次刷机com.google.android.setupwizard报错
  6. 开机向导点击 On-body com.google.android.setupwizard报错
1.多次刷机 开机向导过程中com.google.android.gms.ui Crash 解决方案

Crash Log如下:

--------- beginning of crash
01-01 00:00:16.892  2210  2473 E AndroidRuntime: FATAL EXCEPTION: IPreferenceServiceThread
01-01 00:00:16.892  2210  2473 E AndroidRuntime: Process: com.google.android.gms.ui, PID: 2210
01-01 00:00:16.892  2210  2473 E AndroidRuntime: java.lang.IllegalArgumentException: Service not registered: wfg@202e22a
01-01 00:00:16.892  2210  2473 E AndroidRuntime: 	at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1329)
01-01 00:00:16.892  2210  2473 E AndroidRuntime: 	at android.app.ContextImpl.unbindService(ContextImpl.java:1495)
01-01 00:00:16.892  2210  2473 E AndroidRuntime: 	at android.content.ContextWrapper.unbindService(ContextWrapper.java:648)
01-01 00:00:16.892  2210  2473 E AndroidRuntime: 	at android.content.ContextWrapper.unbindService(ContextWrapper.java:648)
01-01 00:00:16.892  2210  2473 E AndroidRuntime: 	at android.content.ContextWrapper.unbindService(ContextWrapper.java:648)
01-01 00:00:16.892  2210  2473 E AndroidRuntime: 	at android.content.ContextWrapper.unbindService(ContextWrapper.java:648)
01-01 00:00:16.892  2210  2473 E AndroidRuntime: 	at msl.a(:com.google.android.gms@11951440:39)
01-01 00:00:16.892  2210  2473 E AndroidRuntime: 	at wfh.run(:com.google.android.gms@11951440:5)
--------- beginning of system

当绑定服务已经解除绑定,再次解除绑定,会出现此异常

解决方案:

修改1:
在ContextWrapper的 unbindService 方法中try-catch IllegalArgumentException 。
frameworks/base/core/java/android/content/ContextWrapper.java
在ContextWrapper的 unbindService 方法中try-catch IllegalArgumentException

修改点2:
在ContextImpl的unbindService 方法中try-catch IllegalArgumentException 。
frameworks/base/core/java/android/app/ContextImpl.java

在ContextImpl的unbindService 方法中try-catch IllegalArgumentException

2.恢复出厂设置,com.google.android.gms.ui crash 解决方案

Crash Log如下:

12-31 21:01:26.711  3776  3776 E AndroidRuntime: FATAL EXCEPTION: main
12-31 21:01:26.711  3776  3776 E AndroidRuntime: Process: com.google.android.gms.ui, PID: 3776
12-31 21:01:26.711  3776  3776 E AndroidRuntime: android.view.WindowManager$BadTokenException:
                                                  Unable to add window -- token android.os.BinderProxy@f176911 is not valid; is your activity running?
12-31 21:01:26.711  3776  3776 E AndroidRuntime: 	at android.view.ViewRootImpl.setView(ViewRootImpl.java:567)
12-31 21:01:26.711  3776  3776 E AndroidRuntime: 	at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:310)
12-31 21:01:26.711  3776  3776 E AndroidRuntime: 	at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
12-31 21:01:26.711  3776  3776 E AndroidRuntime: 	at android.app.Dialog.show(Dialog.java:319)
12-31 21:01:26.711  3776  3776 E AndroidRuntime: 	at com.google.android.location.network.ConfirmAlertChimeraActivity.a(:com.google.android.gms:164)
12-31 21:01:26.711  3776  3776 E AndroidRuntime: 	at rzo.onServiceConnected(:com.google.android.gms:71)
12-31 21:01:26.711  3776  3776 E AndroidRuntime: 	at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1223)

Unable to add window -- token android.os.BinderProxy@f176911 is not valid; is your activity running

解决方案如下

ViewRootImpl类中,解决恢复出厂设置后的问题
frameworks/base/core/java/android/view/ViewRootImpl.java

 Unable to add window -- token android.os.BinderProxy@f176911 is not valid; is your activity running?

3.恢复出厂,开机向导 com.google.android.setupwizard报错解决方案

Crash Log如下:

--------- beginning of crash
01-01 12:00:00.918  1583  1583 E AndroidRuntime: FATAL EXCEPTION: main
01-01 12:00:00.918  1583  1583 E AndroidRuntime: Process: com.google.android.setupwizard, PID: 1583
01-01 12:00:00.918  1583  1583 E AndroidRuntime: java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.TIME_SET flg=0x25200010 } in com.google.android.setupwizard.time.DateTimeMonitor$1@7465601
01-01 12:00:00.918  1583  1583 E AndroidRuntime: 	at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$-android_app_LoadedApk$ReceiverDispatcher$Args_52497(LoadedApk.java:1323)
01-01 12:00:00.918  1583  1583 E AndroidRuntime: 	at android.app.-$Lambda$aS31cHIhRx41653CMnd4gZqshIQ.$m$7(Unknown Source:4)
01-01 12:00:00.918  1583  1583 E AndroidRuntime: 	at android.app.-$Lambda$aS31cHIhRx41653CMnd4gZqshIQ.run(Unknown Source:39)
01-01 12:00:00.918  1583  1583 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:790)
01-01 12:00:00.918  1583  1583 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:99)
01-01 12:00:00.918  1583  1583 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:164)
01-01 12:00:00.918  1583  1583 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:6523)
01-01 12:00:00.918  1583  1583 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
01-01 12:00:00.918  1583  1583 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
01-01 12:00:00.918  1583  1583 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)
01-01 12:00:00.918  1583  1583 E AndroidRuntime: Caused by: java.util.ConcurrentModificationException
01-01 12:00:00.918  1583  1583 E AndroidRuntime: 	at java.util.ArrayList$Itr.next(ArrayList.java:860)
01-01 12:00:00.918  1583  1583 E AndroidRuntime: 	at com.google.android.setupwizard.time.DateTimeMonitor.updateStatus(DateTimeMonitor.java:134)
01-01 12:00:00.918  1583  1583 E AndroidRuntime: 	at com.google.android.setupwizard.time.DateTimeMonitor.-wrap0(Unknown Source:0)
01-01 12:00:00.918  1583  1583 E AndroidRuntime: 	at com.google.android.setupwizard.time.DateTimeMonitor$1.onReceive(DateTimeMonitor.java:73)
01-01 12:00:00.918  1583  1583 E AndroidRuntime: 	at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$-android_app_LoadedApk$ReceiverDispatcher$Args_52497(LoadedApk.java:1313)
01-01 12:00:00.918  1583  1583 E AndroidRuntime: 	... 9 more
--------- beginning of system

ConcurrentModificationException

解决方案如下:

此问题关键在于解决ConcurrentModificationException,但是没有源码,此问题还未完全解决,尝试规避方案如下:
/frameworks/base/core/java/android/app/LoadedApk.java

 throw new RuntimeException 异常没有被try-catch 导致crash

4.恢复出厂设置或者第一次开机,先闪壁纸再显示开机向导

解决方案如下:

主要修改KeyguardServiceDelegate这个类。
frameworks/base/services/core/java/com/android/server/policy/keyguard/KeyguardServiceDelegate.java

  • 修改点1:

在此类中添加判断方法,获取手机DEVICE_PROVISIONED状态信息。

在此类中添加判断方法

  • 修改点2:

此类的构造方法中,如果获取到的为true,先隐藏

此类的构造方法中,如果获取到的为true,先隐藏

  • 修改点3:

onScreenTurningOn 中判断显示

onScreenTurningOn 中判断显示

系统原生显示与隐藏方法

5. 多次刷机com.google.android.setupwizard报错

Crash Log如下:

--------- beginning of crash
12-12 15:19:11.984  1471  1471 E AndroidRuntime: FATAL EXCEPTION: main
12-12 15:19:11.984  1471  1471 E AndroidRuntime: Process: com.google.android.setupwizard, PID: 1471
12-12 15:19:11.984  1471  1471 E AndroidRuntime: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.wizard.NEXT (has extras) }
12-12 15:19:11.984  1471  1471 E AndroidRuntime: 	at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1843)
12-12 15:19:11.984  1471  1471 E AndroidRuntime: 	at android.app.Instrumentation.execStartActivity(Instrumentation.java:1557)
12-12 15:19:11.984  1471  1471 E AndroidRuntime: 	at android.app.Activity.startActivityForResult(Activity.java:4228)
12-12 15:19:11.984  1471  1471 E AndroidRuntime: 	at android.app.Activity.startActivityForResult(Activity.java:4187)
12-12 15:19:11.984  1471  1471 E AndroidRuntime: 	at com.google.android.setupwizard.BaseActivity.startActivityForResult(BaseActivity.java:665)
12-12 15:19:11.984  1471  1471 E AndroidRuntime: 	at com.google.android.setupwizard.BaseActivity.nextAction(BaseActivity.java:651)
12-12 15:19:11.984  1471  1471 E AndroidRuntime: 	at com.google.android.setupwizard.BaseActivity.nextAction(BaseActivity.java:637)
12-12 15:19:11.984  1471  1471 E AndroidRuntime: 	at com.google.android.setupwizard.user.SuggestedActionsActivity.onItemSelected(SuggestedActionsActivity.java:226)
12-12 15:19:11.984  1471  1471 E AndroidRuntime: 	at com.android.setupwizardlib.items.RecyclerItemAdapter$1.onClick(RecyclerItemAdapter.java:106)
12-12 15:19:11.984  1471  1471 E AndroidRuntime: 	at android.view.View.performClick(View.java:5624)
12-12 15:19:11.984  1471  1471 E AndroidRuntime: 	at android.view.View$PerformClick.run(View.java:22285)

com.google.android.setupwizard 报错log

解决方案如下:

在Instrumentation 类中对Google 开机向导进行特殊处理。
/frameworks/base/core/java/android/app/Instrumentation.java

Instrumentation 类中对Google 开机向导进行特殊处理下

6. 开机向导点击 On-body com.google.android.setupwizard报错

Crash Log如下:

--------- beginning of crash
12-31 19:00:26.668  2010  2010 E AndroidRuntime: FATAL EXCEPTION: main
12-31 19:00:26.668  2010  2010 E AndroidRuntime: Process: com.google.android.setupwizard, PID: 2010
12-31 19:00:26.668  2010  2010 E AndroidRuntime: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.google.android.gms/com.google.android.gms.trustagent.discovery.OnbodyPromotionActivity}; have you declared this activity in your AndroidManifest.xml?
12-31 19:00:26.668  2010  2010 E AndroidRuntime: 	at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1805)
12-31 19:00:26.668  2010  2010 E AndroidRuntime: 	at android.app.Instrumentation.execStartActivity(Instrumentation.java:1523)
12-31 19:00:26.668  2010  2010 E AndroidRuntime: 	at android.app.Activity.startActivityForResult(Activity.java:4229)
12-31 19:00:26.668  2010  2010 E AndroidRuntime: 	at android.app.Activity.startActivityForResult(Activity.java:4188)
12-31 19:00:26.668  2010  2010 E AndroidRuntime: 	at com.google.android.setupwizard.BaseActivity.startActivityForResult(BaseActivity.java:665)
12-31 19:00:26.668  2010  2010 E AndroidRuntime: 	at com.google.android.setupwizard.BaseActivity.startFirstRunActivityForResult(BaseActivity.java:719)
12-31 19:00:26.668  2010  2010 E AndroidRuntime: 	at com.google.android.setupwizard.user.SuggestedActionsActivity.onItemSelected(SuggestedActionsActivity.java:217)
12-31 19:00:26.668  2010  2010 E AndroidRuntime: 	at com.android.setupwizardlib.items.RecyclerItemAdapter$1.onClick(RecyclerItemAdapter.java:106)
12-31 19:00:26.668  2010  2010 E AndroidRuntime: 	at android.view.View.performClick(View.java:5675)
12-31 19:00:26.668  2010  2010 E AndroidRuntime: 	at android.view.View$PerformClick.run(View.java:22641)
12-31 19:00:26.668  2010  2010 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:836)
12-31 19:00:26.668  2010  2010 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:103)
12-31 19:00:26.668  2010  2010 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:203)

Unable to find explicit activity class Log

解决方案如下:

com.google.android.setupwizard 解决方案

GMS ANR解决方案第5张

至此,本篇已结束,如有不对的地方,欢迎您的建议与指正。同时期待您的关注,感谢您的阅读,谢谢!

微信关注公众号: 程序员Android,领福利

免责声明:文章转载自《GMS ANR解决方案》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Side by Side Assembly介绍--manifest文件的使用完整UI组件库Kendo UI for Vue R3 2021下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

freemarker404解决方案(全面)

freemarker404解决方案 1,依赖问题 <!-- 引入freeMarker的依赖包. --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-...

text-indent无效解决方案

text-indent是用来字符缩进的。 1.text-indent所在的元素是行内元素而非块级元素。比如用在span,a等行内元素上。解决方案:在行内元素加上display:block; 或者把目标元素放入<div>等块级元素,然后把text-indent样式应用到<div>等块级元素。 2.text-indent所在的元素未使用...

本地缓存解决方案-Caffeine Cache

1.1 关于Caffeine Cache ​ Google Guava Cache是一种非常优秀本地缓存解决方案,提供了基于容量,时间和引用的缓存回收方式。基于容量的方式内部实现采用LRU算法,基于引用回收很好的利用了Java虚拟机的垃圾回收机制。其中的缓存构造器CacheBuilder采用构建者模式提供了设置好各种参数的缓存对象,缓存核心类LocalCa...

Visual Studio 2010单元测试(2)--运行测试并查看代码覆盖率

Visual Studio 2010 单元测试--运行测试并查看代码覆盖率 运行测试并查看代码覆盖率对程序集中的代码运行测试时,可以通过收集代码覆盖率数据来查看正在测试的项目代码部分。 运行测试并查看代码覆盖率请注意“解决方案资源管理器”中的解决方案的名称。假定解决方案的名称为 CUnitTest。 此解决方案包含测试代码。1)在“解决方案资源管理器”的“...

C#如何为程序打包发布应用(图解教程) (转)

1:新建安装部署项目 打开VS,点击新建项目,选择:其他项目类型->安装与部署->安装向导(安装项目也一样),然后点击确定.(详细见下图) 此主题相关图片如下: 2:安装向导关闭后打开安装向导,点击下一步,或者直接点击完成. 3:开始制作 安装向导完成后即可进入项目文件夹: 双击"应用程序文件夹"在右边的空白处右击,选择添加->文件,将你...

c++学习————VC报错解决方案(vc2013)

相信许多才学习c++的伙伴们,跟阿鑫一样才开始学习会遇见各种各样的奇葩问题,阿鑫会在这里总结,此篇文章会持续更新 环境,vs2013 updata5 professional windows7 一.vs2013无法打开包括文件: “SDKDDKVer.h” 1.首先打开属性 2.将次目录放入包含目录,我们的更具自己的安装目录来决定 C:Program...