Android: Remove context member from QtLoader
Both QtActivityLoader and QtServiceLoader already have separate members for their Activity and Service, respectively, and the QtEmbeddedLoader should become more like a singleton, so holding a reference to the Context, which anyway is only used when setting up the loading, is unnecessary. Task-number: QTBUG-124114 Change-Id: I412f4dbd45e48add9ea091eb589c7ef9a3942399 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit ae0db7a61de1f0f9b36810a94984c69f5d7e5d1e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>bb10
parent
6af4e5f604
commit
984b56d9c9
|
|
@ -8,6 +8,7 @@ import android.annotation.SuppressLint;
|
|||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
|
|
@ -31,7 +32,7 @@ class QtActivityLoader extends QtLoader {
|
|||
super(new ContextWrapper(activity));
|
||||
m_activity = activity;
|
||||
|
||||
extractContextMetaData();
|
||||
extractContextMetaData(m_activity);
|
||||
}
|
||||
|
||||
private void showErrorDialog() {
|
||||
|
|
@ -97,9 +98,9 @@ class QtActivityLoader extends QtLoader {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void extractContextMetaData()
|
||||
protected void extractContextMetaData(Context context)
|
||||
{
|
||||
super.extractContextMetaData();
|
||||
super.extractContextMetaData(context);
|
||||
|
||||
setEnvironmentVariable("QT_USE_ANDROID_NATIVE_DIALOGS", String.valueOf(1));
|
||||
setEnvironmentVariable("QT_ANDROID_APP_ICON_SIZE", String.valueOf(getAppIconSize()));
|
||||
|
|
|
|||
|
|
@ -37,17 +37,14 @@ class QtEmbeddedLoader extends QtLoader {
|
|||
QtEmbeddedLoader(Context context) {
|
||||
super(new ContextWrapper(context));
|
||||
// TODO Service context handling QTBUG-118874
|
||||
int displayDensity = m_context.getResources().getDisplayMetrics().densityDpi;
|
||||
int displayDensity = context.getResources().getDisplayMetrics().densityDpi;
|
||||
setEnvironmentVariable("QT_ANDROID_THEME_DISPLAY_DPI", String.valueOf(displayDensity));
|
||||
String stylePath = ExtractStyle.setup(m_context, "minimal", displayDensity);
|
||||
String stylePath = ExtractStyle.setup(context, "minimal", displayDensity);
|
||||
setEnvironmentVariable("ANDROID_STYLE_PATH", stylePath);
|
||||
setEnvironmentVariable("QT_ANDROID_NO_EXIT_CALL", String.valueOf(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finish() {
|
||||
// Called when loading fails - clear the delegate to make sure we don't hold reference
|
||||
// to the embedding Context
|
||||
QtEmbeddedViewInterfaceFactory.remove((Activity)m_context.getBaseContext());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ abstract class QtLoader {
|
|||
private String m_nativeLibrariesDir = null;
|
||||
private ClassLoader m_classLoader;
|
||||
|
||||
protected final ContextWrapper m_context;
|
||||
protected ComponentInfo m_contextInfo;
|
||||
|
||||
protected String m_mainLibPath;
|
||||
|
|
@ -55,13 +54,13 @@ abstract class QtLoader {
|
|||
* Also, we can already initialize the static classes contexts here.
|
||||
**/
|
||||
public QtLoader(ContextWrapper context) {
|
||||
m_context = context;
|
||||
m_resources = m_context.getResources();
|
||||
m_packageName = m_context.getPackageName();
|
||||
m_resources = context.getResources();
|
||||
m_packageName = context.getPackageName();
|
||||
final Context baseContext = context.getBaseContext();
|
||||
|
||||
initClassLoader();
|
||||
initStaticClasses();
|
||||
initContextInfo();
|
||||
initClassLoader(baseContext);
|
||||
initStaticClasses(baseContext);
|
||||
initContextInfo(baseContext);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -75,9 +74,8 @@ abstract class QtLoader {
|
|||
* the app metadata from the AndroidManifest.xml or other xml resources.
|
||||
* Some values are dependent on the context being an Activity or Service.
|
||||
**/
|
||||
protected void initContextInfo() {
|
||||
protected void initContextInfo(Context context) {
|
||||
try {
|
||||
Context context = m_context.getBaseContext();
|
||||
if (context instanceof Activity) {
|
||||
m_contextInfo = context.getPackageManager().getActivityInfo(
|
||||
((Activity)context).getComponentName(), PackageManager.GET_META_DATA);
|
||||
|
|
@ -100,13 +98,13 @@ abstract class QtLoader {
|
|||
* call context specific metadata extraction. This also sets the various environment
|
||||
* variables and application parameters.
|
||||
**/
|
||||
protected void extractContextMetaData() {
|
||||
protected void extractContextMetaData(Context context) {
|
||||
setEnvironmentVariable("QT_ANDROID_FONTS", "Roboto;Droid Sans;Droid Sans Fallback");
|
||||
String monospaceFonts = "Droid Sans Mono;Droid Sans;Droid Sans Fallback";
|
||||
setEnvironmentVariable("QT_ANDROID_FONTS_MONOSPACE", monospaceFonts);
|
||||
setEnvironmentVariable("QT_ANDROID_FONTS_SERIF", "Droid Serif");
|
||||
setEnvironmentVariable("HOME", m_context.getFilesDir().getAbsolutePath());
|
||||
setEnvironmentVariable("TMPDIR", m_context.getCacheDir().getAbsolutePath());
|
||||
setEnvironmentVariable("HOME", context.getFilesDir().getAbsolutePath());
|
||||
setEnvironmentVariable("TMPDIR", context.getCacheDir().getAbsolutePath());
|
||||
setEnvironmentVariable("QT_BLOCK_EVENT_LOOPS_WHEN_SUSPENDED", isBackgroundRunningBlocked());
|
||||
setEnvironmentVariable("QTRACE_LOCATION", getMetaData("android.app.trace_location"));
|
||||
appendApplicationParameters(getMetaData("android.app.arguments"));
|
||||
|
|
@ -146,8 +144,7 @@ abstract class QtLoader {
|
|||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
private void initStaticClasses() {
|
||||
Context context = m_context.getBaseContext();
|
||||
private void initStaticClasses(Context context) {
|
||||
boolean isActivity = context instanceof Activity;
|
||||
for (String className : getStaticInitClasses()) {
|
||||
try {
|
||||
|
|
@ -190,12 +187,12 @@ abstract class QtLoader {
|
|||
* Initialize the class loader instance and sets it via QtNative.
|
||||
* This would also be used by QJniObject API.
|
||||
**/
|
||||
private void initClassLoader()
|
||||
private void initClassLoader(Context context)
|
||||
{
|
||||
// directory where optimized DEX files should be written.
|
||||
String outDexPath = m_context.getDir("outdex", Context.MODE_PRIVATE).getAbsolutePath();
|
||||
String sourceDir = m_context.getApplicationInfo().sourceDir;
|
||||
m_classLoader = new DexClassLoader(sourceDir, outDexPath, null, m_context.getClassLoader());
|
||||
String outDexPath = context.getDir("outdex", Context.MODE_PRIVATE).getAbsolutePath();
|
||||
String sourceDir = context.getApplicationInfo().sourceDir;
|
||||
m_classLoader = new DexClassLoader(sourceDir, outDexPath, null, context.getClassLoader());
|
||||
QtNative.setClassLoader(m_classLoader);
|
||||
}
|
||||
|
||||
|
|
@ -284,8 +281,10 @@ abstract class QtLoader {
|
|||
* If none of the above are valid, it falls back to predefined system path.
|
||||
**/
|
||||
private void parseNativeLibrariesDir() {
|
||||
if (m_contextInfo == null)
|
||||
return;
|
||||
if (isBundleQtLibs()) {
|
||||
String nativeLibraryPrefix = m_context.getApplicationInfo().nativeLibraryDir + "/";
|
||||
String nativeLibraryPrefix = m_contextInfo.applicationInfo.nativeLibraryDir + "/";
|
||||
File nativeLibraryDir = new File(nativeLibraryPrefix);
|
||||
if (nativeLibraryDir.exists()) {
|
||||
String[] list = nativeLibraryDir.list();
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class QtServiceLoader extends QtLoader {
|
|||
super(new ContextWrapper(service));
|
||||
m_service = service;
|
||||
|
||||
extractContextMetaData();
|
||||
extractContextMetaData(m_service);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue