Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down