Zeevac opened a new issue #1149:
URL: https://github.com/apache/cordova-android/issues/1149


   # Bug Report
   
   ## Problem
   As you know, when orientation change on android platform, activity is killed 
and regenerated. Because of this, cordova platform is also regenerated. In this 
point, until cordova-android 9 version, all versions has executed the 
pluginInitialized method everytime when orientation changed but on 
cordova-android 9 it sometimes executes, sometimes not. When it is not called, 
log prints below lines.
   ```
   gap_init called from restricted origin:
   D/CordovaBridge: Ignoring exec() from previous page load.
    ```
   After I searched for a solution on platform source code, I noticed that 
below code section is removed on cordova-android 9. When I readded lines on 
information section below, it works perfectly. Finally my question is that what 
issue prevent cordova calling pluginInitialize method every time when 
orientation changed?
   
   I added some logs to CordovaBridge.java file. pluginInitialize method is not 
called because in below method jsMessageQueue.isBridgeEnabled() is returns 
false.
   ```
   private boolean verifySecret(String action, int bridgeSecret) throws 
IllegalAccessException {
           Log.d("TAG", action + "---" + jsMessageQueue.isBridgeEnabled());
           if (!jsMessageQueue.isBridgeEnabled()) { //This line returns false 
sometimes.
               if (bridgeSecret == -1) {
                   LOG.d(LOG_TAG, action + " call made before bridge was 
enabled.");
               } else {
                   LOG.d(LOG_TAG, "Ignoring " + action + " from previous page 
load.");
               }
               return false;
           }
           // Bridge secret wrong and bridge not due to it being from the 
previous page.
           if (expectedBridgeSecret < 0 || bridgeSecret != 
expectedBridgeSecret) {
               LOG.e(LOG_TAG, "Bridge access attempt with wrong secret token, 
possibly from malicious code. Disabling exec() bridge!");
               clearBridgeSecret();
               throw new IllegalAccessException();
           }
           return true;
       }
   ```
   When jsMessageQueue.isBridgeEnabled() returns false, no method on 
onDeviceReady event is called.
   These are all logs.
   ```
   I/CordovaActivity: Apache Cordova native platform version 9.0.0 is starting
   D/CordovaActivity: CordovaActivity.onCreate()
   D/SystemWebViewEngine: CordovaWebView is running on device made by: HUAWEI
   D/PluginManager: init()
   D/CordovaWebViewImpl: >>> loadUrl(file:///android_asset/www/index.html)
   D/ActivityThread: add activity client record, r= ActivityRecord{d6daa05 
token=android.os.BinderProxy@c3ccfde 
{com.example.hmsappmessaging/com.example.application.MainActivity}} token= 
android.os.BinderProxy@c3ccfde
   D/CordovaActivity: Started the activity.
   W/cr_AwContents: Application attempted to call on a destroyed WebView
       java.lang.Throwable
           at 
org.chromium.android_webview.AwContents.p(chromium-TrichromeWebViewGoogle.aab-stable-428014133:2)
           at 
vM.loadingStateChanged(chromium-TrichromeWebViewGoogle.aab-stable-428014133:2)
           at android.os.MessageQueue.nativePollOnce(Native Method)
           at android.os.MessageQueue.next(MessageQueue.java:363)
           at android.os.Looper.loop(Looper.java:173)
           at android.app.ActivityThread.main(ActivityThread.java:8178)
           at java.lang.reflect.Method.invoke(Native Method)
           at 
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
   D/HiTouch_PressGestureDetector: onAttached, 
package=com.example.hmsappmessaging, windowType=1, mHiTouchRestricted=false
   D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, 
EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
   D/Whitelist: java.lang.NullPointerException: Attempt to invoke interface 
method 'int java.lang.CharSequence.length()' on a null object reference
   D/Whitelist: java.lang.NullPointerException: Attempt to invoke interface 
method 'int java.lang.CharSequence.length()' on a null object reference
   E/CordovaBridge: gap_init called from restricted origin: 
   D/TAG: setBridgeMode() called with: value = [-1]
   D/CordovaWebViewImpl: onPageDidNavigate(file:///android_asset/www/index.html)
   D/CordovaWebViewImpl: onPageFinished(file:///android_asset/www/index.html)
   D/TAG: jsExec() called with: bridgeSecret = [0]
   D/TAG: exec()---false
   D/CordovaBridge: Ignoring exec() from previous page load.
   D/TAG: jsExec() called with: bridgeSecret = [0]
   D/TAG: exec()---false
   D/CordovaBridge: Ignoring exec() from previous page load.
   D/TAG: jsExec() called with: bridgeSecret = [0]
   D/TAG: exec()---false
   D/CordovaBridge: Ignoring exec() from previous page load.
   I/chromium: [INFO:CONSOLE(23)] "Running [email protected]", source: 
file:///android_asset/www/js/index.js (23)
   D/TAG: jsExec() called with: bridgeSecret = [0]
   D/TAG: exec()---false
   D/CordovaBridge: Ignoring exec() from previous page load.
   D/TAG: jsExec() called with: bridgeSecret = [0
   D/TAG: exec()---false
   D/CordovaBridge: Ignoring exec() from previous page load.
   D/TAG: jsExec() called with: bridgeSecret = [0]
   D/TAG: exec()---false
   D/CordovaBridge: Ignoring exec() from previous page load.
   D/TAG: jsExec() called with: bridgeSecret = [0]
   D/TAG: exec()---false
   D/CordovaBridge: Ignoring exec() from previous page load.
   D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, 
EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 
   ```
   ### What is expected to happen?
   When orientation is changed, pluginInitialize method on native must be 
