Loading apex/jobscheduler/service/java/com/android/server/alarm/AlarmManagerService.java +35 −7 Original line number Diff line number Diff line Loading @@ -4739,8 +4739,14 @@ public class AlarmManagerService extends SystemService { } final ArraySet<Pair<String, Integer>> triggerPackages = new ArraySet<>(); final SparseIntArray countsPerUid = new SparseIntArray(); final SparseIntArray wakeupCountsPerUid = new SparseIntArray(); for (int i = 0; i < triggerList.size(); i++) { final Alarm a = triggerList.get(i); increment(countsPerUid, a.uid); if (a.wakeup) { increment(wakeupCountsPerUid, a.uid); } if (mConstants.USE_TARE_POLICY) { if (!isExemptFromTare(a)) { triggerPackages.add(Pair.create( Loading @@ -4761,7 +4767,8 @@ public class AlarmManagerService extends SystemService { } rescheduleKernelAlarmsLocked(); updateNextAlarmClockLocked(); MetricsHelper.pushAlarmBatchDelivered(triggerList.size(), wakeUps); logAlarmBatchDelivered( triggerList.size(), wakeUps, countsPerUid, wakeupCountsPerUid); } } Loading @@ -4776,6 +4783,32 @@ public class AlarmManagerService extends SystemService { } } private static void increment(SparseIntArray array, int key) { final int index = array.indexOfKey(key); if (index >= 0) { array.setValueAt(index, array.valueAt(index) + 1); } else { array.put(key, 1); } } private void logAlarmBatchDelivered( int alarms, int wakeups, SparseIntArray countsPerUid, SparseIntArray wakeupCountsPerUid) { final int[] uids = new int[countsPerUid.size()]; final int[] countsArray = new int[countsPerUid.size()]; final int[] wakeupCountsArray = new int[countsPerUid.size()]; for (int i = 0; i < countsPerUid.size(); i++) { uids[i] = countsPerUid.keyAt(i); countsArray[i] = countsPerUid.valueAt(i); wakeupCountsArray[i] = wakeupCountsPerUid.get(uids[i], 0); } MetricsHelper.pushAlarmBatchDelivered( alarms, wakeups, uids, countsArray, wakeupCountsArray); } /** * Attribute blame for a WakeLock. * Loading Loading @@ -5695,12 +5728,7 @@ public class AlarmManagerService extends SystemService { } private void incrementAlarmCount(int uid) { final int uidIndex = mAlarmsPerUid.indexOfKey(uid); if (uidIndex >= 0) { mAlarmsPerUid.setValueAt(uidIndex, mAlarmsPerUid.valueAt(uidIndex) + 1); } else { mAlarmsPerUid.put(uid, 1); } increment(mAlarmsPerUid, uid); } /** Loading apex/jobscheduler/service/java/com/android/server/alarm/MetricsHelper.java +6 −2 Original line number Diff line number Diff line Loading @@ -111,10 +111,14 @@ class MetricsHelper { ActivityManager.processStateAmToProto(callerProcState)); } static void pushAlarmBatchDelivered(int numAlarms, int wakeups) { static void pushAlarmBatchDelivered( int numAlarms, int wakeups, int[] uids, int[] alarmsPerUid, int[] wakeupAlarmsPerUid) { FrameworkStatsLog.write( FrameworkStatsLog.ALARM_BATCH_DELIVERED, numAlarms, wakeups); wakeups, uids, alarmsPerUid, wakeupAlarmsPerUid); } } services/tests/mockingservicestests/src/com/android/server/alarm/AlarmManagerServiceTest.java +32 −1 Original line number Diff line number Diff line Loading @@ -205,6 +205,7 @@ public class AlarmManagerServiceTest { private static final String TAG = AlarmManagerServiceTest.class.getSimpleName(); private static final int SYSTEM_UI_UID = 12345; private static final int TEST_CALLING_USER = UserHandle.getUserId(TEST_CALLING_UID); private static final int TEST_CALLING_UID_2 = TEST_CALLING_UID + 1; private long mAppStandbyWindow; private long mAllowWhileIdleWindow; Loading Loading @@ -3375,10 +3376,40 @@ public class AlarmManagerServiceTest { final int type = ((i & 1) == 0) ? ELAPSED_REALTIME : ELAPSED_REALTIME_WAKEUP; setTestAlarm(type, mNowElapsedTest + i, getNewMockPendingIntent()); } for (int i = 0; i < 4; i++) { final int type = ((i & 1) == 0) ? ELAPSED_REALTIME : ELAPSED_REALTIME_WAKEUP; setTestAlarm( type, mNowElapsedTest + i, getNewMockPendingIntent(), 0, FLAG_STANDALONE, TEST_CALLING_UID_2); } mNowElapsedTest += 100; mTestTimer.expire(); verify(() -> MetricsHelper.pushAlarmBatchDelivered(10, 5)); final ArgumentCaptor<int[]> uidsCaptor = ArgumentCaptor.forClass(int[].class); final ArgumentCaptor<int[]> alarmsPerUidCaptor = ArgumentCaptor.forClass(int[].class); final ArgumentCaptor<int[]> wakeupAlarmsPerUidCaptor = ArgumentCaptor.forClass(int[].class); verify(() -> MetricsHelper.pushAlarmBatchDelivered( eq(14), eq(7), uidsCaptor.capture(), alarmsPerUidCaptor.capture(), wakeupAlarmsPerUidCaptor.capture())); assertEquals(2, uidsCaptor.getValue().length); assertEquals(2, alarmsPerUidCaptor.getValue().length); assertEquals(2, wakeupAlarmsPerUidCaptor.getValue().length); final int uid1Idx = uidsCaptor.getValue()[0] == TEST_CALLING_UID ? 0 : 1; final int uid2Idx = 1 - uid1Idx; assertEquals(TEST_CALLING_UID, uidsCaptor.getValue()[uid1Idx]); assertEquals(TEST_CALLING_UID_2, uidsCaptor.getValue()[uid2Idx]); assertEquals(10, alarmsPerUidCaptor.getValue()[uid1Idx]); assertEquals(5, wakeupAlarmsPerUidCaptor.getValue()[uid1Idx]); assertEquals(4, alarmsPerUidCaptor.getValue()[uid2Idx]); assertEquals(2, wakeupAlarmsPerUidCaptor.getValue()[uid2Idx]); } @Test Loading Loading
apex/jobscheduler/service/java/com/android/server/alarm/AlarmManagerService.java +35 −7 Original line number Diff line number Diff line Loading @@ -4739,8 +4739,14 @@ public class AlarmManagerService extends SystemService { } final ArraySet<Pair<String, Integer>> triggerPackages = new ArraySet<>(); final SparseIntArray countsPerUid = new SparseIntArray(); final SparseIntArray wakeupCountsPerUid = new SparseIntArray(); for (int i = 0; i < triggerList.size(); i++) { final Alarm a = triggerList.get(i); increment(countsPerUid, a.uid); if (a.wakeup) { increment(wakeupCountsPerUid, a.uid); } if (mConstants.USE_TARE_POLICY) { if (!isExemptFromTare(a)) { triggerPackages.add(Pair.create( Loading @@ -4761,7 +4767,8 @@ public class AlarmManagerService extends SystemService { } rescheduleKernelAlarmsLocked(); updateNextAlarmClockLocked(); MetricsHelper.pushAlarmBatchDelivered(triggerList.size(), wakeUps); logAlarmBatchDelivered( triggerList.size(), wakeUps, countsPerUid, wakeupCountsPerUid); } } Loading @@ -4776,6 +4783,32 @@ public class AlarmManagerService extends SystemService { } } private static void increment(SparseIntArray array, int key) { final int index = array.indexOfKey(key); if (index >= 0) { array.setValueAt(index, array.valueAt(index) + 1); } else { array.put(key, 1); } } private void logAlarmBatchDelivered( int alarms, int wakeups, SparseIntArray countsPerUid, SparseIntArray wakeupCountsPerUid) { final int[] uids = new int[countsPerUid.size()]; final int[] countsArray = new int[countsPerUid.size()]; final int[] wakeupCountsArray = new int[countsPerUid.size()]; for (int i = 0; i < countsPerUid.size(); i++) { uids[i] = countsPerUid.keyAt(i); countsArray[i] = countsPerUid.valueAt(i); wakeupCountsArray[i] = wakeupCountsPerUid.get(uids[i], 0); } MetricsHelper.pushAlarmBatchDelivered( alarms, wakeups, uids, countsArray, wakeupCountsArray); } /** * Attribute blame for a WakeLock. * Loading Loading @@ -5695,12 +5728,7 @@ public class AlarmManagerService extends SystemService { } private void incrementAlarmCount(int uid) { final int uidIndex = mAlarmsPerUid.indexOfKey(uid); if (uidIndex >= 0) { mAlarmsPerUid.setValueAt(uidIndex, mAlarmsPerUid.valueAt(uidIndex) + 1); } else { mAlarmsPerUid.put(uid, 1); } increment(mAlarmsPerUid, uid); } /** Loading
apex/jobscheduler/service/java/com/android/server/alarm/MetricsHelper.java +6 −2 Original line number Diff line number Diff line Loading @@ -111,10 +111,14 @@ class MetricsHelper { ActivityManager.processStateAmToProto(callerProcState)); } static void pushAlarmBatchDelivered(int numAlarms, int wakeups) { static void pushAlarmBatchDelivered( int numAlarms, int wakeups, int[] uids, int[] alarmsPerUid, int[] wakeupAlarmsPerUid) { FrameworkStatsLog.write( FrameworkStatsLog.ALARM_BATCH_DELIVERED, numAlarms, wakeups); wakeups, uids, alarmsPerUid, wakeupAlarmsPerUid); } }
services/tests/mockingservicestests/src/com/android/server/alarm/AlarmManagerServiceTest.java +32 −1 Original line number Diff line number Diff line Loading @@ -205,6 +205,7 @@ public class AlarmManagerServiceTest { private static final String TAG = AlarmManagerServiceTest.class.getSimpleName(); private static final int SYSTEM_UI_UID = 12345; private static final int TEST_CALLING_USER = UserHandle.getUserId(TEST_CALLING_UID); private static final int TEST_CALLING_UID_2 = TEST_CALLING_UID + 1; private long mAppStandbyWindow; private long mAllowWhileIdleWindow; Loading Loading @@ -3375,10 +3376,40 @@ public class AlarmManagerServiceTest { final int type = ((i & 1) == 0) ? ELAPSED_REALTIME : ELAPSED_REALTIME_WAKEUP; setTestAlarm(type, mNowElapsedTest + i, getNewMockPendingIntent()); } for (int i = 0; i < 4; i++) { final int type = ((i & 1) == 0) ? ELAPSED_REALTIME : ELAPSED_REALTIME_WAKEUP; setTestAlarm( type, mNowElapsedTest + i, getNewMockPendingIntent(), 0, FLAG_STANDALONE, TEST_CALLING_UID_2); } mNowElapsedTest += 100; mTestTimer.expire(); verify(() -> MetricsHelper.pushAlarmBatchDelivered(10, 5)); final ArgumentCaptor<int[]> uidsCaptor = ArgumentCaptor.forClass(int[].class); final ArgumentCaptor<int[]> alarmsPerUidCaptor = ArgumentCaptor.forClass(int[].class); final ArgumentCaptor<int[]> wakeupAlarmsPerUidCaptor = ArgumentCaptor.forClass(int[].class); verify(() -> MetricsHelper.pushAlarmBatchDelivered( eq(14), eq(7), uidsCaptor.capture(), alarmsPerUidCaptor.capture(), wakeupAlarmsPerUidCaptor.capture())); assertEquals(2, uidsCaptor.getValue().length); assertEquals(2, alarmsPerUidCaptor.getValue().length); assertEquals(2, wakeupAlarmsPerUidCaptor.getValue().length); final int uid1Idx = uidsCaptor.getValue()[0] == TEST_CALLING_UID ? 0 : 1; final int uid2Idx = 1 - uid1Idx; assertEquals(TEST_CALLING_UID, uidsCaptor.getValue()[uid1Idx]); assertEquals(TEST_CALLING_UID_2, uidsCaptor.getValue()[uid2Idx]); assertEquals(10, alarmsPerUidCaptor.getValue()[uid1Idx]); assertEquals(5, wakeupAlarmsPerUidCaptor.getValue()[uid1Idx]); assertEquals(4, alarmsPerUidCaptor.getValue()[uid2Idx]); assertEquals(2, wakeupAlarmsPerUidCaptor.getValue()[uid2Idx]); } @Test Loading