aboutsummaryrefslogtreecommitdiffstats
path: root/hooks/after_prepare/remove-permissions.js
diff options
context:
space:
mode:
authorSteven Day <steve@mysociety.org>2016-04-25 16:59:06 +0100
committerSteven Day <steve@mysociety.org>2016-04-25 16:59:06 +0100
commit9a14f241e307a7c054343c482aba977718ca51ed (patch)
treecd8f232ff7527489a28e129d9228018979d81293 /hooks/after_prepare/remove-permissions.js
parentf10b55c1d13f57c7a614407b97032bb313141a8f (diff)
Add a hook to remove unnecessary permissions
The cordova media plugin asks for lots of permissions but we don't actually need them all (it could be used to film video, record audio or play files, but we don't do those things), so they can be removed. It's slightly hacky to do so because Cordova doesn't offer a built-in way, so instead we add an after_prepare hook to remove them from the right file.
Diffstat (limited to 'hooks/after_prepare/remove-permissions.js')
-rwxr-xr-xhooks/after_prepare/remove-permissions.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/hooks/after_prepare/remove-permissions.js b/hooks/after_prepare/remove-permissions.js
new file mode 100755
index 0000000..5628647
--- /dev/null
+++ b/hooks/after_prepare/remove-permissions.js
@@ -0,0 +1,23 @@
+#!/usr/bin/env node
+var fs = require('fs');
+
+if(fs.existsSync('platforms/android')) {
+ var PERMISSIONS_TO_REMOVE = [
+ 'READ_PHONE_STATE',
+ 'RECORD_AUDIO',
+ 'MODIFY_AUDIO_SETTINGS',
+ 'RECORD_VIDEO'
+ ];
+ var MANIFEST = 'platforms/android/AndroidManifest.xml';
+ var manifestLines = fs.readFileSync(MANIFEST).toString().split('\n');
+ var newManifestLines = [];
+ var PERMISSIONS_REGEX = PERMISSIONS_TO_REMOVE.join('|');
+
+ manifestLines.forEach(function(line) {
+ if(!line.match(PERMISSIONS_REGEX)) {
+ newManifestLines.push(line);
+ }
+ });
+
+ fs.writeFileSync(MANIFEST, newManifestLines.join('\n'));
+} \ No newline at end of file