11package com.leohearts.alternativeUnlockHook
22
33import android.os.Bundle
4+ import android.util.Log
45import androidx.activity.ComponentActivity
56import androidx.activity.compose.setContent
67import androidx.compose.foundation.layout.fillMaxSize
@@ -43,13 +44,18 @@ import androidx.compose.ui.unit.em
4344import com.leohearts.alternativeUnlockHook.ui.theme.AlternativeUnlockXposedTheme
4445import kotlinx.coroutines.CoroutineScope
4546import kotlinx.coroutines.launch
47+ import java.io.BufferedReader
48+ import java.io.InputStreamReader
4649import java.util.Properties
4750
51+ val TAG : String = " alternativeUnlockHook"
52+
4853class SettingsActivity : ComponentActivity () {
4954 override fun onCreate (savedInstanceState : Bundle ? ) {
5055 super .onCreate(savedInstanceState)
5156 setContent {
5257 Runtime .getRuntime().exec(" su -c 'id > /data/local/tmp/qwq'" )
58+ migrateOldConfig()
5359 AlternativeUnlockXposedTheme {
5460 // A surface container using the 'background' color from the theme
5561 Surface (
@@ -63,6 +69,28 @@ class SettingsActivity : ComponentActivity() {
6369 }
6470}
6571
72+ fun sudoFileExists (path : String ): Boolean {
73+ try {
74+ return BufferedReader (InputStreamReader (sudo(" cat " + path).inputStream)).readLine()
75+ .chars().count() > 0
76+ }
77+ catch (e: Exception ) {
78+ return false ;
79+ }
80+ }
81+
82+ fun migrateOldConfig () {
83+ if (
84+ (sudoFileExists(" /data/local/tmp/alternativePass.properties" ))
85+ and
86+ (! sudoFileExists(" /data/data/com.android.systemui/alternativePass.properties" ))
87+ ) {
88+ Log .w(TAG , " migrateOldConfig: migrating from old config file" )
89+ sudo(" mv /data/local/tmp/alternativePass.properties /data/data/com.android.systemui/alternativePass.properties" )
90+ setPermission()
91+ }
92+ }
93+
6694fun sudo (cmd : String ): Process {
6795 return Runtime .getRuntime().exec(listOf<String >(" su" , " -c" , cmd).toTypedArray())
6896}
0 commit comments