Bug? NB6 crashes Sony Xperia M5 hard, forcing phone reboot

Sandman

Well-Known Member
Licensed User
For some reason NB6 crashes Sony Xperia M5 (and perhaps more phones) when using NB6.

To reproduce:
- Download the official NB6 (including the updated NB6.bas) and install
- Try the first notification
- Message on screen: "Unfortunately, System UI has stopped"

Result in pic below. After pressing OK, screen starts blinking and phone is completely unresponsive. Only way to fix this is to force a reboot.

upload_2018-8-8_15-36-22.png


It's very difficult to test, especially because the device needs to be rebooted all the time. But as far as I can tell it's the actual .Notify(id) that's causing the problem. Stuff up to that seems to work fine.

The phone is fully updated, which means it's running Android 6.0.

(I found this as I published an update for my app, now with NB6. Users are going ballistic. Needless to say, this is very stressful for me.)
 
Last edited:

Sandman

Well-Known Member
Licensed User
If I create a super simple notification like this, it works fine:

B4X:
Dim n As Notification
n.Initialize
n.Icon = "icon"
n.Sound = False
n.SetInfo("Some title", "Some text", "")
n.Notify(1)
However, if I run the "Simple notification" from NB6 and use USB debugging, these are the logs I get:

B4X:
--------- beginning of crash
FATAL EXCEPTION: main
Process: com.android.systemui, PID: 1465
java.lang.IllegalStateException: called getResPackage() on Icon(typ=BITMAP size=72x72)
    at android.graphics.drawable.Icon.getResPackage(Icon.java:182)
    at com.android.systemui.statusbar.StatusBarIconView.equals(StatusBarIconView.java:305)
    at java.util.ArrayList.contains(ArrayList.java:339)
    at com.android.systemui.statusbar.phone.StatusBarIconController.updateNotificationIcons(StatusBarIconController.java:238)
    at com.android.systemui.statusbar.phone.PhoneStatusBar.updateNotifications(PhoneStatusBar.java:1760)
    at com.android.systemui.statusbar.BaseStatusBar.addNotificationViews(BaseStatusBar.java:1839)
    at com.android.systemui.statusbar.phone.PhoneStatusBar.addNotification(PhoneStatusBar.java:1487)
    at com.android.systemui.statusbar.BaseStatusBar$6$2.run(BaseStatusBar.java:524)
    at android.os.Handler.handleCallback(Handler.java:815)
    at android.os.Handler.dispatchMessage(Handler.java:104)
    at android.os.Looper.loop(Looper.java:207)
    at android.app.ActivityThread.main(ActivityThread.java:5763)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
getAPEInfo not ape 5003
unknown object: 5367674f-200-0-000000000000422a, 0 bytes
error parsing header: -6
readlink('/proc/self/fd/266') failed: Permission denied [fd=266]
warning: unable to get realpath for the library "libpvrANDROID_WSEGL.so". Will use given name.
readlink('/proc/self/fd/266') failed: Permission denied [fd=266]
warning: unable to get realpath for the library "libged.so". Will use given name.
failed to read 27 bytes at offset 0x0000000000c95e, got 0 bytes
Failed to get GED Log Buf, err(0)
onScanSources
setConfig(46:google.vorbis.decoder, ConfigPriority(0x6f800002)) ERROR: Undefined(0x80001001)
getParameter(46:google.vorbis.decoder, ??(0x7f200406)) ERROR: UnsupportedIndex(0x8000101a)
openPcmDriver(), pcm_start(0xeb214000) fail due to cannot start channel: Broken pipe
-getHardwareBufferInfo pcm_get_htimestamp fail, ret = -1, pcm_get_error = cannot start channel: Broken pipe
b4a.example3
b4a.example3
failed to read 27 bytes at offset 0x0000000000c95e, got 0 bytes
readPage returned -1011
TRAFFIC_STATS_POLL true Token 11 num clients 11
 packet count Tx=10717 Rx=15800
notifying of data activity 2
They go on for very long, I hope I copied a reasonable amount.

