Search code examples
javascriptandroidasynchronouscordovasamsung-mobile

Async + ClickBusting + Cordova + Android Galaxy S4 = unexpected exit


This very small Cordova+AngularJS app exits (in a "oh, hey, I crashed, I'm outta here!" kind of way) when run on a Galaxy S4 running Android 4.2.2. It runs fine on every other device I've tested it on. For example, there is no problem on a Galaxy Note II running Android 4.1.2.

The www directory stuff also works fine in browsers, including browsers on the S4/Android 4.2.2 device.

So the bug only seems to happen when this code is:

  • Run as a Cordova app
  • On a Galaxy S4 running Android 4.2.2

Steps to duplicate behavior

  1. Clone the repo
  2. Create the Android executable using Cordova. With cordova command line tool and Android SDK installed:
    • cordova platform add android
    • cordova build
  3. Take the resulting APK and install it on a Galaxy S4 running Android 4.2.2. If you don't own one, you can test with one for free at http://developer.samsung.com/remotetestlab.
  4. Launch the app.
  5. Touch the text on the app's main screen.
  6. Wait a few seconds and the app will exit.

On everything else I've tested, it loads the color list content, which is the expected behavior.

So all that said, my question is: How do I fix this so it doesn't crash? Or how do I go about debugging this?

Relevant code

These files are all in the repo, but if you don't want to click, here you go:

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Galaxy S4 + Android 4.2.2 + Cordova Crash</title>

    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
</head>
<body>
    <div id="ng-app" data-ng-app="main">

        <!-- Begin Templates -->
        <script type="text/ng-template" id="main">
            <a ng-click="showList()">On Galaxy S4, touch here, wait a few seconds, and the app will crash.</a>
        </script>

        <script type="text/ng-template" id="list">
        <progress data-ng-show="loading"></progress>
        <ol data-ng-hide="loading">
            <li data-ng-repeat="color in colors">
                {{color.name}}
            </li>
        </ol>
        </script>
        <!-- End Templates -->

        <div data-ng-view=""></div>
    </div>
    <script src="js/angular.js"></script>
    <script src="js/angular-mobile.js"></script>
    <script src="js/modules/main.js"></script>
    <script src="js/modules/list.js"></script>
</body>
</html>

main.js

(function () {
    'use strict';
    angular.module('main', ['ngMobile','list'])
    .config(['$routeProvider', function ($routeProvider) {
        $routeProvider
        .when('/', {templateUrl: 'main', controller: 'mainController'})
        .otherwise({redirectTo: '/'});
    }]).
    controller('mainController', ['$scope', '$location', function ($scope, $location) {
        $scope.showList = function () {
            $location.path('/list');
        };
    }]);
}());

list.js

(function () {
    'use strict';
    angular.module('list', [])
    .config(['$routeProvider', function ($routeProvider) {
        $routeProvider
        .when('/list', {templateUrl: 'list', controller: 'listController'});
    }])
    .controller(
        'listController',
        ['$scope', '$timeout', function ($scope, $timeout) {
            $scope.loading = true;

            var callback = function () {
                $scope.loading = false;
                $scope.colors = [
                    {name: 'Almost Blue'},
                    {name: 'Kind Of Blue'},
                    {name: 'Totally Not Blue'}
                ];
            };

            // Using $timeout to sort of fake an XHR just to rule out XHR as a cause
            $timeout(callback, 500);
        }]
    );
}());

Logs

This shows up in the Android logs, at least when using http://developer.samsung.com/remotetestlab:

ERROR|10-19 03:39:49.448|6938|6938||CallbackProxy|UPDATE_URL
ASSERT|10-19 03:39:49.493|6938|6953||libc|Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 6953 (WebViewCoreThre)

Additional Notes

I tried it with Cordova 3.1.0. I also tried it with cordova-3.2.0-dev.jar compiled from the cordova-android repo at commit 28c41294bba746c75beae0ab26a42c8412cc665a (most recent commit to master as of October 20, 2013, which is today). No change in behavior--the app still exits unexpectedly.


Solution

  • This is a bug in Samsung's version of Android 4.2.2 Webview on the S4. When the S4 gets an update to Android 4.3, the problem goes away. There are probable workarounds (UA sniffing comes to mind, but that makes me sad--but you could omit the clickbusting for the S4/4.2.2). But the solution is really in Samsung's hands.

    For details, see the relevant issue in the Cordova Android JIRA.