Cordova / Phonegap:不受信任的证书在navigator.app.exitApp()上崩溃

时间:2015-04-02 18:57:42

标签: android cordova cordova-plugins cordova-3

我已经为hypery2k的不受信任的证书插件提交了一个补丁,允许它在最新版本的Cordova中运行,但我遇到了另一个我似乎无法弄清楚的问题。作为参考,此处正在跟踪此问题:https://github.com/hypery2k/cordova-certificate-plugin/issues/3

症状:

这是有效的,大约10秒后应用程序干净地退出(这只是为了演示):

onDeviceReady: function() {
    init();
    setTimeout(function() { navigator.app.exitApp(); }, 10000);
},

然而,这会崩溃并弹出Android中的“意外退出”消息:

onDeviceReady: function() {
    init();
    cordova.plugins.certificates.trustUnsecureCerts(true);
    setTimeout(function() { navigator.app.exitApp(); }, 10000);
},

在logcat中使用它:

D/CordovaActivity( 2561): onMessage(exit,null)
D/CordovaActivity( 2561): Paused the application!
W/PluginManager( 2561): THREAD WARNING: exec() call to App.exitApp blocked the main thread for 90ms. Plugin should use CordovaInterface.getThreadPool().
D/CordovaActivity( 2561): CordovaActivity.onDestroy()
D/CordovaWebView( 2561): >>> loadUrlNow()
D/CordovaWebViewClient( 2561): onPageFinished(about:blank)
D/AndroidRuntime( 2561): Shutting down VM
W/dalvikvm( 2561): threadid=1: thread exiting with uncaught exception (group=0xb0d58b20)
E/AndroidRuntime( 2561): FATAL EXCEPTION: main
E/AndroidRuntime( 2561): Process: com.mycomp.myapp, PID: 2561
E/AndroidRuntime( 2561): java.lang.NullPointerException
E/AndroidRuntime( 2561):        at org.apache.cordova.CordovaWebViewClient.onPageFinished(CordovaWebViewClient.java:215)
E/AndroidRuntime( 2561):        at com.android.webview.chromium.WebViewContentsClientAdapter.onPageFinished(WebViewContentsClientAdapter.java:449)
E/AndroidRuntime( 2561):        at com.android.org.chromium.android_webview.AwContentsClient$AwWebContentsObserver$1.run(AwContentsClient.java:73)
E/AndroidRuntime( 2561):        at android.os.Handler.handleCallback(Handler.java:733)
E/AndroidRuntime( 2561):        at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime( 2561):        at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 2561):        at android.app.ActivityThread.main(ActivityThread.java:5017)
E/AndroidRuntime( 2561):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2561):        at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 2561):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime( 2561):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/AndroidRuntime( 2561):        at dalvik.system.NativeStart.main(Native Method)
I/Process ( 2561): Sending signal. PID: 2561 SIG: 9
I/ActivityManager( 1276): Process com.mycomp.myapp (pid 2561) has died.

其他一切正常,当您尝试实现退出应用程序的代码时,它会崩溃,例如按下后退按钮。

当调用上面的trustUnsecureCerts函数时,这是从插件运行的主要代码块:

@Override
public boolean execute(String action, JSONArray args,
        CallbackContext callbackContext) throws JSONException {

    if (action.equals("setUntrusted")) {
            allowUntrusted = args.getBoolean(0);
            Log.d(LOG_TAG, "Setting allowUntrusted to " + allowUntrusted);
            cordova.getActivity().runOnUiThread(new Runnable() {
                    public void run() {
                            CertificatesCordovaWebViewClient cWebClient = new CertificatesCordovaWebViewClient(cordova);
                            cWebClient.setAllowUntrusted(allowUntrusted);
                            webView.setWebViewClient(cWebClient);
                            CordovaActivity ca = (CordovaActivity) cordova.getActivity();
                            ca.clearCache();
                    }
            });
            callbackContext.success();
            return true;
    }
    callbackContext.error("Invalid Command");
    return false;
}

如果查看整个类定义有帮助,可以在此处找到两个完整的源文件:https://github.com/hypery2k/cordova-certificate-plugin/tree/master/src/android/de/martinreinhardt/cordova/plugins

有什么想法吗?感谢。

0 个答案:

没有答案