Fill the other values for DailyKeepaliveInfoReported
Store the number of requests and app uids on start keepalives. The values are also stored in KeepaliveStats and can be recalculated from KeepaliveStats when reset. Fill the DailyKeepaliveInfoReported proto with these values. Bug: 273451360 Test: atest FrameworksNetTests Change-Id: Ifb9a0048896d31c8ea897cf14768e94dcfd3b010
This commit is contained in:
@@ -21,10 +21,9 @@ import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
|
||||
|
||||
import static com.android.testutils.HandlerUtils.visibleOnHandlerThread;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
@@ -54,6 +53,7 @@ import com.android.metrics.DurationPerNumOfKeepalive;
|
||||
import com.android.metrics.KeepaliveLifetimeForCarrier;
|
||||
import com.android.metrics.KeepaliveLifetimePerCarrier;
|
||||
import com.android.modules.utils.BackgroundThread;
|
||||
import com.android.net.module.util.CollectionUtils;
|
||||
import com.android.testutils.DevSdkIgnoreRule;
|
||||
import com.android.testutils.DevSdkIgnoreRunner;
|
||||
import com.android.testutils.HandlerUtils;
|
||||
@@ -89,6 +89,7 @@ public class KeepaliveStatsTrackerTest {
|
||||
buildCellNetworkCapabilitiesWithSubId(TEST_SUB_ID_1);
|
||||
private static final NetworkCapabilities TEST_NETWORK_CAPABILITIES_2 =
|
||||
buildCellNetworkCapabilitiesWithSubId(TEST_SUB_ID_2);
|
||||
private static final int TEST_UID = 1234;
|
||||
|
||||
private static NetworkCapabilities buildCellNetworkCapabilitiesWithSubId(int subId) {
|
||||
final TelephonyNetworkSpecifier telephonyNetworkSpecifier =
|
||||
@@ -238,9 +239,15 @@ public class KeepaliveStatsTrackerTest {
|
||||
|
||||
private void onStartKeepalive(
|
||||
long time, int slot, NetworkCapabilities nc, int intervalSeconds) {
|
||||
onStartKeepalive(time, slot, nc, intervalSeconds, TEST_UID, /* isAutoKeepalive= */ true);
|
||||
}
|
||||
|
||||
private void onStartKeepalive(long time, int slot, NetworkCapabilities nc, int intervalSeconds,
|
||||
int uid, boolean isAutoKeepalive) {
|
||||
setUptimeMillis(time);
|
||||
visibleOnHandlerThread(mTestHandler, () ->
|
||||
mKeepaliveStatsTracker.onStartKeepalive(TEST_NETWORK, slot, nc, intervalSeconds));
|
||||
mKeepaliveStatsTracker.onStartKeepalive(TEST_NETWORK, slot, nc, intervalSeconds,
|
||||
uid, isAutoKeepalive));
|
||||
}
|
||||
|
||||
private void onPauseKeepalive(long time, int slot) {
|
||||
@@ -270,7 +277,9 @@ public class KeepaliveStatsTrackerTest {
|
||||
TEST_NETWORK,
|
||||
TEST_SLOT,
|
||||
TEST_NETWORK_CAPABILITIES,
|
||||
TEST_KEEPALIVE_INTERVAL_SEC));
|
||||
TEST_KEEPALIVE_INTERVAL_SEC,
|
||||
TEST_UID,
|
||||
/* isAutoKeepalive */ true));
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> mKeepaliveStatsTracker.onPauseKeepalive(TEST_NETWORK, TEST_SLOT));
|
||||
@@ -378,14 +387,20 @@ public class KeepaliveStatsTrackerTest {
|
||||
|
||||
private void assertDailyKeepaliveInfoReported(
|
||||
DailykeepaliveInfoReported dailyKeepaliveInfoReported,
|
||||
int expectRequestsCount,
|
||||
int expectAutoRequestsCount,
|
||||
int[] expectAppUids,
|
||||
int[] expectRegisteredDurations,
|
||||
int[] expectActiveDurations,
|
||||
KeepaliveCarrierStats[] expectKeepaliveCarrierStatsArray) {
|
||||
// TODO(b/273451360) Assert these values when they are filled.
|
||||
assertFalse(dailyKeepaliveInfoReported.hasKeepaliveRequests());
|
||||
assertFalse(dailyKeepaliveInfoReported.hasAutomaticKeepaliveRequests());
|
||||
assertFalse(dailyKeepaliveInfoReported.hasDistinctUserCount());
|
||||
assertTrue(dailyKeepaliveInfoReported.getUidList().isEmpty());
|
||||
assertEquals(expectRequestsCount, dailyKeepaliveInfoReported.getKeepaliveRequests());
|
||||
assertEquals(
|
||||
expectAutoRequestsCount,
|
||||
dailyKeepaliveInfoReported.getAutomaticKeepaliveRequests());
|
||||
assertEquals(expectAppUids.length, dailyKeepaliveInfoReported.getDistinctUserCount());
|
||||
|
||||
final int[] uidArray = CollectionUtils.toIntArray(dailyKeepaliveInfoReported.getUidList());
|
||||
assertArrayEquals(expectAppUids, uidArray);
|
||||
|
||||
final DurationPerNumOfKeepalive actualDurations =
|
||||
dailyKeepaliveInfoReported.getDurationPerNumOfKeepalive();
|
||||
@@ -410,6 +425,9 @@ public class KeepaliveStatsTrackerTest {
|
||||
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported,
|
||||
/* expectRequestsCount= */ 0,
|
||||
/* expectAutoRequestsCount= */ 0,
|
||||
/* expectAppUids= */ new int[0],
|
||||
expectRegisteredDurations,
|
||||
expectActiveDurations,
|
||||
new KeepaliveCarrierStats[0]);
|
||||
@@ -438,6 +456,9 @@ public class KeepaliveStatsTrackerTest {
|
||||
final int[] expectActiveDurations = new int[] {startTime, writeTime - startTime};
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported,
|
||||
/* expectRequestsCount= */ 1,
|
||||
/* expectAutoRequestsCount= */ 1,
|
||||
/* expectAppUids= */ new int[] {TEST_UID},
|
||||
expectRegisteredDurations,
|
||||
expectActiveDurations,
|
||||
new KeepaliveCarrierStats[] {
|
||||
@@ -473,6 +494,9 @@ public class KeepaliveStatsTrackerTest {
|
||||
new int[] {startTime + (writeTime - pauseTime), pauseTime - startTime};
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported,
|
||||
/* expectRequestsCount= */ 1,
|
||||
/* expectAutoRequestsCount= */ 1,
|
||||
/* expectAppUids= */ new int[] {TEST_UID},
|
||||
expectRegisteredDurations,
|
||||
expectActiveDurations,
|
||||
new KeepaliveCarrierStats[] {
|
||||
@@ -514,6 +538,9 @@ public class KeepaliveStatsTrackerTest {
|
||||
};
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported,
|
||||
/* expectRequestsCount= */ 1,
|
||||
/* expectAutoRequestsCount= */ 1,
|
||||
/* expectAppUids= */ new int[] {TEST_UID},
|
||||
expectRegisteredDurations,
|
||||
expectActiveDurations,
|
||||
new KeepaliveCarrierStats[] {
|
||||
@@ -559,6 +586,9 @@ public class KeepaliveStatsTrackerTest {
|
||||
};
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported,
|
||||
/* expectRequestsCount= */ 1,
|
||||
/* expectAutoRequestsCount= */ 1,
|
||||
/* expectAppUids= */ new int[] {TEST_UID},
|
||||
expectRegisteredDurations,
|
||||
expectActiveDurations,
|
||||
new KeepaliveCarrierStats[] {
|
||||
@@ -598,6 +628,9 @@ public class KeepaliveStatsTrackerTest {
|
||||
new int[] {startTime + (writeTime - pauseTime), (pauseTime - startTime)};
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported,
|
||||
/* expectRequestsCount= */ 1,
|
||||
/* expectAutoRequestsCount= */ 1,
|
||||
/* expectAppUids= */ new int[] {TEST_UID},
|
||||
expectRegisteredDurations,
|
||||
expectActiveDurations,
|
||||
new KeepaliveCarrierStats[] {
|
||||
@@ -646,6 +679,9 @@ public class KeepaliveStatsTrackerTest {
|
||||
};
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported,
|
||||
/* expectRequestsCount= */ 1,
|
||||
/* expectAutoRequestsCount= */ 1,
|
||||
/* expectAppUids= */ new int[] {TEST_UID},
|
||||
expectRegisteredDurations,
|
||||
expectActiveDurations,
|
||||
new KeepaliveCarrierStats[] {
|
||||
@@ -719,6 +755,9 @@ public class KeepaliveStatsTrackerTest {
|
||||
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported,
|
||||
/* expectRequestsCount= */ 2,
|
||||
/* expectAutoRequestsCount= */ 2,
|
||||
/* expectAppUids= */ new int[] {TEST_UID},
|
||||
expectRegisteredDurations,
|
||||
expectActiveDurations,
|
||||
// The carrier stats are aggregated here since the keepalives have the same
|
||||
@@ -754,6 +793,9 @@ public class KeepaliveStatsTrackerTest {
|
||||
final int[] expectActiveDurations = new int[] {startTime, writeTime - startTime};
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported,
|
||||
/* expectRequestsCount= */ 1,
|
||||
/* expectAutoRequestsCount= */ 1,
|
||||
/* expectAppUids= */ new int[] {TEST_UID},
|
||||
expectRegisteredDurations,
|
||||
expectActiveDurations,
|
||||
new KeepaliveCarrierStats[] {
|
||||
@@ -767,6 +809,9 @@ public class KeepaliveStatsTrackerTest {
|
||||
// Expect the stored durations to be 0 but still contain the number of keepalive = 1.
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported2,
|
||||
/* expectRequestsCount= */ 1,
|
||||
/* expectAutoRequestsCount= */ 1,
|
||||
/* expectAppUids= */ new int[] {TEST_UID},
|
||||
/* expectRegisteredDurations= */ new int[] {0, 0},
|
||||
/* expectActiveDurations= */ new int[] {0, 0},
|
||||
new KeepaliveCarrierStats[] {getDefaultCarrierStats(0, 0)});
|
||||
@@ -783,6 +828,9 @@ public class KeepaliveStatsTrackerTest {
|
||||
new int[] {writeTime2 - stopTime, stopTime - writeTime};
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported3,
|
||||
/* expectRequestsCount= */ 1,
|
||||
/* expectAutoRequestsCount= */ 1,
|
||||
/* expectAppUids= */ new int[] {TEST_UID},
|
||||
expectRegisteredDurations2,
|
||||
expectActiveDurations2,
|
||||
new KeepaliveCarrierStats[] {
|
||||
@@ -844,6 +892,9 @@ public class KeepaliveStatsTrackerTest {
|
||||
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported,
|
||||
/* expectRequestsCount= */ 2,
|
||||
/* expectAutoRequestsCount= */ 2,
|
||||
/* expectAppUids= */ new int[] {TEST_UID},
|
||||
expectRegisteredDurations,
|
||||
expectActiveDurations,
|
||||
new KeepaliveCarrierStats[] {
|
||||
@@ -868,6 +919,9 @@ public class KeepaliveStatsTrackerTest {
|
||||
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported2,
|
||||
/* expectRequestsCount= */ 1,
|
||||
/* expectAutoRequestsCount= */ 1,
|
||||
/* expectAppUids= */ new int[] {TEST_UID},
|
||||
expectRegisteredDurations2,
|
||||
expectActiveDurations2,
|
||||
new KeepaliveCarrierStats[] {expectKeepaliveCarrierStats3});
|
||||
@@ -893,6 +947,9 @@ public class KeepaliveStatsTrackerTest {
|
||||
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported,
|
||||
/* expectRequestsCount= */ 1,
|
||||
/* expectAutoRequestsCount= */ 1,
|
||||
/* expectAppUids= */ new int[] {TEST_UID},
|
||||
expectRegisteredDurations,
|
||||
expectActiveDurations,
|
||||
new KeepaliveCarrierStats[] {
|
||||
@@ -932,6 +989,9 @@ public class KeepaliveStatsTrackerTest {
|
||||
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported,
|
||||
/* expectRequestsCount= */ 2,
|
||||
/* expectAutoRequestsCount= */ 2,
|
||||
/* expectAppUids= */ new int[] {TEST_UID},
|
||||
expectRegisteredDurations,
|
||||
expectActiveDurations,
|
||||
new KeepaliveCarrierStats[] {
|
||||
@@ -976,6 +1036,9 @@ public class KeepaliveStatsTrackerTest {
|
||||
writeTime - startTime);
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported,
|
||||
/* expectRequestsCount= */ 2,
|
||||
/* expectAutoRequestsCount= */ 2,
|
||||
/* expectAppUids= */ new int[] {TEST_UID},
|
||||
/* expectRegisteredDurations= */ new int[] {startTime, 0, writeTime - startTime},
|
||||
/* expectActiveDurations= */ new int[] {startTime, 0, writeTime - startTime},
|
||||
new KeepaliveCarrierStats[] {
|
||||
@@ -1016,8 +1079,53 @@ public class KeepaliveStatsTrackerTest {
|
||||
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported,
|
||||
/* expectRequestsCount= */ 1,
|
||||
/* expectAutoRequestsCount= */ 1,
|
||||
/* expectAppUids= */ new int[] {TEST_UID},
|
||||
/* expectRegisteredDurations= */ new int[] {startTime, writeTime - startTime},
|
||||
/* expectActiveDurations= */ new int[] {startTime, writeTime - startTime},
|
||||
new KeepaliveCarrierStats[] {expectKeepaliveCarrierStats});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeepaliveCountsAndUids() {
|
||||
final int startTime1 = 1000, startTime2 = 2000, startTime3 = 3000;
|
||||
final int writeTime = 5000;
|
||||
final int[] uids = new int[] {TEST_UID, TEST_UID + 1, TEST_UID + 2};
|
||||
onStartKeepalive(startTime1, TEST_SLOT, TEST_NETWORK_CAPABILITIES,
|
||||
TEST_KEEPALIVE_INTERVAL_SEC, uids[0], /* isAutoKeepalive= */ true);
|
||||
onStartKeepalive(startTime2, TEST_SLOT + 1, TEST_NETWORK_CAPABILITIES,
|
||||
TEST_KEEPALIVE_INTERVAL_SEC, uids[1], /* isAutoKeepalive= */ false);
|
||||
onStartKeepalive(startTime3, TEST_SLOT + 2, TEST_NETWORK_CAPABILITIES,
|
||||
TEST_KEEPALIVE_INTERVAL_SEC, uids[2], /* isAutoKeepalive= */ true);
|
||||
|
||||
final DailykeepaliveInfoReported dailyKeepaliveInfoReported =
|
||||
buildKeepaliveMetrics(writeTime);
|
||||
final int[] expectRegisteredDurations =
|
||||
new int[] {
|
||||
startTime1,
|
||||
(startTime2 - startTime1),
|
||||
(startTime3 - startTime2),
|
||||
(writeTime - startTime3)
|
||||
};
|
||||
final int[] expectActiveDurations =
|
||||
new int[] {
|
||||
startTime1,
|
||||
(startTime2 - startTime1),
|
||||
(startTime3 - startTime2),
|
||||
(writeTime - startTime3)
|
||||
};
|
||||
assertDailyKeepaliveInfoReported(
|
||||
dailyKeepaliveInfoReported,
|
||||
/* expectRequestsCount= */ 3,
|
||||
/* expectAutoRequestsCount= */ 2,
|
||||
/* expectAppUids= */ uids,
|
||||
expectRegisteredDurations,
|
||||
expectActiveDurations,
|
||||
new KeepaliveCarrierStats[] {
|
||||
getDefaultCarrierStats(
|
||||
writeTime * 3 - startTime1 - startTime2 - startTime3,
|
||||
writeTime * 3 - startTime1 - startTime2 - startTime3)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user