@@ -75,7 +75,7 @@ class SplashActivity : AppCompatActivity() {
7575 Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU -> {
7676 arrayOf(Manifest .permission.READ_MEDIA_IMAGES , Manifest .permission.READ_MEDIA_VIDEO )
7777 }
78- else -> arrayOf(Manifest .permission.READ_EXTERNAL_STORAGE )
78+ else -> arrayOf(Manifest .permission.READ_EXTERNAL_STORAGE , Manifest .permission. WRITE_EXTERNAL_STORAGE )
7979 }
8080 }
8181
@@ -94,7 +94,6 @@ class SplashActivity : AppCompatActivity() {
9494 }
9595
9696 private fun requestAppPermissions () {
97- saveAgreement()
9897 val missingBasic = getRequiredPermissions().filter {
9998 ContextCompat .checkSelfPermission(this , it) != PackageManager .PERMISSION_GRANTED
10099 }
@@ -153,6 +152,7 @@ class SplashActivity : AppCompatActivity() {
153152 private fun startLogic () {
154153 if (! started) {
155154 started = true
155+ saveAgreement()
156156 checkRootAndStart()
157157 }
158158 }
@@ -176,19 +176,16 @@ class SplashActivity : AppCompatActivity() {
176176 )
177177 }
178178 }
179- val outJob = launch { readStreamAsync(p.inputStream.bufferedReader()) }
180- val errJob = launch { readStreamAsync(p.errorStream.bufferedReader()) }
179+ launch { readStreamAsync(p.inputStream.bufferedReader()) }
180+ launch { readStreamAsync(p.errorStream.bufferedReader()) }
181+
181182 p.waitFor()
182183 shellJob.join()
183- outJob.join()
184- errJob.join()
185184 }
186185 } catch (e: Exception ) {
187186 e.printStackTrace()
188187 } finally {
189- withContext(Dispatchers .Main ) {
190- gotoHome()
191- }
188+ withContext(Dispatchers .Main ) { gotoHome() }
192189 }
193190 }
194191 }
@@ -197,9 +194,7 @@ class SplashActivity : AppCompatActivity() {
197194 withContext(Dispatchers .IO ) {
198195 reader.useLines { lines ->
199196 lines.forEach { line ->
200- withContext(Dispatchers .Main ) {
201- onLogOutput(line)
202- }
197+ withContext(Dispatchers .Main ) { onLogOutput(line) }
203198 }
204199 }
205200 }
@@ -224,12 +219,7 @@ class SplashActivity : AppCompatActivity() {
224219 if (Locale .getDefault() != locale) {
225220 Locale .setDefault(locale)
226221 val config = Configuration (resources.configuration).apply { setLocale(locale) }
227- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
228- resources.updateConfiguration(config, resources.displayMetrics)
229- } else {
230- @Suppress(" DEPRECATION" )
231- resources.updateConfiguration(config, resources.displayMetrics)
232- }
222+ resources.updateConfiguration(config, resources.displayMetrics)
233223 }
234224 }
235225 }
@@ -240,14 +230,22 @@ class SplashActivity : AppCompatActivity() {
240230 val bgColor = if (typedValue.resourceId != 0 ) ContextCompat .getColor(this , typedValue.resourceId) else typedValue.data
241231 window.statusBarColor = bgColor
242232 window.navigationBarColor = bgColor
243- val controller = WindowCompat .getInsetsController(window, window.decorView)
244- val isDark = ThemeModeState .isDarkMode()
245- controller.isAppearanceLightStatusBars = ! isDark
246- controller.isAppearanceLightNavigationBars = ! isDark
233+
234+ WindowCompat .getInsetsController(window, window.decorView).apply {
235+ val isDark = ThemeModeState .isDarkMode()
236+ isAppearanceLightStatusBars = ! isDark
237+ isAppearanceLightNavigationBars = ! isDark
238+ }
247239 }
248240
249241 private fun showAgreementDialog () {
250- DialogHelper .warning(this , getString(R .string.permission_dialog_title), getString(R .string.permission_dialog_message), { requestAppPermissions() }, { finish() }).setCancelable(false )
242+ DialogHelper .warning(
243+ this ,
244+ getString(R .string.permission_dialog_title),
245+ getString(R .string.permission_dialog_message),
246+ { checkAndRequestPermissions() },
247+ { finish() }
248+ ).setCancelable(false )
251249 }
252250
253251 private fun hasAgreed () = getSharedPreferences(" kr-script-config" , MODE_PRIVATE ).getBoolean(" agreed_permissions" , false )
0 commit comments