@@ -30,7 +30,6 @@ import androidx.work.NetworkType
3030import androidx.work.Operation
3131import androidx.work.PeriodicWorkRequestBuilder
3232import androidx.work.WorkManager
33- import ch.qos.logback.classic.Logger
3433import com.blankj.utilcode.util.ThrowableUtils.getFullStackTrace
3534import com.google.android.material.color.DynamicColors
3635import com.itsaky.androidide.BuildConfig
@@ -44,8 +43,6 @@ import com.itsaky.androidide.events.EditorEventsIndex
4443import com.itsaky.androidide.events.LspApiEventsIndex
4544import com.itsaky.androidide.events.LspJavaEventsIndex
4645import com.itsaky.androidide.events.ProjectsApiEventsIndex
47- import com.itsaky.androidide.logging.LogcatAppender
48- import com.itsaky.androidide.logging.encoder.IDELogFormatEncoder
4946import com.itsaky.androidide.preferences.internal.DevOpsPreferences
5047import com.itsaky.androidide.preferences.internal.GeneralPreferences
5148import com.itsaky.androidide.preferences.internal.StatPreferences
@@ -62,18 +59,19 @@ import com.itsaky.androidide.utils.flashError
6259import com.termux.app.TermuxApplication
6360import com.termux.shared.reflection.ReflectionUtils
6461import io.github.rosemoe.sora.widget.schemes.EditorColorScheme
62+ import io.realm.Realm
6563import kotlinx.coroutines.DelicateCoroutinesApi
6664import kotlinx.coroutines.GlobalScope
6765import kotlinx.coroutines.launch
6866import org.greenrobot.eventbus.EventBus
6967import org.greenrobot.eventbus.Subscribe
7068import org.greenrobot.eventbus.ThreadMode
71- import org.lsposed.hiddenapibypass.HiddenApiBypass
7269import org.slf4j.LoggerFactory
7370import java.lang.Thread.UncaughtExceptionHandler
7471import java.time.Duration
7572import kotlin.system.exitProcess
7673
74+
7775class IDEApplication : TermuxApplication () {
7876
7977 private var uncaughtExceptionHandler: UncaughtExceptionHandler ? = null
@@ -97,7 +95,8 @@ class IDEApplication : TermuxApplication() {
9795
9896 if (BuildConfig .DEBUG ) {
9997 StrictMode .setVmPolicy(
100- StrictMode .VmPolicy .Builder (StrictMode .getVmPolicy()).penaltyLog().detectAll().build())
98+ StrictMode .VmPolicy .Builder (StrictMode .getVmPolicy()).penaltyLog().detectAll().build()
99+ )
101100 if (DevOpsPreferences .dumpLogs) {
102101 startLogcatReader()
103102 }
@@ -109,6 +108,8 @@ class IDEApplication : TermuxApplication() {
109108
110109 EventBus .getDefault().register(this )
111110
111+ Realm .init (this )
112+
112113 AppCompatDelegate .setDefaultNightMode(GeneralPreferences .uiMode)
113114
114115 if (IThemeManager .getInstance().getCurrentTheme() == IDETheme .MATERIAL_YOU ) {
@@ -123,26 +124,6 @@ class IDEApplication : TermuxApplication() {
123124 }
124125 }
125126
126- private fun handleCrash (thread : Thread , th : Throwable ) {
127- writeException(th)
128-
129- try {
130-
131- val intent = Intent ()
132- intent.action = CrashHandlerActivity .REPORT_ACTION
133- intent.putExtra(CrashHandlerActivity .TRACE_KEY , getFullStackTrace(th))
134- intent.addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
135- startActivity(intent)
136- if (uncaughtExceptionHandler != null ) {
137- uncaughtExceptionHandler!! .uncaughtException(thread, th)
138- }
139-
140- exitProcess(1 )
141- } catch (error: Throwable ) {
142- log.error(" Unable to show crash handler activity" , error)
143- }
144- }
145-
146127 fun showChangelog () {
147128 val intent = Intent (Intent .ACTION_VIEW )
148129 var version = BuildInfo .VERSION_NAME_SIMPLE
@@ -168,14 +149,17 @@ class IDEApplication : TermuxApplication() {
168149
169150 val constraints = Constraints .Builder ().setRequiredNetworkType(NetworkType .CONNECTED ).build()
170151 val request = PeriodicWorkRequestBuilder <StatUploadWorker >(Duration .ofHours(24 )).setInputData(
171- AndroidIDEStats .statData.toInputData()).setConstraints(constraints)
152+ AndroidIDEStats .statData.toInputData()
153+ ).setConstraints(constraints)
172154 .addTag(StatUploadWorker .WORKER_WORK_NAME ).build()
173155
174156 val workManager = WorkManager .getInstance(this )
175157
176158 log.info(" reportStatsIfNecessary: Enqueuing StatUploadWorker..." )
177- val operation = workManager.enqueueUniquePeriodicWork(StatUploadWorker .WORKER_WORK_NAME ,
178- ExistingPeriodicWorkPolicy .UPDATE , request)
159+ val operation = workManager.enqueueUniquePeriodicWork(
160+ StatUploadWorker .WORKER_WORK_NAME ,
161+ ExistingPeriodicWorkPolicy .UPDATE , request
162+ )
179163
180164 operation.state.observeForever(object : Observer <Operation .State > {
181165 override fun onChanged (value : Operation .State ) {
@@ -185,22 +169,6 @@ class IDEApplication : TermuxApplication() {
185169 })
186170 }
187171
188- private fun startLogcatReader () {
189- if (ideLogcatReader != null ) {
190- // already started
191- return
192- }
193-
194- log.info(" Starting logcat reader..." )
195- ideLogcatReader = IDELogcatReader ().also { it.start() }
196- }
197-
198- private fun stopLogcatReader () {
199- log.info(" Stopping logcat reader..." )
200- ideLogcatReader?.stop()
201- ideLogcatReader = null
202- }
203-
204172 @Subscribe(threadMode = ThreadMode .MAIN )
205173 fun onPrefChanged (event : PreferenceChangeEvent ) {
206174 val enabled = event.value as ? Boolean?
@@ -230,6 +198,26 @@ class IDEApplication : TermuxApplication() {
230198 }
231199 }
232200
201+ private fun handleCrash (thread : Thread , th : Throwable ) {
202+ writeException(th)
203+
204+ try {
205+
206+ val intent = Intent ()
207+ intent.action = CrashHandlerActivity .REPORT_ACTION
208+ intent.putExtra(CrashHandlerActivity .TRACE_KEY , getFullStackTrace(th))
209+ intent.addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
210+ startActivity(intent)
211+ if (uncaughtExceptionHandler != null ) {
212+ uncaughtExceptionHandler!! .uncaughtException(thread, th)
213+ }
214+
215+ exitProcess(1 )
216+ } catch (error: Throwable ) {
217+ log.error(" Unable to show crash handler activity" , error)
218+ }
219+ }
220+
233221 private fun cancelStatUploadWorker () {
234222 log.info(" Opted-out of stat collection. Cancelling StatUploadWorker if enqueued..." )
235223 val operation = WorkManager .getInstance(this )
@@ -242,6 +230,22 @@ class IDEApplication : TermuxApplication() {
242230 })
243231 }
244232
233+ private fun startLogcatReader () {
234+ if (ideLogcatReader != null ) {
235+ // already started
236+ return
237+ }
238+
239+ log.info(" Starting logcat reader..." )
240+ ideLogcatReader = IDELogcatReader ().also { it.start() }
241+ }
242+
243+ private fun stopLogcatReader () {
244+ log.info(" Stopping logcat reader..." )
245+ ideLogcatReader?.stop()
246+ ideLogcatReader = null
247+ }
248+
245249 companion object {
246250
247251 private val log = LoggerFactory .getLogger(IDEApplication ::class .java)
0 commit comments