我在几个用户(运行android 7.0 / 7.1)崩溃,我无法重现。
崩溃发生在我试图获取已安装应用程序列表的模块中。我在真正的hw和各种模拟器上测试了应用程序没有问题。
我在下面显示了我的代码的简化版本。
崩溃的路线是:
ApplicationInfo ai = packageManager.getApplicationInfo(info.packageName, 0);
函数getInstalledAppList中的。
ListApptest是一个从片段实例化的类:
ListApptest applications = new ListApp(getActivity());
我将packageManager初始化为activity.getPackageManager(),看起来getInstalledApplications()运行正常(我可以添加对返回值的检查吗?)那么可能是PackageManager $ NameNotFoundException的原因?
getInstalledApplications如何返回未知的包名?
这是我的代码:
class ListApptest {
private static final int flags = PackageManager.GET_META_DATA |
PackageManager.GET_SHARED_LIBRARY_FILES |
PackageManager.GET_UNINSTALLED_PACKAGES;
private static Context context;
private static Activity activity;
private static PackageManager packageManager;
ListApptest(Activity a, UsageStatsManager u, ListView l, ProgressBar p){
activity = a;
packageManager = activity.getPackageManager();
}
static class AppsGetInfo extends AsyncTask<Void, Void, Void> {
private List<AppsItem> listAppsItem;
@Override
protected Void doInBackground(Void... arg0) {
getInstalledApp();
return null;
}
void getInstalledApp() {
List<String> installedApps = getInstalledAppList();
}
private List<String> getInstalledAppList() {
List<ApplicationInfo> infos = packageManager.getInstalledApplications(flags);
List<String> installedApps = new ArrayList<>();
for (ApplicationInfo info : infos) {
installedApps.add(info.packageName);
try {
// CRASH HERE
ApplicationInfo ai = packageManager.getApplicationInfo(info.packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
return installedApps;
}
}
}
以下是相关的跟踪:
java.lang.RuntimeException:
at android.os.AsyncTask$3.done (AsyncTask.java:325)
at java.util.concurrent.FutureTask.finishCompletion (FutureTask.java:354)
at java.util.concurrent.FutureTask.setException (FutureTask.java:223)
at java.util.concurrent.FutureTask.run (FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run (AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:607)
at java.lang.Thread.run (Thread.java:762)
Caused by: java.lang.IllegalArgumentException:
at com.narb.listapp.Applications.ListApp$AppsGetInfo.fromUsageStat (ListApp.java:214)
at com.narb.listapp.Applications.ListApp$AppsGetInfo.buildUsageStatsWrapper (ListApp.java:201)
at com.narb.listapp.Applications.ListApp$AppsGetInfo.getInstalledApp (ListApp.java:163)
at com.narb.listapp.Applications.ListApp$AppsGetInfo.doInBackground (ListApp.java:72)
at com.narb.listapp.Applications.ListApp$AppsGetInfo.doInBackground (ListApp.java:60)
at android.os.AsyncTask$2.call (AsyncTask.java:305)
at java.util.concurrent.FutureTask.run (FutureTask.java:237)
Caused by: android.content.pm.PackageManager$NameNotFoundException:
at android.app.ApplicationPackageManager.getApplicationInfoAsUser (ApplicationPackageManager.java:484)
at android.app.ApplicationPackageManager.getApplicationInfo (ApplicationPackageManager.java:466)
at com.narb.listapp.Applications.ListApp$AppsGetInfo.fromUsageStat (ListApp.java:210)
修改
我有一个友好的测试员(不是在同一个城市)发生了崩溃。我能够得到一些数据:
在infos = packageManager.getInstalledApplications:
之后ApplicationInfo{69419b2 com.sec.factory}
ApplicationInfo{e8f5d03 com.samsung.knox.knoxtrustagent}
ApplicationInfo{4b3b480 com.android.htmlviewer},
坠机前:
com.sec.factory
com.samsung.knox.knoxtrustagent
所以它看起来像是在com.samsung.knox.knoxtrustagent崩溃?
可能是什么原因?你是如何解决这个问题的?