Android: Add an enum for QtLoader results
Returning an enum instead of a boolean lets us discern between differences such as libraries have been loaded successfully, or they have already been loaded successfully in a previous call. Later, we could add more values to discern between the different error cases, instead of relying on logging. Task-number: QTBUG-127422 Task-number: QTBUG-124114 Change-Id: I66bd95e66772db8b6f940b30a7b121b35ff4390a Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit 1afb82c41c54d6bbe3cd09cffc679fbfa86f75d3)
This commit is contained in:
parent
cf92f38bb1
commit
a228a3e7b6
@ -110,10 +110,12 @@ public class QtActivityBase extends Activity
|
|||||||
QtActivityLoader loader = QtActivityLoader.getActivityLoader(this);
|
QtActivityLoader loader = QtActivityLoader.getActivityLoader(this);
|
||||||
loader.appendApplicationParameters(m_applicationParams);
|
loader.appendApplicationParameters(m_applicationParams);
|
||||||
|
|
||||||
if (loader.loadQtLibraries()) {
|
QtLoader.LoadingResult result = loader.loadQtLibraries();
|
||||||
|
|
||||||
|
if (result == QtLoader.LoadingResult.Succeeded) {
|
||||||
m_delegate.startNativeApplication(loader.getApplicationParameters(),
|
m_delegate.startNativeApplication(loader.getApplicationParameters(),
|
||||||
loader.getMainLibraryPath());
|
loader.getMainLibraryPath());
|
||||||
} else {
|
} else if (result == QtLoader.LoadingResult.Failed) {
|
||||||
showErrorDialog();
|
showErrorDialog();
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
@ -52,6 +52,8 @@ abstract class QtLoader {
|
|||||||
protected static QtLoader m_instance = null;
|
protected static QtLoader m_instance = null;
|
||||||
protected boolean m_librariesLoaded;
|
protected boolean m_librariesLoaded;
|
||||||
|
|
||||||
|
enum LoadingResult { Succeeded, AlreadyLoaded, Failed }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets and initialize the basic pieces.
|
* Sets and initialize the basic pieces.
|
||||||
* Initializes the class loader since it doesn't rely on anything
|
* Initializes the class loader since it doesn't rely on anything
|
||||||
@ -414,15 +416,17 @@ abstract class QtLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all Qt native bundled libraries and main library.
|
* Returns QtLoader.LoadingResult.Succeeded if libraries are successfully loaded,
|
||||||
|
* QtLoader.LoadingResult.AlreadyLoaded if they have already been loaded,
|
||||||
|
* and QtLoader.LoadingResult.Failed if loading the libraries failed.
|
||||||
**/
|
**/
|
||||||
public boolean loadQtLibraries() {
|
public LoadingResult loadQtLibraries() {
|
||||||
if (m_librariesLoaded)
|
if (m_librariesLoaded)
|
||||||
return true;
|
return LoadingResult.AlreadyLoaded;
|
||||||
|
|
||||||
if (!useLocalQtLibs()) {
|
if (!useLocalQtLibs()) {
|
||||||
Log.w(QtTAG, "Use local Qt libs is false");
|
Log.w(QtTAG, "Use local Qt libs is false");
|
||||||
return false;
|
return LoadingResult.Failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_nativeLibrariesDir == null)
|
if (m_nativeLibrariesDir == null)
|
||||||
@ -430,7 +434,7 @@ abstract class QtLoader {
|
|||||||
|
|
||||||
if (m_nativeLibrariesDir == null || m_nativeLibrariesDir.isEmpty()) {
|
if (m_nativeLibrariesDir == null || m_nativeLibrariesDir.isEmpty()) {
|
||||||
Log.e(QtTAG, "The native libraries directory is null or empty");
|
Log.e(QtTAG, "The native libraries directory is null or empty");
|
||||||
return false;
|
return LoadingResult.Failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
setEnvironmentVariable("QT_PLUGIN_PATH", m_nativeLibrariesDir);
|
setEnvironmentVariable("QT_PLUGIN_PATH", m_nativeLibrariesDir);
|
||||||
@ -461,14 +465,14 @@ abstract class QtLoader {
|
|||||||
|
|
||||||
if (!loadLibraries(nativeLibraries)) {
|
if (!loadLibraries(nativeLibraries)) {
|
||||||
Log.e(QtTAG, "Loading Qt native libraries failed");
|
Log.e(QtTAG, "Loading Qt native libraries failed");
|
||||||
return false;
|
return LoadingResult.Failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add all bundled Qt libs to loader params
|
// add all bundled Qt libs to loader params
|
||||||
ArrayList<String> bundledLibraries = new ArrayList<>(preferredAbiLibs(getBundledLibs()));
|
ArrayList<String> bundledLibraries = new ArrayList<>(preferredAbiLibs(getBundledLibs()));
|
||||||
if (!loadLibraries(bundledLibraries)) {
|
if (!loadLibraries(bundledLibraries)) {
|
||||||
Log.e(QtTAG, "Loading Qt bundled libraries failed");
|
Log.e(QtTAG, "Loading Qt bundled libraries failed");
|
||||||
return false;
|
return LoadingResult.Failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_mainLibName == null)
|
if (m_mainLibName == null)
|
||||||
@ -476,10 +480,10 @@ abstract class QtLoader {
|
|||||||
// Load main lib
|
// Load main lib
|
||||||
if (!loadMainLibrary(m_mainLibName + "_" + m_preferredAbi)) {
|
if (!loadMainLibrary(m_mainLibName + "_" + m_preferredAbi)) {
|
||||||
Log.e(QtTAG, "Loading main library failed");
|
Log.e(QtTAG, "Loading main library failed");
|
||||||
return false;
|
return LoadingResult.Failed;
|
||||||
}
|
}
|
||||||
m_librariesLoaded = true;
|
m_librariesLoaded = true;
|
||||||
return true;
|
return LoadingResult.Succeeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loading libraries using System.load() uses full lib paths
|
// Loading libraries using System.load() uses full lib paths
|
||||||
|
@ -29,11 +29,12 @@ public class QtServiceBase extends Service {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
QtServiceLoader loader = QtServiceLoader.getServiceLoader(this);
|
QtServiceLoader loader = QtServiceLoader.getServiceLoader(this);
|
||||||
if (loader.loadQtLibraries()) {
|
QtLoader.LoadingResult result = loader.loadQtLibraries();
|
||||||
|
if (result == QtLoader.LoadingResult.Succeeded) {
|
||||||
QtNative.startApplication(loader.getApplicationParameters(),
|
QtNative.startApplication(loader.getApplicationParameters(),
|
||||||
loader.getMainLibraryPath());
|
loader.getMainLibraryPath());
|
||||||
QtNative.setApplicationState(QtNative.ApplicationState.ApplicationHidden);
|
QtNative.setApplicationState(QtNative.ApplicationState.ApplicationHidden);
|
||||||
} else {
|
} else if (result == QtLoader.LoadingResult.Failed) {
|
||||||
Log.w(QtNative.QtTAG, "QtServiceLoader: failed to load Qt libraries");
|
Log.w(QtNative.QtTAG, "QtServiceLoader: failed to load Qt libraries");
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}
|
}
|
||||||
|
@ -153,11 +153,12 @@ abstract class QtView extends ViewGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loader.setMainLibraryName(appLibName);
|
loader.setMainLibraryName(appLibName);
|
||||||
if (loader.loadQtLibraries()) {
|
QtLoader.LoadingResult result = loader.loadQtLibraries();
|
||||||
|
if (result == QtLoader.LoadingResult.Succeeded) {
|
||||||
// Start Native Qt application
|
// Start Native Qt application
|
||||||
m_viewInterface.startQtApplication(loader.getApplicationParameters(),
|
m_viewInterface.startQtApplication(loader.getApplicationParameters(),
|
||||||
loader.getMainLibraryPath());
|
loader.getMainLibraryPath());
|
||||||
} else {
|
} else if (result == QtLoader.LoadingResult.Failed) {
|
||||||
// If we weren't able to load the libraries, remove the delegate from the factory
|
// If we weren't able to load the libraries, remove the delegate from the factory
|
||||||
// as it's holding a reference to the Context, and we don't want it leaked
|
// as it's holding a reference to the Context, and we don't want it leaked
|
||||||
QtEmbeddedViewInterfaceFactory.remove(getContext());
|
QtEmbeddedViewInterfaceFactory.remove(getContext());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user