From 9a14f241e307a7c054343c482aba977718ca51ed Mon Sep 17 00:00:00 2001 From: Steven Day Date: Mon, 25 Apr 2016 16:59:06 +0100 Subject: 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. --- .gitignore | 7 ------- hooks/after_prepare/remove-permissions.js | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) create mode 100755 hooks/after_prepare/remove-permissions.js diff --git a/.gitignore b/.gitignore index 3c41102..5ad9264 100644 --- a/.gitignore +++ b/.gitignore @@ -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 -- cgit v1.2.3