()
| 13 | const permissionRegex = /^\s*<uses-permission android:name="android\.permission\.MANAGE_EXTERNAL_STORAGE"\s*\/>\s*$/gm; |
| 14 | |
| 15 | async function addPermission() { |
| 16 | try { |
| 17 | let xml = await readFile(pluginXmlPath, 'utf-8'); |
| 18 | |
| 19 | if (xml.includes('android.permission.MANAGE_EXTERNAL_STORAGE')) { |
| 20 | console.log('Permission already exists in plugin.xml'); |
| 21 | return false; |
| 22 | } |
| 23 | |
| 24 | const pattern = /<config-file\s+target="AndroidManifest\.xml"\s+parent="\/manifest">\s*<\/config-file>/; |
| 25 | |
| 26 | if (pattern.test(xml)) { |
| 27 | xml = xml.replace(pattern, match => { |
| 28 | return match.replace( |
| 29 | '</config-file>', |
| 30 | `\n${permissionLine}\n </config-file>` |
| 31 | ); |
| 32 | }); |
| 33 | |
| 34 | await writeFile(pluginXmlPath, xml, 'utf-8'); |
| 35 | console.log('Permission added inside existing <config-file> block.'); |
| 36 | return true |
| 37 | } else { |
| 38 | console.error('Could not find <config-file parent="/manifest"> block.'); |
| 39 | return false |
| 40 | } |
| 41 | } catch (err) { |
| 42 | console.error('Failed to add permission:', err); |
| 43 | return false |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | async function removePermission() { |
| 48 | try { |
no test coverage detected