Merge changes I5fffc137,Ifc076a8d into main

* changes:
  Add Log.wtf when keepalive metrics are unexpected.
  Add dump of KeepaliveStatsTracker
This commit is contained in:
Hansen Kurli
2023-11-01 08:50:39 +00:00
committed by Gerrit Code Review
4 changed files with 82 additions and 0 deletions

View File

@@ -77,6 +77,7 @@ import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.internal.util.IndentingPrintWriter;
import com.android.server.connectivity.AutomaticOnOffKeepaliveTracker.AutomaticOnOffKeepalive;
import com.android.server.connectivity.KeepaliveTracker.KeepaliveInfo;
import com.android.testutils.DevSdkIgnoreRule;
@@ -94,6 +95,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.io.FileDescriptor;
import java.io.StringWriter;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.Socket;
@@ -974,4 +976,19 @@ public class AutomaticOnOffKeepaliveTrackerTest {
// The keepalive should be removed in AutomaticOnOffKeepaliveTracker.
assertNull(getAutoKiForBinder(testInfo.binder));
}
@Test
public void testDumpDoesNotCrash() throws Exception {
final TestKeepaliveInfo testInfo1 = doStartNattKeepalive();
final TestKeepaliveInfo testInfo2 = doStartNattKeepalive();
checkAndProcessKeepaliveStart(TEST_SLOT, testInfo1.kpd);
checkAndProcessKeepaliveStart(TEST_SLOT + 1, testInfo2.kpd);
final AutomaticOnOffKeepalive autoKi1 = getAutoKiForBinder(testInfo1.binder);
doPauseKeepalive(autoKi1);
final StringWriter stringWriter = new StringWriter();
final IndentingPrintWriter pw = new IndentingPrintWriter(stringWriter, " ");
visibleOnHandlerThread(mTestHandler, () -> mAOOKeepaliveTracker.dump(pw));
assertFalse(stringWriter.toString().isEmpty());
}
}

View File

@@ -37,6 +37,7 @@ import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import android.content.BroadcastReceiver;
@@ -1293,5 +1294,18 @@ public class KeepaliveStatsTrackerTest {
expectRegisteredDurations,
expectActiveDurations,
new KeepaliveCarrierStats[0]);
assertTrue(mKeepaliveStatsTracker.allMetricsExpected(dailyKeepaliveInfoReported));
// Write time after 26 hours.
final int writeTime2 = 26 * 60 * 60 * 1000;
setElapsedRealtime(writeTime2);
visibleOnHandlerThread(mTestHandler, () -> mKeepaliveStatsTracker.writeAndResetMetrics());
verify(mDependencies, times(2)).writeStats(dailyKeepaliveInfoReportedCaptor.capture());
final DailykeepaliveInfoReported dailyKeepaliveInfoReported2 =
dailyKeepaliveInfoReportedCaptor.getValue();
assertFalse(mKeepaliveStatsTracker.allMetricsExpected(dailyKeepaliveInfoReported2));
}
}