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

Commit 7ede382c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "WorkSource: Fix WorkSource#remove for chained worksources."

parents f802130d ee07f627
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -407,11 +407,11 @@ public class WorkSource implements Parcelable {
    }

    public boolean remove(WorkSource other) {
        if (mNum <= 0 || other.mNum <= 0) {
        if (isEmpty() || other.isEmpty()) {
            return false;
        }

        boolean uidRemoved = false;
        boolean uidRemoved;
        if (mNames == null && other.mNames == null) {
            uidRemoved = removeUids(other);
        } else {
@@ -427,14 +427,9 @@ public class WorkSource implements Parcelable {
        }

        boolean chainRemoved = false;
        if (other.mChains != null) {
            if (mChains != null) {
        if (other.mChains != null && mChains != null) {
            chainRemoved = mChains.removeAll(other.mChains);
        }
        } else if (mChains != null) {
            mChains.clear();
            chainRemoved = true;
        }

        return uidRemoved || chainRemoved;
    }
+20 −0
Original line number Diff line number Diff line
@@ -331,4 +331,24 @@ public class WorkSourceTest extends TestCase {
        wc.addNode(200, "tag2");
        assertEquals(100, wc.getAttributionUid());
    }

    public void testRemove_fromChainedWorkSource() {
        WorkSource ws1 = new WorkSource();
        ws1.createWorkChain().addNode(50, "foo");
        ws1.createWorkChain().addNode(75, "bar");
        ws1.add(100);

        WorkSource ws2 = new WorkSource();
        ws2.add(100);

        assertTrue(ws1.remove(ws2));
        assertEquals(2, ws1.getWorkChains().size());
        assertEquals(50, ws1.getWorkChains().get(0).getAttributionUid());
        assertEquals(75, ws1.getWorkChains().get(1).getAttributionUid());

        ws2.createWorkChain().addNode(50, "foo");
        assertTrue(ws1.remove(ws2));
        assertEquals(1, ws1.getWorkChains().size());
        assertEquals(75, ws1.getWorkChains().get(0).getAttributionUid());
    }
}