aftermath of adding kotlinter to all modules

This commit is contained in:
Aria Moradi
2021-09-25 04:34:02 +03:30
parent 13b034875b
commit 13ec45a95c
23 changed files with 125 additions and 124 deletions

View File

@@ -14,7 +14,7 @@ const val CONFIG_PREFIX = "suwayomi.tachidesk.config"
val ApplicationRootDir: String val ApplicationRootDir: String
get(): String { get(): String {
return System.getProperty( return System.getProperty(
"$CONFIG_PREFIX.server.rootDir", "$CONFIG_PREFIX.server.rootDir",
AppDirsFactory.getInstance().getUserDataDir("Tachidesk", null, null) AppDirsFactory.getInstance().getUserDataDir("Tachidesk", null, null)
) )
} }

View File

@@ -6,7 +6,7 @@ import org.kodein.di.singleton
class ConfigKodeinModule { class ConfigKodeinModule {
fun create() = DI.Module("ConfigManager") { fun create() = DI.Module("ConfigManager") {
//Config module // Config module
bind<ConfigManager>() with singleton { GlobalConfigManager } bind<ConfigManager>() with singleton { GlobalConfigManager }
} }
} }

View File

@@ -21,7 +21,7 @@ open class ConfigManager {
private val generatedModules = mutableMapOf<Class<out ConfigModule>, ConfigModule>() private val generatedModules = mutableMapOf<Class<out ConfigModule>, ConfigModule>()
val config by lazy { loadConfigs() } val config by lazy { loadConfigs() }
//Public read-only view of modules // Public read-only view of modules
val loadedModules: Map<Class<out ConfigModule>, ConfigModule> val loadedModules: Map<Class<out ConfigModule>, ConfigModule>
get() = generatedModules get() = generatedModules
@@ -42,29 +42,28 @@ open class ConfigManager {
* Load configs * Load configs
*/ */
fun loadConfigs(): Config { fun loadConfigs(): Config {
//Load reference configs // Load reference configs
val compatConfig = ConfigFactory.parseResources("compat-reference.conf") val compatConfig = ConfigFactory.parseResources("compat-reference.conf")
val serverConfig = ConfigFactory.parseResources("server-reference.conf") val serverConfig = ConfigFactory.parseResources("server-reference.conf")
val baseConfig = val baseConfig =
ConfigFactory.parseMap( ConfigFactory.parseMap(
mapOf( mapOf(
"androidcompat.rootDir" to "$ApplicationRootDir/android-compat" // override AndroidCompat's rootDir "androidcompat.rootDir" to "$ApplicationRootDir/android-compat" // override AndroidCompat's rootDir
)
) )
)
//Load user config // Load user config
val userConfig = val userConfig =
File(ApplicationRootDir, "server.conf").let { File(ApplicationRootDir, "server.conf").let {
ConfigFactory.parseFile(it) ConfigFactory.parseFile(it)
} }
val config = ConfigFactory.empty() val config = ConfigFactory.empty()
.withFallback(baseConfig) .withFallback(baseConfig)
.withFallback(userConfig) .withFallback(userConfig)
.withFallback(compatConfig) .withFallback(compatConfig)
.withFallback(serverConfig) .withFallback(serverConfig)
.resolve() .resolve()
// set log level early // set log level early
if (debugLogsEnabled(config)) { if (debugLogsEnabled(config)) {

View File

@@ -20,7 +20,7 @@ abstract class ConfigModule(config: Config)
/** /**
* Abstract jvm-commandline-argument-overridable config module. * Abstract jvm-commandline-argument-overridable config module.
*/ */
abstract class SystemPropertyOverridableConfigModule(config: Config, moduleName: String): ConfigModule(config) { abstract class SystemPropertyOverridableConfigModule(config: Config, moduleName: String) : ConfigModule(config) {
val overridableConfig = SystemPropertyOverrideDelegate(config, moduleName) val overridableConfig = SystemPropertyOverrideDelegate(config, moduleName)
} }
@@ -34,7 +34,7 @@ class SystemPropertyOverrideDelegate(val config: Config, val moduleName: String)
configValue.toString() configValue.toString()
) )
return when(T::class.simpleName) { return when (T::class.simpleName) {
"Int" -> combined.toInt() "Int" -> combined.toInt()
"Boolean" -> combined.toBoolean() "Boolean" -> combined.toBoolean()
// add more types as needed // add more types as needed

View File

@@ -16,5 +16,5 @@ fun setLogLevel(level: Level) {
(KotlinLogging.logger(Logger.ROOT_LOGGER_NAME).underlyingLogger as ch.qos.logback.classic.Logger).level = level (KotlinLogging.logger(Logger.ROOT_LOGGER_NAME).underlyingLogger as ch.qos.logback.classic.Logger).level = level
} }
fun debugLogsEnabled(config: Config) fun debugLogsEnabled(config: Config) =
= System.getProperty("suwayomi.tachidesk.config.server.debugLogsEnabled", config.getString("server.debugLogsEnabled")).toBoolean() System.getProperty("suwayomi.tachidesk.config.server.debugLogsEnabled", config.getString("server.debugLogsEnabled")).toBoolean()

View File

@@ -3,4 +3,4 @@ package xyz.nulldev.ts.config.util
import com.typesafe.config.Config import com.typesafe.config.Config
operator fun Config.get(key: String) = getString(key) operator fun Config.get(key: String) = getString(key)
?: throw IllegalStateException("Could not find value for config entry: $key!") ?: throw IllegalStateException("Could not find value for config entry: $key!")

View File

@@ -9,8 +9,10 @@ import android.content.Context
class PreferenceManager { class PreferenceManager {
companion object { companion object {
@JvmStatic @JvmStatic
fun getDefaultSharedPreferences(context: Context) fun getDefaultSharedPreferences(context: Context) =
= context.getSharedPreferences(context.applicationInfo.packageName, context.getSharedPreferences(
Context.MODE_PRIVATE)!! context.applicationInfo.packageName,
Context.MODE_PRIVATE
)!!
} }
} }

View File

@@ -5,4 +5,4 @@ import android.arch.persistence.db.framework.FrameworkSQLiteOpenHelperFactory
class RequerySQLiteOpenHelperFactory { class RequerySQLiteOpenHelperFactory {
fun create(configuration: SupportSQLiteOpenHelper.Configuration) = FrameworkSQLiteOpenHelperFactory().create(configuration) fun create(configuration: SupportSQLiteOpenHelper.Configuration) = FrameworkSQLiteOpenHelperFactory().create(configuration)
} }

View File

@@ -14,4 +14,4 @@ class AndroidCompat {
application.attach(context) application.attach(context)
application.onCreate() application.onCreate()
} }
} }

View File

@@ -14,7 +14,7 @@ class AndroidCompatInitializer {
fun init() { fun init() {
DI.global.addImport(AndroidCompatModule().create()) DI.global.addImport(AndroidCompatModule().create())
//Register config modules // Register config modules
GlobalConfigManager.registerModules( GlobalConfigManager.registerModules(
FilesConfigModule.register(GlobalConfigManager.config), FilesConfigModule.register(GlobalConfigManager.config),
ApplicationInfoConfigModule.register(GlobalConfigManager.config), ApplicationInfoConfigModule.register(GlobalConfigManager.config),

View File

@@ -29,7 +29,7 @@ class AndroidCompatModule {
bind<PackageController>() with singleton { PackageController() } bind<PackageController>() with singleton { PackageController() }
//Context // Context
bind<CustomContext>() with singleton { CustomContext() } bind<CustomContext>() with singleton { CustomContext() }
bind<Context>() with singleton { bind<Context>() with singleton {
val context: Context by DI.global.instance<CustomContext>() val context: Context by DI.global.instance<CustomContext>()

View File

@@ -13,7 +13,7 @@ class ApplicationInfoConfigModule(config: Config) : ConfigModule(config) {
val debug: Boolean by config val debug: Boolean by config
companion object { companion object {
fun register(config: Config) fun register(config: Config) =
= ApplicationInfoConfigModule(config.getConfig("android.app")) ApplicationInfoConfigModule(config.getConfig("android.app"))
} }
} }

View File

@@ -9,26 +9,26 @@ import xyz.nulldev.ts.config.ConfigModule
*/ */
class FilesConfigModule(config: Config) : ConfigModule(config) { class FilesConfigModule(config: Config) : ConfigModule(config) {
val dataDir:String by config val dataDir: String by config
val filesDir:String by config val filesDir: String by config
val noBackupFilesDir:String by config val noBackupFilesDir: String by config
val externalFilesDirs: MutableList<String> by config val externalFilesDirs: MutableList<String> by config
val obbDirs: MutableList<String> by config val obbDirs: MutableList<String> by config
val cacheDir:String by config val cacheDir: String by config
val codeCacheDir:String by config val codeCacheDir: String by config
val externalCacheDirs: MutableList<String> by config val externalCacheDirs: MutableList<String> by config
val externalMediaDirs: MutableList<String> by config val externalMediaDirs: MutableList<String> by config
val rootDir:String by config val rootDir: String by config
val externalStorageDir:String by config val externalStorageDir: String by config
val downloadCacheDir:String by config val downloadCacheDir: String by config
val databasesDir:String by config val databasesDir: String by config
val prefsDir:String by config val prefsDir: String by config
val packageDir:String by config val packageDir: String by config
companion object { companion object {
fun register(config: Config) fun register(config: Config) =
= FilesConfigModule(config.getConfig("android.files")) FilesConfigModule(config.getConfig("android.files"))
} }
} }

View File

@@ -1,8 +1,8 @@
package xyz.nulldev.androidcompat.config package xyz.nulldev.androidcompat.config
import com.typesafe.config.Config import com.typesafe.config.Config
import xyz.nulldev.ts.config.ConfigModule
import io.github.config4k.getValue import io.github.config4k.getValue
import xyz.nulldev.ts.config.ConfigModule
class SystemConfigModule(val config: Config) : ConfigModule(config) { class SystemConfigModule(val config: Config) : ConfigModule(config) {
val isDebuggable: Boolean by config val isDebuggable: Boolean by config
@@ -16,7 +16,7 @@ class SystemConfigModule(val config: Config) : ConfigModule(config) {
fun hasProperty(property: String) = config.hasPath("$propertyPrefix$property") fun hasProperty(property: String) = config.hasPath("$propertyPrefix$property")
companion object { companion object {
fun register(config: Config) fun register(config: Config) =
= SystemConfigModule(config.getConfig("android.system")) SystemConfigModule(config.getConfig("android.system"))
} }
} }

View File

@@ -29,7 +29,7 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
val parentMetadata = parent.metaData val parentMetadata = parent.metaData
val columnCount = parentMetadata.columnCount val columnCount = parentMetadata.columnCount
val columnLabels = (1 .. columnCount).map { val columnLabels = (1..columnCount).map {
parentMetadata.getColumnLabel(it) parentMetadata.getColumnLabel(it)
}.toTypedArray() }.toTypedArray()
@@ -41,10 +41,10 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
// How can we optimize this? // How can we optimize this?
// We need to fill the cache as the set is loaded // We need to fill the cache as the set is loaded
//Fill cache // Fill cache
while(parent.next()) { while (parent.next()) {
cachedContent += ResultSetEntry().apply { cachedContent += ResultSetEntry().apply {
for(i in 1 .. columnCount) for (i in 1..columnCount)
data += parent.getObject(i) data += parent.getObject(i)
} }
resultSetLength++ resultSetLength++
@@ -60,8 +60,8 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
} }
private fun internalMove(row: Int) { private fun internalMove(row: Int) {
if(cursor < 0) cursor = 0 if (cursor < 0) cursor = 0
else if(cursor > resultSetLength + 1) cursor = resultSetLength + 1 else if (cursor > resultSetLength + 1) cursor = resultSetLength + 1
else cursor = row else cursor = row
} }
@@ -75,10 +75,10 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
return obj(cachedFindColumn(column)) return obj(cachedFindColumn(column))
} }
private fun cachedFindColumn(column: String?) private fun cachedFindColumn(column: String?) =
= columnCache.getOrPut(column!!, { columnCache.getOrPut(column!!, {
findColumn(column) findColumn(column)
}) })
override fun getNClob(columnIndex: Int): NClob { override fun getNClob(columnIndex: Int): NClob {
return obj(columnIndex) as NClob return obj(columnIndex) as NClob
@@ -157,27 +157,27 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
} }
override fun getDate(columnIndex: Int): Date { override fun getDate(columnIndex: Int): Date {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getDate(columnLabel: String?): Date { override fun getDate(columnLabel: String?): Date {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getDate(columnIndex: Int, cal: Calendar?): Date { override fun getDate(columnIndex: Int, cal: Calendar?): Date {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getDate(columnLabel: String?, cal: Calendar?): Date { override fun getDate(columnLabel: String?, cal: Calendar?): Date {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun beforeFirst() { override fun beforeFirst() {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
@@ -202,12 +202,12 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
} }
override fun getBigDecimal(columnIndex: Int, scale: Int): BigDecimal { override fun getBigDecimal(columnIndex: Int, scale: Int): BigDecimal {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getBigDecimal(columnLabel: String?, scale: Int): BigDecimal { override fun getBigDecimal(columnLabel: String?, scale: Int): BigDecimal {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
@@ -236,22 +236,22 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
} }
override fun getTime(columnIndex: Int): Time { override fun getTime(columnIndex: Int): Time {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getTime(columnLabel: String?): Time { override fun getTime(columnLabel: String?): Time {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getTime(columnIndex: Int, cal: Calendar?): Time { override fun getTime(columnIndex: Int, cal: Calendar?): Time {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getTime(columnLabel: String?, cal: Calendar?): Time { override fun getTime(columnLabel: String?, cal: Calendar?): Time {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
@@ -272,28 +272,28 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
} }
override fun absolute(row: Int): Boolean { override fun absolute(row: Int): Boolean {
if(row > 0) { if (row > 0) {
internalMove(row) internalMove(row)
} else { } else {
last() last()
for(i in 1 .. row) for (i in 1..row)
previous() previous()
} }
return cursorValid() return cursorValid()
} }
override fun getSQLXML(columnIndex: Int): SQLXML? { override fun getSQLXML(columnIndex: Int): SQLXML? {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getSQLXML(columnLabel: String?): SQLXML? { override fun getSQLXML(columnLabel: String?): SQLXML? {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun <T : Any?> unwrap(iface: Class<T>?): T { override fun <T : Any?> unwrap(iface: Class<T>?): T {
if(thisIsWrapperFor(iface)) if (thisIsWrapperFor(iface))
return this as T return this as T
else else
return parent.unwrap(iface) return parent.unwrap(iface)
@@ -426,12 +426,12 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
} }
override fun getBlob(columnIndex: Int): Blob { override fun getBlob(columnIndex: Int): Blob {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getBlob(columnLabel: String?): Blob { override fun getBlob(columnLabel: String?): Blob {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
@@ -500,12 +500,12 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
} }
override fun getObject(columnIndex: Int, map: MutableMap<String, Class<*>>?): Any { override fun getObject(columnIndex: Int, map: MutableMap<String, Class<*>>?): Any {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getObject(columnLabel: String?, map: MutableMap<String, Class<*>>?): Any { override fun getObject(columnLabel: String?, map: MutableMap<String, Class<*>>?): Any {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
@@ -531,9 +531,9 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
} }
private fun castToLong(obj: Any?): Long { private fun castToLong(obj: Any?): Long {
if(obj == null) return 0 if (obj == null) return 0
else if(obj is Long) return obj else if (obj is Long) return obj
else if(obj is Number) return obj.toLong() else if (obj is Number) return obj.toLong()
else throw IllegalStateException("Object is not a long!") else throw IllegalStateException("Object is not a long!")
} }
@@ -546,12 +546,12 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
} }
override fun getClob(columnIndex: Int): Clob { override fun getClob(columnIndex: Int): Clob {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getClob(columnLabel: String?): Clob { override fun getClob(columnLabel: String?): Clob {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
@@ -604,12 +604,12 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
} }
override fun getArray(columnIndex: Int): Array { override fun getArray(columnIndex: Int): Array {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getArray(columnLabel: String?): Array { override fun getArray(columnLabel: String?): Array {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
@@ -688,32 +688,32 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
} }
override fun getTimestamp(columnIndex: Int): Timestamp { override fun getTimestamp(columnIndex: Int): Timestamp {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getTimestamp(columnLabel: String?): Timestamp { override fun getTimestamp(columnLabel: String?): Timestamp {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getTimestamp(columnIndex: Int, cal: Calendar?): Timestamp { override fun getTimestamp(columnIndex: Int, cal: Calendar?): Timestamp {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getTimestamp(columnLabel: String?, cal: Calendar?): Timestamp { override fun getTimestamp(columnLabel: String?, cal: Calendar?): Timestamp {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getRef(columnIndex: Int): Ref { override fun getRef(columnIndex: Int): Ref {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getRef(columnLabel: String?): Ref { override fun getRef(columnLabel: String?): Ref {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
@@ -792,12 +792,12 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
} }
override fun getRowId(columnIndex: Int): RowId { override fun getRowId(columnIndex: Int): RowId {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
override fun getRowId(columnLabel: String?): RowId { override fun getRowId(columnLabel: String?): RowId {
//TODO Maybe? // TODO Maybe?
notImplemented() notImplemented()
} }
@@ -848,4 +848,4 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
class ResultSetEntry { class ResultSetEntry {
val data = mutableListOf<Any?>() val data = mutableListOf<Any?>()
} }
} }

View File

@@ -174,4 +174,4 @@ class JavaSharedPreferences(key: String) : SharedPreferences {
javaPreferences.removeNode() javaPreferences.removeNode()
return true return true
} }
} }

View File

@@ -14,8 +14,6 @@ import java.io.File
import javax.imageio.ImageIO import javax.imageio.ImageIO
import javax.xml.parsers.DocumentBuilderFactory import javax.xml.parsers.DocumentBuilderFactory
data class InstalledPackage(val root: File) { data class InstalledPackage(val root: File) {
val apk = File(root, "package.apk") val apk = File(root, "package.apk")
val jar = File(root, "translated.jar") val jar = File(root, "translated.jar")
@@ -40,20 +38,24 @@ data class InstalledPackage(val root: File) {
}?.filter { }?.filter {
it.tagName == "meta-data" it.tagName == "meta-data"
}?.map { }?.map {
putString(it.attributes.getNamedItem("android:name").nodeValue, putString(
it.attributes.getNamedItem("android:value").nodeValue) it.attributes.getNamedItem("android:name").nodeValue,
it.attributes.getNamedItem("android:value").nodeValue
)
} }
} }
it.signatures = (parsed.apkSingers.flatMap { it.certificateMetas } it.signatures = (
/*+ parsed.apkV2Singers.flatMap { it.certificateMetas }*/) // Blocked by: https://github.com/hsiafan/apk-parser/issues/72 parsed.apkSingers.flatMap { it.certificateMetas }
.map { Signature(it.data) }.toTypedArray() /*+ parsed.apkV2Singers.flatMap { it.certificateMetas }*/
) // Blocked by: https://github.com/hsiafan/apk-parser/issues/72
.map { Signature(it.data) }.toTypedArray()
} }
fun verify(): Boolean { fun verify(): Boolean {
val res = ApkVerifier.Builder(apk) val res = ApkVerifier.Builder(apk)
.build() .build()
.verify() .verify()
return res.isVerified return res.isVerified
} }
@@ -69,7 +71,7 @@ data class InstalledPackage(val root: File) {
}.sortedByDescending { it.width * it.height }.firstOrNull() ?: return }.sortedByDescending { it.width * it.height }.firstOrNull() ?: return
ImageIO.write(read, "png", icon) ImageIO.write(read, "png", icon)
} catch(e: Exception) { } catch (e: Exception) {
icon.delete() icon.delete()
} }
} }
@@ -77,7 +79,7 @@ data class InstalledPackage(val root: File) {
fun writeJar() { fun writeJar() {
try { try {
Dex2jar.from(apk).to(jar.toPath()) Dex2jar.from(apk).to(jar.toPath())
} catch(e: Exception) { } catch (e: Exception) {
jar.delete() jar.delete()
} }
} }
@@ -92,4 +94,4 @@ data class InstalledPackage(val root: File) {
return out return out
} }
} }
} }

View File

@@ -48,7 +48,7 @@ class PackageController {
if (!installed.jar.exists()) { if (!installed.jar.exists()) {
throw IllegalStateException("Failed to translate APK dex!") throw IllegalStateException("Failed to translate APK dex!")
} }
} catch(t: Throwable) { } catch (t: Throwable) {
root.deleteRecursively() root.deleteRecursively()
throw t throw t
} }
@@ -63,7 +63,7 @@ class PackageController {
} }
fun deletePackage(pack: InstalledPackage) { fun deletePackage(pack: InstalledPackage) {
if(!pack.root.exists()) error("Package was never installed!") if (!pack.root.exists()) error("Package was never installed!")
val packageName = pack.info.packageName val packageName = pack.info.packageName
pack.root.deleteRecursively() pack.root.deleteRecursively()
@@ -74,7 +74,7 @@ class PackageController {
fun findPackage(packageName: String): InstalledPackage? { fun findPackage(packageName: String): InstalledPackage? {
val file = File(androidFiles.packagesDir, packageName) val file = File(androidFiles.packagesDir, packageName)
return if(file.exists()) return if (file.exists())
InstalledPackage(file) InstalledPackage(file)
else else
null null
@@ -84,4 +84,4 @@ class PackageController {
val pkgName = ApkParsers.getMetaInfo(apkFile).packageName val pkgName = ApkParsers.getMetaInfo(apkFile).packageName
return findPackage(pkgName)?.jar return findPackage(pkgName)?.jar
} }
} }

View File

@@ -24,4 +24,4 @@ fun ApkMeta.toPackageInfo(apk: File): PackageInfo {
sourceDir = apk.absolutePath sourceDir = apk.absolutePath
} }
} }
} }

View File

@@ -24,4 +24,4 @@ interface Resource {
fun getType(): Class<out Resource> fun getType(): Class<out Resource>
fun getValue(): Any? fun getValue(): Any?
} }

View File

@@ -27,10 +27,10 @@ class ServiceSupport {
runningServices[name] = service runningServices[name] = service
//Setup service // Setup service
thread { thread {
callOnCreate(service) callOnCreate(service)
//TODO Handle more complex cases // TODO Handle more complex cases
service.onStartCommand(intent, 0, 0) service.onStartCommand(intent, 0, 0)
} }
} }
@@ -43,7 +43,7 @@ class ServiceSupport {
fun stopService(name: String) { fun stopService(name: String) {
logger.debug { "Stopping service: $name" } logger.debug { "Stopping service: $name" }
val service = runningServices.remove(name) val service = runningServices.remove(name)
if(service == null) { if (service == null) {
logger.warn { "An attempt was made to stop a service that is not running: $name" } logger.warn { "An attempt was made to stop a service that is not running: $name" }
} else { } else {
thread { thread {
@@ -63,6 +63,6 @@ class ServiceSupport {
fun serviceInstanceFromClass(className: String): Service { fun serviceInstanceFromClass(className: String): Service {
val clazzObj = Class.forName(className) val clazzObj = Class.forName(className)
return clazzObj.getDeclaredConstructor().newInstance() as? Service return clazzObj.getDeclaredConstructor().newInstance() as? Service
?: throw IllegalArgumentException("$className is not a Service!") ?: throw IllegalArgumentException("$className is not a Service!")
} }
} }

View File

@@ -27,7 +27,7 @@ object KodeinGlobalHelper {
@JvmStatic @JvmStatic
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
fun <T : Any> instance(type: Class<T>, kodein: DI? = null): T { fun <T : Any> instance(type: Class<T>, kodein: DI? = null): T {
return when(type) { return when (type) {
AndroidFiles::class.java -> { AndroidFiles::class.java -> {
val instance: AndroidFiles by (kodein ?: kodein()).instance() val instance: AndroidFiles by (kodein ?: kodein()).instance()
instance as T instance as T
@@ -64,5 +64,4 @@ object KodeinGlobalHelper {
fun <T : Any> instance(type: Class<T>): T { fun <T : Any> instance(type: Class<T>): T {
return instance(type, null) return instance(type, null)
} }
} }

View File

@@ -440,7 +440,6 @@ class LocalSource : HttpSource() {
private object FileSystemInterceptor : Interceptor { private object FileSystemInterceptor : Interceptor {
fun fakeUrlFrom(path: String): String = "http://$path" fun fakeUrlFrom(path: String): String = "http://$path"
private fun restoreFilePath(url: String): String { private fun restoreFilePath(url: String): String {
val path = URLDecoder.decode(url.replaceFirst("http://", ""), "UTF-8") val path = URLDecoder.decode(url.replaceFirst("http://", ""), "UTF-8")