diff options
author | Steven Day <steve@mysociety.org> | 2016-04-25 16:59:06 +0100 |
---|---|---|
committer | Steven Day <steve@mysociety.org> | 2016-04-25 16:59:06 +0100 |
commit | 9a14f241e307a7c054343c482aba977718ca51ed (patch) | |
tree | cd8f232ff7527489a28e129d9228018979d81293 | |
parent | f10b55c1d13f57c7a614407b97032bb313141a8f (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.
-rw-r--r-- | .gitignore | 7 | ||||
-rwxr-xr-x | hooks/after_prepare/remove-permissions.js | 23 |
2 files changed, 23 insertions, 7 deletions
@@ -9,15 +9,8 @@ tags *.mo www/js/config.js -Android/bin/ platforms plugins -hooks -iPhone/FixMyStreet.xcodeproj/project.xcworkspace/xcuserdata -iPhone/FixMyStreet.xcodeproj/xcuserdata -iPhone/CordovaLib/CordovaLib.xcodeproj/project.xcworkspace/xcuserdata -iPhone/CordovaLib/CordovaLib.xcodeproj/xcuserdata -Android/gen/ compiled locale/lang_list config.xml 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 |