called eveytime.
   
   
   ### What does actually happen?
   It is called sometimes, sometimes not.
   
   
   ## Information
   <!-- Include all relevant information that might help understand and 
reproduce the problem -->
   When I add below lines to the cordova.js file, everything works perfectly. 
These lines are removed from platform on cordova-android 9.0.0.
   ```
   
   var utils = require('cordova/utils');
   // Replace navigator before any modules are required(), to ensure it happens 
as soon as possible.
   // We replace it so that properties that can't be clobbered can instead be 
overridden.
   function replaceNavigator (origNavigator) {
       var CordovaNavigator = function () {};
       CordovaNavigator.prototype = origNavigator;
       var newNavigator = new CordovaNavigator();
       // This work-around really only applies to new APIs that are newer than 
Function.bind.
       // Without it, APIs such as getGamepads() break.
       if (CordovaNavigator.bind) {
           for (var key in origNavigator) {
               if (typeof origNavigator[key] === 'function') {
                   newNavigator[key] = origNavigator[key].bind(origNavigator);
               } else {
                   (function (k) {
                       utils.defineGetterSetter(newNavigator, key, function () {
                           return origNavigator[k];
                       });
                   })(key);
               }
           }
       }
       return newNavigator;
   }
   
   ```
   
   
   ### Command or Code
   <!-- What command or code is needed to reproduce the problem? -->
   Just change orientation.
   
   
   ### Environment, Platform, Device
   <!-- In what environment, on what platform or on which device are you 
experiencing the issue? -->
   Windows 10
   Cordova CLI 10.0.0
   Cordova Android 9.0.0
   Huawei P Smart Pro(probably all devices)
   
   ### Version information
   <!-- 
   What are relevant versions you are using?
   For example:
   Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins 
   Other Frameworks: Ionic Framework and CLI version
   Operating System, Android Studio, Xcode etc.
   -->
   ❯ cordova -v
   10.0.0
   ❯ cordova platform ls
   Installed platforms:
     android 9.0.0
   
   
   ## Checklist
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [X] I searched for existing GitHub issues
   - [X] I updated all Cordova tooling to most recent version
   - [X] I included all the necessary information above


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to