• 11

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


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

I have a started foreground service. I've taken care to return START_STICKY from onStartCommand. I've observed that foreground services don't run indefinitely but are periodically terminated by an Android internal module called the RestartProcessManager. Essentially a process LRU is maintained and the newly terminated service gets scheduled again if it's configured to do so(sticky or not).

The issue I'm facing is with how the restart is being handled. Logcat indicates the service intent was being delivered, but failed because the "process is bad"

After scouring through other sources I was led to believe that there's a memory leak within my service. To validate this claim I created a vanilla foreground service that did nothing other than log a statement during onStartCommand within the same app. This too observed the same issue.

Tried the exact same thing in a new project (with a new package name obviously) and service restarts worked perfectly fine. Also, I simulate a restart by clicking the red cross button under studio->logcat (which essentially kills the process). Anyway, the service intent was successfully delivered this time and the service was up and running again. I assumed it could be some dependencies in my project that may be messing in some manner. I replicated the dependencies in the new project and it continued to work as expected.

Now this is where it gets absurd. I change the package name in the buggy project and I don't encounter the issue anymore. I'd have settled for this as a fix because I spent close to 2 days diagnosing this, but changing the package name isn't feasible for me as my app is published already.

Edit-1: I must mention that I've observed this currently on my device running Oreo(one plus 5)

Edit-2: The service is running in the same process as the app. And I've included the logcat dump as well.

02-15 14:26:50.850  1395  1445 D RestartProcessManager: updateSelf :  com.ambee, size : 30
02-15 14:26:50.852  1395  1445 D RestartProcessManager: com.ambee got score 26.17240489145331 in DayDuration for duration : 525176
02-15 14:26:50.853  1395  1445 D RestartProcessManager: com.ambee got score 99.80218232889891 in DayLRU for LRU diff : 47707034
02-15 14:26:50.853  1395  1445 D RestartProcessManager: com.ambee got score 90.9090909090909 in DayLaunchTimes for launch times : 10
02-15 14:26:50.854  1395  1445 D RestartProcessManager: com.ambee : X : 2727.272727272727, Y : 785.1721467435993, Z : 2994.0654698669673
02-15 14:26:51.082  1395  1445 I ActivityManager: Killing 13839:com.ambee/u0a260 (adj 200): [BgDetect][RNK] kill com.ambee (uid 10260) usage 4
02-15 14:26:51.083  1395  1445 D ActivityManager: Process com.ambee has 1 services
02-15 14:26:51.083  1395  1445 W ActivityManager: Scheduling restart of crashed service com.ambee/.vson.LinkService in 10996ms
02-15 14:26:51.084  1395  1445 D EmbryoManager: prepare com.ambee user 0
02-15 14:26:51.099  3710  3710 D NotificationListener: onNotificationRemoved# hash: 68226270 sbn: StatusBarNotification(pkg=com.ambee user=UserHandle{0} id=903 tag=null key=0|com.ambee|903|null|10260: Notification(channel=default pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x72 color=0x00000000 actions=2 vis=PRIVATE))
02-15 14:26:54.121  1395  1444 I ActivityManager: Start proc 22570:com.ambee/u0a260 for embryo com.ambee
02-15 14:26:54.121  1395  1444 D Embryo_Uterus: Embryo created.com.ambee, pid=22570
02-15 14:26:54.796 22570 22570 D Embryo  : preload com.ambee, 10ms, hwui=true, layout=false, decor=false
02-15 14:27:02.084  1395  1445 W ActivityManager: Unable to launch app com.ambee/10260 for service Intent { cmp=com.ambee/.vson.LinkService }: process is bad
02-15 14:27:04.214  1395  1444 D Embryo_Uterus: rank:63, com.ambee, 35767806
      • 1
    • Have you tried de-installing the app with adb before reinstalling? I have sometimes issues that android is faking the uninstall and maybe there is something wrong with caches in the device or something. Also you need to call startForeground(context,Notification) within 5 seconds of calling startForegroundService(). But I guess you are doing that because otherwise you should get an ANR (at least this is the behaviour on 8.1).
      • 1
    • I have so far tried: uninstalling the app, restarting the phone, wiping the cache all to no effect. I am indeed calling startForeground in quick succession.
      • 2
    • I had a just a simple log statement in onTaskRemoved before calling super. It prevented my foreground service from restarting on the Redmi Note 4. I could never explain it - I ended up not overriding it at all. I wouldn't suggest hard resetting your device - whatever issues you are having now, will be experienced in production by your users. You'll curse that you can no longer replicate the issue when the reports start to come in... I'm out of suggestions for now, but I strongly advise to hang in there & solve it! A complete memory dump from a full day's usage would be my next suggestion

For your vanilla version of your service, consider followings:

1- uninstall your app 2- reboot your device 3- reinstall your vanilla service version to just logging.

It should work.

For your foreground service consider using stopSelf or stopService methods and not stopForegroundService method. stopForegroundService just stop the service from being a foreground. It does not stop it from being a background service. It restarts over and over and if your service going to crash or not doing his job within 5 seconds, so OS kill your service over and over and eventually your service is going to blacklist of OS.

  • 2
Reply Report

It annoyed me that the system wouldn't restart my service until I rebooted the box. Then I found this trick to clear the crash counts much more quickly:

adb shell killall system_server
  • 0
Reply Report