当我使用“getPackageInfo”方法

时间:2017-04-10 04:55:20

标签: android package-managers

例外

java.lang.RuntimeException: Package manager has died 
at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:139)
at com.crypt.lord.e.a.f(AppHelper.java:375)
at com.crypt.lord.a.f.a(InstallListData.java:56)
at com.crypt.lord.a.f.a(InstallListData.java:34)
at com.crypt.lord.a.f.c(InstallListData.java:90)
at com.crypt.lord.impl.CryptLordServiceImpl$5.run(CryptLordServiceImpl.java:429)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.os.DeadObjectException: Transaction failed on small 
parcel; remote process probably died
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:503)
at android.content.pm.IPackageManager$Stub$Proxy.getPackageInfo(IPackageManager.ja
va:2187)
at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:134)
... 6 more   

我的代码

    public int isSystemApp(String packageName) {
    int systemApp = 1;
    int notSystemApp = 2;
    int unKnown = 3;
    if (TextUtils.isEmpty(packageName)) {
        return unKnown;
    }
    if (mContext == null) {
        return unKnown;
    }
    try {
        PackageManager packageManager = mContext.getPackageManager();
        if (packageManager != null && packageName != null) {
            PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
            if (packageInfo != null && packageInfo.applicationInfo != null && ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0)) {
                return systemApp;
            } else {
                return notSystemApp;
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return unKnown;
}

我发现了一些其他问题“包管理器已经死了”,由TransactionTooLargeException引发,答案是Binder事务的1MB限制。但是我还没有找到原因“包管理器已经死亡导致By DeadObjectException”,是PackageManagerServeice死了吗?如何解决这个问题?

0 个答案:

没有答案