chiark / gitweb /
Added functionality to parse android permission data from the appropriate XML file...
authorHans-Emil Skogh <hansemil@gmail.com>
Tue, 27 Dec 2011 19:29:45 +0000 (20:29 +0100)
committerHans-Emil Skogh <hansemil@gmail.com>
Tue, 27 Dec 2011 19:29:45 +0000 (20:29 +0100)
wp-fdroid/android-permissions.php [new file with mode: 0644]

diff --git a/wp-fdroid/android-permissions.php b/wp-fdroid/android-permissions.php
new file mode 100644 (file)
index 0000000..9901a70
--- /dev/null
@@ -0,0 +1,39 @@
+<?php\r
+// 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.\r
+$android_manifest_file_path = 'AndroidManifest.xml';\r
+\r
+// Returns an associative array with android permissions and data about them\r
+function get_android_permissions_array($android_manifest_file_path) {\r
+\r
+       $doc = new DOMDocument;\r
+       $doc->load($android_manifest_file_path);\r
+\r
+       $xpath = new DOMXPath($doc);\r
+\r
+       $description = '';\r
+       \r
+       foreach ($xpath->query('node()') as $node) {\r
+               // Save permissions and permission groups from tags\r
+               if($node->nodeName == 'permission-group' || $node->nodeName == 'permission') {\r
+                       $name = $node->attributes->getNamedItem('name')->value;\r
+                       $name = substr(strrchr($name,'.'), 1);\r
+                       $permissions[$node->nodeName][$name]['description'] = str_replace(array("\r\n", "\r", "\n", "\t", '  '), '', $description);\r
+                       \r
+                       if($node->nodeName == 'permission') {\r
+                               $permissions[$node->nodeName][$name]['permissionGroup'] = substr(strrchr($node->attributes->getNamedItem('permissionGroup')->value,'.'), 1);\r
+                               $permissions[$node->nodeName][$name]['protectionLevel'] = $node->attributes->getNamedItem('protectionLevel')->value;\r
+                       }\r
+               }\r
+\r
+               // Cache descriptions from comments preceding the tags\r
+               if($node->nodeName == '#comment') {\r
+                       $description .= $node->textContent;\r
+               }\r
+               elseif($node->nodeName != '#text') {\r
+                       $description = '';\r
+               }\r
+       }\r
+       \r
+       return $permissions;\r
+}\r
+?>
\ No newline at end of file