OSDN Git Service

WorkSource: Fix getAttributionUid.
authorNarayan Kamath <narayan@google.com>
Wed, 27 Dec 2017 14:22:47 +0000 (14:22 +0000)
committerNarayan Kamath <narayan@google.com>
Wed, 27 Dec 2017 14:40:52 +0000 (14:40 +0000)
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
core/tests/coretests/src/android/os/WorkSourceTest.java

index e9d4fe8..21bd6a8 100644 (file)
@@ -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
index e2f800f..90b4575 100644 (file)
@@ -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());
+    }
 }