Loading src/com/android/networkstack/metrics/DataStallStatsUtils.java +7 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ import android.annotation.Nullable; import android.net.captiveportal.CaptivePortalProbeResult; import android.util.Log; import androidx.annotation.VisibleForTesting; import com.android.internal.util.HexDump; import com.android.server.connectivity.nano.DataStallEventProto; Loading @@ -38,7 +40,11 @@ public class DataStallStatsUtils { private static final String TAG = DataStallStatsUtils.class.getSimpleName(); private static final boolean DBG = false; private static int probeResultToEnum(@Nullable final CaptivePortalProbeResult result) { /** * Map {@link CaptivePortalProbeResult} to {@link DataStallEventProto}. */ @VisibleForTesting public static int probeResultToEnum(@Nullable final CaptivePortalProbeResult result) { if (result == null) return DataStallEventProto.INVALID; if (result.isSuccessful()) { Loading tests/unit/src/android/networkstack/metrics/DataStallStatsUtilsTest.kt 0 → 100644 +44 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.networkstack.metrics import android.net.captiveportal.CaptivePortalProbeResult import androidx.test.filters.SmallTest import androidx.test.runner.AndroidJUnit4 import com.android.networkstack.metrics.DataStallStatsUtils import com.android.server.connectivity.nano.DataStallEventProto import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) @SmallTest class DataStallStatsUtilsTest { @Test fun testProbeResultToEnum() { assertEquals(DataStallStatsUtils.probeResultToEnum(null), DataStallEventProto.INVALID) assertEquals(DataStallStatsUtils.probeResultToEnum(CaptivePortalProbeResult.FAILED), DataStallEventProto.INVALID) assertEquals(DataStallStatsUtils.probeResultToEnum(CaptivePortalProbeResult.SUCCESS), DataStallEventProto.VALID) assertEquals(DataStallStatsUtils.probeResultToEnum(CaptivePortalProbeResult.PARTIAL), DataStallEventProto.PARTIAL) assertEquals(DataStallStatsUtils.probeResultToEnum( CaptivePortalProbeResult(CaptivePortalProbeResult.PORTAL_CODE)), DataStallEventProto.PORTAL) } } Loading
src/com/android/networkstack/metrics/DataStallStatsUtils.java +7 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ import android.annotation.Nullable; import android.net.captiveportal.CaptivePortalProbeResult; import android.util.Log; import androidx.annotation.VisibleForTesting; import com.android.internal.util.HexDump; import com.android.server.connectivity.nano.DataStallEventProto; Loading @@ -38,7 +40,11 @@ public class DataStallStatsUtils { private static final String TAG = DataStallStatsUtils.class.getSimpleName(); private static final boolean DBG = false; private static int probeResultToEnum(@Nullable final CaptivePortalProbeResult result) { /** * Map {@link CaptivePortalProbeResult} to {@link DataStallEventProto}. */ @VisibleForTesting public static int probeResultToEnum(@Nullable final CaptivePortalProbeResult result) { if (result == null) return DataStallEventProto.INVALID; if (result.isSuccessful()) { Loading
tests/unit/src/android/networkstack/metrics/DataStallStatsUtilsTest.kt 0 → 100644 +44 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.networkstack.metrics import android.net.captiveportal.CaptivePortalProbeResult import androidx.test.filters.SmallTest import androidx.test.runner.AndroidJUnit4 import com.android.networkstack.metrics.DataStallStatsUtils import com.android.server.connectivity.nano.DataStallEventProto import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) @SmallTest class DataStallStatsUtilsTest { @Test fun testProbeResultToEnum() { assertEquals(DataStallStatsUtils.probeResultToEnum(null), DataStallEventProto.INVALID) assertEquals(DataStallStatsUtils.probeResultToEnum(CaptivePortalProbeResult.FAILED), DataStallEventProto.INVALID) assertEquals(DataStallStatsUtils.probeResultToEnum(CaptivePortalProbeResult.SUCCESS), DataStallEventProto.VALID) assertEquals(DataStallStatsUtils.probeResultToEnum(CaptivePortalProbeResult.PARTIAL), DataStallEventProto.PARTIAL) assertEquals(DataStallStatsUtils.probeResultToEnum( CaptivePortalProbeResult(CaptivePortalProbeResult.PORTAL_CODE)), DataStallEventProto.PORTAL) } }