Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mywalkb committed Sep 4, 2023
2 parents 157ce75 + 134cd71 commit 174743c
Show file tree
Hide file tree
Showing 73 changed files with 532 additions and 1,172 deletions.
13 changes: 2 additions & 11 deletions app/src/main/java/org/lsposed/manager/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,7 @@ public void onReceive(Context context, Intent inIntent) {
var intent = (Intent) inIntent.getParcelableExtra(Intent.EXTRA_INTENT);
Log.d(TAG, "onReceive: " + intent);
switch (intent.getAction()) {
case Intent.ACTION_PACKAGE_ADDED:
case Intent.ACTION_PACKAGE_CHANGED:
case Intent.ACTION_PACKAGE_FULLY_REMOVED:
case Intent.ACTION_UID_REMOVED: {
case Intent.ACTION_PACKAGE_ADDED, Intent.ACTION_PACKAGE_CHANGED, Intent.ACTION_PACKAGE_FULLY_REMOVED, Intent.ACTION_UID_REMOVED -> {
var userId = intent.getIntExtra(Intent.EXTRA_USER, 0);
var packageName = intent.getStringExtra("android.intent.extra.PACKAGES");
var packageRemovedForAllUsers = intent.getBooleanExtra(EXTRA_REMOVED_FOR_ALL_USERS, false);
Expand All @@ -236,14 +233,8 @@ public void onReceive(Context context, Intent inIntent) {
else
App.getExecutorService().submit(() -> AppHelper.getAppList(true));
}
break;
}
case ACTION_USER_ADDED:
case ACTION_USER_REMOVED:
case ACTION_USER_INFO_CHANGED: {
App.getExecutorService().submit(() -> ModuleUtil.getInstance().reloadInstalledModules());
break;
}
case ACTION_USER_ADDED, ACTION_USER_REMOVED, ACTION_USER_INFO_CHANGED -> App.getExecutorService().submit(() -> ModuleUtil.getInstance().reloadInstalledModules());
}
}
}, intentFilter, Context.RECEIVER_NOT_EXPORTED);
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/org/lsposed/manager/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static boolean setModuleEnabled(String packageName, boolean enable) {
}
}

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 -> {
Expand All @@ -109,6 +109,12 @@ public static boolean setModuleScope(String packageName, Set<ScopeAdapter.Applic
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));
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/org/lsposed/manager/adapters/ScopeAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void onSwitchChanged(Switch view, boolean isChecked) {
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;
}
Expand Down Expand Up @@ -234,7 +234,7 @@ private void checkRecommended() {
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);
});
Expand Down Expand Up @@ -300,12 +300,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
tmpChkList.add(info.application);
}
ConfigManager.setModuleScope(module.packageName, tmpChkList);
ConfigManager.setModuleScope(module.packageName, module.legacy, tmpChkList);
} else if (itemId == R.id.select_none) {
if (ConfigManager.getModuleScope(module.packageName).contains(new ApplicationWithEquals("android", 0))) {
fragment.showHint(R.string.reboot_required, true, R.string.reboot, v -> ConfigManager.reboot());
}
ConfigManager.setModuleScope(module.packageName, new HashSet<ApplicationWithEquals>());
ConfigManager.setModuleScope(module.packageName, module.legacy, new HashSet<ApplicationWithEquals>());
} else if (itemId == R.id.automatic_add) {
item.setChecked(!item.isChecked());
ConfigManager.setAutomaticAdd(module.packageName, item.isChecked());
Expand Down Expand Up @@ -591,7 +591,7 @@ protected void onCheckedChange(CompoundButton buttonView, boolean isChecked, App
} 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);
Expand All @@ -612,7 +612,7 @@ public boolean isLoaded() {
return isLoaded;
}

