and supported by Android Manifest specification.
Sample usage from shell script:
-python permissions_mapping.py --jsonfile=/path/to/manifest.json
+python handle_permissions.py --jsonfile=/path/to/manifest.json
--manifest=/path/to/AndroidManifest.xml
"""
# The global permission mapping table.
# TODO: update the permission mapping table for added permission.
permission_mapping_table = {
- 'contacts' : ['android.permission.READ_CONTACTS',
- 'android.permission.WRITE_CONTACTS'],
- 'geolocation' : ['android.permission.ACCESS_FINE_LOCATION'],
- 'messaging' : ['android.permission.READ_SMS',
- 'android.permission.READ_PHONE_STATE',
- 'android.permission.RECEIVE_SMS',
- 'android.permission.SEND_SMS',
- 'android.permission.WRITE_SMS'],
- 'devicecapabilities' : [],
- 'fullscreen' : [],
- 'presentation' : [],
- 'rawsockets' : []
+ 'contacts': ['android.permission.READ_CONTACTS',
+ 'android.permission.WRITE_CONTACTS'],
+ 'geolocation': ['android.permission.ACCESS_FINE_LOCATION'],
+ 'messaging': ['android.permission.READ_SMS',
+ 'android.permission.READ_PHONE_STATE',
+ 'android.permission.RECEIVE_SMS',
+ 'android.permission.SEND_SMS',
+ 'android.permission.WRITE_SMS'],
+ 'devicecapabilities': [],
+ 'fullscreen': [],
+ 'presentation': [],
+ 'rawsockets': [],
+ 'screenorientation': [],
+ 'vibration': ['android.permission.VIBRATE']
}
-def HandlePermissions(options, xmldoc):
+def HandlePermissions(permissions, xmldoc):
""" Implement the mapping of permission list to the AndroidManifest.xml file.
Args:
- options: the parsed options with permissions.
+ permissions: the permissions defined in Crosswalk and Android Manifest
+ specification.
xmldoc: the parsed xmldoc of the AndroidManifest.xml file, used for
reading and writing.
"""
- if options.permissions:
+ if permissions:
existing_permission_list = []
used_permissions = xmldoc.getElementsByTagName("uses-permission")
for item in used_permissions:
existing_permission_list.append(item.getAttribute("android:name"))
- for permission in options.permissions.split(':'):
- if permission.lower() not in permission_mapping_table.keys():
- print 'Error: permission \'%s\' related API is not supported.' \
- % permission
+ for permission in permissions.split(':'):
+ if permission.lower() not in list(permission_mapping_table.keys()):
+ print('Error: permission \'%s\' related API is not supported.'
+ % permission)
sys.exit(1)
permission_item = permission_mapping_table.get(permission.lower())
if permission_item:
parser.print_help()
return 0
if not options.jsonfile:
- print 'Please set the manifest.json file.'
+ print('Please set the manifest.json file.')
return 1
if not options.manifest:
- print 'Please set the AndroidManifest.xml file.'
+ print('Please set the AndroidManifest.xml file.')
return 1
try:
json_parser = ManifestJsonParser(os.path.expanduser(options.jsonfile))
if json_parser.GetPermissions():
options.permissions = json_parser.GetPermissions()
- except SystemExit, ec:
- print 'Exiting with error code: %d' % ec.code
+ except SystemExit as ec:
+ print('Exiting with error code: %d' % ec.code)
return ec.code
try:
xmldoc = minidom.parse(options.manifest)
- HandlePermissions(options, xmldoc)
+ HandlePermissions(options.permissions, xmldoc)
file_handle = open(options.manifest, 'wb')
xmldoc.writexml(file_handle)
file_handle.close()
except (ExpatError, IOError):
- print 'There is an error in AndroidManifest.xml.'
+ print('There is an error in AndroidManifest.xml.')
return 1
return 0