mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-09 00:40:11 +01:00
Added functionality to parse android permission data from the appropriate XML file from the Android source.
This commit is contained in:
parent
59fa3f3a19
commit
34ae635f50
39
wp-fdroid/android-permissions.php
Normal file
39
wp-fdroid/android-permissions.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// Path to the AndroidManifest.xml-file from the Android source. Get it from https://raw.github.com/android/platform_frameworks_base/master/core/res/AndroidManifest.xml for example.
|
||||
$android_manifest_file_path = 'AndroidManifest.xml';
|
||||
|
||||
// Returns an associative array with android permissions and data about them
|
||||
function get_android_permissions_array($android_manifest_file_path) {
|
||||
|
||||
$doc = new DOMDocument;
|
||||
$doc->load($android_manifest_file_path);
|
||||
|
||||
$xpath = new DOMXPath($doc);
|
||||
|
||||
$description = '';
|
||||
|
||||
foreach ($xpath->query('node()') as $node) {
|
||||
// Save permissions and permission groups from tags
|
||||
if($node->nodeName == 'permission-group' || $node->nodeName == 'permission') {
|
||||
$name = $node->attributes->getNamedItem('name')->value;
|
||||
$name = substr(strrchr($name,'.'), 1);
|
||||
$permissions[$node->nodeName][$name]['description'] = str_replace(array("\r\n", "\r", "\n", "\t", ' '), '', $description);
|
||||
|
||||
if($node->nodeName == 'permission') {
|
||||
$permissions[$node->nodeName][$name]['permissionGroup'] = substr(strrchr($node->attributes->getNamedItem('permissionGroup')->value,'.'), 1);
|
||||
$permissions[$node->nodeName][$name]['protectionLevel'] = $node->attributes->getNamedItem('protectionLevel')->value;
|
||||
}
|
||||
}
|
||||
|
||||
// Cache descriptions from comments preceding the tags
|
||||
if($node->nodeName == '#comment') {
|
||||
$description .= $node->textContent;
|
||||
}
|
||||
elseif($node->nodeName != '#text') {
|
||||
$description = '';
|
||||
}
|
||||
}
|
||||
|
||||
return $permissions;
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user