-
-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
145 changed files
with
2,449 additions
and
665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
plugins { | ||
id("com.android.library") | ||
id("org.jetbrains.kotlin.android") | ||
id("kotlin-android") | ||
id("kotlin-kapt") | ||
} | ||
|
||
android { | ||
namespace = "eu.darken.sdmse.common" | ||
compileSdk = ProjectConfig.compileSdk | ||
|
||
defaultConfig { | ||
minSdk = ProjectConfig.minSdk | ||
targetSdk = ProjectConfig.targetSdk | ||
} | ||
|
||
setupModuleBuildTypes() | ||
|
||
buildFeatures { | ||
viewBinding = true | ||
} | ||
|
||
setupCompileOptions() | ||
|
||
setupKotlinOptions() | ||
|
||
testOptions { | ||
unitTests { | ||
isIncludeAndroidResources = true | ||
} | ||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:${Versions.Desugar.core}") | ||
implementation(project(":app-common")) | ||
|
||
addAndroidCore() | ||
addIO() | ||
addSerialization() | ||
|
||
implementation("junit:junit:4.13.2") | ||
implementation("org.junit.vintage:junit-vintage-engine:5.8.2") | ||
implementation("androidx.test:core-ktx:1.4.0") | ||
|
||
implementation("io.mockk:mockk:1.12.4") | ||
|
||
runtimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2") | ||
implementation("org.junit.jupiter:junit-jupiter-api:5.8.2") | ||
implementation("org.junit.jupiter:junit-jupiter-params:5.8.2") | ||
|
||
|
||
implementation("io.kotest:kotest-runner-junit5:5.3.0") | ||
implementation("io.kotest:kotest-assertions-core-jvm:5.3.0") | ||
implementation("io.kotest:kotest-property-jvm:5.3.0") | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest> | ||
|
||
</manifest> |
8 changes: 3 additions & 5 deletions
8
app/src/test/java/testhelper/BaseTest.kt → ...est/src/main/java/testhelpers/BaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...lper/coroutine/CoroutinesTestExtension.kt → ...pers/coroutine/CoroutinesTestExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...elper/coroutine/TestDispatcherProvider.kt → ...lpers/coroutine/TestDispatcherProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...va/testhelper/coroutine/TestExtensions.kt → ...a/testhelpers/coroutine/TestExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...src/test/java/testhelper/flow/FlowTest.kt → ...rc/main/java/testhelpers/flow/FlowTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...st/java/testhelper/json/JsonExtensions.kt → ...n/java/testhelpers/json/JsonExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...lper/livedata/InstantExecutorExtension.kt → ...pers/livedata/InstantExecutorExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
plugins { | ||
id("com.android.library") | ||
id("org.jetbrains.kotlin.android") | ||
id("kotlin-android") | ||
id("kotlin-kapt") | ||
id("kotlin-parcelize") | ||
} | ||
|
||
apply(plugin = "dagger.hilt.android.plugin") | ||
|
||
android { | ||
namespace = "${ProjectConfig.packageName}.common" | ||
compileSdk = ProjectConfig.compileSdk | ||
|
||
defaultConfig { | ||
minSdk = ProjectConfig.minSdk | ||
targetSdk = ProjectConfig.targetSdk | ||
} | ||
|
||
setupModuleBuildTypes() | ||
|
||
buildFeatures { | ||
viewBinding = true | ||
} | ||
|
||
setupCompileOptions() | ||
|
||
setupKotlinOptions() | ||
|
||
testOptions { | ||
unitTests { | ||
isIncludeAndroidResources = true | ||
} | ||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:${Versions.Desugar.core}") | ||
testImplementation(project(":app-common-test")) | ||
|
||
addAndroidCore() | ||
addAndroidUI() | ||
addDI() | ||
addCoroutines() | ||
addSerialization() | ||
addIO() | ||
addTesting() | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
22 changes: 22 additions & 0 deletions
22
app-common/src/androidTest/java/eu/darken/sdmse/common/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package eu.darken.sdmse.common | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import org.junit.Assert.* | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("eu.darken.sdmse.common.test", appContext.packageName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest> | ||
|
||
</manifest> |
63 changes: 63 additions & 0 deletions
63
app-common/src/main/java/eu/darken/sdmse/common/common/BuildConfigWrap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package eu.darken.sdmse.common | ||
|
||
import android.util.Log | ||
import androidx.annotation.Keep | ||
import java.lang.reflect.Field | ||
import java.time.Instant | ||
|
||
|
||
// Can't be const because that prevents them from being mocked in tests | ||
@Suppress("MayBeConstant") | ||
@Keep | ||
object BuildConfigWrap { | ||
val APPLICATION_ID = getBuildConfigValue("PACKAGENAME") as String | ||
val DEBUG: Boolean = getBuildConfigValue("DEBUG") as Boolean | ||
val BUILD_TYPE: BuildType = when (val typ = getBuildConfigValue("BUILD_TYPE") as String) { | ||
"debug" -> BuildType.DEV | ||
"beta" -> BuildType.BETA | ||
"release" -> BuildType.RELEASE | ||
else -> throw IllegalArgumentException("Unknown buildtype: $typ") | ||
} | ||
|
||
@Keep | ||
enum class BuildType { | ||
DEV, | ||
BETA, | ||
RELEASE, | ||
; | ||
} | ||
|
||
val FLAVOR: Flavor = when (val flav = getBuildConfigValue("FLAVOR") as String?) { | ||
"gplay" -> Flavor.GPLAY | ||
"foss" -> Flavor.FOSS | ||
null -> Flavor.NONE | ||
else -> throw IllegalStateException("Unknown flavor: $flav") | ||
} | ||
|
||
enum class Flavor { | ||
GPLAY, | ||
FOSS, | ||
NONE, | ||
; | ||
} | ||
|
||
val BUILD_TIME: Instant = Instant.parse(getBuildConfigValue("BUILDTIME") as String) | ||
|
||
val VERSION_CODE: Long = (getBuildConfigValue("VERSION_CODE") as String).toLong() | ||
val VERSION_NAME: String = getBuildConfigValue("VERSION_NAME") as String | ||
val GIT_SHA: String = getBuildConfigValue("GITSHA") as String | ||
|
||
val VERSION_DESCRIPTION: String = "v$VERSION_NAME ($VERSION_CODE) ~ $GIT_SHA/$FLAVOR/$BUILD_TYPE" | ||
|
||
private fun getBuildConfigValue(fieldName: String): Any? = try { | ||
val c = Class.forName("eu.darken.sdmse.BuildConfig") | ||
val f: Field = c.getField(fieldName).apply { | ||
isAccessible = true | ||
} | ||
f.get(null) | ||
} catch (e: Exception) { | ||
Log.e("getBuildConfigValue", "fieldName: $fieldName") | ||
e.printStackTrace() | ||
null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
app-common/src/main/java/eu/darken/sdmse/common/common/JUnitLogger.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package eu.darken.sdmse.common | ||
|
||
import eu.darken.sdmse.common.debug.logging.Logging | ||
|
||
class JUnitLogger(private val minLogLevel: Logging.Priority = Logging.Priority.VERBOSE) : Logging.Logger { | ||
|
||
override fun isLoggable(priority: Logging.Priority): Boolean = priority.intValue >= minLogLevel.intValue | ||
|
||
override fun log(priority: Logging.Priority, tag: String, message: String, metaData: Map<String, Any>?) { | ||
println("${System.currentTimeMillis()} ${priority.shortLabel}/$tag: $message") | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
app-common/src/main/java/eu/darken/sdmse/common/common/PackageManagerExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package eu.darken.sdmse.common | ||
|
||
import android.content.pm.ApplicationInfo | ||
import android.content.pm.PackageInfo | ||
import android.content.pm.PackageManager | ||
import android.graphics.drawable.Drawable | ||
|
||
fun PackageManager.getPackageInfo2( | ||
packageName: String, | ||
flags: Int = 0 | ||
): PackageInfo? = try { | ||
getPackageInfo(packageName, flags) | ||
} catch (_: PackageManager.NameNotFoundException) { | ||
null | ||
} | ||
|
||
fun PackageManager.getLabel2( | ||
pkgId: String, | ||
): String? = getPackageInfo2(pkgId) | ||
?.applicationInfo | ||
?.let { | ||
if (it.labelRes != 0) it.loadLabel(this).toString() | ||
else it.nonLocalizedLabel?.toString() | ||
} | ||
|
||
fun PackageManager.getIcon2( | ||
pkgId: String, | ||
): Drawable? = getPackageInfo2(pkgId) | ||
?.applicationInfo | ||
?.let { if (it.icon != 0) it.loadIcon(this) else null } | ||
|
||
val PackageInfo.isSystemApp: Boolean | ||
get() = applicationInfo?.run { flags and ApplicationInfo.FLAG_SYSTEM != 0 } ?: true |
11 changes: 11 additions & 0 deletions
11
app-common/src/main/java/eu/darken/sdmse/common/common/TextExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package eu.darken.sdmse.common | ||
|
||
import android.text.SpannableString | ||
import android.text.style.ForegroundColorSpan | ||
import androidx.annotation.ColorInt | ||
|
||
fun colorString(@ColorInt color: Int, string: String): SpannableString { | ||
val colored = SpannableString(string) | ||
colored.setSpan(ForegroundColorSpan(color), 0, string.length, 0) | ||
return colored | ||
} |
Oops, something went wrong.