mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-05 15:00:30 +03:00
Wrapped the android permissions function in a class holding config variables.
This commit is contained in:
parent
044914777f
commit
5f4a422b62
2 changed files with 106 additions and 94 deletions
|
|
@ -1,29 +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';
|
||||
// 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';
|
||||
// Class that provides PHP-friendly android permissions information from the raw Andoid source XML files that describes the permissions.
|
||||
class AndroidPermissions
|
||||
{
|
||||
|
||||
$cache_file_path = 'android-permissions.cache';
|
||||
// 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.
|
||||
private $android_manifest_file_path;
|
||||
// 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.
|
||||
private $android_strings_file_path;
|
||||
// Path to the file where the resulting permissions data will be cached. NOTE: Must be writable by PHP!
|
||||
private $cache_file_path;
|
||||
|
||||
public function __construct($android_manifest_file_path_in = 'AndroidManifest.xml', $android_strings_file_path_in = 'strings.xml', $cache_file_path_in = 'android-permissions.cache') {
|
||||
$this->android_manifest_file_path = $android_manifest_file_path_in;
|
||||
$this->android_strings_file_path = $android_strings_file_path_in;
|
||||
$this->cache_file_path = $cache_file_path_in;
|
||||
}
|
||||
|
||||
// Returns an associative array with android permissions and data about them
|
||||
function get_android_permissions_array($android_manifest_file_path, $android_strings_file_path, $cache_file_path) {
|
||||
function get_permissions_array() {
|
||||
|
||||
// Check status of cache
|
||||
$android_manifest_file_stat = stat($android_manifest_file_path);
|
||||
$android_manifest_file_stat = stat($this->android_manifest_file_path);
|
||||
$android_manifest_file_mtime = $android_manifest_file_stat['mtime'];
|
||||
$android_strings_file_stat = stat($android_strings_file_path);
|
||||
$android_strings_file_stat = stat($this->android_strings_file_path);
|
||||
$android_strings_file_mtime = $android_strings_file_stat['mtime'];
|
||||
$cache_file_mtime = 0;
|
||||
if(file_exists($cache_file_path)) {
|
||||
$cache_file_stat = stat($cache_file_path);
|
||||
if(file_exists($this->cache_file_path)) {
|
||||
$cache_file_stat = stat($this->cache_file_path);
|
||||
$cache_file_mtime = $cache_file_stat['mtime'];
|
||||
}
|
||||
|
||||
// If the cache is fresh, use it instead
|
||||
if($android_manifest_file_mtime < $cache_file_mtime && $android_strings_file_mtime < $cache_file_mtime ) {
|
||||
$cache_file_handle = fopen($cache_file_path, 'r');
|
||||
$cache_file_content = fread($cache_file_handle, filesize($cache_file_path));
|
||||
$cache_file_handle = fopen($this->cache_file_path, 'r');
|
||||
$cache_file_content = fread($cache_file_handle, filesize($this->cache_file_path));
|
||||
fclose($cache_file_handle);
|
||||
|
||||
$permissions = unserialize($cache_file_content);
|
||||
|
|
@ -32,15 +42,15 @@ function get_android_permissions_array($android_manifest_file_path, $android_str
|
|||
}
|
||||
|
||||
// We are updating the cache, touch the file (note: race condition possible between stating the cache file above and this line...)
|
||||
touch($cache_file_path);
|
||||
touch($this->cache_file_path);
|
||||
|
||||
// Get permission raw data from XML
|
||||
$manifestDoc = new DOMDocument;
|
||||
$manifestDoc->load($android_manifest_file_path);
|
||||
$manifestDoc->load($this->android_manifest_file_path);
|
||||
$manifestXpath = new DOMXPath($manifestDoc);
|
||||
|
||||
$stringsDoc = new DOMDocument;
|
||||
$stringsDoc->load($android_strings_file_path);
|
||||
$stringsDoc->load($this->android_strings_file_path);
|
||||
$stringsXpath = new DOMXPath($stringsDoc);
|
||||
|
||||
$comment = '';
|
||||
|
|
@ -100,4 +110,5 @@ function get_android_permissions_array($android_manifest_file_path, $android_str
|
|||
|
||||
return $permissions;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -103,7 +103,8 @@ class FDroid
|
|||
|
||||
|
||||
function get_app($query_vars) {
|
||||
$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');
|
||||
$permissions_object = new AndroidPermissions($this->site_path.'/repo/AndroidManifest.xml', $this->site_path.'/repo/strings.xml', $this->site_path.'/repo/android-permissions.cache');
|
||||
$permissions_data = $permissions_object->get_permissions_array();
|
||||
|
||||
$xml = simplexml_load_file($this->site_path.'/repo/index.xml');
|
||||
foreach($xml->children() as $app) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue