[core] Use array list (#870)

This commit is contained in:
vvb2060 2021-08-07 22:34:28 +08:00 committed by GitHub
parent 49163768d6
commit ad5cd87d4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 17 additions and 18 deletions

View File

@ -24,7 +24,6 @@ import java.nio.file.Paths
import java.time.Instant import java.time.Instant
plugins { plugins {
id("org.gradle.idea")
id("com.android.application") id("com.android.application")
id("androidx.navigation.safeargs") id("androidx.navigation.safeargs")
} }

View File

@ -1,5 +1,6 @@
package org.lsposed.lspd.models; package org.lsposed.lspd.models;
parcelable ModuleConfig { parcelable ModuleConfig {
SharedMemory[] preLoadedDexes; List<SharedMemory> preLoadedDexes;
List<String> moduleClassNames;
} }

View File

@ -5,7 +5,6 @@ import org.lsposed.lspd.models.Module;
interface ILSPApplicationService { interface ILSPApplicationService {
IBinder requestModuleBinder(String name); IBinder requestModuleBinder(String name);
//TODO: after array copy bug fixed, use array instead of list
boolean requestManagerBinder(String packageName, String path, out List<IBinder> binder); boolean requestManagerBinder(String packageName, String path, out List<IBinder> binder);
boolean isResourcesHookEnabled(); boolean isResourcesHookEnabled();

View File

@ -3,5 +3,5 @@ package org.lsposed.lspd.service;
import org.lsposed.lspd.service.ILSPApplicationService; import org.lsposed.lspd.service.ILSPApplicationService;
interface ILSPSystemServerService { interface ILSPSystemServerService {
ILSPApplicationService requestApplicationService(int uid, int pid, String processName, IBinder heartBeat) = 1; ILSPApplicationService requestApplicationService(int uid, int pid, String processName, IBinder heartBeat);
} }

View File

@ -3,7 +3,7 @@ package org.lsposed.lspd.service;
import org.lsposed.lspd.service.ILSPApplicationService; import org.lsposed.lspd.service.ILSPApplicationService;
interface ILSPosedService { interface ILSPosedService {
ILSPApplicationService requestApplicationService(int uid, int pid, String processName, IBinder heartBeat) = 1; ILSPApplicationService requestApplicationService(int uid, int pid, String processName, IBinder heartBeat);
oneway void dispatchSystemServerContext(in IBinder activityThread, in IBinder activityToken) = 4; oneway void dispatchSystemServerContext(in IBinder activityThread, in IBinder activityToken);
} }

View File

@ -57,6 +57,7 @@ import java.lang.ref.WeakReference;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -355,7 +356,7 @@ public final class XposedInit {
* in <code>assets/xposed_init</code>. * in <code>assets/xposed_init</code>.
*/ */
@SuppressLint("PrivateApi") @SuppressLint("PrivateApi")
private static boolean loadModule(String name, String apk, SharedMemory[] dexes) { private static boolean loadModule(String name, String apk, List<SharedMemory> dexes) {
Log.i(TAG, "Loading module " + name + " from " + apk); Log.i(TAG, "Loading module " + name + " from " + apk);
if (!new File(apk).exists()) { if (!new File(apk).exists()) {

View File

@ -91,7 +91,7 @@ public class LoadedApkGetCLHooker extends XC_MethodHook {
hookNewXSP(lpparam); hookNewXSP(lpparam);
} }
var binder = new ArrayList<IBinder>(); var binder = new ArrayList<IBinder>(1);
var blocked = false; var blocked = false;
var info = loadedApk.getApplicationInfo(); var info = loadedApk.getApplicationInfo();
if (info != null) { if (info != null) {

View File

@ -201,7 +201,7 @@ public class ConfigManager {
private final Map<ProcessScope, List<Module>> cachedScope = new ConcurrentHashMap<>(); private final Map<ProcessScope, List<Module>> cachedScope = new ConcurrentHashMap<>();
// apkPath, dexes // apkPath, dexes
private final Map<String, SharedMemory[]> cachedDexes = new ConcurrentHashMap<>(); private final Map<String, List<SharedMemory>> cachedDexes = new ConcurrentHashMap<>();
// appId, packageName // appId, packageName
private final Map<Integer, String> cachedModule = new ConcurrentHashMap<>(); private final Map<Integer, String> cachedModule = new ConcurrentHashMap<>();
@ -547,7 +547,7 @@ public class ConfigManager {
}); });
} }
private SharedMemory[] loadModuleDexes(String path) { private List<SharedMemory> loadModuleDexes(String path) {
var sharedMemories = new ArrayList<SharedMemory>(); var sharedMemories = new ArrayList<SharedMemory>();
try (var apkFile = new ZipFile(path)) { try (var apkFile = new ZipFile(path)) {
int secondary = 2; int secondary = 2;
@ -567,10 +567,10 @@ public class ConfigManager {
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Can not open " + path, e); Log.e(TAG, "Can not open " + path, e);
} }
return sharedMemories.toArray(new SharedMemory[0]); return sharedMemories;
} }
private SharedMemory[] getModuleDexes(String path) { private List<SharedMemory> getModuleDexes(String path) {
return cachedDexes.computeIfAbsent(path, this::loadModuleDexes); return cachedDexes.computeIfAbsent(path, this::loadModuleDexes);
} }
@ -579,7 +579,7 @@ public class ConfigManager {
var path = entry.getKey(); var path = entry.getKey();
var dexes = entry.getValue(); var dexes = entry.getValue();
if (!new File(path).exists()) { if (!new File(path).exists()) {
Arrays.stream(dexes).parallel().forEach(SharedMemory::close); dexes.stream().parallel().forEach(SharedMemory::close);
return true; return true;
} }
return false; return false;
@ -856,8 +856,7 @@ public class ConfigManager {
} }
public boolean shouldBlock(String packageName) { public boolean shouldBlock(String packageName) {
return packageName.equals("io.github.lsposed.manager") || return packageName.equals("io.github.lsposed.manager") || isManager(packageName);
packageName.equals(BuildConfig.DEFAULT_MANAGER_PACKAGE_NAME);
} }
public String getPrefsPath(String fileName, int uid) { public String getPrefsPath(String fileName, int uid) {

View File

@ -177,10 +177,10 @@ public final class LspModuleClassLoader extends ByteBufferDexClassLoader {
} }
public static LspModuleClassLoader loadApk(File apk, public static LspModuleClassLoader loadApk(File apk,
SharedMemory[] dexes, List<SharedMemory> dexes,
String librarySearchPath, String librarySearchPath,
ClassLoader parent) { ClassLoader parent) {
var dexBuffers = Arrays.stream(dexes).parallel().map(dex -> { var dexBuffers = dexes.stream().parallel().map(dex -> {
try { try {
return dex.mapReadOnly(); return dex.mapReadOnly();
} catch (ErrnoException e) { } catch (ErrnoException e) {
@ -197,7 +197,7 @@ public final class LspModuleClassLoader extends ByteBufferDexClassLoader {
cl.initNativeLibraryDirs(librarySearchPath); cl.initNativeLibraryDirs(librarySearchPath);
} }
Arrays.stream(dexBuffers).parallel().forEach(SharedMemory::unmap); Arrays.stream(dexBuffers).parallel().forEach(SharedMemory::unmap);
Arrays.stream(dexes).parallel().forEach(SharedMemory::close); dexes.stream().parallel().forEach(SharedMemory::close);
return cl; return cl;
} }
} }