• 10
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

GetPackageInfo results in DeadObjectException

I have the following code snippet:

 public static String getAppVersion(Context context) {

        String versionName = null;
        try {
            versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; //This is the problematic line
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        return versionName;
    }

Now according to Crashlytics, there was a case when the app crashed giving the following exception:

Caused by android.os.DeadObjectException
com.tawkon.data.lib.util.ParameterUtils.getAppVersion
    android.os.BinderProxy.transactNative (Binder.java)
    android.os.BinderProxy.transact (Binder.java:503)
    android.content.pm.IPackageManager$Stub$Proxy.getPackageInfo (IPackageManager.java:2684)
    android.app.ApplicationPackageManager.getPackageInfo (ApplicationPackageManager.java:193)
    com.tawkon.data.lib.util.ParameterUtils.getAppVersion (ParameterUtils.java:44)
    com.tawkon.data.lib.helper.analytics.NetworkRequestHelper.generateHttpRequest (NetworkRequestHelper.java:28)
    com.tawkon.data.lib.service.DataThroughputScanJobIntentService$2.onTestFinished (DataThroughputScanJobIntentService.java:342)
    com.tawkon.data.lib.collector.DataThroughputManager$1.run (DataThroughputManager.java:171) 

The device specs are Samsung with OS 6.

It seems that this is a rare crash in my case. Regardless, what can be causing this to happen? How can I prevent it from happening again?

      • 1
    • "what can be causing this to happen?" -- something crashed in an OS process. "How can I prevent it from happening again?" -- I doubt that is possible.
      • 1
    • I ran into the same problem a while back. It seems when the IPC Communication from the PackageManager tries to send too much data it somehow dies. It will stay dead until your app restarts. The only "solution" I found is to limit the data provided from getPackageInfo with it's flags.

A better way to fetch your own versionName (which I assume you are trying to do, judging your code) is to call BuildConfig.VERSION_NAME. This requires that the App is built with gradle and the version is defined in your app.gradle file.

For the PackageManager Problem itself I have a theory, though only anecdotal (copying from my comment on the question):

I ran into the same problem a while back. It seems when the IPC Communication from the PackageManager tries to send too much data it somehow dies. It will stay dead until your app restarts. The only "solution" I found is to limit the data provided from getPackageInfo with it's flags.

  • 1
Reply Report
      • 2
    • The code snippet is part of SDK, that later is added as a dependency into another app. Will your suggested solution still work in that case?
      • 2
    • If you are able to change that SDK yes. If you're unable to change it, you will have to find a work around so that you can implement your own code instead of calling this function
      • 2
    • Just to clarify, " .. and the version is defined in your app.gradle .." it should be defined in the Gradle of the app that uses my SDK? If that's the case I can't guaranty that.