030_remove_permissions.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env node
  2. //
  3. // This hook removes specific permissions from the AndroidManifest.xml
  4. // The AndroidManifest is re-generated during the prepare stage,
  5. // so this must be run on the "after_prepare" hook.
  6. //
  7. // Configure the permissions to be forcefully removed.
  8. // NOTE: These permissions will be removed regardless of how many plugins
  9. // require the permission. You can check the permission is only required
  10. // by the plugin you *think* needs it, by looking at the "count" shown in
  11. // your /plugins/android.json file.
  12. // If the count is more than 1, you should search through
  13. // the /plugins//plugin.xml files for <uses-permission> tags.
  14. var permsToRm = [ "RECORD_AUDIO", "MODIFY_AUDIO_SETTINGS", "READ_PHONE_STATE" ];
  15. var fs = require('fs');
  16. var path = require('path');
  17. var rootdir = process.argv[2];
  18. var manifestFile = path.join(rootdir, "plugin/cordova-plugin-media/config.xml");
  19. /*
  20. "platforms/android/app/AndroidManifest.xml"
  21. */
  22. fs.readFile( manifestFile, "utf8", function( err, data ) {
  23. if (err)
  24. return console.log( "Error reading plugin/cordova-plugin-media/config.xml", err );
  25. var result = data;
  26. for(var i = 0; i < permsToRm.length; i++) {
  27. var search = '<uses-permission android:name="android.permission.' + permsToRm[i] + '" />';
  28. result = result.replace(search, '');
  29. }
  30. fs.writeFile( manifestFile, result, "utf8", function( err ){
  31. if (err)
  32. return console.log( "Error writing AndroidManifest.xml", err );
  33. });
  34. } );