Browse Source

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.
cordova-6-fix-maps
Steven Day 6 years ago
parent
commit
9a14f241e3
  1. 7
      .gitignore
  2. 23
      hooks/after_prepare/remove-permissions.js

7
.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

23
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'));
}
Loading…
Cancel
Save