2016-03-19 17:48:55 +01:00
|
|
|
package eu.kanade.tachiyomi
|
|
|
|
|
|
|
|
|
|
import android.app.Application
|
2016-10-15 11:12:16 +02:00
|
|
|
import android.content.Context
|
2016-12-13 20:47:46 +01:00
|
|
|
import android.content.res.Configuration
|
2019-04-14 19:51:20 +02:00
|
|
|
import android.graphics.Color
|
2019-08-07 21:47:43 +02:00
|
|
|
import android.os.Build
|
2019-04-14 05:47:57 +02:00
|
|
|
import android.os.Environment
|
2016-10-15 11:12:16 +02:00
|
|
|
import android.support.multidex.MultiDex
|
2019-04-14 05:47:57 +02:00
|
|
|
import com.elvishew.xlog.LogConfiguration
|
|
|
|
|
import com.elvishew.xlog.LogLevel
|
|
|
|
|
import com.elvishew.xlog.XLog
|
|
|
|
|
import com.elvishew.xlog.printer.AndroidPrinter
|
|
|
|
|
import com.elvishew.xlog.printer.Printer
|
|
|
|
|
import com.elvishew.xlog.printer.file.FilePrinter
|
2019-04-14 19:57:14 +02:00
|
|
|
import com.elvishew.xlog.printer.file.backup.NeverBackupStrategy
|
2019-04-14 05:47:57 +02:00
|
|
|
import com.elvishew.xlog.printer.file.clean.FileLastModifiedCleanStrategy
|
|
|
|
|
import com.elvishew.xlog.printer.file.naming.DateFileNameGenerator
|
2016-11-06 18:44:14 +01:00
|
|
|
import com.evernote.android.job.JobManager
|
2017-08-24 23:11:43 +02:00
|
|
|
import com.github.ajalt.reprint.core.Reprint
|
2019-08-07 21:47:43 +02:00
|
|
|
import com.google.android.gms.common.GooglePlayServicesNotAvailableException
|
|
|
|
|
import com.google.android.gms.common.GooglePlayServicesRepairableException
|
|
|
|
|
import com.google.android.gms.security.ProviderInstaller
|
2019-04-14 05:47:57 +02:00
|
|
|
import com.kizitonwose.time.days
|
2019-04-14 19:51:20 +02:00
|
|
|
import com.ms_square.debugoverlay.DebugOverlay
|
|
|
|
|
import com.ms_square.debugoverlay.modules.FpsModule
|
2017-04-04 17:42:17 +02:00
|
|
|
import eu.kanade.tachiyomi.data.backup.BackupCreatorJob
|
2016-11-06 18:44:14 +01:00
|
|
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
2017-10-10 14:15:41 +02:00
|
|
|
import eu.kanade.tachiyomi.data.notification.Notifications
|
2017-12-11 20:01:28 +01:00
|
|
|
import eu.kanade.tachiyomi.data.updater.UpdaterJob
|
2016-12-13 20:47:46 +01:00
|
|
|
import eu.kanade.tachiyomi.util.LocaleHelper
|
2019-08-05 03:27:59 +02:00
|
|
|
import exh.debug.DebugToggles
|
2019-04-14 05:47:57 +02:00
|
|
|
import exh.log.CrashlyticsPrinter
|
2019-04-14 19:51:20 +02:00
|
|
|
import exh.log.EHDebugModeOverlay
|
2019-04-14 16:46:06 +02:00
|
|
|
import exh.log.EHLogLevel
|
2017-08-25 23:31:38 +02:00
|
|
|
import io.realm.Realm
|
|
|
|
|
import io.realm.RealmConfiguration
|
2019-04-14 05:47:57 +02:00
|
|
|
import kotlinx.coroutines.GlobalScope
|
|
|
|
|
import kotlinx.coroutines.launch
|
2016-03-19 17:48:55 +01:00
|
|
|
import timber.log.Timber
|
2016-06-14 15:13:48 +02:00
|
|
|
import uy.kohesive.injekt.Injekt
|
2016-06-15 17:58:28 +02:00
|
|
|
import uy.kohesive.injekt.api.InjektScope
|
|
|
|
|
import uy.kohesive.injekt.registry.default.DefaultRegistrar
|
2017-08-25 23:31:38 +02:00
|
|
|
import java.io.File
|
2019-08-07 21:47:43 +02:00
|
|
|
import java.security.NoSuchAlgorithmException
|
|
|
|
|
import javax.net.ssl.SSLContext
|
2017-08-25 23:31:38 +02:00
|
|
|
import kotlin.concurrent.thread
|
2016-03-19 17:48:55 +01:00
|
|
|
|
|
|
|
|
open class App : Application() {
|
|
|
|
|
override fun onCreate() {
|
|
|
|
|
super.onCreate()
|
2018-01-09 12:27:45 +01:00
|
|
|
if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree())
|
2019-04-14 18:48:59 +02:00
|
|
|
setupExhLogging() // EXH logging
|
2018-01-09 12:27:45 +01:00
|
|
|
|
2019-08-07 21:47:43 +02:00
|
|
|
workaroundAndroid7BrokenSSL()
|
|
|
|
|
|
2016-06-15 17:58:28 +02:00
|
|
|
Injekt = InjektScope(DefaultRegistrar())
|
2016-06-14 15:13:48 +02:00
|
|
|
Injekt.importModule(AppModule(this))
|
2016-06-15 17:58:28 +02:00
|
|
|
|
2016-11-06 18:44:14 +01:00
|
|
|
setupJobManager()
|
2017-10-10 14:15:41 +02:00
|
|
|
setupNotificationChannels()
|
2019-04-14 05:47:57 +02:00
|
|
|
GlobalScope.launch { deleteOldMetadataRealm() } // Delete old metadata DB (EH)
|
2017-08-24 23:11:43 +02:00
|
|
|
Reprint.initialize(this) //Setup fingerprint (EH)
|
2019-08-05 03:27:59 +02:00
|
|
|
if((BuildConfig.DEBUG || BuildConfig.BUILD_TYPE == "releaseTest") && DebugToggles.ENABLE_DEBUG_OVERLAY.enabled) {
|
2019-04-14 19:51:20 +02:00
|
|
|
setupDebugOverlay()
|
|
|
|
|
}
|
2016-12-13 20:47:46 +01:00
|
|
|
|
2016-12-26 16:56:19 +01:00
|
|
|
LocaleHelper.updateConfiguration(this, resources.configuration)
|
2016-03-19 17:48:55 +01:00
|
|
|
}
|
|
|
|
|
|
2016-10-15 11:12:16 +02:00
|
|
|
override fun attachBaseContext(base: Context) {
|
|
|
|
|
super.attachBaseContext(base)
|
2019-04-13 15:10:44 +02:00
|
|
|
MultiDex.install(this)
|
2016-10-15 11:12:16 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-13 20:47:46 +01:00
|
|
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
|
|
|
|
super.onConfigurationChanged(newConfig)
|
2016-12-26 16:56:19 +01:00
|
|
|
LocaleHelper.updateConfiguration(this, newConfig, true)
|
2016-12-13 20:47:46 +01:00
|
|
|
}
|
|
|
|
|
|
2019-08-07 21:47:43 +02:00
|
|
|
private fun workaroundAndroid7BrokenSSL() {
|
|
|
|
|
if(Build.VERSION.SDK_INT == Build.VERSION_CODES.N
|
|
|
|
|
|| Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1) {
|
|
|
|
|
try {
|
|
|
|
|
SSLContext.getInstance("TLSv1.2")
|
|
|
|
|
} catch (e: NoSuchAlgorithmException) {
|
|
|
|
|
XLog.e("Could not install Android 7 broken SSL workaround!", e)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
ProviderInstaller.installIfNeeded(applicationContext)
|
|
|
|
|
} catch (e: GooglePlayServicesRepairableException) {
|
|
|
|
|
XLog.e("Could not install Android 7 broken SSL workaround!", e)
|
|
|
|
|
} catch (e: GooglePlayServicesNotAvailableException) {
|
|
|
|
|
XLog.e("Could not install Android 7 broken SSL workaround!", e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-06 18:44:14 +01:00
|
|
|
protected open fun setupJobManager() {
|
2019-03-14 21:44:20 +01:00
|
|
|
try {
|
|
|
|
|
JobManager.create(this).addJobCreator { tag ->
|
|
|
|
|
when (tag) {
|
|
|
|
|
LibraryUpdateJob.TAG -> LibraryUpdateJob()
|
|
|
|
|
UpdaterJob.TAG -> UpdaterJob()
|
|
|
|
|
BackupCreatorJob.TAG -> BackupCreatorJob()
|
|
|
|
|
else -> null
|
|
|
|
|
}
|
2016-11-06 18:44:14 +01:00
|
|
|
}
|
2019-03-14 21:44:20 +01:00
|
|
|
} catch (e: Exception) {
|
|
|
|
|
Timber.w("Can't initialize job manager")
|
2016-11-06 18:44:14 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 14:15:41 +02:00
|
|
|
protected open fun setupNotificationChannels() {
|
|
|
|
|
Notifications.createChannels(this)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-24 03:03:49 +01:00
|
|
|
// EXH
|
2019-04-14 05:47:57 +02:00
|
|
|
private fun deleteOldMetadataRealm() {
|
2017-08-25 23:31:38 +02:00
|
|
|
Realm.init(this)
|
|
|
|
|
val config = RealmConfiguration.Builder()
|
|
|
|
|
.name("gallery-metadata.realm")
|
2018-04-16 15:53:18 +02:00
|
|
|
.schemaVersion(3)
|
2017-08-26 09:40:59 +02:00
|
|
|
.deleteRealmIfMigrationNeeded()
|
2017-08-25 23:31:38 +02:00
|
|
|
.build()
|
2019-04-14 05:47:57 +02:00
|
|
|
Realm.deleteRealm(config)
|
2017-08-25 23:31:38 +02:00
|
|
|
|
|
|
|
|
//Delete old paper db files
|
|
|
|
|
listOf(
|
|
|
|
|
File(filesDir, "gallery-ex"),
|
|
|
|
|
File(filesDir, "gallery-perveden"),
|
|
|
|
|
File(filesDir, "gallery-nhentai")
|
|
|
|
|
).forEach {
|
|
|
|
|
if(it.exists()) {
|
|
|
|
|
thread {
|
|
|
|
|
it.deleteRecursively()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-14 05:47:57 +02:00
|
|
|
|
|
|
|
|
// EXH
|
|
|
|
|
private fun setupExhLogging() {
|
2019-04-14 18:48:59 +02:00
|
|
|
EHLogLevel.init(this)
|
|
|
|
|
|
2019-04-14 19:54:31 +02:00
|
|
|
val logLevel = if(EHLogLevel.shouldLog(EHLogLevel.EXTRA)) {
|
2019-04-14 05:47:57 +02:00
|
|
|
LogLevel.ALL
|
|
|
|
|
} else {
|
|
|
|
|
LogLevel.WARN
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val logConfig = LogConfiguration.Builder()
|
|
|
|
|
.logLevel(logLevel)
|
|
|
|
|
.t()
|
|
|
|
|
.st(2)
|
|
|
|
|
.nb()
|
|
|
|
|
.build()
|
|
|
|
|
|
|
|
|
|
val printers = mutableListOf<Printer>(AndroidPrinter())
|
|
|
|
|
|
|
|
|
|
val logFolder = File(Environment.getExternalStorageDirectory().absolutePath + File.separator +
|
|
|
|
|
getString(R.string.app_name), "logs")
|
|
|
|
|
|
|
|
|
|
printers += FilePrinter
|
|
|
|
|
.Builder(logFolder.absolutePath)
|
2019-04-15 01:35:02 +02:00
|
|
|
.fileNameGenerator(object : DateFileNameGenerator() {
|
|
|
|
|
override fun generateFileName(logLevel: Int, timestamp: Long): String {
|
|
|
|
|
return super.generateFileName(logLevel, timestamp) + "-${BuildConfig.BUILD_TYPE}"
|
|
|
|
|
}
|
|
|
|
|
})
|
2019-04-14 05:47:57 +02:00
|
|
|
.cleanStrategy(FileLastModifiedCleanStrategy(7.days.inMilliseconds.longValue))
|
2019-04-14 19:57:14 +02:00
|
|
|
.backupStrategy(NeverBackupStrategy())
|
2019-04-14 05:47:57 +02:00
|
|
|
.build()
|
|
|
|
|
|
|
|
|
|
// Install Crashlytics in prod
|
|
|
|
|
if(!BuildConfig.DEBUG) {
|
|
|
|
|
printers += CrashlyticsPrinter(LogLevel.ERROR)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XLog.init(
|
|
|
|
|
logConfig,
|
|
|
|
|
*printers.toTypedArray()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
XLog.d("Application booting...")
|
|
|
|
|
}
|
2019-04-14 19:51:20 +02:00
|
|
|
|
|
|
|
|
// EXH
|
|
|
|
|
private fun setupDebugOverlay() {
|
2019-08-11 20:40:01 +02:00
|
|
|
try {
|
|
|
|
|
DebugOverlay.Builder(this)
|
|
|
|
|
.modules(FpsModule(), EHDebugModeOverlay(this))
|
|
|
|
|
.bgColor(Color.parseColor("#7F000000"))
|
|
|
|
|
.notification(false)
|
|
|
|
|
.allowSystemLayer(false)
|
|
|
|
|
.build()
|
|
|
|
|
.install()
|
|
|
|
|
} catch(e: IllegalStateException) {
|
|
|
|
|
// Crashes if app is in background
|
|
|
|
|
XLog.e("Failed to initialize debug overlay, app in background?", e)
|
|
|
|
|
}
|
2019-04-14 19:51:20 +02:00
|
|
|
}
|
2016-03-19 17:48:55 +01:00
|
|
|
}
|