[app] Fix opening modules and apps for other users (#584)
This commit is contained in:
parent
fe17834fa3
commit
64efa50685
|
|
@ -20,12 +20,14 @@
|
||||||
|
|
||||||
package org.lsposed.manager.adapters;
|
package org.lsposed.manager.adapters;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import org.lsposed.manager.ConfigManager;
|
import org.lsposed.manager.ConfigManager;
|
||||||
|
|
@ -49,6 +51,16 @@ public class AppHelper {
|
||||||
return getIntentForCategory(packageName, userId, packageManager, Intent.CATEGORY_LAUNCHER);
|
return getIntentForCategory(packageName, userId, packageManager, Intent.CATEGORY_LAUNCHER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void startActivityAsUser(Activity activity, Intent intent, UserHandle user) {
|
||||||
|
try {
|
||||||
|
//noinspection JavaReflectionMemberAccess
|
||||||
|
var startActivityAsUserMethod = Activity.class.getMethod("startActivityAsUser", Intent.class, UserHandle.class);
|
||||||
|
startActivityAsUserMethod.invoke(activity, intent, user);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Intent getIntentForCategory(String packageName, int userId, PackageManager packageManager, String category) {
|
public static Intent getIntentForCategory(String packageName, int userId, PackageManager packageManager, String category) {
|
||||||
Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
|
Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
|
||||||
intentToResolve.addCategory(category);
|
intentToResolve.addCategory(category);
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
@ -98,6 +99,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
private final ModuleUtil moduleUtil;
|
private final ModuleUtil moduleUtil;
|
||||||
|
|
||||||
private final ModuleUtil.InstalledModule module;
|
private final ModuleUtil.InstalledModule module;
|
||||||
|
private final UserHandle userHandle;
|
||||||
|
|
||||||
private final HashSet<ApplicationWithEquals> recommendedList = new HashSet<>();
|
private final HashSet<ApplicationWithEquals> recommendedList = new HashSet<>();
|
||||||
private final HashSet<ApplicationWithEquals> checkedList = new HashSet<>();
|
private final HashSet<ApplicationWithEquals> checkedList = new HashSet<>();
|
||||||
|
|
@ -132,9 +134,10 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
private boolean refreshing = false;
|
private boolean refreshing = false;
|
||||||
private boolean enabled = true;
|
private boolean enabled = true;
|
||||||
|
|
||||||
public ScopeAdapter(AppListActivity activity, ModuleUtil.InstalledModule module) {
|
public ScopeAdapter(AppListActivity activity, ModuleUtil.InstalledModule module, UserHandle userHandle) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
this.module = module;
|
this.module = module;
|
||||||
|
this.userHandle = userHandle;
|
||||||
moduleUtil = ModuleUtil.getInstance();
|
moduleUtil = ModuleUtil.getInstance();
|
||||||
HandlerThread handlerThread = new HandlerThread("appList");
|
HandlerThread handlerThread = new HandlerThread("appList");
|
||||||
handlerThread.start();
|
handlerThread.start();
|
||||||
|
|
@ -256,7 +259,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
} else if (itemId == R.id.menu_launch) {
|
} else if (itemId == R.id.menu_launch) {
|
||||||
Intent launchIntent = AppHelper.getSettingsIntent(module.packageName, module.userId, pm);
|
Intent launchIntent = AppHelper.getSettingsIntent(module.packageName, module.userId, pm);
|
||||||
if (launchIntent != null) {
|
if (launchIntent != null) {
|
||||||
activity.startActivity(launchIntent);
|
AppHelper.startActivityAsUser(activity, launchIntent, userHandle);
|
||||||
} else {
|
} else {
|
||||||
activity.makeSnackBar(R.string.module_no_ui, Snackbar.LENGTH_LONG);
|
activity.makeSnackBar(R.string.module_no_ui, Snackbar.LENGTH_LONG);
|
||||||
}
|
}
|
||||||
|
|
@ -289,7 +292,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
if (itemId == R.id.menu_launch) {
|
if (itemId == R.id.menu_launch) {
|
||||||
Intent launchIntent = pm.getLaunchIntentForPackage(info.packageName);
|
Intent launchIntent = pm.getLaunchIntentForPackage(info.packageName);
|
||||||
if (launchIntent != null) {
|
if (launchIntent != null) {
|
||||||
activity.startActivity(launchIntent);
|
AppHelper.startActivityAsUser(activity, launchIntent, userHandle);
|
||||||
}
|
}
|
||||||
} else if (itemId == R.id.menu_compile_speed) {
|
} else if (itemId == R.id.menu_compile_speed) {
|
||||||
CompileDialogFragment.speed(activity.getSupportFragmentManager(), info);
|
CompileDialogFragment.speed(activity.getSupportFragmentManager(), info);
|
||||||
|
|
@ -303,7 +306,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else if (itemId == R.id.menu_app_info) {
|
} else if (itemId == R.id.menu_app_info) {
|
||||||
activity.startActivity(new Intent(ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", info.packageName, null)));
|
AppHelper.startActivityAsUser(activity, new Intent(ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", info.packageName, null)), userHandle);
|
||||||
} else if (itemId == R.id.menu_force_stop) {
|
} else if (itemId == R.id.menu_force_stop) {
|
||||||
if (info.packageName.equals("android")) {
|
if (info.packageName.equals("android")) {
|
||||||
ConfigManager.reboot(false, null, false);
|
ConfigManager.reboot(false, null, false);
|
||||||
|
|
@ -412,14 +415,10 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
holder.itemView.setOnCreateContextMenuListener((menu, v, menuInfo) -> {
|
holder.itemView.setOnCreateContextMenuListener((menu, v, menuInfo) -> {
|
||||||
activity.getMenuInflater().inflate(R.menu.menu_app_item, menu);
|
activity.getMenuInflater().inflate(R.menu.menu_app_item, menu);
|
||||||
menu.setHeaderTitle(appName);
|
menu.setHeaderTitle(appName);
|
||||||
Intent launchIntent = pm.getLaunchIntentForPackage(appInfo.packageName);
|
Intent launchIntent = AppHelper.getIntentForCategory(appInfo.packageName, userId, pm, Intent.CATEGORY_LAUNCHER);
|
||||||
if (launchIntent == null) {
|
if (launchIntent == null) {
|
||||||
menu.removeItem(R.id.menu_launch);
|
menu.removeItem(R.id.menu_launch);
|
||||||
}
|
}
|
||||||
if (userId != 0) {
|
|
||||||
menu.removeItem(R.id.menu_launch);
|
|
||||||
menu.removeItem(R.id.menu_app_info);
|
|
||||||
}
|
|
||||||
if (android) {
|
if (android) {
|
||||||
menu.findItem(R.id.menu_force_stop).setTitle(R.string.reboot);
|
menu.findItem(R.id.menu_force_stop).setTitle(R.string.reboot);
|
||||||
menu.removeItem(R.id.menu_compile_speed);
|
menu.removeItem(R.id.menu_compile_speed);
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ package org.lsposed.manager.ui.activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
|
|
@ -46,6 +47,8 @@ import org.lsposed.manager.util.BackupUtils;
|
||||||
import org.lsposed.manager.util.LinearLayoutManagerFix;
|
import org.lsposed.manager.util.LinearLayoutManagerFix;
|
||||||
import org.lsposed.manager.util.ModuleUtil;
|
import org.lsposed.manager.util.ModuleUtil;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import rikka.recyclerview.RecyclerViewKt;
|
import rikka.recyclerview.RecyclerViewKt;
|
||||||
|
|
||||||
public class AppListActivity extends BaseActivity {
|
public class AppListActivity extends BaseActivity {
|
||||||
|
|
@ -62,6 +65,7 @@ public class AppListActivity extends BaseActivity {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
String modulePackageName = getIntent().getStringExtra("modulePackageName");
|
String modulePackageName = getIntent().getStringExtra("modulePackageName");
|
||||||
int moduleUserId = getIntent().getIntExtra("moduleUserId", -1);
|
int moduleUserId = getIntent().getIntExtra("moduleUserId", -1);
|
||||||
|
UserHandle userHandle = getIntent().getParcelableExtra("userHandle");
|
||||||
binding = ActivityAppListBinding.inflate(getLayoutInflater());
|
binding = ActivityAppListBinding.inflate(getLayoutInflater());
|
||||||
setContentView(binding.getRoot());
|
setContentView(binding.getRoot());
|
||||||
setAppBar(binding.appBar, binding.toolbar);
|
setAppBar(binding.appBar, binding.toolbar);
|
||||||
|
|
@ -75,10 +79,14 @@ public class AppListActivity extends BaseActivity {
|
||||||
ActionBar bar = getSupportActionBar();
|
ActionBar bar = getSupportActionBar();
|
||||||
if (bar != null) {
|
if (bar != null) {
|
||||||
bar.setDisplayHomeAsUpEnabled(true);
|
bar.setDisplayHomeAsUpEnabled(true);
|
||||||
bar.setTitle(module.getAppName());
|
if (module.userId != 0) {
|
||||||
|
bar.setTitle(String.format(Locale.US, "%s (%d)", module.getAppName(), module.userId));
|
||||||
|
} else {
|
||||||
|
bar.setTitle(module.getAppName());
|
||||||
|
}
|
||||||
bar.setSubtitle(module.packageName);
|
bar.setSubtitle(module.packageName);
|
||||||
}
|
}
|
||||||
scopeAdapter = new ScopeAdapter(this, module);
|
scopeAdapter = new ScopeAdapter(this, module, userHandle);
|
||||||
scopeAdapter.setHasStableIds(true);
|
scopeAdapter.setHasStableIds(true);
|
||||||
binding.recyclerView.setAdapter(scopeAdapter);
|
binding.recyclerView.setAdapter(scopeAdapter);
|
||||||
binding.recyclerView.setHasFixedSize(true);
|
binding.recyclerView.setHasFixedSize(true);
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,8 @@ import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
@ -79,6 +81,7 @@ import org.lsposed.manager.util.ModuleUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
@ -99,6 +102,8 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
||||||
private PackageManager pm;
|
private PackageManager pm;
|
||||||
private ModuleUtil moduleUtil;
|
private ModuleUtil moduleUtil;
|
||||||
private ModuleUtil.InstalledModule selectedModule;
|
private ModuleUtil.InstalledModule selectedModule;
|
||||||
|
private UserHandle selectedModuleUser;
|
||||||
|
private UserManager userManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
@ -108,6 +113,7 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
||||||
moduleUtil = ModuleUtil.getInstance();
|
moduleUtil = ModuleUtil.getInstance();
|
||||||
pm = getPackageManager();
|
pm = getPackageManager();
|
||||||
moduleUtil.addListener(this);
|
moduleUtil.addListener(this);
|
||||||
|
userManager = getSystemService(UserManager.class);
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
binding = ActivityModuleDetailBinding.inflate(getLayoutInflater());
|
binding = ActivityModuleDetailBinding.inflate(getLayoutInflater());
|
||||||
setContentView(binding.getRoot());
|
setContentView(binding.getRoot());
|
||||||
|
|
@ -171,15 +177,20 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
int[] users = ConfigManager.getUsers();
|
int[] userIds = ConfigManager.getUsers();
|
||||||
if (users != null) {
|
if (userIds != null) {
|
||||||
if (users.length != adapters.size()) {
|
List<UserHandle> users = userManager.getUserProfiles();
|
||||||
|
HashMap<Integer, UserHandle> handles = new HashMap<>();
|
||||||
|
for (UserHandle handle : users) {
|
||||||
|
handles.put(handle.hashCode(), handle);
|
||||||
|
}
|
||||||
|
if (userIds.length != adapters.size()) {
|
||||||
adapters.clear();
|
adapters.clear();
|
||||||
if (users.length != 1) {
|
if (users.size() != 1) {
|
||||||
binding.viewPager.setUserInputEnabled(true);
|
binding.viewPager.setUserInputEnabled(true);
|
||||||
ArrayList<String> titles = new ArrayList<>();
|
ArrayList<String> titles = new ArrayList<>();
|
||||||
for (int userId : users) {
|
for (int userId : userIds) {
|
||||||
var adapter = new ModuleAdapter(userId);
|
var adapter = new ModuleAdapter(userId, handles.get(userId));
|
||||||
adapter.setHasStableIds(true);
|
adapter.setHasStableIds(true);
|
||||||
adapters.add(adapter);
|
adapters.add(adapter);
|
||||||
titles.add(getString(R.string.user_title, userId));
|
titles.add(getString(R.string.user_title, userId));
|
||||||
|
|
@ -188,7 +199,7 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
||||||
binding.tabLayout.setVisibility(View.VISIBLE);
|
binding.tabLayout.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
binding.viewPager.setUserInputEnabled(false);
|
binding.viewPager.setUserInputEnabled(false);
|
||||||
var adapter = new ModuleAdapter(0);
|
var adapter = new ModuleAdapter(0, users.get(0));
|
||||||
adapter.setHasStableIds(true);
|
adapter.setHasStableIds(true);
|
||||||
adapters.add(adapter);
|
adapters.add(adapter);
|
||||||
binding.tabLayout.setVisibility(View.GONE);
|
binding.tabLayout.setVisibility(View.GONE);
|
||||||
|
|
@ -243,7 +254,7 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
||||||
}
|
}
|
||||||
Intent intent = AppHelper.getSettingsIntent(packageName, module.userId, pm);
|
Intent intent = AppHelper.getSettingsIntent(packageName, module.userId, pm);
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
startActivity(intent);
|
AppHelper.startActivityAsUser(this, intent, selectedModuleUser);
|
||||||
} else {
|
} else {
|
||||||
Snackbar.make(binding.snackbar, R.string.module_no_ui, Snackbar.LENGTH_LONG).show();
|
Snackbar.make(binding.snackbar, R.string.module_no_ui, Snackbar.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
|
|
@ -259,7 +270,7 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.menu_app_info) {
|
} else if (itemId == R.id.menu_app_info) {
|
||||||
startActivity(new Intent(ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", module.packageName, null)));
|
AppHelper.startActivityAsUser(this, (new Intent(ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", module.packageName, null))), selectedModuleUser);
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.menu_uninstall) {
|
} else if (itemId == R.id.menu_uninstall) {
|
||||||
new AlertDialog.Builder(this)
|
new AlertDialog.Builder(this)
|
||||||
|
|
@ -332,10 +343,12 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
||||||
private final List<ModuleUtil.InstalledModule> searchList = new ArrayList<>();
|
private final List<ModuleUtil.InstalledModule> searchList = new ArrayList<>();
|
||||||
private final List<ModuleUtil.InstalledModule> showList = new ArrayList<>();
|
private final List<ModuleUtil.InstalledModule> showList = new ArrayList<>();
|
||||||
private final int userId;
|
private final int userId;
|
||||||
|
private final UserHandle userHandle;
|
||||||
private boolean isLoaded;
|
private boolean isLoaded;
|
||||||
|
|
||||||
ModuleAdapter(int userId) {
|
ModuleAdapter(int userId, UserHandle userHandle) {
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
|
this.userHandle = userHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
@ -418,11 +431,13 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
||||||
Intent intent = new Intent(ModulesActivity.this, AppListActivity.class);
|
Intent intent = new Intent(ModulesActivity.this, AppListActivity.class);
|
||||||
intent.putExtra("modulePackageName", item.packageName);
|
intent.putExtra("modulePackageName", item.packageName);
|
||||||
intent.putExtra("moduleUserId", item.userId);
|
intent.putExtra("moduleUserId", item.userId);
|
||||||
|
intent.putExtra("userHandle", userHandle);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
});
|
});
|
||||||
|
|
||||||
holder.itemView.setOnLongClickListener(v -> {
|
holder.itemView.setOnLongClickListener(v -> {
|
||||||
selectedModule = item;
|
selectedModule = item;
|
||||||
|
selectedModuleUser = userHandle;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue