Function | Description |
---|---|
preloadClasses | Loads core Java classes listed in /system/etc/preloaded-classes, which are necessary for the system and apps. |
cacheNonBootClasspathClassLoaders | Loads libraries and classes commonly used by many apps but not part of the boot classpath, such as HIDL libraries, android.test.base, apache.http and certain AndroidX window manager components. |
preloadResources | Loads frequently used resources like drawables, colors, strings, and typed arrays so they can be shared across processes. |
nativePreloadAppProcessHALs | Loads HAL native libraries, including Audio HAL, Camera HAL, and other shared native components, to prepar |
This file contains hidden or 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
class Application : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
if (BuildConfig.DEBUG) { | |
applyStrictMode() | |
} | |
} | |
private fun applyStrictMode() { |
This file contains hidden or 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 is simple processor that use KSP API to generate | |
* extension function for annotated classes with [HelloWorldAnnotation] | |
*/ | |
class HelloWorldProcessor( | |
private val logger: KSPLogger, | |
private val codeGenerator: CodeGenerator | |
) : SymbolProcessor { | |
override fun process(resolver: Resolver): List<KSAnnotated> { |
This file contains hidden or 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
@Retention(AnnotationRetention.RUNTIME) | |
@Target(AnnotationTarget.CLASS) | |
@SinceKotlin("1.3") | |
annotation class Metadata( | |
@get:JvmName("k") val kind: Int = 1, | |
@get:JvmName("mv") val metadataVersion: IntArray = [], | |
@get:JvmName("bv") val bytecodeVersion: IntArray = [1, 0, 3], | |
@get:JvmName("di") val data1: Array<String> = [], | |
@get:JvmName("d2") val data2: Array<String> = [], | |
@get:JvmName("xs") val extraString: String = "", |
This file contains hidden or 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
// Declare Annotation in Kotlin | |
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | |
@Retention(AnnotationRetention.SOURCE) | |
@Repeatable | |
annotation class HelloWorldAnnotation |
This file contains hidden or 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 is simple processor that use JSR-269 API and kotlinpoet library to generate | |
* extension function for annotated classes with [HelloWorldAnnotation] | |
*/ | |
class HelloWorldProcessor : AbstractProcessor() { | |
override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment?): Boolean { | |
val typeElement = annotations?.firstOrNull() ?: return false | |
for (annotatedElement in roundEnv?.getElementsAnnotatedWith(typeElement) ?: setOf()) { |
This file contains hidden or 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
/** | |
* Simply security manager that check the packages and if equal | |
* to "java.lang.reflect" or "kotlin.reflect" throws [SecurityException] | |
*/ | |
class AppSecurityManager : SecurityManager() { | |
override fun checkPackageAccess(pkg: String?) { | |
if (pkg == "java.lang.reflect" || pkg == "kotlin.reflect") { | |
throw SecurityException("Reflection is not allowed in this program") | |
} |
This file contains hidden or 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
/** | |
* Simple singleton class with double-check pattern | |
*/ | |
class Singleton private constructor() { | |
private val data: String = "data property value" | |
@Volatile | |
private var singleton: Singleton? = null |
This file contains hidden or 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
fun main() { | |
val singletonKClass = Singleton::class | |
singletonKClass.constructors.firstOrNull { it.visibility == KVisibility.PRIVATE }?.also { privateConstructor -> | |
/** | |
* We give access to private constructor and we can create instance | |
* from [Singleton] class [privateConstructor.call] method | |
*/ | |
privateConstructor.isAccessible = true | |
val singletonNewObject = privateConstructor.call() |
This file contains hidden or 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
dependencies { | |
implementation "org.jetbrains.kotlin:kotlin-reflect:{latest_version}" | |
} |
NewerOlder