问题
I have a issue when using release build android app calling an api to an invalid ssl certificate server.
From what i know. in release build, if the api server's ssl certificate is invalid, Cordova will call below method.
org.apache.cordova.engine.SystemWebViewClient.onReceivedSslError()
/**
* Notify the host application that an SSL error occurred while loading a resource.
* The host application must call either handler.cancel() or handler.proceed().
* Note that the decision may be retained for use in response to future SSL errors.
* The default behavior is to cancel the load.
*
* @param view The WebView that is initiating the callback.
* @param handler An SslErrorHandler object that will handle the user's response.
* @param error The SSL error object.
*/
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
final String packageName = parentEngine.cordova.getActivity().getPackageName();
final PackageManager pm = parentEngine.cordova.getActivity().getPackageManager();
ApplicationInfo appInfo;
try {
appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
// debug = true
handler.proceed();
return;
} else {
// debug = false
super.onReceivedSslError(view, handler, error);
}
} catch (NameNotFoundException e) {
// When it doubt, lock it out!
super.onReceivedSslError(view, handler, error);
}
}
and then below method will be called.
super.onReceivedSslError(view, handler, error);
which isandroid.webkit.SslErrorHandler.cancel()
/**
* Cancel this request and all pending requests for the WebView that had
* the error.
*/
public void cancel() {
sendMessage(obtainMessage(HANDLE_RESPONSE, 0, 0));
}
My problem is my app is waiting for the response forever and never get any response. Only if i setup a timeout in my frontend, or it will be waiting response forever...
What will be the response when above SslErrorHandler.cancel()
is called?
Do i need to override this default behavior in my app to create a plugin or something?
Or is there something wrong with my app?
Does anyone have a familiar issue. Thanks in advance.
Updated on 2019/12/11
After several research and investigation. I figured this out.
Since the request is cancelled, there will be no response, so front end app (angular) will not get any response until timeout.
So i created a custom plugin to handle the ssl error.
来源:https://stackoverflow.com/questions/59208176/cordova-ionic-android-app-cant-receive-response-when-default-cordova-onreceived