[core] Migrate configuation
This commit is contained in:
parent
8f76679a38
commit
f56cf01e9f
|
|
@ -34,7 +34,7 @@ Note: debug build is only available on Github Actions.
|
||||||
## Get Help
|
## Get Help
|
||||||
|
|
||||||
- GitHub issues: [Issues](https://github.com/LSPosed/LSPosed/issues/)
|
- GitHub issues: [Issues](https://github.com/LSPosed/LSPosed/issues/)
|
||||||
- (For Chinese speakers) 本项目只接受英语标题的issue。如果您不懂英语,请使用[谷歌翻译](https://translate.google.cn)
|
- (For Chinese speakers) 本项目只接受英语**标题**的issue。如果您不懂英语,请使用[翻译工具](https://www.deepl.com/zh/translator)
|
||||||
|
|
||||||
## For Developers
|
## For Developers
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,23 +8,32 @@ import android.database.sqlite.SQLiteStatement;
|
||||||
import android.os.FileObserver;
|
import android.os.FileObserver;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.system.ErrnoException;
|
||||||
|
import android.system.Os;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
|
import androidx.annotation.Keep;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
|
@ -515,7 +524,66 @@ public class ConfigManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// migrate setting
|
||||||
|
@Keep
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
if (!miscFile.exists()) {
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
File miscPath = new File("/data/misc/" + readText(miscFile, "lspd"));
|
||||||
|
if (!miscPath.exists()) {
|
||||||
|
System.exit(2);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
HashMap<String, List<Application>> modulesScope = new HashMap<>();
|
||||||
|
for (File dir : miscPath.listFiles(File::isDirectory)) {
|
||||||
|
try {
|
||||||
|
int userId = Integer.parseInt(dir.getName());
|
||||||
|
System.out.println("Processing user: " + userId);
|
||||||
|
File conf = new File(dir, "conf");
|
||||||
|
if (!conf.exists()) System.exit(0);
|
||||||
|
File enabledModules = new File(conf, "enabled_modules.list");
|
||||||
|
if (!enabledModules.exists()) System.exit(0);
|
||||||
|
|
||||||
|
System.out.println("updating modules...");
|
||||||
|
|
||||||
|
try (InputStream inputStream = new FileInputStream(enabledModules); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||||
|
String packageName;
|
||||||
|
while ((packageName = reader.readLine()) != null) {
|
||||||
|
System.out.println("\t" + packageName);
|
||||||
|
PackageInfo pkgInfo = PackageService.getPackageInfo(packageName, 0, 0);
|
||||||
|
if (pkgInfo == null || pkgInfo.applicationInfo == null) continue;
|
||||||
|
getInstance().enableModule(packageName, pkgInfo.applicationInfo.sourceDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("updating scope...");
|
||||||
|
|
||||||
|
for (File scopeConf : conf.listFiles(name -> name.getName().endsWith(".conf"))) {
|
||||||
|
String packageName = scopeConf.getName().replaceAll(".conf$", "");
|
||||||
|
System.out.println("\t" + packageName);
|
||||||
|
List<Application> scope = modulesScope.computeIfAbsent(packageName, ignored -> new ArrayList<>());
|
||||||
|
try (InputStream inputStream = new FileInputStream(scopeConf); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
Application app = new Application();
|
||||||
|
app.packageName = line;
|
||||||
|
app.userId = userId;
|
||||||
|
System.out.println("\t\t" + app.packageName);
|
||||||
|
scope.add(app);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (HashMap.Entry<String, List<Application>> entry : modulesScope.entrySet()) {
|
||||||
|
getInstance().setModuleScope(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
System.out.println(Log.getStackTraceString(e));
|
||||||
|
System.exit(3);
|
||||||
|
}
|
||||||
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,7 @@ LANG_UTIL_ERR_ANDROID_UNSUPPORT_3="Learn more from our GitHub Wiki"
|
||||||
LANG_UTIL_ERR_PLATFORM_UNSUPPORT="Unsupported platform"
|
LANG_UTIL_ERR_PLATFORM_UNSUPPORT="Unsupported platform"
|
||||||
LANG_UTIL_ERR_VARIANT_SELECTION="Error occurred when selecting variant"
|
LANG_UTIL_ERR_VARIANT_SELECTION="Error occurred when selecting variant"
|
||||||
LANG_UTIL_ERR_VARIANT_UNSUPPORT="Unsupported variant"
|
LANG_UTIL_ERR_VARIANT_UNSUPPORT="Unsupported variant"
|
||||||
|
LANG_CUST_INST_MIGRATE_CONF="Migrating configuration"
|
||||||
|
|
||||||
# Load lang
|
# Load lang
|
||||||
if [[ ${BOOTMODE} == true ]]; then
|
if [[ ${BOOTMODE} == true ]]; then
|
||||||
|
|
@ -154,15 +155,6 @@ else
|
||||||
abortC "${LANG_UTIL_ERR_PLATFORM_UNSUPPORT}"
|
abortC "${LANG_UTIL_ERR_PLATFORM_UNSUPPORT}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
extract "${ZIPFILE}" "${BIN_PATH}/key_selector" "${TMPDIR}"
|
|
||||||
SELECTOR_PATH="${TMPDIR}/${BIN_PATH}/key_selector"
|
|
||||||
chmod 755 "${SELECTOR_PATH}"
|
|
||||||
"${SELECTOR_PATH}"
|
|
||||||
VARIANT=$?
|
|
||||||
if [ VARIANT -lt 16 ]; then
|
|
||||||
abortC "${LANG_UTIL_ERR_VARIANT_SELECTION}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
ui_print "- ${LANG_CUST_INST_EXT_FILES}"
|
ui_print "- ${LANG_CUST_INST_EXT_FILES}"
|
||||||
|
|
||||||
# extract module files
|
# extract module files
|
||||||
|
|
@ -224,15 +216,28 @@ else
|
||||||
fi
|
fi
|
||||||
touch /data/adb/lspd/new_install || abortC "! ${LANG_CUST_ERR_CONF_FIRST}"
|
touch /data/adb/lspd/new_install || abortC "! ${LANG_CUST_ERR_CONF_FIRST}"
|
||||||
ui_print "- ${LANG_CUST_INST_COPY_LIB}"
|
ui_print "- ${LANG_CUST_INST_COPY_LIB}"
|
||||||
mkdir -p /data/adb/lspd/config
|
|
||||||
rm -rf "/data/adb/lspd/framework"
|
rm -rf "/data/adb/lspd/framework"
|
||||||
mv "${MODPATH}/system/framework" "/data/adb/lspd/framework"
|
mv "${MODPATH}/system/framework" "/data/adb/lspd/framework"
|
||||||
set_perm_recursive /data/adb/lspd root root 0700 0600 "u:object_r:magisk_file:s0" || abortC "! ${LANG_CUST_ERR_PERM}"
|
|
||||||
mkdir -p /data/misc/$MISC_PATH/0/conf/ || abortC "! ${LANG_CUST_ERR_CONF_CREATE}"
|
|
||||||
set_perm /data/misc/$MISC_PATH root root 0771 "u:object_r:magisk_file:s0" || abortC "! ${LANG_CUST_ERR_PERM}"
|
set_perm /data/misc/$MISC_PATH root root 0771 "u:object_r:magisk_file:s0" || abortC "! ${LANG_CUST_ERR_PERM}"
|
||||||
|
|
||||||
|
if [[ ! -d /data/adb/lspd/config ]]; then
|
||||||
|
mkdir -p /data/adb/lspd/config
|
||||||
|
ui_print "- ${LANG_CUST_INST_MIGRATE_CONF}"
|
||||||
|
cp -r /data/misc/$MISC_PATH/0/prefs /data/misc/$MISC_PATH/prefs
|
||||||
|
/system/bin/app_process -Djava.class.path=/data/adb/lspd/framework/lspd.dex /system/bin --nice-name=lspd_config io.github.lsposed.lspd.service.ConfigManager
|
||||||
|
fi
|
||||||
echo "rm -rf /data/misc/$MISC_PATH" >> "${MODPATH}/uninstall.sh" || abortC "! ${LANG_CUST_ERR_CONF_UNINST}"
|
echo "rm -rf /data/misc/$MISC_PATH" >> "${MODPATH}/uninstall.sh" || abortC "! ${LANG_CUST_ERR_CONF_UNINST}"
|
||||||
echo "[[ -f /data/adb/lspd/new_install ]] || rm -rf /data/adb/lspd" >> "${MODPATH}/uninstall.sh" || abortC "! ${LANG_CUST_ERR_CONF_UNINST}"
|
echo "[[ -f /data/adb/lspd/new_install ]] || rm -rf /data/adb/lspd" >> "${MODPATH}/uninstall.sh" || abortC "! ${LANG_CUST_ERR_CONF_UNINST}"
|
||||||
|
|
||||||
|
extract "${ZIPFILE}" "${BIN_PATH}/key_selector" "${TMPDIR}"
|
||||||
|
SELECTOR_PATH="${TMPDIR}/${BIN_PATH}/key_selector"
|
||||||
|
chmod 755 "${SELECTOR_PATH}"
|
||||||
|
"${SELECTOR_PATH}"
|
||||||
|
VARIANT=$?
|
||||||
|
if [ $VARIANT -lt 16 ]; then
|
||||||
|
abortC "${LANG_UTIL_ERR_VARIANT_SELECTION}"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $VARIANT == 17 ]; then # YAHFA
|
if [ $VARIANT == 17 ]; then # YAHFA
|
||||||
echo "1" > /data/adb/lspd/config/variant
|
echo "1" > /data/adb/lspd/config/variant
|
||||||
elif [ $VARIANT == 18 ]; then # SandHook
|
elif [ $VARIANT == 18 ]; then # SandHook
|
||||||
|
|
|
||||||
|
|
@ -286,36 +286,27 @@ int main() {
|
||||||
Variant cursor = Variant::YAHFA;
|
Variant cursor = Variant::YAHFA;
|
||||||
|
|
||||||
// Load current variant
|
// Load current variant
|
||||||
std::filesystem::path lspd_folder;
|
std::filesystem::path lspd_folder("/data/adb/lspd/config");
|
||||||
bool found = false;
|
std::filesystem::create_directories(lspd_folder);
|
||||||
for (auto &item: std::filesystem::directory_iterator("/data/misc/")) {
|
|
||||||
if (item.is_directory() && item.path().string().starts_with("/data/misc/lspd")) {
|
|
||||||
lspd_folder = item;
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (found) {
|
const auto variant_file = lspd_folder / "variant";
|
||||||
const auto variant_file = lspd_folder / "variant";
|
if (std::filesystem::exists(variant_file)) {
|
||||||
if (std::filesystem::exists(variant_file)) {
|
std::ifstream ifs(variant_file);
|
||||||
std::ifstream ifs(variant_file);
|
if (ifs.good()) {
|
||||||
if (ifs.good()) {
|
std::string line;
|
||||||
std::string line;
|
std::getline(ifs, line);
|
||||||
std::getline(ifs, line);
|
char* end;
|
||||||
char* end;
|
int i = std::strtol(line.c_str(), &end, 10);
|
||||||
int i = std::strtol(line.c_str(), &end, 10);
|
switch (i) {
|
||||||
switch (i) {
|
default:
|
||||||
default:
|
case 1:
|
||||||
case 1:
|
cursor = Variant::YAHFA;
|
||||||
cursor = Variant::YAHFA;
|
break;
|
||||||
break;
|
case 2:
|
||||||
case 2:
|
cursor = Variant::SandHook;
|
||||||
cursor = Variant::SandHook;
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
timeout = 5;
|
|
||||||
}
|
}
|
||||||
|
timeout = 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue