Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
</config-file>

<hook type="before_prepare" src="hooks/restore-cordova-resources.js" />
<hook type="before_prepare" src="hooks/modify-java-files.js" />
<hook type="after_prepare" src="hooks/modify-java-files.js" />
<hook type="after_prepare" src="hooks/post-process.js" />
</platform>
<preference name="AndroidBlacklistSecureSocketProtocols" value="SSLv3,TLSv1" />
Expand Down
42 changes: 34 additions & 8 deletions hooks/modify-java-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const prettier = require('prettier');
main();

async function main() {
const patchVersion = '2';
const patchVersion = '3';
const flagFile = path.resolve(__dirname, '../platforms/android/.flag_done');
if (fs.existsSync(flagFile)) {
const appliedVersion = fs.readFileSync(flagFile, 'utf8').trim();
Expand Down Expand Up @@ -144,9 +144,7 @@ async function main() {
if (type == NO_SUGGESTIONS) {
outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
} else if (type == NO_SUGGESTIONS_AGGRESSIVE) {
outAttrs.inputType =
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS |
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
} else {
outAttrs.inputType |= InputType.TYPE_NULL;
}
Expand Down Expand Up @@ -380,6 +378,20 @@ async function main() {
const contentToAddTo = contentToAdd[file];
const text = removeComments(content);
let newContent = await format(text);

if (file === 'SystemWebView.java') {
newContent = newContent.replace(
/outAttrs\\.inputType\\s*=\\s*InputType\\.TYPE_TEXT_FLAG_NO_SUGGESTIONS\\s*\\|\\s*InputType\\.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD\\s*;/g,
'outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;',
);
}

if (file === 'SystemWebView.java') {
newContent = newContent.replace(
/outAttrs\.inputType\s*=\s*InputType\.TYPE_TEXT_FLAG_NO_SUGGESTIONS\s*\|\s*InputType\.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD\s*;/g,
'outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;',
);
}
if (contentToAddTo.import) {
const imports = contentToAddTo.import.map(importStr => {
return `import ${importStr};`;
Expand All @@ -400,9 +412,14 @@ async function main() {
);
}
if (contentToAddTo.methods) {
const methods = contentToAddTo.methods.map(method => {
return getMethodString(method);
}).join('\n');
if (file === 'SystemWebView.java') {
newContent = removeMethod(newContent, 'onCreateInputConnection');
}

const methods = contentToAddTo.methods
.filter(method => !(file === 'SystemWebView.java' && method.name === 'onCreateInputConnection'))
.map(method => getMethodString(method))
.join('\n');

if (isInterface(file, content)) {
const regex = getInterfaceDeclarationRegex(file);
Expand Down Expand Up @@ -456,7 +473,16 @@ async function main() {
});
}

function getMethodString(method) {
function removeMethod(content, methodName) {
const regex = new RegExp(
`\\n\\s*@Override\\s*\\n\\s*public\\s+[^\\s]+\\s+${methodName}\\s*\\([^)]*\\)\\s*\\{[^]*?\\n\\s*\\}`,
'm',
);
Comment on lines +477 to +480

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Method removal corrupts Java

When upgrading an Android platform previously patched by version 2, this regex processes an onCreateInputConnection method containing nested if blocks. Its lazy match stops at the first inner closing brace, leaving the else if, else, and return statements behind. This produces invalid SystemWebView.java source and causes the Android build to fail during formatting or compilation.


return content.replace(regex, '');
}

function getMethodString(method) {
const params = method.params.map(param => {
return `${param.type} ${param.name}`;
}).join(', ');
Expand Down