Android Question DownloadService random crash

mokrokuce

Member
Licensed User
Hello,
I have an app where I use DownloadService to download and save files. Up until recently it worked fine on my test device (Huawei P20 lite, Android 9, EMUI 9.1.0), but about 3 weeks ago it started crashing on downloading file without any message.
I use the DownloadService like this (I deliberately ommited url variable since it is a production server):
B4X:
    Dim dd As DownloadData
    dd.url = url
    dd.EventName = "dd"
    dd.Target = Me
    ProgressBar1.Visible=True
    Sleep(100)
    CallSubDelayed2(DownloadService, "StartDownload", dd)
And in the DownloadService module I have pinned the problem down to this sub:
B4X:
Private Sub StartTimer (Target As Object)
    Log("DownloadService StartTimer")
    Dim n As Notification
    n.Initialize
    Log("5")
    n.Icon = "icon"
    Log("6")
    n.Vibrate = False
    Log("7")
    n.Sound = False
    Log("8")
    n.Light = False
    Log("9")
    n.SetInfo("Downloading file...", "", Target)
    Log("10")
    Service.StartForeground(1, n)
    Log("11")
    timer1.Enabled = True
    Log("12")
    pw.PartialLock
    Log("13")
End Sub
And here is the unfiltered log output:

*** Service (downloadservice) Create ***
** Service (downloadservice) Start **
Starting download
1
2
3
4
DownloadService StartTimer
5
6
7
8
9
new HwNotificationEx
isPureColorIcon
mHWColorUtil is null get it agin
Called getWidth() on a recycle()'d bitmap! This is undefined behavior!
Called getHeight() on a recycle()'d bitmap! This is undefined behavior!
Called getGenerationId() on a recycle()'d bitmap! This is undefined behavior!
Called getHeight() on a recycle()'d bitmap! This is undefined behavior!
Called getWidth() on a recycle()'d bitmap! This is undefined behavior!
Error, cannot access an invalid/free'd bitmap here!
Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 24519 (psoftware.kompa), pid 24519 (psoftware.kompa)
obtaining output fd from tombstoned, type: kDebuggerdTombstone
received crash request for pid 24519
performing dump of process 24519 (target tid = 24519)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

So, I guess it starts crashing on this line
B4X:
n.SetInfo("Downloading file...", "", Target)
I have tried commenting the line out, and I the app doesn't crash, but what bothers me is that it crashes randomly. My guess is that this is something to do with the Icon bitmap, since in the log it is mentioned a few times.
Also, I don't know if I made something else worse by commenting the "n.setinfo" line.

I will appreciate any advice on this matter.
 

mokrokuce

Member
Licensed User
This one: https://www.b4x.com/android/forum/threads/7572 ?
If so then it is a mistake. You should use OkHttpUtils2 isntead.
I am not sure this is the same module. I attached the service module I have. I did add some lines for logging so that I could catch where it crashed.
Can I go without changing my app to use OkHttpUtils2?

Are these the full logs?
This was part of unfiltered log at the moment of crash. It is very difficult to reproduce, since I have to do the download several times in a row for the crash to happen.
 

Attachments

mokrokuce

Member
Licensed User
No, the biggest would be ~10MB.

I have seen in this post https://www.b4x.com/android/forum/threads/b4x-okhttputils2-with-wait-for.79345/ the code is practically the same for the download of files. The main difference is that the timer is not started and there is no calling for progress bar, rather the app waits for JobDone.
What if download takes a while, how can a user know what is happening?
Can there be a progress bar shown for the download?
 

Erel

Administrator
Staff member
Licensed User
I don't think that the error is related to the download. It is related to the notification. Maybe the icon file is too large.
 

mokrokuce

Member
Licensed User
As we are corresponding, I have removed the line:
B4X:
n.Icon = "icon"
...and restored:
B4X:
n.SetInfo("Downloading file...", "", Target)
...and I have not gotten any crashes since. Still, I see the notification is displayed with the default app icon.
I will try to make a loop to download several (hundreds) times and see if I get an error.

Thanks for all the replies.
 

mokrokuce

Member
Licensed User
Update:
I have since made a loop to do the download 100 times in a row.
When I remove the line
B4X:
n.Icon = "icon"
...the app downloads the file without crashing. Tested 5 times = 500 downloads.
When I bring back the line
B4X:
n.Icon = "icon"
...the download crashes randomly (1st, 21st, 3rd time etc).
I have again removed the line
B4X:
n.Icon = "icon"
...and another 100 downloads were done without crash.

I will continue without this line.
 
Top