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);
|
||||
loader.appendApplicationParameters(m_applicationParams);
|
||||
|
||||
if (loader.loadQtLibraries()) {
|
||||
QtLoader.LoadingResult result = loader.loadQtLibraries();
|
||||
|
||||
if (result == QtLoader.LoadingResult.Succeeded) {
|
||||
m_delegate.startNativeApplication(loader.getApplicationParameters(),
|
||||
loader.getMainLibraryPath());
|
||||
} else {
|
||||
} else if (result == QtLoader.LoadingResult.Failed) {
|
||||
showErrorDialog();
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
@ -52,6 +52,8 @@ abstract class QtLoader {
|
||||
protected static QtLoader m_instance = null;
|
||||
protected boolean m_librariesLoaded;
|
||||
|
||||
enum LoadingResult { Succeeded, AlreadyLoaded, Failed }
|
||||
|
||||
/**
|
||||
* Sets and initialize the basic pieces.
|
||||
* 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)
|
||||
return true;
|
||||
return LoadingResult.AlreadyLoaded;
|
||||
|
||||
if (!useLocalQtLibs()) {
|
||||
Log.w(QtTAG, "Use local Qt libs is false");
|
||||
return false;
|
||||
return LoadingResult.Failed;
|
||||
}
|
||||
|
||||
if (m_nativeLibrariesDir == null)
|
||||
@ -430,7 +434,7 @@ abstract class QtLoader {
|
||||
|
||||
if (m_nativeLibrariesDir == null || m_nativeLibrariesDir.isEmpty()) {
|
||||
Log.e(QtTAG, "The native libraries directory is null or empty");
|
||||
return false;
|
||||
return LoadingResult.Failed;
|
||||
}
|
||||
|
||||
setEnvironmentVariable("QT_PLUGIN_PATH", m_nativeLibrariesDir);
|
||||
@ -461,14 +465,14 @@ abstract class QtLoader {
|
||||
|
||||
if (!loadLibraries(nativeLibraries)) {
|
||||
Log.e(QtTAG, "Loading Qt native libraries failed");
|
||||
return false;
|
||||
return LoadingResult.Failed;
|
||||
}
|
||||
|
||||
// add all bundled Qt libs to loader params
|
||||
ArrayList<String> bundledLibraries = new ArrayList<>(preferredAbiLibs(getBundledLibs()));
|
||||
if (!loadLibraries(bundledLibraries)) {
|
||||
Log.e(QtTAG, "Loading Qt bundled libraries failed");
|
||||
return false;
|
||||
return LoadingResult.Failed;
|
||||
}
|
||||
|
||||
if (m_mainLibName == null)
|
||||
@ -476,10 +480,10 @@ abstract class QtLoader {
|
||||
// Load main lib
|
||||
if (!loadMainLibrary(m_mainLibName + "_" + m_preferredAbi)) {
|
||||
Log.e(QtTAG, "Loading main library failed");
|
||||
return false;
|
||||
return LoadingResult.Failed;
|
||||
}
|
||||
m_librariesLoaded = true;
|
||||
return true;
|
||||
return LoadingResult.Succeeded;
|
||||
}
|
||||
|
||||
// Loading libraries using System.load() uses full lib paths
|
||||
|
@ -29,11 +29,12 @@ public class QtServiceBase extends Service {
|
||||
|
||||
try {
|
||||
QtServiceLoader loader = QtServiceLoader.getServiceLoader(this);
|
||||
if (loader.loadQtLibraries()) {
|
||||
QtLoader.LoadingResult result = loader.loadQtLibraries();
|
||||
if (result == QtLoader.LoadingResult.Succeeded) {
|
||||
QtNative.startApplication(loader.getApplicationParameters(),
|
||||
loader.getMainLibraryPath());
|
||||
QtNative.setApplicationState(QtNative.ApplicationState.ApplicationHidden);
|
||||
} else {
|
||||
} else if (result == QtLoader.LoadingResult.Failed) {
|
||||
Log.w(QtNative.QtTAG, "QtServiceLoader: failed to load Qt libraries");
|
||||
stopSelf();
|
||||
}
|
||||
|
@ -153,11 +153,12 @@ abstract class QtView extends ViewGroup {
|
||||
}
|
||||
|
||||
loader.setMainLibraryName(appLibName);
|
||||
if (loader.loadQtLibraries()) {
|
||||
QtLoader.LoadingResult result = loader.loadQtLibraries();
|
||||
if (result == QtLoader.LoadingResult.Succeeded) {
|
||||
// Start Native Qt application
|
||||
m_viewInterface.startQtApplication(loader.getApplicationParameters(),
|
||||
loader.getMainLibraryPath());
|
||||
} else {
|
||||
} else if (result == QtLoader.LoadingResult.Failed) {
|
||||
// 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
|
||||
QtEmbeddedViewInterfaceFactory.remove(getContext());
|
||||
|
Loading…
x
Reference in New Issue
Block a user