[app] Fix scope list
This commit is contained in:
parent
a8b6449a06
commit
bb173abbe4
|
|
@ -29,6 +29,7 @@ import java.util.List;
|
||||||
|
|
||||||
import io.github.lsposed.lspd.Application;
|
import io.github.lsposed.lspd.Application;
|
||||||
import io.github.lsposed.lspd.utils.ParceledListSlice;
|
import io.github.lsposed.lspd.utils.ParceledListSlice;
|
||||||
|
import io.github.lsposed.manager.adapters.ScopeAdapter;
|
||||||
import io.github.lsposed.manager.receivers.LSPosedManagerServiceClient;
|
import io.github.lsposed.manager.receivers.LSPosedManagerServiceClient;
|
||||||
|
|
||||||
public class ConfigManager {
|
public class ConfigManager {
|
||||||
|
|
@ -88,19 +89,30 @@ public class ConfigManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean setModuleScope(String packageName, List<Application> applications) {
|
public static boolean setModuleScope(String packageName, List<ScopeAdapter.ApplicationWithEquals> applications) {
|
||||||
try {
|
try {
|
||||||
return LSPosedManagerServiceClient.setModuleScope(packageName, new ParceledListSlice<>(applications));
|
List<Application> list = new ArrayList<>();
|
||||||
|
applications.forEach(application -> {
|
||||||
|
Application app = new Application();
|
||||||
|
app.userId = application.userId;
|
||||||
|
app.packageName = application.packageName;
|
||||||
|
list.add(app);
|
||||||
|
});
|
||||||
|
return LSPosedManagerServiceClient.setModuleScope(packageName, new ParceledListSlice<>(list));
|
||||||
} catch (RemoteException | NullPointerException e) {
|
} catch (RemoteException | NullPointerException e) {
|
||||||
Log.e(App.TAG, Log.getStackTraceString(e));
|
Log.e(App.TAG, Log.getStackTraceString(e));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Application> getModuleScope(String packageName) {
|
public static List<ScopeAdapter.ApplicationWithEquals> getModuleScope(String packageName) {
|
||||||
List<Application> list = new ArrayList<>();
|
List<ScopeAdapter.ApplicationWithEquals> list = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
list.addAll(LSPosedManagerServiceClient.getModuleScope(packageName).getList());
|
List<Application> applications = LSPosedManagerServiceClient.getModuleScope(packageName).getList();
|
||||||
|
if (applications == null) {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
applications.forEach(application -> list.add(new ScopeAdapter.ApplicationWithEquals(application)));
|
||||||
} catch (RemoteException | NullPointerException e) {
|
} catch (RemoteException | NullPointerException e) {
|
||||||
Log.e(App.TAG, Log.getStackTraceString(e));
|
Log.e(App.TAG, Log.getStackTraceString(e));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,8 +89,8 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
private final String modulePackageName;
|
private final String modulePackageName;
|
||||||
private final String moduleName;
|
private final String moduleName;
|
||||||
private final SwitchBar masterSwitch;
|
private final SwitchBar masterSwitch;
|
||||||
private final List<Application> recommendedList = new ArrayList<>();
|
private final List<ApplicationWithEquals> recommendedList = new ArrayList<>();
|
||||||
private final List<Application> checkedList = new ArrayList<>();
|
private final List<ApplicationWithEquals> checkedList = new ArrayList<>();
|
||||||
private final List<AppInfo> searchList = new ArrayList<>();
|
private final List<AppInfo> searchList = new ArrayList<>();
|
||||||
private List<AppInfo> showList = new ArrayList<>();
|
private List<AppInfo> showList = new ArrayList<>();
|
||||||
private ApplicationInfo selectedInfo;
|
private ApplicationInfo selectedInfo;
|
||||||
|
|
@ -132,14 +132,12 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
activity.runOnUiThread(() -> masterSwitch.setChecked(enabled));
|
activity.runOnUiThread(() -> masterSwitch.setChecked(enabled));
|
||||||
|
|
||||||
checkedList.addAll(ConfigManager.getModuleScope(modulePackageName));
|
checkedList.addAll(ConfigManager.getModuleScope(modulePackageName));
|
||||||
ArrayList<Application> installedList = new ArrayList<>();
|
ArrayList<ApplicationWithEquals> installedList = new ArrayList<>();
|
||||||
List<String> scopeList = ModuleUtil.getInstance().getModule(modulePackageName).getScopeList();
|
List<String> scopeList = ModuleUtil.getInstance().getModule(modulePackageName).getScopeList();
|
||||||
boolean emptyCheckedList = checkedList.isEmpty();
|
boolean emptyCheckedList = checkedList.isEmpty();
|
||||||
for (PackageInfo info : appList) {
|
for (PackageInfo info : appList) {
|
||||||
int uid = info.applicationInfo.uid;
|
int uid = info.applicationInfo.uid;
|
||||||
Application application = new Application();
|
ApplicationWithEquals application = new ApplicationWithEquals(info.packageName, uid / 100000);
|
||||||
application.userId = uid / 100000;
|
|
||||||
application.packageName = info.packageName;
|
|
||||||
|
|
||||||
if (!installedList.contains(application)) installedList.add(application);
|
if (!installedList.contains(application)) installedList.add(application);
|
||||||
|
|
||||||
|
|
@ -170,7 +168,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
activity.onDataReady();
|
activity.onDataReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldHideApp(PackageInfo info, Application app) {
|
private boolean shouldHideApp(PackageInfo info, ApplicationWithEquals app) {
|
||||||
if (info.packageName.equals(this.modulePackageName)) {
|
if (info.packageName.equals(this.modulePackageName)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -567,9 +565,29 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
|
|
||||||
public static class AppInfo {
|
public static class AppInfo {
|
||||||
public PackageInfo packageInfo;
|
public PackageInfo packageInfo;
|
||||||
public Application application;
|
public ApplicationWithEquals application;
|
||||||
public ApplicationInfo applicationInfo;
|
public ApplicationInfo applicationInfo;
|
||||||
public String packageName;
|
public String packageName;
|
||||||
public CharSequence label = null;
|
public CharSequence label = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ApplicationWithEquals extends Application {
|
||||||
|
public ApplicationWithEquals(String packageName, int userId) {
|
||||||
|
this.packageName = packageName;
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationWithEquals(Application application) {
|
||||||
|
packageName = application.packageName;
|
||||||
|
userId = application.userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(@Nullable Object obj) {
|
||||||
|
if (!(obj instanceof Application)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return packageName.equals(((Application) obj).packageName) && userId == ((Application) obj).userId;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue