Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dllewellyn committed Sep 23, 2023
2 parents b82b618 + 389ce9e commit b0b5abb
Show file tree
Hide file tree
Showing 15 changed files with 277 additions and 242 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 = "11"
jvmTarget = JavaVersion.VERSION_11.toString()
}

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
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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 @@ -11,7 +12,7 @@ jwt = "3.15.0"
serialization = "1.5.0"
mockHttp = "5.11.2"
coreKtx = "1.6.0"
robolectric = "4.4"
robolectric = "4.10.3"
jupiter = "5.8.1"
junit = "4.13.2"
androidXTest = "1.4.0"
Expand All @@ -27,6 +28,7 @@ mockHttpVersion = "5.11.2"
jupiterVersion = "5.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
Original file line number Diff line number Diff line change
Expand Up @@ -7,75 +7,89 @@ import android.os.Build
*
* @param minOSVersion minimum os version
*/
inline fun minOsVersionCheck(minOSVersion: Int) =
minOSVersion > Build.VERSION.SDK_INT
inline fun minOsVersionCheck(
minOSVersion: Int,
osCheck: OSInformationQuery = osInformationQuery()
) =
minOSVersion > osCheck.osVersion()

/**
* 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) =
Build.MANUFACTURER == manufacturerName
inline fun notManufacturerCheck(
manufacturerName: String,
osCheck: OSInformationQuery = osInformationQuery()
) =
osCheck.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) =
Build.MODEL == bannedModel
inline fun bannedModelCheck(
bannedModel: String,
osCheck: OSInformationQuery = osInformationQuery()
) =
osCheck.model() == bannedModel

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

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

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

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

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

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

import android.os.Build
import com.safetorun.features.oscheck.OSInformationQuery
import com.safetorun.features.oscheck.OsCheckConstants
import com.safetorun.features.oscheck.OsCheckConstants.XIAOMI
import com.safetorun.features.oscheck.osInformationQuery

/**
* Return true if we're running on an emulator
*
* @return true if we're running on avd
*/
inline fun banAvdEmulatorCheck() =
isXiaomi().not() && (Build.BOOTLOADER == OsCheckConstants.UNKNOWN ||
Build.DEVICE == OsCheckConstants.AVD_DEVICE_TYPE ||
Build.BOARD == OsCheckConstants.AVD_EMULATOR_BOARD)
inline fun banAvdEmulatorCheck(osInformationQuery: OSInformationQuery = osInformationQuery()) =
isXiaomi(osInformationQuery).not() && (osInformationQuery.bootloader() == OsCheckConstants.UNKNOWN ||
osInformationQuery.device() == OsCheckConstants.AVD_DEVICE_TYPE ||
osInformationQuery.board() == OsCheckConstants.AVD_EMULATOR_BOARD)

/**
* Ban bluestacks
*
* @return true if we're running on bluestacks
*/
inline fun banBluestacksEmulatorCheck() =
isXiaomi().not() && Build.BOOTLOADER == OsCheckConstants.UNKNOWN
inline fun banBluestacksEmulatorCheck(osInformationQuery: OSInformationQuery = osInformationQuery()) =
isXiaomi(osInformationQuery).not() && osInformationQuery.bootloader() == OsCheckConstants.UNKNOWN

/**
* Ban the genymotion emulator
*
* @return true if we're running on the genymotion emulator
*/
inline fun banGenymotionEmulatorCheck() =
isXiaomi().not() && (Build.BOARD == OsCheckConstants.UNKNOWN ||
Build.MANUFACTURER == OsCheckConstants.GENYMOTION_MANUFACTURER ||
Build.BOOTLOADER == OsCheckConstants.UNKNOWN)
inline fun banGenymotionEmulatorCheck(osInformationQuery: OSInformationQuery = osInformationQuery()) =
isXiaomi(osInformationQuery).not() && (osInformationQuery.board() == OsCheckConstants.UNKNOWN ||
osInformationQuery.manufacturer() == OsCheckConstants.GENYMOTION_MANUFACTURER ||
osInformationQuery.bootloader() == OsCheckConstants.UNKNOWN)

/**
* Returns true if the device is a Xiaomi device
*
* @return true if we're on a Xiaomi device
*/
inline fun isXiaomi() = Build.MANUFACTURER == XIAOMI
inline fun isXiaomi(osInformationQuery: OSInformationQuery = osInformationQuery()) =
osInformationQuery.manufacturer() == XIAOMI
Loading

0 comments on commit b0b5abb

Please sign in to comment.