mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-09-11 15:13:27 +02:00
Added human readable labels and descriptions for permissions.
The information is parsed from strings information from the Android source. This is really *much* to slow to do in real time, but a first step. Must be cached somehow.
This commit is contained in:
parent
34ae635f50
commit
51d00edf86
@ -1,36 +1,67 @@
|
||||
<?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';
|
||||
// Path to the strings.xml-file from the Android source. Get it from https://raw.github.com/android/platform_frameworks_base/master/core/res/res/values/strings.xml for example.
|
||||
$android_strings_file_path = 'strings.xml';
|
||||
|
||||
// Returns an associative array with android permissions and data about them
|
||||
function get_android_permissions_array($android_manifest_file_path) {
|
||||
function get_android_permissions_array($android_manifest_file_path, $android_strings_file_path) {
|
||||
|
||||
$doc = new DOMDocument;
|
||||
$doc->load($android_manifest_file_path);
|
||||
$manifestDoc = new DOMDocument;
|
||||
$manifestDoc->load($android_manifest_file_path);
|
||||
$manifestXpath = new DOMXPath($manifestDoc);
|
||||
|
||||
$xpath = new DOMXPath($doc);
|
||||
|
||||
$description = '';
|
||||
$stringsDoc = new DOMDocument;
|
||||
$stringsDoc->load($android_strings_file_path);
|
||||
$stringsXpath = new DOMXPath($stringsDoc);
|
||||
|
||||
foreach ($xpath->query('node()') as $node) {
|
||||
$comment = '';
|
||||
foreach ($manifestXpath->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);
|
||||
|
||||
// Lookup the human readable title
|
||||
$labelObject = $node->attributes->getNamedItem('label');
|
||||
$labelString = $name;
|
||||
if( $labelObject !== NULL ) {
|
||||
$labelName = substr(strrchr($labelObject->value,'/'),1);
|
||||
$labelStringObject = $stringsXpath->query('//string[@name="'.$labelName.'"]');
|
||||
$labelString = ucfirst($labelStringObject->item(0)->nodeValue);
|
||||
}
|
||||
|
||||
// Lookup the human readable description
|
||||
$descriptionObject = $node->attributes->getNamedItem('description');
|
||||
$descriptionString = '(Description missing)';
|
||||
if($descriptionObject !== NULL) {
|
||||
$descriptionName = substr(strrchr($descriptionObject->value,'/'),1);
|
||||
$descriptionStringObject = $stringsXpath->query('//string[@name="'.$descriptionName.'"]');
|
||||
$descriptionString = ucfirst($descriptionStringObject->item(0)->nodeValue);
|
||||
}
|
||||
|
||||
$permissions[$node->nodeName][$name]['label'] = $labelString;
|
||||
$permissions[$node->nodeName][$name]['description'] = $descriptionString;
|
||||
$permissions[$node->nodeName][$name]['comment'] = str_replace(array("\r\n", "\r", "\n", "\t", ' '), '', $comment);
|
||||
|
||||
if($node->nodeName == 'permission') {
|
||||
$permissions[$node->nodeName][$name]['permissionGroup'] = substr(strrchr($node->attributes->getNamedItem('permissionGroup')->value,'.'), 1);
|
||||
$permissionGroupObject = $node->attributes->getNamedItem('permissionGroup');
|
||||
$permissionGroup = 'none';
|
||||
if($permissionGroupObject !== NULL) {
|
||||
$permissionGroup = substr(strrchr($permissionGroupObject->value,'.'), 1);
|
||||
}
|
||||
|
||||
$permissions[$node->nodeName][$name]['permissionGroup'] = $permissionGroup;
|
||||
$permissions[$node->nodeName][$name]['protectionLevel'] = $node->attributes->getNamedItem('protectionLevel')->value;
|
||||
}
|
||||
}
|
||||
|
||||
// Cache descriptions from comments preceding the tags
|
||||
if($node->nodeName == '#comment') {
|
||||
$description .= $node->textContent;
|
||||
$comment .= $node->textContent;
|
||||
}
|
||||
elseif($node->nodeName != '#text') {
|
||||
$description = '';
|
||||
$comment = '';
|
||||
}
|
||||
}
|
||||
|
||||
|
3389
wp-fdroid/strings.xml
Executable file
3389
wp-fdroid/strings.xml
Executable file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user