15

I launched app into BETA testing and multiple users with 4.4 Devices reported that the app causes whole phone to crash, phone pretty much restarts after app launch even though app doesn't even have such permissions.

The report I got from testers is as follows:

java.lang.RuntimeException: bad array lengths
at android.os.Parcel.readIntArray(Parcel.java:820)
at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:348)
at android.app.NotificationManager.notify(NotificationManager.java:139)
at android.app.NotificationManager.notify(NotificationManager.java:112)
at als.wakeup.Awake_Alarm$MyLocationListener.onLocationChanged(Awake_Alarm.java:272)
at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:279)
at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:208)
at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:224)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)

This works fine on 4.2, 4.3 but it seems that Galaxy Note 3 and Galaxy S5 which run 4.4 restart.

What could the cause be? Is it app related or could it be glitch in new OS?

Just found out it works fine on Xperia Z1 with 4.4 and no crashes. It seems that only samsung causes this, any tips?

Notification Creating function:

public Notification CreateNotification(double distance){


    Intent notificationIntentStop = new Intent(this.getApplicationContext(), StopService.class);
    PendingIntent contentIntentStop = PendingIntent.getActivity(this.getApplicationContext(), 0, notificationIntentStop, 0);


    Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.logo);
    Shortcuts shorts = new Shortcuts(this);
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.logo)
            .setContentTitle("Localarm Running")
            .setLargeIcon(largeIcon);
    //mBuilder.addAction(R.drawable.ico, "Stop", contentIntentStop);
    if(distance > 0){
    mBuilder.setContentText(String.valueOf(roundTwoDecimals(shorts.ConvertUnits(distance))+" "+shorts.GetUnitNames(distance)+" to Alarm."));
    }
    else{
    mBuilder.setContentText(String.valueOf("You've reached your destination"));
    }
    mBuilder.setPriority(Notification.PRIORITY_MAX);
    Notification bui = mBuilder.build();

    bui.flags|= Notification.FLAG_NO_CLEAR;
        Intent notificationIntent = new Intent(this.getApplicationContext(), Intro.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, notificationIntent, 0);
        bui.contentIntent = contentIntent;



    return bui;

}

it gets called by: onLocationChanged()

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);        
    notificationManager.notify(0, CreateNotification(dist_difference-alert_range));
arleitiss
  • 1,304
  • 1
  • 14
  • 38
  • Would this do anything ? http://stackoverflow.com/questions/13463727/readbooleanarray-throws-runtimeexceptionbad-array-lengths – Nabin Aug 24 '14 at 01:27
  • and may be similar http://stackoverflow.com/questions/7988018/custom-notification-java-lang-runtimeexception-bad-array-lengths – Nabin Aug 24 '14 at 01:31
  • I saw those befure, but what bothers me is that code works perfect on all other phones and OS, even same OS but Sony phone, yet on Samsung it crashes. – arleitiss Aug 24 '14 at 03:08
  • 1
    Surely its about the memory – Nabin Aug 24 '14 at 03:24
  • What's line Awake_Alarm.java:272? Check if [this](http://stackoverflow.com/a/20830017/1777090) is issue in your case – MysticMagicϡ Aug 26 '14 at 11:41
  • The line 272: notificationManager.notify(0, CreateNotification(dist_difference-alert_range)); – arleitiss Aug 28 '14 at 12:39
  • Can you add example code to reproduce the issue? – ozbek Aug 29 '14 at 07:10
  • @shoerat I've updated question with code. – arleitiss Aug 29 '14 at 12:33
  • Calling `CreateNotification(-1)`, `CreateNotification(0)` or `CreateNotification(10)` is not failing and I can see a "Localarm Running" notification in status bar on my Galaxy S5. Is there some specific argument that needs to be supplied for the error to occur? – ozbek Aug 29 '14 at 12:51
  • Some key points: *App works fine on all phones expect Samsung 4.4 Version android. *The onLocationChanged is in background service, so it's calling notification from background service. – arleitiss Aug 29 '14 at 12:59
  • I tested the above code on Samsung Galaxy S5 with Android 4.4.2 and showed the notification from a background service. The only difference is that I did not wait for location change. – ozbek Aug 29 '14 at 13:53
  • Well so what could it be? Is there any alternative way I could get this to work? – arleitiss Aug 29 '14 at 14:18
  • 2
    It looks like a bug in the IPC implementation. From the id you pass in notify, an array of length 1 called idOut will be created in NotificationManager. Then this will call an implementation of INotificationManager (basically a Binder) through IPC marshalling that array. When Parcel unmarshalls the same array, its size does not match with what it expects and thus it throws an Exception. That's my best guess from the framework source code, but I have no idea if it can be fixed at all – Gil Vegliach Aug 29 '14 at 16:09
  • If only this was reproducible locally...:) – ozbek Sep 01 '14 at 01:01
  • @ozbek Did you end up finding a workout for this crash? I'm running into this problem. – Marco RS Jul 22 '15 at 01:04
  • @Marco: No, I never was able to reproduce it. – ozbek Jul 22 '15 at 04:26

1 Answers1

2

This is an issue in Android. Unfortunately, I don't think you can do anything about it.

Malcolm
  • 41,014
  • 11
  • 68
  • 91