From 48c40f9516c6140e499ed855cde254b987f01a77 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 17 Oct 2018 19:44:48 -0400 Subject: [PATCH] Prevent Resources Fix #619 --- .../magisk/adapters/ApplicationAdapter.java | 24 ++++--------------- .../topjohnwu/magisk/container/Policy.java | 4 +++- .../magisk/fragments/SuperuserFragment.java | 2 +- .../com/topjohnwu/magisk/utils/Utils.java | 17 +++++++++++++ 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java b/app/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java index 67d1a70e6..65c860dd4 100644 --- a/app/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java +++ b/app/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java @@ -3,8 +3,6 @@ package com.topjohnwu.magisk.adapters; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; -import android.content.res.Configuration; -import android.content.res.Resources; import android.os.AsyncTask; import android.text.TextUtils; import android.view.LayoutInflater; @@ -17,8 +15,8 @@ import android.widget.TextView; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.utils.LocaleManager; import com.topjohnwu.magisk.utils.Topic; +import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.Shell; import java.util.ArrayList; @@ -52,19 +50,6 @@ public class ApplicationAdapter extends RecyclerView.Adapter 0) { - try { - Resources res = pm.getResourcesForApplication(info); - Configuration config = new Configuration(); - config.setLocale(LocaleManager.locale); - res.updateConfiguration(config, res.getDisplayMetrics()); - return res.getString(info.labelRes); - } catch (PackageManager.NameNotFoundException ignored) { /* Impossible */ } - } - return info.loadLabel(pm).toString(); - } - private void loadApps() { fullList = pm.getInstalledApplications(0); hideList = Shell.su("magiskhide --ls").exec().getOut(); @@ -78,7 +63,8 @@ public class ApplicationAdapter extends RecyclerView.Adapter(); String filter = constraint.toString().toLowerCase(); for (ApplicationInfo info : fullList) { - if (lowercaseContains(getLabel(info), filter) + if (lowercaseContains(Utils.getAppLabel(info, pm), filter) || lowercaseContains(info.packageName, filter)) { showList.add(info); } diff --git a/app/src/full/java/com/topjohnwu/magisk/container/Policy.java b/app/src/full/java/com/topjohnwu/magisk/container/Policy.java index 4518ee14c..79828d0e7 100644 --- a/app/src/full/java/com/topjohnwu/magisk/container/Policy.java +++ b/app/src/full/java/com/topjohnwu/magisk/container/Policy.java @@ -5,6 +5,8 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.database.Cursor; +import com.topjohnwu.magisk.utils.Utils; + import androidx.annotation.NonNull; @@ -26,7 +28,7 @@ public class Policy implements Comparable{ this.uid = uid; packageName = pkgs[0]; info = pm.getApplicationInfo(packageName, 0); - appName = info.loadLabel(pm).toString(); + appName = Utils.getAppLabel(info, pm); } public Policy(Cursor c, PackageManager pm) throws PackageManager.NameNotFoundException { diff --git a/app/src/full/java/com/topjohnwu/magisk/fragments/SuperuserFragment.java b/app/src/full/java/com/topjohnwu/magisk/fragments/SuperuserFragment.java index f8b49603e..8e07b66fc 100644 --- a/app/src/full/java/com/topjohnwu/magisk/fragments/SuperuserFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/fragments/SuperuserFragment.java @@ -31,7 +31,7 @@ public class SuperuserFragment extends BaseFragment { View view = inflater.inflate(R.layout.fragment_superuser, container, false); unbinder = new SuperuserFragment_ViewBinding(this, view); - pm = getActivity().getPackageManager(); + pm = requireActivity().getPackageManager(); return view; } diff --git a/app/src/full/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/full/java/com/topjohnwu/magisk/utils/Utils.java index 950f72158..86a8ee036 100644 --- a/app/src/full/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/full/java/com/topjohnwu/magisk/utils/Utils.java @@ -6,6 +6,10 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.content.res.Configuration; +import android.content.res.Resources; import android.database.Cursor; import android.net.Uri; import android.os.AsyncTask; @@ -123,4 +127,17 @@ public class Utils { Topic.publish(Topic.MODULE_LOAD_DONE, moduleMap); }); } + + public static String getAppLabel(ApplicationInfo info, PackageManager pm) { + try { + if (info.labelRes > 0) { + Resources res = pm.getResourcesForApplication(info); + Configuration config = new Configuration(); + config.setLocale(LocaleManager.locale); + res.updateConfiguration(config, res.getDisplayMetrics()); + return res.getString(info.labelRes); + } + } catch (Exception ignored) {} + return info.loadLabel(pm).toString(); + } } \ No newline at end of file