Skip to content

Commit

Permalink
Revert "Various fixes to tests"
Browse files Browse the repository at this point in the history
This reverts commit 1cd8eb8.
  • Loading branch information
dllewellyn committed Sep 22, 2023
1 parent 1cd8eb8 commit e58f8fa
Show file tree
Hide file tree
Showing 20 changed files with 327 additions and 282 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ android {
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
jvmTarget = "1.8"
}

buildTypes {
Expand Down
50 changes: 25 additions & 25 deletions app/src/main/java/com/andro/secure/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,31 @@ class MainActivity : AppCompatActivity() {

private inline fun Context.canIRun(checkName: String, actionOnFailure: () -> Unit) {

// if (safeToRunWithLogger(
// logger = logger(checkName),
// { banAvdEmulatorCheck() },
// { banGenymotionEmulatorCheck() },
// { banBluestacksEmulatorCheck() },
// { blacklistedAppCheck("Test app", "Test app 2") },
// { rootDetectionCheck() },
// {
// safeToRunCombinedCheck(
// listOf(
// { bannedHardwareCheck("hardware") },
// { bannedBoardCheck("board") }
// )
// )
// },
// {
// safeToRunCombinedCheck(
// listOf { installOriginCheckWithDefaultsCheck() },
// listOf { !BuildConfig.DEBUG }
// )
// },
// )()
// ) {
// actionOnFailure()
// }
if (safeToRunWithLogger(
logger = logger(checkName),
{ banAvdEmulatorCheck() },
{ banGenymotionEmulatorCheck() },
{ banBluestacksEmulatorCheck() },
{ blacklistedAppCheck("Test app", "Test app 2") },
{ rootDetectionCheck() },
{
safeToRunCombinedCheck(
listOf(
{ bannedHardwareCheck("hardware") },
{ bannedBoardCheck("board") }
)
)
},
{
safeToRunCombinedCheck(
listOf { installOriginCheckWithDefaultsCheck() },
listOf { !BuildConfig.DEBUG }
)
},
)()
) {
actionOnFailure()
}
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
Expand Down
56 changes: 28 additions & 28 deletions app/src/main/java/com/andro/secure/report/ReportFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,34 +68,34 @@ class ReportFragment : Fragment() {


private inline fun Context.canIRun(checkName: String, actionOnFailure: () -> Unit) {
// if (safeToRunWithLogger(
// logger = loggerForCheck(checkName),
// { verifySignatureCheck() },
// { banAvdEmulatorCheck() },
// { banGenymotionEmulatorCheck() },
// { banBluestacksEmulatorCheck() },
// { blacklistedAppCheck("Test app", "Test app 2") },
// { rootDetectionCheck() },
// { isDebuggableCheck() },
// {
// safeToRunCombinedCheck(
// listOf(
// { bannedHardwareCheck("hardware") },
// { bannedBoardCheck("board") }
// )
// )
// },
// {
// safeToRunCombinedCheck(
// listOf { installOriginCheckWithDefaultsCheck() },
// listOf { !BuildConfig.DEBUG }
// )
// },
// { verifySignatureCheck("Abc") }
// )()
// ) {
// actionOnFailure()
// }
if (safeToRunWithLogger(
logger = loggerForCheck(checkName),
{ verifySignatureCheck() },
{ banAvdEmulatorCheck() },
{ banGenymotionEmulatorCheck() },
{ banBluestacksEmulatorCheck() },
{ blacklistedAppCheck("Test app", "Test app 2") },
{ rootDetectionCheck() },
{ isDebuggableCheck() },
{
safeToRunCombinedCheck(
listOf(
{ bannedHardwareCheck("hardware") },
{ bannedBoardCheck("board") }
)
)
},
{
safeToRunCombinedCheck(
listOf { installOriginCheckWithDefaultsCheck() },
listOf { !BuildConfig.DEBUG }
)
},
{ verifySignatureCheck("Abc") }
)()
) {
actionOnFailure()
}
}

companion object {
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ buildscript {
}



plugins {
id "com.diffplug.spotless" version "5.7.0"
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ recyclerView=1.2.1
jwtVersion=3.15.0
mockHttpVersion=5.11.2
coreKtxVersion=1.6.0
robolectricVersion=4.4
jupiterVersion=5.8.1
junitVersion=4.13.2
androidXTest=1.4.0
Expand Down
4 changes: 1 addition & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ kotlin = "1.8.10"
mockk = "1.13.5"
rootbeer = "0.1.0"
googleTruth = "1.1.3"
securityCrypto = "1.0.0"
spek_ = "2.0.12"
epoxy = "4.6.4"
recyclerView = "1.3.0"
Expand All @@ -12,7 +11,7 @@ jwt = "3.15.0"
serialization = "1.5.0"
mockHttp = "5.11.2"
coreKtx = "1.6.0"
robolectric = "4.10.3"
robolectric = "4.4"
jupiter = "5.8.1"
junit = "4.13.2"
androidXTest = "1.4.0"
Expand All @@ -26,7 +25,6 @@ safeToRun = "2.2.4"
work_version = "2.8.1"

[libraries]
androidx-security-crypto = { module = "androidx.security:security-crypto", version.ref = "securityCrypto" }
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "serialization" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
Expand Down
6 changes: 3 additions & 3 deletions safeToRun/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
jvmTarget = JavaVersion.VERSION_1_8.toString()
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,89 +7,75 @@ import android.os.Build
*
* @param minOSVersion minimum os version
*/
inline fun minOsVersionCheck(
minOSVersion: Int,
osCheck: OSInformationQuery = osInformationQuery()
) =
minOSVersion > osCheck.osVersion()
inline fun minOsVersionCheck(minOSVersion: Int) =
minOSVersion > Build.VERSION.SDK_INT

/**
* Configure to disallow a manufacturer - i.e. fail if it's this
* manufacturer specified
*
* @param manufacturerName name of the manufacturer
*/
inline fun notManufacturerCheck(
manufacturerName: String,
osCheck: OSInformationQuery = osInformationQuery()
) =
osCheck.manufacturer() == manufacturerName
inline fun notManufacturerCheck(manufacturerName: String) =
Build.MANUFACTURER == manufacturerName

/**
* Ban a model from running - i.e. if you add a model that
* model will not run if that is the model
*
* @param bannedModel the model to ban
*/
inline fun bannedModelCheck(
bannedModel: String,
osCheck: OSInformationQuery = osInformationQuery()
) =
osCheck.model() == bannedModel
inline fun bannedModelCheck(bannedModel: String) =
Build.MODEL == bannedModel

/**
* Add a banned board to the list
*
* @param bannedBoard the model to ban
*/
inline fun bannedBoardCheck(
bannedBoard: String,
osCheck: OSInformationQuery = osInformationQuery()
) =
osCheck.board() == bannedBoard
inline fun bannedBoardCheck(bannedBoard: String) =
Build.BOARD == bannedBoard

/**
* Add a banned cpuAbis
*
* @param cpuAbi the model to ban
*/
inline fun bannedCpusCheck(cpuAbi: String, osCheck: OSInformationQuery = osInformationQuery()) =
osCheck.cpuAbi().contains(cpuAbi)
inline fun bannedCpusCheck(cpuAbi: String) =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Build.SUPPORTED_ABIS.contains(cpuAbi)
} else {
false
}

/**
* Add a banned bootloader to the list
*
* @param bannedBootloader the model to ban
*/
inline fun bannedBootloaderCheck(
bannedBootloader: String,
osCheck: OSInformationQuery = osInformationQuery()
) =
osCheck.bootloader() == bannedBootloader
inline fun bannedBootloaderCheck(bannedBootloader: String) =
Build.BOOTLOADER == bannedBootloader

/**
* Add a banned device
*
* @param device device to ban
*/
inline fun bannedDeviceCheck(device: String, osCheck: OSInformationQuery = osInformationQuery()) =
osCheck.device() == device
inline fun bannedDeviceCheck(device: String) =
Build.DEVICE == device

/**
* Add a banned host
*
* @param hardware hardware to ban
*/
inline fun bannedHardwareCheck(
hardware: String,
osCheck: OSInformationQuery = osInformationQuery()
) =
osCheck.hardware() == hardware
inline fun bannedHardwareCheck(hardware: String) =
Build.HARDWARE == hardware

/**
* Add a banned host
*
* @param host the model to ban
*/
inline fun bannedHostCheck(host: String, osCheck: OSInformationQuery = osInformationQuery()) =
osCheck.host() == host
inline fun bannedHostCheck(host: String) =
Build.HOST == host
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,20 @@ package com.safetorun.features.oscheck

import android.os.Build

/**
* OSInformationQueryAndroid is a concrete implementation of the OSInformationQuery interface.
* It uses Android's Build class to query various details about the device's operating system.
*/
class OSInformationQueryAndroid : OSInformationQuery {

/**
* Returns the SDK version of the current Android operating system.
*/
internal class OSInformationQueryAndroid : OSInformationQuery {
override fun osVersion(): Int = Build.VERSION.SDK_INT

/**
* Returns the manufacturer of the device.
*/
override fun manufacturer(): String = Build.MANUFACTURER

/**
* Returns the model of the device.
*/
override fun model(): String = Build.MODEL

/**
* Returns the board of the device.
*/
override fun board(): String = Build.BOARD

/**
* Returns the bootloader version of the device.
*/
override fun bootloader(): String = Build.BOOTLOADER

/**
* Returns a list of supported ABI (Application Binary Interface).
* If the SDK version is lower than LOLLIPOP, returns an empty list.
*/
override fun cpuAbi(): List<String> =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Build.SUPPORTED_ABIS.toList()
} else {
emptyList()
}

/**
* Returns the hostname of the device.
*/
override fun host(): String = Build.HOST

/**
* Returns the hardware information of the device.
*/
override fun hardware(): String = Build.HARDWARE

/**
* Returns the device identifier.
*/
override fun device(): String = Build.DEVICE
}

/**
* Creates and returns an instance of OSInformationQueryAndroid.
* This function serves as a factory for creating OSInformationQueryAndroid instances.
*/
inline fun osInformationQuery(): OSInformationQuery = OSInformationQueryAndroid()
Loading

0 comments on commit e58f8fa

Please sign in to comment.