Google App ANR 优化案例,Golang面试题集2024版

46 阅读3分钟

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信息

img img img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Go语言开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以戳这里获取