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

Commit 6192f732 authored by Narayan Kamath's avatar Narayan Kamath
Browse files

WorkSource: Fix NPE on set(int) / set(int, String).

mChains might be null.

Bug: 62390666
Test: WorkSourceTest
Test: run cts-dev -m CtsOsTestCases -t android.os.cts.WorkSourceTest
Change-Id: I1dbc2abc576c280ad41ad6214745b0d34c5727a0
parent 24721ea0
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -266,8 +266,10 @@ public class WorkSource implements Parcelable {
        if (mUids == null) mUids = new int[2];
        mUids[0] = uid;
        mNames = null;
        if (mChains != null) {
            mChains.clear();
        }
    }

    /** @hide */
    public void set(int uid, String name) {
@@ -281,8 +283,10 @@ public class WorkSource implements Parcelable {
        }
        mUids[0] = uid;
        mNames[0] = name;
        if (mChains != null) {
            mChains.clear();
        }
    }

    /**
     * Legacy API, DO NOT USE: Only deals with flat UIDs and tags. No chains are transferred, and no
+13 −0
Original line number Diff line number Diff line
@@ -205,4 +205,17 @@ public class WorkSourceTest extends TestCase {
        ws.add(ws2);
        assertEquals(2, workChains.size());
    }

    public void testSet_noWorkChains() {
        WorkSource ws = new WorkSource();
        ws.set(10);
        assertEquals(1, ws.size());
        assertEquals(10, ws.get(0));

        WorkSource ws2 = new WorkSource();
        ws2.set(20, "foo");
        assertEquals(1, ws2.size());
        assertEquals(20, ws2.get(0));
        assertEquals("foo", ws2.getName(0));
    }
}