Skip to content

Commit

Permalink
Android: Set up style also when using QtEmbeddedLoader
Browse files Browse the repository at this point in the history
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
Pick-to: 6.7
Change-Id: I434233e173cc2c90d981bbf2aa0044117a20b17f
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
  • Loading branch information
Tinja Paavoseppä committed Jan 31, 2024
1 parent 4488dad commit bd5ae42
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ private static boolean isUiModeDark(Configuration config)
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())
Expand All @@ -168,7 +168,7 @@ public static String setup(Activity activity, String extractOption, int dpi) {
// 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");
Expand All @@ -181,7 +181,7 @@ public static String setup(Activity activity, String extractOption, int dpi) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bd5ae42

Please sign in to comment.