Don't add self to scope for modern modules (#2717)

This commit is contained in:
Nullptr 2023-08-29 11:21:26 +08:00 committed by GitHub
parent b9d282cdfd
commit 8d7e0bb4d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 12 deletions

View File

@ -100,7 +100,7 @@ public class ConfigManager {
}
}
public static boolean setModuleScope(String packageName, Set<ScopeAdapter.ApplicationWithEquals> applications) {
public static boolean setModuleScope(String packageName, boolean legacy, Set<ScopeAdapter.ApplicationWithEquals> applications) {
try {
List<Application> list = new ArrayList<>();
applications.forEach(application -> {
@ -109,6 +109,12 @@ public class ConfigManager {
app.packageName = application.packageName;
list.add(app);
});
if (legacy) {
Application app = new Application();
app.userId = 0;
app.packageName = packageName;
list.add(app);
}
return LSPManagerServiceHolder.getService().setModuleScope(packageName, list);
} catch (RemoteException e) {
Log.e(App.TAG, Log.getStackTraceString(e));

View File

@ -136,7 +136,7 @@ public class ScopeAdapter extends EmptyStateRecyclerView.EmptyStateAdapter<Scope
enabled = !isChecked;
}
var tmpChkList = new HashSet<>(checkedList);
if (isChecked && !tmpChkList.isEmpty() && !ConfigManager.setModuleScope(module.packageName, tmpChkList)) {
if (isChecked && !tmpChkList.isEmpty() && !ConfigManager.setModuleScope(module.packageName, module.legacy, tmpChkList)) {
view.setChecked(false);
enabled = false;
}
@ -234,7 +234,7 @@ public class ScopeAdapter extends EmptyStateRecyclerView.EmptyStateAdapter<Scope
var tmpChkList = new HashSet<>(checkedList);
tmpChkList.removeIf(i -> i.userId == module.userId);
tmpChkList.addAll(recommendedList);
ConfigManager.setModuleScope(module.packageName, tmpChkList);
ConfigManager.setModuleScope(module.packageName, module.legacy, tmpChkList);
checkedList = tmpChkList;
fragment.runOnUiThread(this::notifyDataSetChanged);
});
@ -573,7 +573,7 @@ public class ScopeAdapter extends EmptyStateRecyclerView.EmptyStateAdapter<Scope
} else {
tmpChkList.remove(appInfo.application);
}
if (!ConfigManager.setModuleScope(module.packageName, tmpChkList)) {
if (!ConfigManager.setModuleScope(module.packageName, module.legacy, tmpChkList)) {
fragment.showHint(R.string.failed_to_save_scope_list, true);
if (!isChecked) {
tmpChkList.add(appInfo.application);

View File

@ -112,7 +112,7 @@ public class BackupUtils {
scope.add(new ScopeAdapter.ApplicationWithEquals(scopeArray.getString(j), 0));
}
}
ConfigManager.setModuleScope(name, scope);
ConfigManager.setModuleScope(name, module.legacy, scope);
}
}
} else {

View File

@ -26,7 +26,6 @@ import static org.lsposed.lspd.service.ServiceManager.existsInGlobalNamespace;
import static org.lsposed.lspd.service.ServiceManager.toGlobalNamespace;
import android.annotation.SuppressLint;
import android.app.ActivityThread;
import android.content.ContentValues;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
@ -44,7 +43,6 @@ import android.os.RemoteException;
import android.os.SELinux;
import android.os.SharedMemory;
import android.os.SystemClock;
import android.permission.IPermissionManager;
import android.system.ErrnoException;
import android.system.Os;
import android.util.Log;
@ -62,7 +60,6 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
@ -831,10 +828,6 @@ public class ConfigManager {
enableModule(packageName);
int mid = getModuleId(packageName);
if (mid == -1) return false;
Application self = new Application();
self.packageName = packageName;
self.userId = 0;
scopes.add(self);
executeInTransaction(() -> {
db.delete("scope", "mid = ?", new String[]{String.valueOf(mid)});
for (Application app : scopes) {