Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-26509
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaysingh-axway committed Mar 7, 2019
2 parents 8b7f2dd + e5258e1 commit 1083086
Show file tree
Hide file tree
Showing 27 changed files with 1,615 additions and 1,146 deletions.
9 changes: 8 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{
"files": [ "tests/Resources/es6.*.js" ],
"parserOptions": {
"ecmaVersion": 2015,
"ecmaVersion": 2017,
"sourceType": "module"
}
},
Expand All @@ -42,6 +42,13 @@
"ecmaVersion": 6,
"sourceType": "script"
}
},
{
"files": [ "common/Resources/ti.main.js" ],
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
}
}
]
}
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = function (grunt) {
'apidoc/**/*.js',
'build/**/*.js',
'cli/!(locales)/**/*.js',
'common/**/*.js',
'android/cli/!(locales)/**/*.js',
'android/modules/**/src/js/**/*.js',
'android/runtime/common/src/js/**/*.js',
Expand Down Expand Up @@ -125,7 +126,6 @@ module.exports = function (grunt) {
grunt.registerMultiTask('checkFormat', 'Validates the source code formatting.', validateFormatting);

// Load grunt plugins for modules
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-appc-js');
grunt.loadNpmTasks('grunt-clang-format');
grunt.loadNpmTasks('grunt-contrib-clean');
Expand Down
6 changes: 5 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ def unitTests(os, nodeVersion, npmVersion, testSuiteBranch) {
dir('scripts') {
try {
timeout(20) {
sh "node test.js -b ../../${zipName} -p ${os}"
if ('ios'.equals(os)) {
sh "node test.js -b ../../${zipName} -p ${os}"
} else {
sh "node test.js -C android-23-x86 -T emulator -b ../../${zipName} -p ${os}"
}
} // timeout
} catch (e) {
if ('ios'.equals(os)) {
Expand Down
65 changes: 23 additions & 42 deletions android/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -1518,9 +1518,18 @@ AndroidBuilder.prototype.validate = function validate(logger, config, cli) {
const manifestHashes = [],
nativeHashes = [],
bindingsHashes = [],
jarHashes = {};
jarHashes = {},
blacklist = [ 'com.soasta.touchtest' ];

modules.found.forEach(function (module) {

// skip modules from blacklist
// TODO: remove SOASTA files from project in 8.1.0
if (blacklist.includes(module.id)) {
this.logger.warn(__('Skipping unsupported module "%s"', module.id.cyan));
return;
}

manifestHashes.push(this.hash(JSON.stringify(module.manifest)));

if (module.platform.indexOf('commonjs') !== -1) {
Expand Down Expand Up @@ -1749,11 +1758,11 @@ AndroidBuilder.prototype.run = function run(logger, config, cli, finished) {
},

'createBuildDirs',
'removeOldFiles',
'copyResources',
'generateRequireIndex',
'processTiSymbols',
'copyModuleResources',
'removeOldFiles',
'copyGradleTemplate',
'generateJavaFiles',
'generateAidl',
Expand Down Expand Up @@ -2414,9 +2423,7 @@ AndroidBuilder.prototype.copyResources = function copyResources(next) {

// if this is a directory, recurse
if (isDir) {
setImmediate(function () {
recursivelyCopy.call(_t, from, path.join(destDir, filename), null, opts, next);
});
recursivelyCopy.call(_t, from, path.join(destDir, filename), null, opts, next);
return;
}

Expand Down Expand Up @@ -2669,18 +2676,19 @@ AndroidBuilder.prototype.copyResources = function copyResources(next) {
}, this);

appc.async.series(this, tasks, function () {
var templateDir = path.join(this.platformPath, 'templates', 'app', 'default', 'template', 'Resources', 'android');
const templateDir = path.join(this.platformPath, 'templates', 'app', 'default', 'template', 'Resources', 'android');

// if an app icon hasn't been copied, copy the default one
var destIcon = path.join(this.buildBinAssetsResourcesDir, this.tiapp.icon);
const srcIcon = path.join(templateDir, 'appicon.png');
const destIcon = path.join(this.buildBinAssetsResourcesDir, this.tiapp.icon);
if (!fs.existsSync(destIcon)) {
copyFile.call(this, path.join(templateDir, 'appicon.png'), destIcon);
copyFile.call(this, srcIcon, destIcon);
}
delete this.lastBuildFiles[destIcon];

const destIcon2 = path.join(this.buildResDrawableDir, this.tiapp.icon);
if (!fs.existsSync(destIcon2)) {
copyFile.call(this, destIcon, destIcon2);
copyFile.call(this, srcIcon, destIcon2);
}
delete this.lastBuildFiles[destIcon2];

Expand Down Expand Up @@ -2710,6 +2718,7 @@ AndroidBuilder.prototype.copyResources = function copyResources(next) {

// copy js files into assets directory and minify if needed
this.logger.info(__('Processing JavaScript files'));
const sdkCommonFolder = path.join(this.titaniumSdkPath, 'common', 'Resources');
appc.async.series(this, Object.keys(jsFiles).map(function (id) {
return function (done) {
const from = jsFiles[id];
Expand Down Expand Up @@ -2749,10 +2758,13 @@ AndroidBuilder.prototype.copyResources = function copyResources(next) {
const source = r.contents;
// Analyze Ti API usage, possibly also minify/transpile
try {
// DO NOT TRANSPILE CODE inside SDK's common folder. It's already transpiled!
const transpile = from.startsWith(sdkCommonFolder) ? false : this.transpile;
const minify = from.startsWith(sdkCommonFolder) ? false : this.minifyJS;
const modified = jsanalyze.analyzeJs(source, {
filename: from,
minify: this.minifyJS,
transpile: this.transpile,
minify,
transpile,
sourceMap: this.sourceMaps || this.deployType === 'development',
targets: {
chrome: this.chromeVersion
Expand Down Expand Up @@ -2796,37 +2808,6 @@ AndroidBuilder.prototype.copyResources = function copyResources(next) {
}
};
}), function () {
// jsanalyze will copy polyfils into buildBinAssetsResourcesDir and we need
// to unmark them here so they won't get removed on subsequent builds
if (this.transpile) {
/**
* Recursively unmarks a module and it's dependencies from the last
* build files list.
*
* @param {String} moduleId The module to remove from the list of files
* @param {String} nodeModulesPath Path to the node_modules folder
*/
const unmarkPackageAndDependencies = (moduleId, nodeModulesPath) => {
let packageJsonPath;
if (require.resolve.paths) {
packageJsonPath = require.resolve(path.join(moduleId, 'package.json'), { paths: [ nodeModulesPath ] });
} else {
packageJsonPath = require.resolve(path.join(moduleId, 'package.json'));
packageJsonPath = path.join(nodeModulesPath, packageJsonPath.substring(packageJsonPath.indexOf('node_modules') + 12));
}
const modulePath = path.dirname(packageJsonPath);
Object.keys(this.lastBuildFiles).forEach(p => {
if (p.startsWith(modulePath)) {
delete this.lastBuildFiles[p];
}
});
const packageJson = fs.readJSONSync(packageJsonPath);
for (const dependency in packageJson.dependencies) {
unmarkPackageAndDependencies(dependency, nodeModulesPath);
}
};
unmarkPackageAndDependencies('@babel/polyfill', path.join(this.buildBinAssetsResourcesDir, 'node_modules'));
}

// write the properties file
const buildAssetsPath = this.encryptJS ? this.buildAssetsDir : this.buildBinAssetsResourcesDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ public class GeolocationModule extends KrollModule implements Handler.Callback,
public int numLocationListeners = 0;
public HashMap<String, LocationProviderProxy> simpleLocationProviders =
new HashMap<String, LocationProviderProxy>();
@Deprecated
public HashMap<String, LocationProviderProxy> legacyLocationProviders =
new HashMap<String, LocationProviderProxy>();

protected static final int MSG_ENABLE_LOCATION_PROVIDERS = KrollModule.MSG_LAST_ID + 100;
protected static final int MSG_LAST_ID = MSG_ENABLE_LOCATION_PROVIDERS;
Expand All @@ -135,17 +132,10 @@ public class GeolocationModule extends KrollModule implements Handler.Callback,
private ArrayList<LocationRuleProxy> simpleLocationRules = new ArrayList<LocationRuleProxy>();
private LocationRuleProxy simpleLocationGpsRule;
private LocationRuleProxy simpleLocationNetworkRule;
private int simpleLocationAccuracyProperty = ACCURACY_LOW;
private Location currentLocation;
//currentLocation is conditionally updated. lastLocation is unconditionally updated
//since currentLocation determines when to send out updates, and lastLocation is passive
private Location lastLocation;
@Deprecated
private HashMap<Integer, Double> legacyLocationAccuracyMap = new HashMap<Integer, Double>();
@Deprecated
private double legacyLocationFrequency = 5000;
@Deprecated
private String legacyLocationPreferredProvider = AndroidModule.PROVIDER_NETWORK;

private FusedLocationProvider fusedLocationProvider;

Expand Down Expand Up @@ -178,6 +168,8 @@ public GeolocationModule()
simpleLocationNetworkRule =
new LocationRuleProxy(AndroidModule.PROVIDER_NETWORK, SIMPLE_LOCATION_NETWORK_DISTANCE_RULE,
SIMPLE_LOCATION_NETWORK_MIN_AGE_RULE, null);
simpleLocationRules.add(simpleLocationNetworkRule);
simpleLocationRules.add(simpleLocationGpsRule);
}

/**
Expand Down Expand Up @@ -321,40 +313,21 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
@SuppressLint("MissingPermission")
private void propertyChangedAccuracy(Object newValue)
{
// is simple mode enabled (registered with OS, not just selected via the accuracy property)
boolean simpleModeEnabled = false;
if (!(getManualMode()) && (numLocationListeners > 0)) {
simpleModeEnabled = true;
}

int accuracyProperty = TiConvert.toInt(newValue);

if ((accuracyProperty == ACCURACY_HIGH) || (accuracyProperty == ACCURACY_LOW)) {
// has the value changed from the last known good value?
if (accuracyProperty != simpleLocationAccuracyProperty) {
simpleLocationAccuracyProperty = accuracyProperty;
LocationProviderProxy gpsProvider = simpleLocationProviders.get(AndroidModule.PROVIDER_GPS);

if ((accuracyProperty == ACCURACY_HIGH) && (gpsProvider == null)) {
gpsProvider = new LocationProviderProxy(AndroidModule.PROVIDER_GPS, SIMPLE_LOCATION_GPS_DISTANCE,
SIMPLE_LOCATION_GPS_TIME, this);
simpleLocationProviders.put(AndroidModule.PROVIDER_GPS, gpsProvider);
simpleLocationRules.add(simpleLocationNetworkRule);
simpleLocationRules.add(simpleLocationGpsRule);

if (simpleModeEnabled) {
registerLocationProvider(gpsProvider);
}

} else if ((accuracyProperty == ACCURACY_LOW) && (gpsProvider != null)) {
simpleLocationProviders.remove(AndroidModule.PROVIDER_GPS);
simpleLocationRules.remove(simpleLocationNetworkRule);
simpleLocationRules.remove(simpleLocationGpsRule);
double accuracyDistance = SIMPLE_LOCATION_GPS_DISTANCE;
if (accuracyProperty == ACCURACY_LOW) {
accuracyDistance = 3000.0;
}
LocationProviderProxy gpsProvider =
new LocationProviderProxy(AndroidModule.PROVIDER_GPS, accuracyDistance, SIMPLE_LOCATION_GPS_TIME, this);

if (simpleModeEnabled) {
unregisterLocationProvider(gpsProvider);
}
}
unregisterLocationProvider(simpleLocationProviders.get(AndroidModule.PROVIDER_GPS));
simpleLocationProviders.put(AndroidModule.PROVIDER_GPS, gpsProvider);

if (!getManualMode()) {
registerLocationProvider(gpsProvider);
}
}
}
Expand All @@ -367,15 +340,6 @@ private void propertyChangedAccuracy(Object newValue)
private void propertyChangedFrequency(Object newValue)
{
double frequencyProperty = TiConvert.toDouble(newValue) * 1000;
if (frequencyProperty != legacyLocationFrequency) {
legacyLocationFrequency = frequencyProperty;

Iterator<String> iterator = legacyLocationProviders.keySet().iterator();
while (iterator.hasNext()) {
LocationProviderProxy locationProvider = legacyLocationProviders.get(iterator.next());
locationProvider.setProperty(TiC.PROPERTY_MIN_UPDATE_TIME, legacyLocationFrequency);
}
}
}

/**
Expand All @@ -391,24 +355,6 @@ private void propertyChangedPreferredProvider(Object newValue)
&& (!(preferredProviderProperty.equals(AndroidModule.PROVIDER_GPS)))) {
return;
}

if (!(preferredProviderProperty.equals(legacyLocationPreferredProvider))) {
LocationProviderProxy oldProvider = legacyLocationProviders.get(legacyLocationPreferredProvider);
LocationProviderProxy newProvider = legacyLocationProviders.get(preferredProviderProperty);

if (oldProvider != null) {
legacyLocationProviders.remove(legacyLocationPreferredProvider);
}

if (newProvider == null) {
newProvider = new LocationProviderProxy(preferredProviderProperty,
legacyLocationAccuracyMap.get(simpleLocationAccuracyProperty),
legacyLocationFrequency, this);
legacyLocationProviders.put(preferredProviderProperty, newProvider);
}

legacyLocationPreferredProvider = preferredProviderProperty;
}
}

/**
Expand Down Expand Up @@ -562,17 +508,21 @@ public boolean hasLocationPermissions()
public void requestLocationPermissions(@Kroll.argument(optional = true) Object type,
@Kroll.argument(optional = true) KrollFunction permissionCallback)
{
if (hasLocationPermissions()) {
return;
}

KrollFunction permissionCB;
if (type instanceof KrollFunction && permissionCallback == null) {
permissionCB = (KrollFunction) type;
} else {
permissionCB = permissionCallback;
}

// already have permissions, fall through
if (hasLocationPermissions()) {
KrollDict response = new KrollDict();
response.putCodeAndMessage(0, null);
permissionCB.callAsync(getKrollObject(), response);
return;
}

TiBaseActivity.registerPermissionRequestCallback(TiC.PERMISSION_CODE_LOCATION, permissionCB, getKrollObject());
Activity currentActivity = TiApplication.getInstance().getCurrentActivity();
currentActivity.requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
Expand All @@ -591,6 +541,9 @@ public void registerLocationProvider(final LocationProviderProxy locationProvide
if (!hasLocationPermissions()) {
Log.e(TAG, "Location permissions missing", Log.DEBUG_MODE);
return;
} else if (locationProvider == null) {
Log.e(TAG, "Invalid location provider", Log.DEBUG_MODE);
return;
}

if (FusedLocationProvider.hasPlayServices(context)) {
Expand All @@ -615,6 +568,9 @@ public void registerLocationProvider(final LocationProviderProxy locationProvide
@SuppressLint("MissingPermission")
public void unregisterLocationProvider(LocationProviderProxy locationProvider)
{
if (locationProvider == null) {
return;
}
if (FusedLocationProvider.hasPlayServices(context)) {
fusedLocationProvider.unregisterLocationProvider(locationProvider);
} else {
Expand Down Expand Up @@ -673,10 +629,6 @@ private void doEnableLocationProviders(HashMap<String, LocationProviderProxy> lo
@SuppressLint("MissingPermission")
private void disableLocationProviders()
{
for (LocationProviderProxy locationProvider : legacyLocationProviders.values()) {
unregisterLocationProvider(locationProvider);
}

for (LocationProviderProxy locationProvider : simpleLocationProviders.values()) {
unregisterLocationProvider(locationProvider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
@Kroll.proxy
public class LocationProviderProxy extends KrollProxy implements LocationListener
{
public static final int STATE_DISABLED = 0;
public static final int STATE_ENABLED = 1;
public static final int STATE_ENABLED = 0;
public static final int STATE_DISABLED = 1;
public static final int STATE_OUT_OF_SERVICE = 2;
public static final int STATE_UNAVAILABLE = 3;
public static final int STATE_AVAILABLE = 4;
Expand Down

0 comments on commit 1083086

Please sign in to comment.