time_in_state: handle SDK sandbox UIDs

Add a check to detect UIDs in the SDK sandbox range. CPU times for
these UIDs will be attributed to corresponding app UID, calculated by
subtracting a fixed offset from the current UID. We also attribute
these times to AID_SDK_SANDBOX, a UID reserved specifically for the
purpose of collecting aggregate stats across all SDK sandbox uids.

To avoid redundant code, factor out per-UID accounting logic into a
helper function that we can call twice in this new case.

Add a new test case to verify such UIDs are handled correctly.

Test: atest --test-mapping system/bpfprogs
Bug: 219080829
Signed-off-by: Connor O'Brien <connoro@google.com>
Change-Id: I6aa5404a2201c2583e7b6a1292d3c80b9e3ec5cb
diff --git a/time_in_state_test.cpp b/time_in_state_test.cpp
index e94ec1a..1042221 100644
--- a/time_in_state_test.cpp
+++ b/time_in_state_test.cpp
@@ -241,3 +241,26 @@
 
     assertConcurrentTimes(42, 0, {100}, {100});
 }
+
+TEST(time_in_state, tp_sched_switch_sdk_sandbox) {
+    mock_bpf_set_ktime_ns(1000);
+    mock_bpf_set_current_uid_gid(AID_SDK_SANDBOX_PROCESS_START);
+
+    initCpuPolicy(0, {0}, {1000, 2000}, true);
+
+    enableTracking();
+
+    mock_bpf_set_smp_processor_id(0);
+
+    noteSchedSwitch(0, 1);
+
+    mock_bpf_set_ktime_ns(1100);
+
+    noteSchedSwitch(1, 2);
+
+    assertTimeInState(AID_APP_START, 0, {100, 0});
+    assertTimeInState(AID_SDK_SANDBOX, 0, {100, 0});
+
+    assertConcurrentTimes(AID_APP_START, 0, {100}, {100});
+    assertConcurrentTimes(AID_SDK_SANDBOX, 0, {100}, {100});
+}