Dealing with Samsung SPCM killer
<p>Lately we acquired a new Galaxy S6 with Android 5.1.1 and we are having some troubles with the new Samsung SPCM memory manager that comes with it. It is aggressively closing our app's background service, which even though is set to START_STICKY, it is not being restarted. </p>

<p>Additionally, the service takes no more than 5MB of RAM, but still somehow we end up with the lowest score of the SPCM algorithm and gets chosen to be killed.</p>

<p>This is our service:</p>

<pre><code>Public class IncomingService extends Service {

    @Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);
    return START_STICKY;

}

@Override
public void onCreate() {
    if (mPhoneListener == null) {
        mPhoneListener = new CallStateListener();
        TelephonyManager tm = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
        tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
}

    /**
 * Listener for call states
 * Listens for different call states
 */
private class CallStateListener extends PhoneStateListener {

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
       // Doing something with incomingNumber
    }
}
</code></pre>

<p>And in the manifest:</p>

<pre><code>    &lt;service
        android:name="com.services.IncomingService"
        android:enabled="true"
        android:priority="999" &gt;
    &lt;/service&gt;    
</code></pre>

<p>A log of SPCM killing our services:</p>

<pre><code>Force stopping com.special.app appid=10499 user=0: SPCM kill lowestscore package!
03-18 22:48:11.280 3562-3562/? I/ActivityManager: Killing 2279:com.special.app/u0a499 (adj 8): stop com.special.app cause SPCM kill lowestscore package!
03-18 22:48:11.280 3562-3562/? W/ActivityManager: Scheduling restart of crashed service com.special.app/com.services.IncomingService in 1000ms
03-18 22:48:11.280 3562-3562/? I/ActivityManager:   Force stopping service ServiceRecord{27d2c408 u0 com.special.app/com.services.IncomingService}
</code></pre>

<p>Even though the ActivityManager log states it is rescheduling a restart for our service, it never actually gets restarted.</p>

<p>We have seen the same SPCM logs regarding other apps (Facebook, TrueCaller, etc.) but their services somehow manage to restart.</p>

<p>So to sum up, our questions are:</p>

<ol>
<li>How to prevent SPCM from targeting our app as lowestscore package?</li>
<li>If we have been targeted, how to make sure our service will be successfully restarted after getting killed?</li>
<li>Any other ideas that can help us?</li>
</ol>