Bug 1546267 - Detect system locale/timezone change. r=geckoview-reviewers,owlish

We should notify system locale and timezone of changes to Gecko.

Differential Revision: https://phabricator.services.mozilla.com/D218514
This commit is contained in:
Makoto Kato 2024-08-27 08:40:58 +00:00
Родитель c7184830cf
Коммит 8d8645b6a8
3 изменённых файлов: 56 добавлений и 0 удалений

Просмотреть файл

@ -1604,4 +1604,10 @@ public class GeckoAppShell {
// this on any SDK level but must suppress the new API lint.
return android.os.Process.isIsolated();
}
@WrapForJNI(dispatchTo = "gecko")
public static native void onSystemLocaleChanged();
@WrapForJNI(dispatchTo = "gecko")
public static native void onTimezoneChanged();
}

Просмотреть файл

@ -5,8 +5,11 @@
package org.mozilla.gecko;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.database.ContentObserver;
import android.hardware.input.InputManager;
@ -30,6 +33,8 @@ public class GeckoSystemStateListener implements InputManager.InputDeviceListene
private static Context sApplicationContext;
private InputManager mInputManager;
private boolean mIsNightMode;
private BroadcastReceiver mBroadcastReceiver;
private IntentFilter mIntentFilter;
public static GeckoSystemStateListener getInstance() {
return listenerInstance;
@ -66,6 +71,28 @@ public class GeckoSystemStateListener implements InputManager.InputDeviceListene
/*Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED*/ "high_text_contrast_enabled");
contentResolver.registerContentObserver(textContrastSetting, false, mContentObserver);
mBroadcastReceiver =
new BroadcastReceiver() {
@Override
public void onReceive(final Context context, final Intent intent) {
if (!GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
return;
}
if (intent.getAction().equals(Intent.ACTION_LOCALE_CHANGED)) {
GeckoAppShell.onSystemLocaleChanged();
return;
}
if (intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED)) {
GeckoAppShell.onTimezoneChanged();
return;
}
}
};
final IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_LOCALE_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
context.registerReceiver(mBroadcastReceiver, filter);
mIsNightMode =
(sApplicationContext.getResources().getConfiguration().uiMode
& Configuration.UI_MODE_NIGHT_MASK)
@ -90,9 +117,12 @@ public class GeckoSystemStateListener implements InputManager.InputDeviceListene
final ContentResolver contentResolver = sApplicationContext.getContentResolver();
contentResolver.unregisterContentObserver(mContentObserver);
GeckoAppShell.getApplicationContext().unregisterReceiver(mBroadcastReceiver);
mInitialized = false;
mInputManager = null;
mContentObserver = null;
mBroadcastReceiver = null;
}
@WrapForJNI(calledFrom = "gecko")

Просмотреть файл

@ -336,6 +336,26 @@ class GeckoAppShellSupport final
static bool IsGpuProcessEnabled() {
return gfx::gfxVars::GPUProcessEnabled();
}
static void OnSystemLocaleChanged() {
MOZ_ASSERT(NS_IsMainThread());
if (PastShutdownPhase(ShutdownPhase::XPCOMShutdown)) {
return;
}
intl::OSPreferences::GetInstance()->Refresh();
}
static void OnTimezoneChanged() {
MOZ_ASSERT(NS_IsMainThread());
if (PastShutdownPhase(ShutdownPhase::XPCOMShutdown)) {
return;
}
nsBaseAppShell::OnSystemTimezoneChange();
}
};
class XPCOMEventTargetWrapper final