diff --git a/app-core/src/main/java/com/topjohnwu/magisk/App.java b/app-core/src/main/java/com/topjohnwu/magisk/App.java index beffb98ef..3849cbacd 100644 --- a/app-core/src/main/java/com/topjohnwu/magisk/App.java +++ b/app-core/src/main/java/com/topjohnwu/magisk/App.java @@ -28,8 +28,6 @@ public class App extends ContainerApp { public MagiskDB mDB; public RepoDatabaseHelper repoDB; - private Resources mResource; - static { Shell.Config.setFlags(Shell.FLAG_MOUNT_MASTER | Shell.FLAG_USE_MAGISK_BUSYBOX); Shell.Config.verboseLogging(BuildConfig.DEBUG); @@ -41,7 +39,6 @@ public class App extends ContainerApp { protected void attachBaseContext(Context base) { super.attachBaseContext(base); self = this; - mResource = base.getResources(); prefs = PreferenceManager.getDefaultSharedPreferences(this); mDB = new MagiskDB(this); @@ -51,15 +48,6 @@ public class App extends ContainerApp { LocaleManager.setLocale(this); } - @Override - public Resources getResources() { - return mResource; - } - - public void setResources(Resources res) { - mResource = res; - } - @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); diff --git a/app-core/src/main/java/com/topjohnwu/magisk/utils/LocaleManager.java b/app-core/src/main/java/com/topjohnwu/magisk/utils/LocaleManager.java index 71df4cf79..3b0d4a3b6 100644 --- a/app-core/src/main/java/com/topjohnwu/magisk/utils/LocaleManager.java +++ b/app-core/src/main/java/com/topjohnwu/magisk/utils/LocaleManager.java @@ -1,6 +1,7 @@ package com.topjohnwu.magisk.utils; import android.content.Context; +import android.content.ContextWrapper; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; @@ -8,6 +9,7 @@ import android.os.Build; import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.Config; import com.topjohnwu.superuser.Shell; +import com.topjohnwu.superuser.internal.InternalUtils; import java.util.ArrayList; import java.util.Collections; @@ -86,7 +88,7 @@ public class LocaleManager { } } - public static void setLocale(App app) { + public static void setLocale(ContextWrapper wrapper) { String localeConfig = Config.get(Config.Key.LOCALE); if (localeConfig.isEmpty()) { locale = defaultLocale; @@ -94,13 +96,17 @@ public class LocaleManager { locale = forLanguageTag(localeConfig); } Locale.setDefault(locale); - app.setResources(getLocaleContext(locale).getResources()); + InternalUtils.replaceBaseContext(wrapper, getLocaleContext(locale)); + } + + public static Context getLocaleContext(Context context, Locale locale) { + Configuration config = new Configuration(context.getResources().getConfiguration()); + config.setLocale(locale); + return context.createConfigurationContext(config); } public static Context getLocaleContext(Locale locale) { - Configuration config = new Configuration(App.self.getBaseContext().getResources().getConfiguration()); - config.setLocale(locale); - return App.self.createConfigurationContext(config); + return getLocaleContext(App.self.getBaseContext(), locale); } public static String getString(Locale locale, @StringRes int id) { 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 65c860dd4..68c7fb13c 100644 --- a/app/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java +++ b/app/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java @@ -63,8 +63,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter