Skip to content

Commit

Permalink
fix(android): improve merge of <uses-feature/> elements (#11111)
Browse files Browse the repository at this point in the history
- Fixed so that Android setting <uses-feature/> required "true" in "tiapp.xml" should override "false" setting in libraries.
  * Merge is supposed to do a logical-OR on the "android:required" value.
- Added "tools:replace" attribute support to <uses-feature/>.
  * Allows overriding "android:required" to "false" if set "true" by library. (Only means of doing this.)

Fixes TIMOB-27304
  • Loading branch information
jquick-axway authored and sgtcoolguy committed Aug 20, 2019
1 parent 74f6e10 commit 710083a
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions android/cli/lib/AndroidManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,39 @@ function AndroidManifest(filename) {
case 'uses-feature':
this[tag] || (this[tag] = []);
src[tag].forEach(function (tagItem) {
// Check for already added features.
let duplicateItem = this[tag].find(function (nextItem) {
// If given "uses-feature" name has already been added, then fetch its object.
const duplicateItem = this[tag].find(function (nextItem) {
// Compare them directly or by name.
return (nextItem === tagItem) || (nextItem.name === tagItem.name);
});
if (!duplicateItem) {
if (duplicateItem === tagItem) {
// Given reference was already added. Do nothing.
} else if (duplicateItem) {
// This is a duplicate "uses-feature" element name. Merge its settings.
if (typeof tagItem['tools:replace'] === 'string') {
// This attribute provides an array of other attributes that must be replaced.
tagItem['tools:replace'].split(',').forEach(function (attributeName) {
attributeName = attributeName.replace(androidAttrPrefixRegExp, '');
if (attributeName !== 'name') {
const value = tagItem[attributeName];
if (typeof value === 'undefined') {
delete duplicateItem[attributeName];
} else {
duplicateItem[attributeName] = value;
}
}
});
} else if (duplicateItem.required === false) {
// Do a logical OR on the "required" attribute value.
// If the "required" attribute is not defined, then it is considered true.
if (typeof tagItem.required === 'undefined') {
delete duplicateItem.required;
} else if (tagItem.required) {
duplicateItem.required = tagItem.required;
}
}
} else {
// The given "uses-feature" name has not been added yet. Do so now.
this[tag].push(tagItem);
}
}, this);
Expand Down

0 comments on commit 710083a

Please sign in to comment.