Class ShadowLocaleManager

java.lang.Object
org.robolectric.shadows.ShadowLocaleManager

@Implements(value=android.app.LocaleManager.class, minSdk=33, isInAndroidSdk=false) public class ShadowLocaleManager extends Object
Shadow of LocaleManager
  • Constructor Details

    • ShadowLocaleManager

      public ShadowLocaleManager()
  • Method Details

    • reset

      @Resetter public static void reset()
    • getApplicationLocales

      @RequiresApi(api=24) @Implementation protected LocaleList getApplicationLocales(String packageName)
      Returns the stored locales from in-memory map for the given package when LocaleManager.getApplicationLocales() is invoked in source code via tests.

      If enforceInstallerCheck is set as true, this method will return locales only if the package is installed by caller. Else it will throw a SecurityException.

      Adds the package name in a set to record that this method was invoked for given package.

      See Also:
    • setApplicationLocales

      @Implementation(maxSdk=33) protected void setApplicationLocales(String packageName, LocaleList locales)
      Stores the passed locales for the given package in-memory.

      Starting in Android U, this method just invokes the 3-arg version (below).

      Use this method in tests to substitute call for LocaleManager.setApplicationLocales(LocaleList).

    • setApplicationLocales

      @Implementation(minSdk=34) protected void setApplicationLocales(String packageName, LocaleList locales, boolean fromDelegate)
      Stores the passed locales for the given package in-memory.

      Use this method in tests to substitute call for LocaleManager.setApplicationLocales(LocaleList).

    • getSystemLocales

      @RequiresApi(api=24) @Implementation protected LocaleList getSystemLocales()
    • enforceInstallerCheck

      public void enforceInstallerCheck(boolean value)
      Sets the value of enforceInstallerCheck.

      Set this to true if the intention to invoke getApplicationLocales(java.lang.String) is as an installer of the app.

      In order to mark apps as installed by the caller(installer), use setCallerAsInstallerForPackage(java.lang.String).

    • setCallerAsInstallerForPackage

      public void setCallerAsInstallerForPackage(String packageName)
      Sets the caller as the installer of the given package.

      We are explicitly not storing the package name of the installer. It's implied that the test app is the installer if using this method.