Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 42ecdf3d authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix issue #74248644: Swiping away task increments start ID of running services

The start item for reporting onTaskRemoved() no longer increments
the current start id, reusing the last one.  Instead we explicitly
disambiguate between normal starts and task removed starts (which
we should have been doing anyway).

Test: manual
Bug: 74248644
Change-Id: Iba6de98353bac459d9769b103a3ee5a9de1df49a
parent b622906d
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -782,7 +782,7 @@ public final class ActiveServices {
                // Asked to only stop if done with all work.  Note that
                // to avoid leaks, we will take this as dropping all
                // start items up to and including this one.
                ServiceRecord.StartItem si = r.findDeliveredStart(startId, false);
                ServiceRecord.StartItem si = r.findDeliveredStart(startId, false, false);
                if (si != null) {
                    while (r.deliveredStarts.size() > 0) {
                        ServiceRecord.StartItem cur = r.deliveredStarts.remove(0);
@@ -2856,14 +2856,14 @@ public final class ActiveServices {
                    case Service.START_STICKY_COMPATIBILITY:
                    case Service.START_STICKY: {
                        // We are done with the associated start arguments.
                        r.findDeliveredStart(startId, true);
                        r.findDeliveredStart(startId, false, true);
                        // Don't stop if killed.
                        r.stopIfKilled = false;
                        break;
                    }
                    case Service.START_NOT_STICKY: {
                        // We are done with the associated start arguments.
                        r.findDeliveredStart(startId, true);
                        r.findDeliveredStart(startId, false, true);
                        if (r.getLastStartId() == startId) {
                            // There is no more work, and this service
                            // doesn't want to hang around if killed.
@@ -2875,7 +2875,7 @@ public final class ActiveServices {
                        // We'll keep this item until they explicitly
                        // call stop for it, but keep track of the fact
                        // that it was delivered.
                        ServiceRecord.StartItem si = r.findDeliveredStart(startId, false);
                        ServiceRecord.StartItem si = r.findDeliveredStart(startId, false, false);
                        if (si != null) {
                            si.deliveryCount = 0;
                            si.doneExecutingCount++;
@@ -2887,7 +2887,7 @@ public final class ActiveServices {
                    case Service.START_TASK_REMOVED_COMPLETE: {
                        // Special processing for onTaskRemoved().  Don't
                        // impact normal onStartCommand() processing.
                        r.findDeliveredStart(startId, true);
                        r.findDeliveredStart(startId, true, true);
                        break;
                    }
                    default:
@@ -3174,7 +3174,7 @@ public final class ActiveServices {
                    stopServiceLocked(sr);
                } else {
                    sr.pendingStarts.add(new ServiceRecord.StartItem(sr, true,
                            sr.makeNextStartId(), baseIntent, null, 0));
                            sr.getLastStartId(), baseIntent, null, 0));
                    if (sr.app != null && sr.app.thread != null) {
                        // We always run in the foreground, since this is called as
                        // part of the "remove task" UI operation.
+2 −2
Original line number Diff line number Diff line
@@ -550,11 +550,11 @@ final class ServiceRecord extends Binder {
        restartTime = 0;
    }

    public StartItem findDeliveredStart(int id, boolean remove) {
    public StartItem findDeliveredStart(int id, boolean taskRemoved, boolean remove) {
        final int N = deliveredStarts.size();
        for (int i=0; i<N; i++) {
            StartItem si = deliveredStarts.get(i);
            if (si.id == id) {
            if (si.id == id && si.taskRemoved == taskRemoved) {
                if (remove) deliveredStarts.remove(i);
                return si;
            }