static class ViewHolder extends RecyclerView.ViewHolder {
public static class ViewHolder extends RecyclerView.ViewHolder {
ConstraintLayout root;
ImageView appIcon;
TextView appName;
Expand Down Expand Up @@ -692,11 +692,11 @@ public void onBackPressed() {
builder.setNegativeButton(!recommendedList.isEmpty() ? android.R.string.cancel : android.R.string.ok, (dialog, which) -> {
moduleUtil.setModuleEnabled(module.packageName, false);
Toast.makeText(activity, activity.getString(R.string.module_disabled_no_selection, module.getAppName()), Toast.LENGTH_LONG).show();
fragment.getNavController().navigateUp();
fragment.navigateUp();
});
builder.show();
} else {
fragment.getNavController().navigateUp();
fragment.navigateUp();
}
}

Expand Down
27 changes: 14 additions & 13 deletions app/src/main/java/org/lsposed/manager/repo/RepoLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,20 @@ public static synchronized RepoLoader getInstance() {
synchronized public void loadRemoteData() {
repoLoaded = false;
try {
var response = App.getOkHttpClient().newCall(new Request.Builder().url(repoUrl + "modules.json").build()).execute();

if (response.isSuccessful()) {
ResponseBody body = response.body();
if (body != null) {
try {
String bodyString = body.string();
Files.write(repoFile, bodyString.getBytes(StandardCharsets.UTF_8));
loadLocalData(false);
} catch (Throwable t) {
Log.e(App.TAG, Log.getStackTraceString(t));
for (RepoListener listener : listeners) {
listener.onThrowable(t);
try (var response = App.getOkHttpClient().newCall(new Request.Builder().url(repoUrl + "modules.json").build()).execute()) {

if (response.isSuccessful()) {
ResponseBody body = response.body();
if (body != null) {
try {
String bodyString = body.string();
Files.write(repoFile, bodyString.getBytes(StandardCharsets.UTF_8));
loadLocalData(false);
} catch (Throwable t) {
Log.e(App.TAG, Log.getStackTraceString(t));
for (RepoListener listener : listeners) {
listener.onThrowable(t);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.lsposed.manager.util.UpdateUtil;

import java.util.HashSet;
import java.util.Objects;

import rikka.core.util.ResourceUtils;

Expand Down Expand Up @@ -122,27 +123,22 @@ private void handleIntent(Intent intent) {
} else if (ConfigManager.isBinderAlive()) {
if (!TextUtils.isEmpty(intent.getDataString())) {
switch (intent.getDataString()) {
case "modules":
nav.setSelectedItemId(R.id.modules_nav);
break;
case "logs":
nav.setSelectedItemId(R.id.logs_fragment);
break;
case "repo":
case "modules" -> nav.setSelectedItemId(R.id.modules_nav);
case "logs" -> nav.setSelectedItemId(R.id.logs_fragment);
case "repo" -> {
if (ConfigManager.isMagiskInstalled()) {
nav.setSelectedItemId(R.id.repo_nav);
}
break;
case "settings":
nav.setSelectedItemId(R.id.settings_fragment);
break;
default:
}
case "settings" -> nav.setSelectedItemId(R.id.settings_fragment);
default -> {
var data = intent.getData();
if (data != null && data.getScheme().equals("module")) {
if (data != null && Objects.equals(data.getScheme(), "module")) {
navController.navigate(
new Uri.Builder().scheme("lsposed").authority("module").appendQueryParameter("modulePackageName", data.getHost()).appendQueryParameter("moduleUserId", String.valueOf(data.getPort())).build(),
new NavOptions.Builder().setEnterAnim(R.anim.fragment_enter).setExitAnim(R.anim.fragment_exit).setPopEnterAnim(R.anim.fragment_enter_pop).setPopExitAnim(R.anim.fragment_exit_pop).setLaunchSingleTop(true).setPopUpTo(navController.getGraph().getStartDestinationId(), false, true).build());
}
}
}
}
}
Expand Down
31 changes: 11 additions & 20 deletions app/src/main/java/org/lsposed/manager/ui/fragment/BaseFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

package org.lsposed.manager.ui.fragment;

import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.Toast;

Expand All @@ -33,7 +31,6 @@
import androidx.navigation.NavDirections;
import androidx.navigation.fragment.NavHostFragment;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

Expand All @@ -45,7 +42,6 @@
import java.util.concurrent.FutureTask;

public abstract class BaseFragment extends Fragment {
private final Handler uiHandler = new Handler(Looper.getMainLooper());

public void navigateUp() {
getNavController().navigateUp();
Expand Down Expand Up @@ -93,8 +89,7 @@ public void setupToolbar(Toolbar toolbar, View tipsView, String title, int menu,
if (tipsView != null) tipsView.setTooltipText(title);
if (menu != -1) {
toolbar.inflateMenu(menu);
if (this instanceof MenuProvider) {
var self = (MenuProvider) this;
if (this instanceof MenuProvider self) {
toolbar.setOnMenuItemClickListener(self::onMenuItemSelected);
self.onPrepareMenu(toolbar.getMenu());
}
Expand All @@ -110,7 +105,7 @@ public <T> Future<T> runAsync(Callable<T> callable) {
}

public void runOnUiThread(Runnable runnable) {
uiHandler.post(runnable);
App.getMainHandler().post(runnable);
}

public <T> Future<T> runOnUiThread(Callable<T> callable) {
Expand All @@ -132,19 +127,15 @@ public void showHint(CharSequence str, boolean lengthShort) {
}

public void showHint(CharSequence str, boolean lengthShort, CharSequence actionStr, View.OnClickListener action) {
if (isResumed()) {
var container = requireActivity().findViewById(R.id.container);
if (container != null) {
var snackbar = Snackbar.make(container, str, lengthShort ? Snackbar.LENGTH_SHORT : Snackbar.LENGTH_LONG);
if (container.findViewById(R.id.nav) instanceof BottomNavigationView)
snackbar.setAnchorView(R.id.nav);
var fab = container.findViewById(R.id.fab);
if (fab instanceof FloatingActionButton && ((FloatingActionButton) fab).isOrWillBeShown())
snackbar.setAnchorView(fab);
if (actionStr != null && action != null) snackbar.setAction(actionStr, action);
snackbar.show();
return;
}
var container = getView();
if (isResumed() && container != null) {
var snackbar = Snackbar.make(container, str, lengthShort ? Snackbar.LENGTH_SHORT : Snackbar.LENGTH_LONG);
var fab = container.findViewById(R.id.fab);
if (fab instanceof FloatingActionButton && ((FloatingActionButton) fab).isOrWillBeShown())
snackbar.setAnchorView(fab);
if (actionStr != null && action != null) snackbar.setAction(actionStr, action);
snackbar.show();
return;
}
runOnUiThread(() -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private void updateStates(Activity activity, boolean binderAlive, boolean needUp
binding.apiVersion.setText(String.valueOf(ConfigManager.getXposedApiVersion()));
binding.api.setText(ConfigManager.isDexObfuscateEnabled() ? R.string.enabled : R.string.not_enabled);
binding.frameworkVersion.setText(String.format(LocaleDelegate.getDefaultLocale(), "%1$s (%2$d)", ConfigManager.getXposedVersionName(), ConfigManager.getXposedVersionCode()));
binding.managerVersion.setText(activity.getPackageName());
binding.managerPackageName.setText(activity.getPackageName());
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
binding.dex2oatWrapper.setText(String.format(LocaleDelegate.getDefaultLocale(), "%s (%s)", getString(R.string.unsupported), getString(R.string.android_version_unsatisfied)));
} else switch (ConfigManager.getDex2OatWrapperCompatibility()) {
Expand All @@ -190,7 +190,7 @@ private void updateStates(Activity activity, boolean binderAlive, boolean needUp
binding.apiVersion.setText(R.string.not_installed);
binding.api.setText(R.string.not_installed);
binding.frameworkVersion.setText(R.string.not_installed);
binding.managerVersion.setText(String.format(LocaleDelegate.getDefaultLocale(), "%1$s (%2$d)", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE));
binding.managerPackageName.setText(activity.getPackageName());
}

if (Build.VERSION.PREVIEW_SDK_INT != 0) {
Expand All @@ -217,9 +217,9 @@ private void updateStates(Activity activity, boolean binderAlive, boolean needUp
"\n" +
binding.frameworkVersion.getText() +
"\n\n" +
activity.getString(R.string.info_manager_version) +
activity.getString(R.string.info_manager_package_name) +
"\n" +
binding.managerVersion.getText() +
binding.managerPackageName.getText() +
"\n\n" +
activity.getString(R.string.info_system_version) +
"\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,20 @@ public void onPageSelected(int position) {
@Override
public void onPrepareMenu(Menu menu) {
searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
searchView.setOnQueryTextListener(searchListener);
searchView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View arg0) {
binding.appBar.setExpanded(false, true);
}
if (searchView != null) {
searchView.setOnQueryTextListener(searchListener);
searchView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(@NonNull View arg0) {
binding.appBar.setExpanded(false, true);
}

@Override
public void onViewDetachedFromWindow(View v) {
}
});
searchView.findViewById(androidx.appcompat.R.id.search_edit_frame).setLayoutDirection(View.LAYOUT_DIRECTION_INHERIT);
@Override
public void onViewDetachedFromWindow(@NonNull View v) {
}
});
searchView.findViewById(androidx.appcompat.R.id.search_edit_frame).setLayoutDirection(View.LAYOUT_DIRECTION_INHERIT);
}
}

@Override
Expand Down Expand Up @@ -367,12 +369,12 @@ public void onChanged() {

private final View.OnAttachStateChangeListener searchViewLocker = new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View v) {
public void onViewAttachedToWindow(@NonNull View v) {
binding.recyclerView.setNestedScrollingEnabled(false);
}

@Override
public void onViewDetachedFromWindow(View v) {
public void onViewDetachedFromWindow(@NonNull View v) {
binding.recyclerView.setNestedScrollingEnabled(true);
}
};
Expand All @@ -399,8 +401,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

void attachListeners() {
var parent = getParentFragment();
if (parent instanceof ModulesFragment) {
var moduleFragment = (ModulesFragment) parent;
if (parent instanceof ModulesFragment moduleFragment) {
binding.recyclerView.getBorderViewDelegate().setBorderVisibilityChangedListener((top, oldTop, bottom, oldBottom) -> moduleFragment.binding.appBar.setLifted(!top));
moduleFragment.binding.appBar.setLifted(!binding.recyclerView.getBorderViewDelegate().isShowingTopBorder());
moduleFragment.searchView.addOnAttachStateChangeListener(searchViewLocker);
Expand All @@ -419,8 +420,7 @@ void attachListeners() {
void detachListeners() {
binding.recyclerView.getBorderViewDelegate().setBorderVisibilityChangedListener(null);
var parent = getParentFragment();
if (parent instanceof ModulesFragment) {
var moduleFragment = (ModulesFragment) parent;
if (parent instanceof ModulesFragment moduleFragment) {
moduleFragment.searchView.removeOnAttachStateChangeListener(searchViewLocker);
binding.recyclerView.setNestedScrollingEnabled(true);
}
Expand Down Expand Up @@ -517,7 +517,7 @@ public UserInfo getUser() {
@NonNull
@Override
public ModuleAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ModuleAdapter.ViewHolder(ItemModuleBinding.inflate(getLayoutInflater(), parent, false));
return new ViewHolder(ItemModuleBinding.inflate(getLayoutInflater(), parent, false));
}

public boolean isPick() {
Expand Down Expand Up @@ -746,7 +746,7 @@ public boolean isLoaded() {
return isLoaded && moduleUtil.isModulesLoaded();
}

class ViewHolder extends RecyclerView.ViewHolder {
static class ViewHolder extends RecyclerView.ViewHolder {
ConstraintLayout root;
ImageView appIcon;
TextView appName;
Expand Down
Loading

0 comments on commit 174743c

Please sign in to comment.