Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 88bbe820 authored by Jeremy Meyer's avatar Jeremy Meyer
Browse files

Allow disk reads when context creates LocaleConfig

ContextImpl needs to create a LocaleConfig so resources has access to it
for multilocale. This can cause disk reads which cause a strict mode
violation because it happens on the UI thread. This temporary allows it
on the UI thread just around that read.

Fixes: 309232726
Test: manual
Change-Id: I9e1ad21a19bbbdbe6b2fff78489f43e291babad1
parent cc5ffba1
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -3484,9 +3484,20 @@ class ContextImpl extends Context {
        // only do this if the user already has more than one preferred locale
        if (android.content.res.Flags.defaultLocale()
                && r.getConfiguration().getLocales().size() > 1) {
            LocaleConfig lc = getUserId() < 0
                    ? LocaleConfig.fromContextIgnoringOverride(this)
                    : new LocaleConfig(this);
            LocaleConfig lc;
            if (getUserId() < 0) {
                lc = LocaleConfig.fromContextIgnoringOverride(this);
            } else {
                // This is needed because the app might have locale config overrides that need to
                // be read from disk in order for resources to correctly choose which values to
                // load.
                StrictMode.ThreadPolicy policy = StrictMode.allowThreadDiskReads();
                try {
                    lc = new LocaleConfig(this);
                } finally {
                    StrictMode.setThreadPolicy(policy);
                }
            }
            mResourcesManager.setLocaleConfig(lc);
        }
    }