Skip to content

Commit 3265696

Browse files
committed
feat: add automatic config migration
1 parent 5edebce commit 3265696

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

app/src/main/java/com/leohearts/alternativeUnlockHook/HookClass.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ public Process system(String cmd) throws IOException {
4545
public void initConfig(){
4646
try {
4747
Properties properties = new Properties();
48-
properties.load(new FileReader("/data/data/com.android.systemui/alternativePass.properties"));
48+
FileReader f;
49+
try {
50+
f = new FileReader("/data/data/com.android.systemui/alternativePass.properties");
51+
} catch (FileNotFoundException e) {
52+
f = new FileReader("/data/local/tmp/alternativePass.properties"); // make sure module can work if migration process hasn't been started
53+
}
54+
properties.load(f);
4955
fakePassword = properties.getProperty("fakePassword", "114514");
5056
realPassword = properties.getProperty("realPassword", "1919810"); // nobody sets 1919810 as real password , right ???
5157
actionType = properties.getProperty("actionType", "sh");

app/src/main/java/com/leohearts/alternativeUnlockHook/SettingsActivity.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.leohearts.alternativeUnlockHook
22

33
import android.os.Bundle
4+
import android.util.Log
45
import androidx.activity.ComponentActivity
56
import androidx.activity.compose.setContent
67
import androidx.compose.foundation.layout.fillMaxSize
@@ -43,13 +44,18 @@ import androidx.compose.ui.unit.em
4344
import com.leohearts.alternativeUnlockHook.ui.theme.AlternativeUnlockXposedTheme
4445
import kotlinx.coroutines.CoroutineScope
4546
import kotlinx.coroutines.launch
47+
import java.io.BufferedReader
48+
import java.io.InputStreamReader
4649
import java.util.Properties
4750

51+
val TAG: String = "alternativeUnlockHook"
52+
4853
class 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+
6694
fun sudo(cmd: String): Process {
6795
return Runtime.getRuntime().exec(listOf<String>("su", "-c", cmd).toTypedArray())
6896
}

0 commit comments

Comments
 (0)