var exec = require('cordova/exec');
var eventEmitter = cordova.require('com.feedhenry.eventemitter.EventEmitter');

var obj = function() {

  var self = this;

  var _logPrefix = '[PasLock] ';
  var _isPlatformSupported = -1;
  var _isTracking = false;
  var _trackInterval = 500;
  var _trackerHandle;
  var _lastKnownState = -1;

  self.status = {
    disabled: 0,
    enabled: 1,
    unknown: -1
  };

  var _disablePlatformSupportCheck = false;

  self.setDisablePlatformCheck = function(value) {
    _disablePlatformSupportCheck = value;
  }

  var _getStatus = function(success, error, options, immediate) {

    if(_isTracking && !immediate) {
      success(_lastKnownState);
      return;
    }

    options = options || [];

    return exec( function(result) {
      success(result);
    }, function(result) {
      error(result);
    } , 'passlock', 'status', options );

  };

  self.isPlatformSupported = function() {
    if(_isPlatformSupported == -1) {
      _isPlatformSupported = _getIsPlatformSupported();
    }
    return _isPlatformSupported;
  }

  self.getStatus = function(success, error, options) {

    if(!self.disablePlatformSupportCheck && !_isPlatformSupported) {
      console.log(_logPrefix + 'this platform is not supported');
      return false;
    } else {
      return _getStatus(success, error, options, false);
    }

  }

  var _getIsPlatformSupported = function(success, error, options) {
    
    exec( function(result) {
      success( (result == 1) );
    }, function(result) {
      error(result);
    } , 'passlock', 'isPlatformSupported', options );

  }

  self.start = function() {

    if(_isTracking) {
      console.log(_logPrefix + 'already watching for changes');
      return;
    }

    _isTracking = true;
    _trackerHandle = setInterval(function() {

      _getStatus(function success(result) {

        self.emit('tick', result);

        if(result != _lastKnownState) {
          self.emit('change', result);
        }
        _lastKnownState = result;

        if(result == self.status.enabled) {
          self.emit('enabled');
        } else {
          self.emit('disabled');
        } 

      }, function error(err) {
        console.log(_logPrefix + ' error: ' + err );
        self.emit('error', [err]);
      },null,true);

    }, _trackInterval);

  };

  this.stop = function() {
    clearInterval(_trackerHandle);
    _trackerHandle = null;
    _isTracking = false;
    _lastKnownState = self.status.unknown;
  }

};

obj.prototype = new eventEmitter();

var passlock = new obj();

module.exports = passlock;
@@ -1127,14 +1127,9 @@
  if(
-!self.
+_
 disa
@@ -1152,18 +1152,18 @@
 rtCheck 
-&&
+%7C%7C
  !_isPla
@@ -1259,21 +1259,29 @@
  return 
-false
+success(true)
 ;%0A    %7D 
@@ -2424,24 +2424,25 @@
 acking = fal
+0
 se;%0A    _las

Fix to unsupported devices