Looking at the error message I get the distinct feeling that this is caused by a too large icon. (I've seen other threads in the forum where that seems to have been the problem.) However, the Smiley is 160x160 pixels, and it's resized in NB6 like this:

B4X:
smiley = LoadBitmapResize(File.DirAssets, "smiley.png", 24dip, 24dip, False)
And the comment for SmallIcon is as below, so that seems to be correct? Or?
B4X:
'Sets the status bar icon. The icon size should be 24 x 24.
 

JohnnyHamburg

Member
Licensed User
I use NB6 also since some days for an app that is on market. And I got told of some crashes in developer console only concerning Android 6. Didn't know yet why they crash.

My code for notification is:

B4X:
Sub Process_Globals
    
    Public startzeit As Long
    Public WDnotifi As Bitmap
    Public n As NB6
End Sub

Sub Service_Create
WDnotifi = LoadBitmapResize(File.DirAssets, "WDnotifi.png", 24dip, 24dip, False)

Simple_Notification
End Sub

Sub Simple_Notification
    
    n.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(WDnotifi)
    
End Sub
 

Sandman

Well-Known Member
Licensed User
I'm making progress. Will report back in the thread as soon as I have something. Thanks for pic. Sorry for short text, fighting clock
 

Sandman

Well-Known Member
Licensed User
Thanks to expert advice from @JordiCP, this is mostly solved. He took the thought of making NB6 work with a resource rather than a file and made it into reality - and as it turned out, that got rid of the crashes.

It seems that some versions of Android crashes in a really awful way when one tries to use a bitmap as icon. This means that this is the sub from NB6 that causes the problem:

B4X:
Public Sub SmallIcon (Icon As Bitmap) As NB6
    If IsBuilder Then
        NotificationBuilder.RunMethod("setSmallIcon", Array(CreateIconFromBitmap(Icon)))
    End If
    Return Me
End Sub
This is what @JordiCP came up with instead. First of all, make sure that the icon is 72x72 and in gray-scale with transparency. This is important, otherwise the icon will just be a filled box. Place the file in Objects\Res\Drawable (read-only)

Then use this code instead of SmallIcon above.

B4X:
Public Sub SmallIcon (Icon as Bitmap) As NB6
    If IsBuilder Then
        Dim jo2 As JavaObject
        jo2=Me
        Dim id As Int = jo2.RunMethod("retrieveResourceId",Null)
        NotificationBuilder.RunMethod("setSmallIcon", Array(id))       
    End If
    Return Me
End Sub

#if JAVA
public int retrieveResourceIdStatus() {
    return R.drawable.the_icon_file;
}
#End If
This is not at all as polished as it should be. For instance, the Icon as Bitmap part is not used as the icon is referenced in the Java code. But it was enough to stop the crashes and display the correct icon.

Some quick notes:
- 72x72 seems to be fine regardless of display scale
- Some devices (Jordi can comment on this) failed to get the correct icon and instead showed the app icon - but at least neither the app nor the phone did crash

Again, let me point out that this is not at all as polished as it should be, there's room for improvements.

(I'm hoping that Erel might be able to comment and adjust it to make it rock solid. :) )
 

Sandman

Well-Known Member
Licensed User
what theory?
Jordi and I tested a theory that NB6 would work out of the box on the Xperia if the icon was grayscale with transparency (as opposed to your current icon, which was in color). Sorry to say, that wasn't the solution, and instead we had to go for the solution I just posted in #11.

Do you know what devices that have reported the problem? It sure would be great if you could try this solution and see if they start working.
 

JohnnyHamburg

Member
Licensed User
I don`t want the users of my app to get serious crashes, so I went back to the simple notification yesterday. Hoping this was the problem. Maybe I try NB6 another time again.

The crashes appeared on Samsung S5 and Note4 devices but only those using Android 6.0.

But thank you anyway for finding out this problem and a solution. I will test in future.
 

Sandman

Well-Known Member
Licensed User
What is the output of this code on the failed devices
Sony Xperia M5 (the device having crashes):
B4X:
6.0
1376301686
I also have two other 6.0 devices so for completeness I ran it there too.

Alcatel Pixi 4 (no NB6 crashes):
B4X:
6.0
v3DL5-0
Motorola Moto X (no NB6 crashes):
B4X:
6.0
7
 
Top