Search code examples
androidserviceipcforeground-service

does a remote bound service get foreground affinity of process it is bound to?


I have an app that has two Processes. Lets call them Main and Remote. Both have services. The Main process service is a foreground service (with a notification). The Remote service is bound to the main process but is not itself foreground (no notification, no call to startForeground).

The question is will android consider Remote service foreground since it is bound to a foreground process?

I tried to suss this info out of the adb, but as far as I can tell the info is not there:

* ServiceRecord{eb553a7 u0 com.example.app/.remote.remoteProcess.ipcCommunication.RemoteProcessService}
    intent={cmp=com.example.app/.remote.remoteProcess.ipcCommunication.RemoteProcessService}
    packageName=com.example.app
    processName=com.example.app:remote
    baseDir=/data/app/com.example.app-2/base.apk
    dataDir=/data/user/0/com.example.app
    app=ProcessRecord{d194a7f 11618:com.example.app:remote/u0a222}
    createTime=-8m5s459ms startingBgTimeout=--
    lastActivity=-45s353ms restartTime=-7m29s395ms createdFromFg=true
    startRequested=true delayedStop=false stopIfKilled=false callStart=true lastStartId=11
    Bindings:
    * IntentBindRecord{608134d CREATE}:
      intent={cmp=com.example.app/.remote.remoteProcess.ipcCommunication.RemoteProcessService}
      binder=android.os.BinderProxy@1dfde02
      requested=true received=true hasBound=true doRebind=false
      * Client AppBindRecord{9825313 ProcessRecord{8cb8fdb 11552:com.example.app/u0a222}}
        Per-process Connections:
          ConnectionRecord{40c25cb u0 CR com.example.app/.remote.remoteProcess.ipcCommunication.RemoteProcessService:@5a6e89a}
    All Connections:
      ConnectionRecord{40c25cb u0 CR com.example.app/.remote.remoteProcess.ipcCommunication.RemoteProcessService:@5a6e89a}

Solution

  • I believe the answer you are looking for is here:

    An app is considered to be in the foreground if any of the following is true:

    ... Another foreground app is connected to the app, either by binding to one of its services or by making use of one of its content providers...