У меня серьезная проблема с получением appName из всех приложений на устройстве - как systemapps, так и userapps.Проблема возникает, если их слишком много - в моем Samsung S7 userapps и systemapps суммируются до 433.
Кажется, существует ограничение на количество обращений к методу ApplicationInfo "loadLabel".Например, если я получаю только имя из systemapps, оно работает нормально, то же самое, если вместо этого я получаю только имена из userapps.Но если я получаю как userapps, так и systemapps, происходит сбой приложения - особенно если у меня есть индикатор загрузки, показывающий загрузку.
Это исключение вне JVM (EGL, кажется, злится), но перед фатальным сигналом можно увидеть сообщения ослишком много файлов открыто и не может получить идентификатор ресурса.и т.д.
У меня вопрос - есть ли простой способ заставить это работать?
Я использую asynctask, а вот фрагмент doInBackground
@Override
public String doInBackground(String ... params) {
//commenting out one the calls makes everything work
//if you call both the app crashces
appInfoRetriever.parseUserApps();
appInfoRetriever.parseSystemApps();
return "done! :)";
}
А вот и appInfoRetriever
public AppInfoRetriever_(Context context) {
this.context = context;
packageManager = context.getPackageManager();
packageInfoList = getInstalledPackages(context, PackageManager.GET_META_DATA);
split();
}
private void split() {
for(PackageInfo pInfo: packageInfoList) {
if(isSystemApp(pInfo.packageName))
packageInfoListS.add(pInfo);
else
packageInfoListU.add(pInfo);
}
}
public void parseUserApps() {
packageManager = context.getPackageManager();
for (PackageInfo pInfo: packageInfoListU) {
ApplicationInfo info = pInfo.applicationInfo;
parseHelper(info);
AppDataHolder appDataHolder = parseHelper(info);
appUserDataHolderList.add(appDataHolder);
}
}
public void parseSystemApps() {
packageManager = context.getPackageManager();
for (PackageInfo pInfo: packageInfoListS) {
ApplicationInfo info = pInfo.applicationInfo;
AppDataHolder appDataHolder = parseHelper(info);
appSystemDataHolderList.add(appDataHolder);
}
}
private AppDataHolder parseHelper(ApplicationInfo info) {
//namn
String appName = "";
try {
appName = info.loadLabel(packageManager).toString();
} catch(Exception e) {
System.err.println("UNDANTAG loadLabel(PackageManager)");
e.printStackTrace();
appName = "null";
}
AppDataHolder appDataHolder = new AppDataHolder();
appDataHolder.setAppName(appName);
//appDataHolderList.add(appDataHolder);
return appDataHolder;
}
А вот и критическая строка, которая нетерпима ко многим вызовам
appName = info.loadLabel(packageManager).toString();
Исключения в logcat
03-24 18:03:19.337 2288-2307/se.task.asynctrial W/ResourceType: ResTable_typeSpec entry count inconsistent: given 18, previously 25
ResTable_typeSpec entry count inconsistent: given 316, previously 454
ResTable_typeSpec entry count inconsistent: given 18, previously 25
ResTable_typeSpec entry count inconsistent: given 316, previously 454
03-24 18:03:19.346 2288-2307/se.task.asynctrial W/ResourceType: ResTable_typeSpec entry count inconsistent: given 576, previously 575
ResTable_typeSpec entry count inconsistent: given 169, previously 777
03-24 18:03:19.578 2288-2307/se.task.asynctrial W/ResourceType: ResTable_typeSpec entry count inconsistent: given 1313, previously 1357
03-24 18:03:22.029 2288-2306/se.task.asynctrial E/Parcel: fcntl(F_DUPFD_CLOEXEC) failed in Parcel::read, i is 0, fds[i] is -1, fd_count is 1, error: Too many open files
03-24 18:03:22.029 2288-2306/se.task.asynctrial I/OpenGLRenderer: Surface query width is 1440
03-24 18:03:22.030 2288-2306/se.task.asynctrial A/OpenGLRenderer: Failed to set damage region on surface 0x769e8ec780, error=EGL_BAD_ACCESS
03-24 18:03:22.059 2288-2307/se.task.asynctrial W/ziparchive: Unable to open '/system/priv-app/FingerprintService2/FingerprintService2.apk': Too many open files
03-24 18:03:22.060 2288-2307/se.task.asynctrial W/zipro: Error opening archive /system/priv-app/FingerprintService2/FingerprintService2.apk: I/O Error
03-24 18:03:22.060 2288-2307/se.task.asynctrial D/asset: failed to open Zip archive '/system/priv-app/FingerprintService2/FingerprintService2.apk'
03-24 18:03:22.067 2288-2307/se.task.asynctrial W/ResourceType: No known package when getting value for resource number 0x7f070004
03-24 18:03:22.068 2288-2307/se.task.asynctrial W/PackageManager: Failure retrieving text 0x7f070004 in package com.samsung.android.fingerprint.service
android.content.res.Resources$NotFoundException: String resource ID #0x7f070004
at android.content.res.Resources.getText(Resources.java:353)
at android.app.ApplicationPackageManager.getText(ApplicationPackageManager.java:2165)
at android.content.pm.PackageItemInfo.loadLabel(PackageItemInfo.java:173)
at se.task.asynctrial.AppInfoRetriever_.parseHelper(AppInfoRetriever_.java:88)
at se.task.asynctrial.AppInfoRetriever_.parseSystemApps(AppInfoRetriever_.java:75)
at se.task.asynctrial.AsyncLoader.doInBackground(AsyncLoader.java:34)
at se.task.asynctrial.AsyncLoader.doInBackground(AsyncLoader.java:8)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
03-24 18:03:22.071 2288-2307/se.task.asynctrial W/ziparchive: Unable to open '/system/priv-app/SamsungCamera7/SamsungCamera7.apk': Too many open files
03-24 18:03:22.071 2288-2307/se.task.asynctrial W/zipro: Error opening archive /system/priv-app/SamsungCamera7/SamsungCamera7.apk: I/O Error
03-24 18:03:22.071 2288-2307/se.task.asynctrial D/asset: failed to open Zip archive '/system/priv-app/SamsungCamera7/SamsungCamera7.apk'
03-24 18:03:22.078 2288-2307/se.task.asynctrial W/ResourceType: No known package when getting value for resource number 0x7f09012c
03-24 18:03:22.078 2288-2307/se.task.asynctrial W/PackageManager: Failure retrieving text 0x7f09012c in package com.sec.android.app.camera
android.content.res.Resources$NotFoundException: String resource ID #0x7f09012c
at android.content.res.Resources.getText(Resources.java:353)
at android.app.ApplicationPackageManager.getText(ApplicationPackageManager.java:2165)
at android.content.pm.PackageItemInfo.loadLabel(PackageItemInfo.java:173)
at se.task.asynctrial.AppInfoRetriever_.parseHelper(AppInfoRetriever_.java:88)
at se.task.asynctrial.AppInfoRetriever_.parseSystemApps(AppInfoRetriever_.java:75)
at se.task.asynctrial.AsyncLoader.doInBackground(AsyncLoader.java:34)
at se.task.asynctrial.AsyncLoader.doInBackground(AsyncLoader.java:8)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
03-24 18:03:22.080 2288-2307/se.task.asynctrial W/ziparchive: Unable to open '/system/app/Bluetooth/Bluetooth.apk': Too many open files
03-24 18:03:22.080 2288-2307/se.task.asynctrial W/zipro: Error opening archive /system/app/Bluetooth/Bluetooth.apk: I/O Error
03-24 18:03:22.080 2288-2307/se.task.asynctrial D/asset: failed to open Zip archive '/system/app/Bluetooth/Bluetooth.apk'