Class ShadowLocaleManager
LocaleManager
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
enforceInstallerCheck
(boolean value) Sets the value ofenforceInstallerCheck
.protected LocaleList
getApplicationLocales
(String packageName) Returns the stored locales from in-memory map for the given package whenLocaleManager.getApplicationLocales()
is invoked in source code via tests.protected LocaleList
protected void
setApplicationLocales
(String packageName, LocaleList locales) Stores the passed locales for the given package in-memory.protected void
setApplicationLocales
(String packageName, LocaleList locales, boolean fromDelegate) Stores the passed locales for the given package in-memory.void
setCallerAsInstallerForPackage
(String packageName) Sets the caller as the installer of the given package.
-
Constructor Details
-
ShadowLocaleManager
public ShadowLocaleManager()
-
-
Method Details
-
getApplicationLocales
Returns the stored locales from in-memory map for the given package whenLocaleManager.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 aSecurityException
.Adds the package name in a set to record that this method was invoked for given package.
- See Also:
-
enforceInstallerCheck
setCallerAsInstallerForPackage(java.lang.String)
-
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(android.os.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(android.os.LocaleList)
. -
getSystemLocales
-
enforceInstallerCheck
public void enforceInstallerCheck(boolean value) Sets the value ofenforceInstallerCheck
.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
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.
-