use of android.os.LocaleList in project platform_frameworks_base by android.
the class LocaleUtilsTest method testFilterByLanguageEmptyLanguageList.
@SmallTest
public void testFilterByLanguageEmptyLanguageList() throws Exception {
final ArrayList<Locale> availableLocales = new ArrayList<>();
availableLocales.add(Locale.forLanguageTag("en-US"));
availableLocales.add(Locale.forLanguageTag("fr-CA"));
availableLocales.add(Locale.forLanguageTag("in"));
availableLocales.add(Locale.forLanguageTag("ja"));
availableLocales.add(Locale.forLanguageTag("fil"));
final LocaleList preferredLocales = LocaleList.getEmptyLocaleList();
final ArrayList<Locale> dest = new ArrayList<>();
LocaleUtils.filterByLanguage(availableLocales, sIdentityMapper, preferredLocales, dest);
assertEquals(0, dest.size());
}
use of android.os.LocaleList in project platform_frameworks_base by android.
the class ActivityManagerService method updateConfigurationLocked.
/**
* Do either or both things: (1) change the current configuration, and (2)
* make sure the given activity is running with the (now) current
* configuration. Returns true if the activity has been left running, or
* false if <var>starting</var> is being destroyed to match the new
* configuration.
*
* @param userId is only used when persistent parameter is set to true to persist configuration
* for that particular user
*/
private boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, boolean initLocale, boolean persistent, int userId, boolean deferResume) {
int changes = 0;
if (mWindowManager != null) {
mWindowManager.deferSurfaceLayout();
}
if (values != null) {
Configuration newConfig = new Configuration(mConfiguration);
changes = newConfig.updateFrom(values);
if (changes != 0) {
if (DEBUG_SWITCH || DEBUG_CONFIGURATION)
Slog.i(TAG_CONFIGURATION, "Updating configuration to: " + values);
EventLog.writeEvent(EventLogTags.CONFIGURATION_CHANGED, changes);
if (!initLocale && !values.getLocales().isEmpty() && values.userSetLocale) {
final LocaleList locales = values.getLocales();
int bestLocaleIndex = 0;
if (locales.size() > 1) {
if (mSupportedSystemLocales == null) {
mSupportedSystemLocales = Resources.getSystem().getAssets().getLocales();
}
bestLocaleIndex = Math.max(0, locales.getFirstMatchIndex(mSupportedSystemLocales));
}
SystemProperties.set("persist.sys.locale", locales.get(bestLocaleIndex).toLanguageTag());
LocaleList.setDefault(locales, bestLocaleIndex);
mHandler.sendMessage(mHandler.obtainMessage(SEND_LOCALE_TO_MOUNT_DAEMON_MSG, locales.get(bestLocaleIndex)));
}
mConfigurationSeq++;
if (mConfigurationSeq <= 0) {
mConfigurationSeq = 1;
}
newConfig.seq = mConfigurationSeq;
mConfiguration = newConfig;
Slog.i(TAG, "Config changes=" + Integer.toHexString(changes) + " " + newConfig);
mUsageStatsService.reportConfigurationChange(newConfig, mUserController.getCurrentUserIdLocked());
//mUsageStatsService.noteStartConfig(newConfig);
final Configuration configCopy = new Configuration(mConfiguration);
// TODO: If our config changes, should we auto dismiss any currently
// showing dialogs?
mShowDialogs = shouldShowDialogs(newConfig, mInVrMode);
AttributeCache ac = AttributeCache.instance();
if (ac != null) {
ac.updateConfiguration(configCopy);
}
// Make sure all resources in our process are updated
// right now, so that anyone who is going to retrieve
// resource values after we return will be sure to get
// the new ones. This is especially important during
// boot, where the first config change needs to guarantee
// all resources have that config before following boot
// code is executed.
mSystemThread.applyConfigurationToResources(configCopy);
if (persistent && Settings.System.hasInterestingConfigurationChanges(changes)) {
Message msg = mHandler.obtainMessage(UPDATE_CONFIGURATION_MSG);
msg.obj = new Configuration(configCopy);
msg.arg1 = userId;
mHandler.sendMessage(msg);
}
final boolean isDensityChange = (changes & ActivityInfo.CONFIG_DENSITY) != 0;
if (isDensityChange) {
// Reset the unsupported display size dialog.
mUiHandler.sendEmptyMessage(SHOW_UNSUPPORTED_DISPLAY_SIZE_DIALOG_MSG);
killAllBackgroundProcessesExcept(Build.VERSION_CODES.N, ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE);
}
for (int i = mLruProcesses.size() - 1; i >= 0; i--) {
ProcessRecord app = mLruProcesses.get(i);
try {
if (app.thread != null) {
if (DEBUG_CONFIGURATION)
Slog.v(TAG_CONFIGURATION, "Sending to proc " + app.processName + " new config " + mConfiguration);
app.thread.scheduleConfigurationChanged(configCopy);
}
} catch (Exception e) {
}
}
Intent intent = new Intent(Intent.ACTION_CONFIGURATION_CHANGED);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_REPLACE_PENDING | Intent.FLAG_RECEIVER_FOREGROUND);
broadcastIntentLocked(null, null, intent, null, null, 0, null, null, null, AppOpsManager.OP_NONE, null, false, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
if ((changes & ActivityInfo.CONFIG_LOCALE) != 0) {
intent = new Intent(Intent.ACTION_LOCALE_CHANGED);
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
if (initLocale || !mProcessesReady) {
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
}
broadcastIntentLocked(null, null, intent, null, null, 0, null, null, null, AppOpsManager.OP_NONE, null, false, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
}
}
// ensureActivityConfigurationLocked().
if (mWindowManager != null) {
final int[] resizedStacks = mWindowManager.setNewConfiguration(mConfiguration);
if (resizedStacks != null) {
for (int stackId : resizedStacks) {
final Rect newBounds = mWindowManager.getBoundsForNewConfiguration(stackId);
mStackSupervisor.resizeStackLocked(stackId, newBounds, null, null, false, false, deferResume);
}
}
}
}
boolean kept = true;
final ActivityStack mainStack = mStackSupervisor.getFocusedStack();
// mainStack is null during startup.
if (mainStack != null) {
if (changes != 0 && starting == null) {
// If the configuration changed, and the caller is not already
// in the process of starting an activity, then find the top
// activity to check if its configuration needs to change.
starting = mainStack.topRunningActivityLocked();
}
if (starting != null) {
kept = mainStack.ensureActivityConfigurationLocked(starting, changes, false);
// And we need to make sure at this point that all other activities
// are made visible with the correct configuration.
mStackSupervisor.ensureActivitiesVisibleLocked(starting, changes, !PRESERVE_WINDOWS);
}
}
if (mWindowManager != null) {
mWindowManager.continueSurfaceLayout();
}
return kept;
}
use of android.os.LocaleList in project platform_frameworks_base by android.
the class ResourcesLocaleTest method testEnglishIsAlwaysConsideredSupported.
@SmallTest
public void testEnglishIsAlwaysConsideredSupported() throws Exception {
final Resources resources = createResourcesWithApk(R.raw.locales);
ensureNoLanguage(resources, "en");
final LocaleList preferredLocales = LocaleList.forLanguageTags("en-US,pl-PL");
final Configuration config = new Configuration();
config.setLocales(preferredLocales);
resources.updateConfiguration(config, null);
// The APK we loaded has default and Polish languages. If English is first in the list,
// always take it the default (assumed to be English).
assertEquals(Locale.forLanguageTag("en-US"), resources.getConfiguration().getLocales().get(0));
}
use of android.os.LocaleList in project platform_frameworks_base by android.
the class InputMethodManagerService method resetAllInternalStateLocked.
private void resetAllInternalStateLocked(final boolean updateOnlyWhenLocaleChanged, final boolean resetDefaultEnabledIme) {
if (!mSystemReady) {
// not system ready
return;
}
final LocaleList newLocales = mRes.getConfiguration().getLocales();
if (!updateOnlyWhenLocaleChanged || (newLocales != null && !newLocales.equals(mLastSystemLocales))) {
if (!updateOnlyWhenLocaleChanged) {
hideCurrentInputLocked(0, null);
resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_RESET_IME);
}
if (DEBUG) {
Slog.i(TAG, "LocaleList has been changed to " + newLocales);
}
buildInputMethodListLocked(resetDefaultEnabledIme);
if (!updateOnlyWhenLocaleChanged) {
final String selectedImiId = mSettings.getSelectedInputMethod();
if (TextUtils.isEmpty(selectedImiId)) {
// This is the first time of the user switch and
// set the current ime to the proper one.
resetDefaultImeLocked(mContext);
}
} else {
// If the locale is changed, needs to reset the default ime
resetDefaultImeLocked(mContext);
}
updateFromSettingsLocked(true);
mLastSystemLocales = newLocales;
if (!updateOnlyWhenLocaleChanged) {
try {
startInputInnerLocked();
} catch (RuntimeException e) {
Slog.w(TAG, "Unexpected exception", e);
}
}
}
}
use of android.os.LocaleList in project platform_frameworks_base by android.
the class Configuration method readFromParcel.
public void readFromParcel(Parcel source) {
fontScale = source.readFloat();
mcc = source.readInt();
mnc = source.readInt();
final int localeListSize = source.readInt();
final Locale[] localeArray = new Locale[localeListSize];
for (int i = 0; i < localeListSize; ++i) {
localeArray[i] = Locale.forLanguageTag(source.readString());
}
mLocaleList = new LocaleList(localeArray);
locale = mLocaleList.get(0);
userSetLocale = (source.readInt() == 1);
touchscreen = source.readInt();
keyboard = source.readInt();
keyboardHidden = source.readInt();
hardKeyboardHidden = source.readInt();
navigation = source.readInt();
navigationHidden = source.readInt();
orientation = source.readInt();
screenLayout = source.readInt();
uiMode = source.readInt();
screenWidthDp = source.readInt();
screenHeightDp = source.readInt();
smallestScreenWidthDp = source.readInt();
densityDpi = source.readInt();
compatScreenWidthDp = source.readInt();
compatScreenHeightDp = source.readInt();
compatSmallestScreenWidthDp = source.readInt();
seq = source.readInt();
}
Aggregations