Check module configuration (#2403)
Co-authored-by: vvb2060 <vvb2060@gmail.com>
This commit is contained in:
parent
a31162e284
commit
6751b7350f
|
|
@ -38,12 +38,11 @@ import org.lsposed.manager.ConfigManager;
|
||||||
import org.lsposed.manager.repo.RepoLoader;
|
import org.lsposed.manager.repo.RepoLoader;
|
||||||
import org.lsposed.manager.repo.model.OnlineModule;
|
import org.lsposed.manager.repo.model.OnlineModule;
|
||||||
|
|
||||||
import java.io.EOFException;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -51,7 +50,7 @@ import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.stream.Collectors;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
public final class ModuleUtil {
|
public final class ModuleUtil {
|
||||||
|
|
@ -218,21 +217,6 @@ public final class ModuleUtil {
|
||||||
return enabledModules.contains(packageName);
|
return enabledModules.contains(packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String readZipEntryToString(ZipFile file, ZipEntry entry) throws IOException {
|
|
||||||
try (var is = file.getInputStream(entry)) {
|
|
||||||
var bytes = new byte[(int) entry.getSize()];
|
|
||||||
int offset = 0;
|
|
||||||
while (offset < bytes.length) {
|
|
||||||
int read = is.read(bytes, offset, bytes.length - offset);
|
|
||||||
if (read < 0) {
|
|
||||||
throw new EOFException();
|
|
||||||
}
|
|
||||||
offset += read;
|
|
||||||
}
|
|
||||||
return new String(bytes, StandardCharsets.UTF_8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getEnabledModulesCount() {
|
public int getEnabledModulesCount() {
|
||||||
return modulesLoaded ? enabledModules.size() : -1;
|
return modulesLoaded ? enabledModules.size() : -1;
|
||||||
}
|
}
|
||||||
|
|
@ -271,8 +255,8 @@ public final class ModuleUtil {
|
||||||
public final boolean staticScope;
|
public final boolean staticScope;
|
||||||
public final long installTime;
|
public final long installTime;
|
||||||
public final long updateTime;
|
public final long updateTime;
|
||||||
public ApplicationInfo app;
|
public final ApplicationInfo app;
|
||||||
public PackageInfo pkg;
|
public final PackageInfo pkg;
|
||||||
private String appName; // loaded lazyily
|
private String appName; // loaded lazyily
|
||||||
private String description; // loaded lazyily
|
private String description; // loaded lazyily
|
||||||
private List<String> scopeList; // loaded lazyily
|
private List<String> scopeList; // loaded lazyily
|
||||||
|
|
@ -318,11 +302,11 @@ public final class ModuleUtil {
|
||||||
}
|
}
|
||||||
var scopeEntry = modernModuleApk.getEntry("META-INF/xposed/scope.list");
|
var scopeEntry = modernModuleApk.getEntry("META-INF/xposed/scope.list");
|
||||||
if (scopeEntry != null) {
|
if (scopeEntry != null) {
|
||||||
scopeList = Arrays.asList(readZipEntryToString(modernModuleApk, scopeEntry).split("\\n|\\r\\n"));
|
try (var reader = new BufferedReader(new InputStreamReader(modernModuleApk.getInputStream(scopeEntry)))) {
|
||||||
} else {
|
scopeList = reader.lines().collect(Collectors.toList());
|
||||||
scopeList = Collections.emptyList();
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
}
|
||||||
|
} catch (IOException | OutOfMemoryError e) {
|
||||||
Log.e(App.TAG, "Error while closing modern module APK", e);
|
Log.e(App.TAG, "Error while closing modern module APK", e);
|
||||||
}
|
}
|
||||||
this.minVersion = minVersion;
|
this.minVersion = minVersion;
|
||||||
|
|
@ -342,8 +326,8 @@ public final class ModuleUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
if (this.description == null) {
|
if (this.description != null) return this.description;
|
||||||
String descriptionTmp = null;
|
String descriptionTmp = "";
|
||||||
if (legacy) {
|
if (legacy) {
|
||||||
Object descriptionRaw = app.metaData.get("xposeddescription");
|
Object descriptionRaw = app.metaData.get("xposeddescription");
|
||||||
if (descriptionRaw instanceof String) {
|
if (descriptionRaw instanceof String) {
|
||||||
|
|
@ -357,15 +341,16 @@ public final class ModuleUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
descriptionTmp = app.loadDescription(pm).toString();
|
var des = app.loadDescription(pm);
|
||||||
}
|
if (des != null) descriptionTmp = des.toString();
|
||||||
this.description = (descriptionTmp != null) ? descriptionTmp : "";
|
|
||||||
}
|
}
|
||||||
|
this.description = descriptionTmp;
|
||||||
return this.description;
|
return this.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getScopeList() {
|
public List<String> getScopeList() {
|
||||||
if (scopeList == null) {
|
if (scopeList != null) return scopeList;
|
||||||
|
if (legacy) {
|
||||||
try {
|
try {
|
||||||
int scopeListResourceId = app.metaData.getInt("xposedscope");
|
int scopeListResourceId = app.metaData.getInt("xposedscope");
|
||||||
if (scopeListResourceId != 0) {
|
if (scopeListResourceId != 0) {
|
||||||
|
|
@ -375,17 +360,15 @@ public final class ModuleUtil {
|
||||||
if (scopeListString != null)
|
if (scopeListString != null)
|
||||||
scopeList = Arrays.asList(scopeListString.split(";"));
|
scopeList = Arrays.asList(scopeListString.split(";"));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception ignored) {
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
}
|
||||||
RepoLoader repoLoader = RepoLoader.getInstance();
|
|
||||||
if (scopeList == null) {
|
if (scopeList == null) {
|
||||||
OnlineModule module = repoLoader.getOnlineModule(packageName);
|
OnlineModule module = RepoLoader.getInstance().getOnlineModule(packageName);
|
||||||
if (module != null && module.getScope() != null) {
|
if (module != null && module.getScope() != null) {
|
||||||
scopeList = module.getScope();
|
scopeList = module.getScope();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return scopeList;
|
return scopeList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -356,7 +356,7 @@ public class ConfigFileManager {
|
||||||
if (name.isEmpty() || name.startsWith("#")) continue;
|
if (name.isEmpty() || name.startsWith("#")) continue;
|
||||||
names.add(name);
|
names.add(name);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException | OutOfMemoryError e) {
|
||||||
Log.e(TAG, "Can not open " + initEntry, e);
|
Log.e(TAG, "Can not open " + initEntry, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue