From 0b96b39f1be3a4478687c366aa1f7afd589d612f Mon Sep 17 00:00:00 2001 From: jpantonow Date: Wed, 26 Aug 2026 11:12:51 -0300 Subject: [PATCH] Fix calculateChildType --- .../accesspoint/AccessPointsAdapterData.kt | 15 ++-------- .../wifi/graphutils/GraphConstants.kt | 10 +++++++ .../wifi/graphutils/GraphWrapper.kt | 13 ++------ .../wifi/graphutils/GraphWrapperTest.kt | 30 +++++++++++++++---- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/app/src/main/kotlin/com/vrem/wifianalyzer/wifi/accesspoint/AccessPointsAdapterData.kt b/app/src/main/kotlin/com/vrem/wifianalyzer/wifi/accesspoint/AccessPointsAdapterData.kt index 690b6fd71..ae912824d 100644 --- a/app/src/main/kotlin/com/vrem/wifianalyzer/wifi/accesspoint/AccessPointsAdapterData.kt +++ b/app/src/main/kotlin/com/vrem/wifianalyzer/wifi/accesspoint/AccessPointsAdapterData.kt @@ -25,10 +25,10 @@ import com.vrem.wifianalyzer.SIZE_MIN import com.vrem.wifianalyzer.wifi.graphutils.TYPE1 import com.vrem.wifianalyzer.wifi.graphutils.TYPE2 import com.vrem.wifianalyzer.wifi.graphutils.TYPE3 +import com.vrem.wifianalyzer.wifi.graphutils.applicationType import com.vrem.wifianalyzer.wifi.model.WiFiData import com.vrem.wifianalyzer.wifi.model.WiFiDetail import com.vrem.wifianalyzer.wifi.predicate.makeAccessPointsPredicate -import java.security.MessageDigest @OpenClass class AccessPointsAdapterData( @@ -62,17 +62,6 @@ class AccessPointsAdapterData( fun onGroupExpanded(groupPosition: Int) = accessPointsAdapterGroup.onGroupExpanded(wiFiDetails, groupPosition) - private fun calculateChildType(): Int = - runCatching { - with(MessageDigest.getInstance("MD5")) { - update( - MainContext.INSTANCE.mainActivity.packageName - .toByteArray(), - ) - val digest: ByteArray = digest() - digest.contentHashCode() - } - }.getOrDefault(TYPE1) - + private fun calculateChildType(): Int = applicationType(MainContext.INSTANCE.mainActivity.packageName) private fun type(value: Int): Int = if (value == TYPE1 || value == TYPE2 || value == TYPE3) SIZE_MAX else SIZE_MIN } diff --git a/app/src/main/kotlin/com/vrem/wifianalyzer/wifi/graphutils/GraphConstants.kt b/app/src/main/kotlin/com/vrem/wifianalyzer/wifi/graphutils/GraphConstants.kt index ca7a65f00..9864cb76e 100644 --- a/app/src/main/kotlin/com/vrem/wifianalyzer/wifi/graphutils/GraphConstants.kt +++ b/app/src/main/kotlin/com/vrem/wifianalyzer/wifi/graphutils/GraphConstants.kt @@ -32,3 +32,13 @@ const val TYPE1 = 1147798476 const val TYPE2 = 535509942 const val TYPE3 = 1256180258 const val TYPE4 = 1546740952 + +private const val APPLICATION_ID_BASE = "com.vrem.wifianalyzer" +private const val APPLICATION_ID_DEBUG = "com.vrem.wifianalyzer.BETA" + +fun applicationType(applicationId: String): Int = + when (applicationId) { + APPLICATION_ID_BASE -> TYPE1 + APPLICATION_ID_DEBUG -> TYPE3 + else -> TYPE4 + } diff --git a/app/src/main/kotlin/com/vrem/wifianalyzer/wifi/graphutils/GraphWrapper.kt b/app/src/main/kotlin/com/vrem/wifianalyzer/wifi/graphutils/GraphWrapper.kt index e303a5f25..a5db1aa1c 100644 --- a/app/src/main/kotlin/com/vrem/wifianalyzer/wifi/graphutils/GraphWrapper.kt +++ b/app/src/main/kotlin/com/vrem/wifianalyzer/wifi/graphutils/GraphWrapper.kt @@ -36,7 +36,7 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.cancel import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.launch -import java.security.MessageDigest + data class GraphViewport( val rangeProvider: CartesianLayerRangeProvider, @@ -168,16 +168,7 @@ class GraphWrapper( fun newSeries(wiFiDetail: WiFiDetail): Boolean = !seriesExists(wiFiDetail) fun calculateGraphType(): Int = - runCatching { - with(MessageDigest.getInstance("MD5")) { - update( - MainContext.INSTANCE.mainActivity.packageName - .toByteArray(), - ) - val digest: ByteArray = digest() - digest.contentHashCode() - } - }.getOrDefault(TYPE1) + applicationType(MainContext.INSTANCE.mainActivity.packageName) fun show() { chartView.visibility = View.VISIBLE diff --git a/app/src/test/kotlin/com/vrem/wifianalyzer/wifi/graphutils/GraphWrapperTest.kt b/app/src/test/kotlin/com/vrem/wifianalyzer/wifi/graphutils/GraphWrapperTest.kt index f7494343b..6a484a5ab 100644 --- a/app/src/test/kotlin/com/vrem/wifianalyzer/wifi/graphutils/GraphWrapperTest.kt +++ b/app/src/test/kotlin/com/vrem/wifianalyzer/wifi/graphutils/GraphWrapperTest.kt @@ -226,20 +226,40 @@ class GraphWrapperTest { } @Test - fun calculateGraphType() { + fun calculateGraphTypeUsesSharedApplicationIdentity() { // Act val actual = fixture.calculateGraphType() // Assert - assertThat(actual).isGreaterThan(0) + assertThat(actual).isEqualTo(applicationType(mainActivity.packageName)) } @Test - fun getSize() { + fun applicationTypeMapsKnownApplicationIdsToMaximumSize() { + // Act + val baseType = applicationType("com.vrem.wifianalyzer") + val debugType = applicationType("com.vrem.wifianalyzer.BETA") + // Assert + assertThat(baseType).isEqualTo(TYPE1) + assertThat(fixture.size(baseType)).isEqualTo(SIZE_MAX) + assertThat(debugType).isEqualTo(TYPE3) + assertThat(fixture.size(debugType)).isEqualTo(SIZE_MAX) + } + + @Test + fun applicationTypeMapsUnknownApplicationIdToMinimumSize() { + // Act + val actual = applicationType("com.vrem.wifianalyzer.UNKNOWN") + // Assert + assertThat(actual).isEqualTo(TYPE4) + assertThat(fixture.size(actual)).isEqualTo(SIZE_MIN) + } + + @Test + fun sizeRetainsLegacyType2AndFallbackBehavior() { // Act & assert - assertThat(fixture.size(TYPE1)).isEqualTo(SIZE_MAX) assertThat(fixture.size(TYPE2)).isEqualTo(SIZE_MAX) - assertThat(fixture.size(TYPE3)).isEqualTo(SIZE_MAX) assertThat(fixture.size(TYPE4)).isEqualTo(SIZE_MIN) + assertThat(fixture.size(Int.MIN_VALUE)).isEqualTo(SIZE_MIN) } @Test