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

Commit 44acbc44 authored by Mattias Nilsson's avatar Mattias Nilsson
Browse files

Root locale need a configuration context

KEY_WFC_SPN_USE_ROOT_LOCALE does not return the root
resource in CarrierDisplayNameResolver. The reason is
that setLocale() on default context does not change the
locale in the configuration being used to get resources
in native AssetManager.

For temporary changes to a configuration there is already
a template, you create a new context with new resources.

Test: Manual
Test: atest CarrierDisplayNameResolverTest
Bug: 174237107
Change-Id: I8694685f4d210b32fc7cc3eb8a7f3a79f385ee48
parent 5d0a87bc
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static com.android.internal.telephony.cdnr.EfData.EF_SOURCE_VOICE_OPERATO

import android.annotation.NonNull;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
@@ -340,8 +341,14 @@ public class CarrierDisplayNameResolver {
            CarrierDisplayNameData rawCarrierDisplayNameData) {
        PersistableBundle config = getCarrierConfig();
        boolean useRootLocale = config.getBoolean(CarrierConfigManager.KEY_WFC_SPN_USE_ROOT_LOCALE);
        Resources r = mContext.getResources();
        if (useRootLocale) r.getConfiguration().setLocale(Locale.ROOT);
        Context displayNameContext = mContext;
        if (useRootLocale) {
            Configuration displayNameConfig = mContext.getResources().getConfiguration();
            displayNameConfig.setLocale(Locale.ROOT);
            // Create a new Context for this temporary change
            displayNameContext = mContext.createConfigurationContext(displayNameConfig);
        }
        Resources r = displayNameContext.getResources();
        String[] wfcSpnFormats = r.getStringArray(com.android.internal.R.array.wfcSpnFormats);
        WfcCarrierNameFormatter wfcFormatter = new WfcCarrierNameFormatter(config, wfcSpnFormats,
                getServiceState().getState() == ServiceState.STATE_POWER_OFF);