030_remove_permissions.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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, "platforms/android/app/src/main/AndroidManifest.xml");
  19. fs.readFile( manifestFile, "utf8", function( err, data ) {
  20. if (err)
  21. return console.log( "Error reading AndroidManifest.xml", err );
  22. var result = data;
  23. for(var i = 0; i < permsToRm.length; i++) {
  24. var search = '<uses-permission android:name="android.permission.' + permsToRm[i] + '" />';
  25. result = result.replace(search, '');
  26. }
  27. fs.writeFile( manifestFile, result, "utf8", function( err ){
  28. if (err)
  29. return console.log( "Error writing AndroidManifest.xml", err );
  30. });
  31. } );