From cbe06778dd5ee32a108278d5ac710105e8ae1358 Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Wed, 27 Dec 2017 14:22:47 +0000 Subject: WorkSource: Fix getAttributionUid. We define it as the UID that initiated the work, and not the UID performing the work. Test: WorkSourceTest. Bug: 62390666 Change-Id: I1583e3f24b492e3f11a1281215c066fedf489b5f --- core/java/android/os/WorkSource.java | 6 +++--- core/tests/coretests/src/android/os/WorkSourceTest.java | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/java/android/os/WorkSource.java b/core/java/android/os/WorkSource.java index e9d4fe82cec2..21bd6a873e32 100644 --- a/core/java/android/os/WorkSource.java +++ b/core/java/android/os/WorkSource.java @@ -853,11 +853,11 @@ public class WorkSource implements Parcelable { } /** - * Return the UID to which this WorkChain should be attributed to, i.e, the UID performing - * the actual work. + * Return the UID to which this WorkChain should be attributed to, i.e, the UID that + * initiated the work and not the UID performing it. */ public int getAttributionUid() { - return mUids[mSize - 1]; + return mUids[0]; } // TODO: The following three trivial getters are purely for testing and will be removed diff --git a/core/tests/coretests/src/android/os/WorkSourceTest.java b/core/tests/coretests/src/android/os/WorkSourceTest.java index e2f800fb7db3..90b457561180 100644 --- a/core/tests/coretests/src/android/os/WorkSourceTest.java +++ b/core/tests/coretests/src/android/os/WorkSourceTest.java @@ -322,4 +322,13 @@ public class WorkSourceTest extends TestCase { assertEquals(new WorkChain().addNode(0, "tag0"), diffs[1].get(0)); assertEquals(new WorkChain().addNode(2, "tag2"), diffs[1].get(1)); } + + public void testGetAttributionId() { + WorkSource ws1 = new WorkSource(); + WorkChain wc = ws1.createWorkChain(); + wc.addNode(100, "tag"); + assertEquals(100, wc.getAttributionUid()); + wc.addNode(200, "tag2"); + assertEquals(100, wc.getAttributionUid()); + } } -- cgit v1.2.3-59-g8ed1b