多次调用ApplicationInfo.loadLabel会导致崩溃

时间:2019-03-24 17:24:55

标签: android android-package-managers egl android-applicationinfo

关于从设备中的所有应用程序(包括systemapps和userapps)获取appName,我遇到了一个严重的问题。如果数量太多,就会出现问题-在我的Samsung S7 userapps和systemapps中总和为433。

似乎可以限制对ApplicationInfo的方法“ loadLabel”进行的调用次数。例如-如果我仅从systemapps获取名称,则工作正常-如果我仅从userapps获取名称,则效果相同。但是,如果同时获取userapp和systemapp,则App崩溃-尤其是当我有一个进度条显示正在加载时。

这是JVM外部的一个异常(EGL似乎很生气),但是在致命信号出现之前,您可以看到有关打开太多文件的消息,并且无法获得resourceID。等

我的问题是-有一种简单的方法可以使它起作用吗?

我使用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'

0 个答案:

没有答案