Google App ANR 优化案例

和你一起终身学习,这里是程序员Android

经典好文推荐,通过阅读本文,您将收获以下知识点:

一、开机向导时 Google DUO 概率ANR
二、开机向导时 Google Calendar 概率 ANR
三、开机向导时 ANR 弹框不show的解决方案
四、开机向导时 Google Music 概率 ANR
五、开机向导时 Google Play Store 概率 ANR
六、 Google play Store 下载apk 概率性闪退

一、开机向导时 DUO 概率ANR

Log中分析主要原因是android.intent.action.LOCALE_CHANGED 广播接收超时导致的ANR

1.ANR Log 如下:

ANR Log

2.ANR 规避方案如下:

BroadcastQueue类的 processNextBroadcast方法中,当第一次开机时候,跳过此Action。

3.修改类路径如下:

/alps/frameworks/base/services/core/java/com/android/server/am/BroadcastQueue.java

public final class BroadcastQueue {
  ... ...
    final void processNextBroadcastLocked(boolean fromMsg, boolean skipOomAdj) {
        BroadcastRecord r;
          ... ...
         // 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;
                 }
            }  

        // This is safe to do even if we are skipping the broadcast, and we need
        // this information now to evaluate whether it is going to be allowed to run.
        final int receiverUid = info.activityInfo.applicationInfo.uid;
        // If it's a singleton, it needs to be the same app or a special app
          ... ...
  }
    ... ...
}

4. git diff 修改如下:

git 修改记录

二、开机向导时 Calendar 概率 ANR

1.ANR Log 如下:

Calendar ANR log

2.ANR 规避方案如下:

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

3.修改方案

请参考修改一

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

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

class AppErrors {
        ... ...
        void handleShowAppErrorUi(Message msg) {
                             ... ... 
                // 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();
                        }
                }
            ... ...
        }
        ... ...
}

1. git 解决方案

git 修改差别的

四、开机向导时 Google Music 概率 ANR

开机向导时候 接收android.intent.action.LOCALE_CHANGED 广播超时导致的ANR。

1.ANR Log 如下:

ANR Log

2. 修改方案

请参考修改一

五、开机向导时 Google Play Store 概率 ANR

开机向导时候 接收android.intent.action.LOCALE_CHANGED 广播超时导致的ANR。

1.ANR Log 如下:

ANR Log

2.ANR 规避方案如下:

请参考修改一

六、Google play Store 下载apk 概率性闪退

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

闪退 Log 信息

Google Play Store 被kill Log信息

1.解决闪退问题方法

ActivityManagerService中的applyOomAdjLocked方法中修改adj值,防止apk 低内存情况下被杀掉。
修改类如下:frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java

public class ActivityManagerService extends IActivityManager.Stub
        implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {
        ... ...
        protected boolean applyOomAdjLocked(ProcessRecord app, boolean doingAll, long now,
            long nowElapsed) {
              ... ...
            // add by  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 for google play store was killed in sometime 
            ... ...
         }
        ... ...   
}

2. 解决方案如下

解决闪退方案

至此,本篇已结束。转载网络的文章,小编觉得很优秀,欢迎点击阅读原文,支持原创作者,如有侵权,恳请联系小编删除。同时感谢您的阅读,期待您的关注。

点个在看,方便您使用时快速查找!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员Android

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值