/** * Copyright© 2016, Oracle and/or its affiliates. All rights reserved. */ // // Needs to have console, geolocation, PushPlugin, sqlite-storage and device plugins to be installed. // /** * Platform class for Cordova applications. Derives from [BrowserPlatform]{@link BrowserPlatform}. * @constructor * @global */ function CordovaPlatform(manager, logger, utils) { // init dependency injection parameters manager = manager || mcs.mobileBackendManager; logger = logger || mcs._logger; utils = utils || mcs._utils; // call parent constructor BrowserPlatform.call(this, manager, logger, utils); this.isBrowser = false; this.isCordova = true; var _latitude = null; var _longitude = null; var gpsLocationInitialised = false; this.initGPSLocation = function () { logger.verbose('Subscribe to location changes'); if(!gpsLocationInitialised) { document.addEventListener("deviceready", function () { navigator.geolocation.getCurrentPosition(setPosition, onError); navigator.geolocation.watchPosition(setPosition, onError); }, false); gpsLocationInitialised = true; } function setPosition(position){ _latitude = position.coords.latitude; _longitude = position.coords.longitude; } function onError(error){ logger.error('Error while subscribing for position.', error); } }; /** * Overrides [Platform.getGPSLocation()]{@link Platform#getGPSLocation} * @override */ this.getGPSLocation = function () { return { latitude: '' + _latitude, longitude: '' + _longitude }; }; /** * Checks the current state of the device. Platform implementations should call this function * when the state changes. The state is inspected before background operations * like synchronization are performed. * Cordova Network Information Plugin MUST be installed for this function to operate. */ this.checkConnection = function () { var networkState = navigator.connection.type; var states = {}; states[Connection.UNKNOWN] = 'Unknown connection'; states[Connection.ETHERNET] = 'Ethernet connection'; states[Connection.WIFI] = 'WiFi connection'; states[Connection.CELL_2G] = 'Cell 2G connection'; states[Connection.CELL_3G] = 'Cell 3G connection'; states[Connection.CELL_4G] = 'Cell 4G connection'; states[Connection.CELL] = 'Cell generic connection'; states[Connection.NONE] = 'No network connection'; logger.info('Connection type: ' + states[networkState]); return states[networkState]; }; }; CordovaPlatform.prototype = Object.create(BrowserPlatform.prototype); CordovaPlatform.prototype.constructor = CordovaPlatform; /** @return Returns an object of variables used to return device specific information like: @return model: Nexus One returns "Passion", Motorola Droid returns "voles", etc. * @return manufacturer: Returns the manufacturer name: * * Samsung * LG * Motorola * Micosoft * Sony * Apple * @return OS Name: Depending on the device, a few examples are: * "Android" * "BlackBerry 10" * Browser: returns "MacIntel" on Mac * returns "Win32" on Windows * "iOS" * "WinCE" * "Tizen" * @return OS Version: Depending on the device, a few examples are: * Android: Froyo OS would return "2.2" Eclair OS would return "2.1", "2.0.1", or "2.0" Version can also return update level "2.1-update1" * BlackBerry: Torch 9800 using OS 6.0 would return "6.0.0.600" * * Browser: Returns version number for the browser * iPhone: iOS 3.2 returns "3.2" * Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720 * Tizen: returns "TIZEN_20120425_2" * @return OS Build: Get the version of Cordova running on the device. * Overrides [Platform.getDeviceInformation()]{@link Platform#getDeviceInformation} * @override */ CordovaPlatform.prototype.getDeviceInformation = function () { if (typeof device == "undefined") { return { "model": "<unknown>", "manufacturer": "<unknown>", "osName": "<unknown>", "osVersion": "<unknown>", "osBuild": "<unknown>", "carrier": "<unknown>" } } else { return { "model": device.model, "manufacturer": device.manufacturer, "osName": device.platform, "osVersion": device.version, "osBuild": "cordova " + device.cordova, "carrier": "<unknown>" } } };