[app] Only allow setting modules' scope when enabled (#1455)
This commit is contained in:
parent
ed4d230821
commit
62667a4e05
|
|
@ -109,6 +109,10 @@ public class ScopeAdapter extends EmptyStateRecyclerView.EmptyStateAdapter<Scope
|
|||
if (!moduleUtil.setModuleEnabled(module.packageName, isChecked)) {
|
||||
return false;
|
||||
}
|
||||
var tmpChkList = new HashSet<>(checkedList);
|
||||
if (isChecked && !tmpChkList.isEmpty() && !ConfigManager.setModuleScope(module.packageName, tmpChkList)) {
|
||||
return false;
|
||||
}
|
||||
enabled = isChecked;
|
||||
notifyDataSetChanged();
|
||||
return true;
|
||||
|
|
@ -200,6 +204,10 @@ public class ScopeAdapter extends EmptyStateRecyclerView.EmptyStateAdapter<Scope
|
|||
}
|
||||
|
||||
private void checkRecommended() {
|
||||
if (!fragment.binding.masterSwitch.isChecked()) {
|
||||
fragment.showHint(R.string.module_is_not_activated_yet, false);
|
||||
return;
|
||||
}
|
||||
fragment.runAsync(() -> {
|
||||
var tmpChkList = new HashSet<>(checkedList);
|
||||
tmpChkList.removeIf(i -> i.userId == module.userId);
|
||||
|
|
@ -514,9 +522,6 @@ public class ScopeAdapter extends EmptyStateRecyclerView.EmptyStateAdapter<Scope
|
|||
}
|
||||
});
|
||||
tmpChkList.retainAll(installedList);
|
||||
if (emptyCheckedList) {
|
||||
ConfigManager.setModuleScope(module.packageName, tmpChkList);
|
||||
}
|
||||
checkedList = tmpChkList;
|
||||
recommendedList = tmpRecList;
|
||||
searchList = tmpList.parallelStream().sorted(this::sortApps).collect(Collectors.toList());
|
||||
|
|
|
|||
|
|
@ -96,7 +96,9 @@ public class BackupUtils {
|
|||
}
|
||||
ModuleUtil.InstalledModule module = ModuleUtil.getInstance().getModule(name);
|
||||
if (module != null) {
|
||||
ModuleUtil.getInstance().setModuleEnabled(name, moduleObject.getBoolean("enable"));
|
||||
var enabled = moduleObject.getBoolean("enable");
|
||||
ModuleUtil.getInstance().setModuleEnabled(name, enabled);
|
||||
if (!enabled) continue;
|
||||
JSONArray scopeArray = moduleObject.getJSONArray("scope");
|
||||
HashSet<ScopeAdapter.ApplicationWithEquals> scope = new HashSet<>();
|
||||
for (int j = 0; j < scopeArray.length(); j++) {
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@
|
|||
<string name="menu_show_games">Games</string>
|
||||
<string name="menu_show_modules">Modules</string>
|
||||
<string name="menu_show_denylist">Denylist</string>
|
||||
<string name="failed_to_save_scope_list">Failed save scope list</string>
|
||||
<string name="failed_to_save_scope_list">Failed to save scope list</string>
|
||||
<string name="app_description">%1$s\nVersion %2$s</string>
|
||||
<string name="use_recommended">Recommended</string>
|
||||
<string name="no_scope_selected_has_recommended">You did not select any app. Select recommended apps?</string>
|
||||
|
|
|
|||
|
|
@ -711,21 +711,21 @@ public class ConfigManager {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean setModuleScope(String packageName, List<Application> scopes) {
|
||||
public boolean setModuleScope(String packageName, List<Application> scopes) throws RemoteException {
|
||||
if (scopes == null) return false;
|
||||
enableModule(packageName);
|
||||
int mid = getModuleId(packageName);
|
||||
if (mid == -1) return false;
|
||||
Application self = new Application();
|
||||
self.packageName = packageName;
|
||||
self.userId = 0;
|
||||
scopes.add(self);
|
||||
int finalMid = mid;
|
||||
executeInTransaction(() -> {
|
||||
db.delete("scope", "mid = ?", new String[]{String.valueOf(finalMid)});
|
||||
db.delete("scope", "mid = ?", new String[]{String.valueOf(mid)});
|
||||
for (Application app : scopes) {
|
||||
if (app.packageName.equals("android") && app.userId != 0) continue;
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("mid", finalMid);
|
||||
values.put("mid", mid);
|
||||
values.put("app_pkg_name", app.packageName);
|
||||
values.put("user_id", app.userId);
|
||||
db.insertWithOnConflict("scope", null, values, SQLiteDatabase.CONFLICT_IGNORE);
|
||||
|
|
@ -810,8 +810,12 @@ public class ConfigManager {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean enableModule(String packageName, ApplicationInfo info) {
|
||||
if (packageName.equals("lspd") || !updateModuleApkPath(packageName, getModuleApkPath(info), false))
|
||||
public boolean enableModule(String packageName) throws RemoteException {
|
||||
PackageInfo pkgInfo = PackageService.getPackageInfo(packageName, PackageService.MATCH_ALL_FLAGS, 0);
|
||||
if (pkgInfo == null || pkgInfo.applicationInfo == null) {
|
||||
return false;
|
||||
}
|
||||
if (packageName.equals("lspd") || !updateModuleApkPath(packageName, getModuleApkPath(pkgInfo.applicationInfo), false))
|
||||
return false;
|
||||
boolean changed = executeInTransaction(() -> {
|
||||
ContentValues values = new ContentValues();
|
||||
|
|
|
|||
|
|
@ -521,16 +521,11 @@ public class LSPManagerService extends ILSPManagerService.Stub {
|
|||
|
||||
@Override
|
||||
public boolean enableModule(String packageName) throws RemoteException {
|
||||
PackageInfo pkgInfo = PackageService.getPackageInfo(packageName, PackageService.MATCH_ALL_FLAGS, 0);
|
||||
if (pkgInfo != null && pkgInfo.applicationInfo != null) {
|
||||
return ConfigManager.getInstance().enableModule(packageName, pkgInfo.applicationInfo);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return ConfigManager.getInstance().enableModule(packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setModuleScope(String packageName, ParceledListSlice<Application> scope) {
|
||||
public boolean setModuleScope(String packageName, ParceledListSlice<Application> scope) throws RemoteException {
|
||||
return ConfigManager.getInstance().setModuleScope(packageName, scope.getList());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -115,9 +115,9 @@ public class LSPosedService extends ILSPosedService.Stub {
|
|||
}
|
||||
if (isXposedModule) {
|
||||
broadcastOrShowNotification(moduleName, userId, intentAction);
|
||||
// When installing a new Xposed module, we update the apk path to prepare for
|
||||
// the first activation of a module with a recommended scope or for a user to
|
||||
// uninstall a module that has not been activated before.
|
||||
// When installing a new Xposed module, we update the apk path to mark it as a
|
||||
// module to send a broadcast when modules that have not been activated are
|
||||
// uninstalled.
|
||||
ConfigManager.getInstance().updateModuleApkPath(moduleName, ConfigManager.getInstance().getModuleApkPath(applicationInfo), true);
|
||||
// when package is changed, we may need to update cache (module cache or process cache)
|
||||
ConfigManager.getInstance().updateCache();
|
||||
|
|
|
|||
Loading…
Reference in New Issue