Android: Set up style also when using QtEmbeddedLoader

Embedded loader was missing style set up, leading to a crash
when platform theme style data was loaded. As a drive by, change
the style set up to use Context instead of Activity, since it doesn't
require Activity.

Fixes: QTBUG-119532
Change-Id: I434233e173cc2c90d981bbf2aa0044117a20b17f
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit bd5ae42cf86857fa08c2607eb8c9e434317374f6)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tinja Paavoseppä 2024-01-12 08:50:22 +02:00 committed by Qt Cherry-pick Bot
parent f57539d4f5
commit c86002f7ab
2 changed files with 8 additions and 4 deletions

View File

@ -149,9 +149,9 @@ class ExtractStyle {
return (config.uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
}
public static String setup(Activity activity, String extractOption, int dpi) {
public static String setup(Context context, String extractOption, int dpi) {
String dataDir = activity.getApplicationInfo().dataDir;
String dataDir = context.getApplicationInfo().dataDir;
m_stylePath = dataDir + "/qt-reserved-files/android-style/" + dpi + "/";
if (extractOption.isEmpty())
@ -168,7 +168,7 @@ class ExtractStyle {
// SDK version >= 28 when the target SDK version is set to something lower then 28,
// so default to "none" and issue a warning if that is the case.
if (extractOption.equals("default")) {
int targetSdk = activity.getApplicationInfo().targetSdkVersion;
int targetSdk = context.getApplicationInfo().targetSdkVersion;
if (targetSdk < 28 && Build.VERSION.SDK_INT >= 28) {
Log.e(QtTAG, "extract_android_style option set to \"none\" when " +
"targetSdkVersion is less then 28");
@ -181,7 +181,7 @@ class ExtractStyle {
m_missingNormalStyle = !(new File(m_stylePath + "style.json").exists());
m_extractMinimal = extractOption.equals("minimal");
ExtractStyle.runIfNeeded(activity, isUiModeDark(activity.getResources().getConfiguration()));
ExtractStyle.runIfNeeded(context, isUiModeDark(context.getResources().getConfiguration()));
return m_stylePath;
}

View File

@ -37,6 +37,10 @@ class QtEmbeddedLoader extends QtLoader {
public QtEmbeddedLoader(Context context) {
super(new ContextWrapper(context));
// TODO Service context handling QTBUG-118874
int displayDensity = m_context.getResources().getDisplayMetrics().densityDpi;
setEnvironmentVariable("QT_ANDROID_THEME_DISPLAY_DPI", String.valueOf(displayDensity));
String stylePath = ExtractStyle.setup(m_context, "minimal", displayDensity);
setEnvironmentVariable("ANDROID_STYLE_PATH", stylePath);
}
@Override