// 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.\r
$android_strings_file_path = 'strings.xml';\r
\r
+$cache_file_path = 'android-permissions.cache';\r
+\r
// Returns an associative array with android permissions and data about them\r
-function get_android_permissions_array($android_manifest_file_path, $android_strings_file_path) {\r
+function get_android_permissions_array($android_manifest_file_path, $android_strings_file_path, $cache_file_path) {\r
\r
+ // Check status of cache\r
+ $android_manifest_file_stat = stat($android_manifest_file_path);\r
+ $android_manifest_file_mtime = $android_manifest_file_stat['mtime'];\r
+ $android_strings_file_stat = stat($android_strings_file_path);\r
+ $android_strings_file_mtime = $android_strings_file_stat['mtime'];\r
+ $cache_file_mtime = 0;\r
+ if(file_exists($cache_file_path)) {\r
+ $cache_file_stat = stat($cache_file_path);\r
+ $cache_file_mtime = $cache_file_stat['mtime'];\r
+ }\r
+ \r
+ // If the cache is fresh, use it instead\r
+ if($android_manifest_file_mtime < $cache_file_mtime && $android_strings_file_mtime < $cache_file_mtime ) {\r
+ $cache_file_handle = fopen($cache_file_path, 'r');\r
+ $cache_file_content = fread($cache_file_handle, filesize($cache_file_path));\r
+ fclose($cache_file_handle);\r
+ \r
+ $permissions = unserialize($cache_file_content);\r
+ \r
+ return $permissions;\r
+ }\r
+\r
+ // We are updating the cache, touch the file (note: race condition possible between stating the cache file above and this line...)\r
+ touch($cache_file_path);\r
+ \r
+ // Get permission raw data from XML\r
$manifestDoc = new DOMDocument;\r
$manifestDoc->load($android_manifest_file_path);\r
$manifestXpath = new DOMXPath($manifestDoc);\r
$comment = '';\r
}\r
}\r
+\r
+ // Update cache with serialized permissions\r
+ $cache_file_handle = fopen($cache_file_path, 'w');\r
+ fwrite($cache_file_handle, serialize($permissions));\r
+ fclose($cache_file_handle);\r
\r
return $permissions;\r
}\r
\r
\r
function get_app($query_vars) {\r
- $permissions_data = get_android_permissions_array($this->site_path.'/repo/AndroidManifest.xml', $this->site_path.'/repo/strings.xml');\r
+ $permissions_data = get_android_permissions_array($this->site_path.'/repo/AndroidManifest.xml', $this->site_path.'/repo/strings.xml', $this->site_path.'/repo/android-permissions.cache');\r
\r
$xml = simplexml_load_file($this->site_path.'/repo/index.xml');\r
foreach($xml->children() as $app) {\r