本篇文章主要介绍 ​​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​

解决方案


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

解决闪退问题方法

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