2012-06-21 22:50:05 +08:00
|
|
|
#include "IOpenCVEngine.h"
|
|
|
|
#include "CommonPackageManager.h"
|
|
|
|
#include "HardwareDetector.h"
|
|
|
|
#include <utils/Log.h>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#undef LOG_TAG
|
|
|
|
#define LOG_TAG "CommonPackageManager"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
set<string> CommonPackageManager::GetInstalledVersions()
|
|
|
|
{
|
|
|
|
set<string> result;
|
|
|
|
vector<PackageInfo> installed_packages = GetInstalledPackages();
|
2012-09-14 21:20:59 +08:00
|
|
|
|
2012-06-21 22:50:05 +08:00
|
|
|
for (vector<PackageInfo>::const_iterator it = installed_packages.begin(); it != installed_packages.end(); ++it)
|
|
|
|
{
|
2012-10-24 16:47:43 +08:00
|
|
|
string version = it->GetVersion();
|
|
|
|
assert(!version.empty());
|
|
|
|
result.insert(version);
|
2012-06-21 22:50:05 +08:00
|
|
|
}
|
2012-09-14 21:20:59 +08:00
|
|
|
|
2012-06-21 22:50:05 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CommonPackageManager::CheckVersionInstalled(const std::string& version, int platform, int cpu_id)
|
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
LOGD("CommonPackageManager::CheckVersionInstalled() begin");
|
|
|
|
PackageInfo target_package(version, platform, cpu_id);
|
|
|
|
LOGD("GetInstalledPackages() call");
|
|
|
|
vector<PackageInfo> packages = GetInstalledPackages();
|
2012-09-14 21:20:59 +08:00
|
|
|
|
2012-06-21 22:50:05 +08:00
|
|
|
for (vector<PackageInfo>::const_iterator it = packages.begin(); it != packages.end(); ++it)
|
|
|
|
{
|
2012-10-24 16:47:43 +08:00
|
|
|
LOGD("Found package: \"%s\"", it->GetFullName().c_str());
|
2012-06-21 22:50:05 +08:00
|
|
|
}
|
2012-09-14 21:20:59 +08:00
|
|
|
|
2012-06-21 22:50:05 +08:00
|
|
|
if (!packages.empty())
|
|
|
|
{
|
2012-10-24 16:47:43 +08:00
|
|
|
vector<PackageInfo>::const_iterator it = find(packages.begin(), packages.end(), target_package);
|
|
|
|
result = (it != packages.end());
|
2012-06-21 22:50:05 +08:00
|
|
|
}
|
|
|
|
LOGD("CommonPackageManager::CheckVersionInstalled() end");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CommonPackageManager::InstallVersion(const std::string& version, int platform, int cpu_id)
|
|
|
|
{
|
|
|
|
LOGD("CommonPackageManager::InstallVersion() begin");
|
2012-10-17 07:18:30 +08:00
|
|
|
PackageInfo package(version, platform, cpu_id);
|
2012-06-21 22:50:05 +08:00
|
|
|
return InstallPackage(package);
|
|
|
|
}
|
|
|
|
|
|
|
|
string CommonPackageManager::GetPackagePathByVersion(const std::string& version, int platform, int cpu_id)
|
|
|
|
{
|
|
|
|
string result;
|
|
|
|
PackageInfo target_package(version, platform, cpu_id);
|
|
|
|
vector<PackageInfo> all_packages = GetInstalledPackages();
|
|
|
|
vector<PackageInfo> packages;
|
2012-09-14 21:20:59 +08:00
|
|
|
|
2012-06-21 22:50:05 +08:00
|
|
|
for (vector<PackageInfo>::iterator it = all_packages.begin(); it != all_packages.end(); ++it)
|
|
|
|
{
|
2012-10-24 16:47:43 +08:00
|
|
|
LOGD("Check version \"%s\" compatibility with \"%s\"\n", version.c_str(), it->GetVersion().c_str());
|
|
|
|
if (IsVersionCompatible(version, it->GetVersion()))
|
2012-10-17 07:18:30 +08:00
|
|
|
{
|
2012-10-24 16:47:43 +08:00
|
|
|
LOGD("Compatible");
|
|
|
|
packages.push_back(*it);
|
2012-10-17 07:18:30 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-24 16:47:43 +08:00
|
|
|
LOGD("NOT Compatible");
|
2012-10-17 07:18:30 +08:00
|
|
|
}
|
2012-10-24 16:47:43 +08:00
|
|
|
}
|
2012-10-17 07:18:30 +08:00
|
|
|
|
2012-10-24 16:47:43 +08:00
|
|
|
if (!packages.empty())
|
|
|
|
{
|
|
|
|
vector<PackageInfo>::iterator found = find(packages.begin(), packages.end(), target_package);
|
|
|
|
if (packages.end() != found)
|
2012-10-17 07:18:30 +08:00
|
|
|
{
|
|
|
|
result = found->GetInstalationPath();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-24 16:47:43 +08:00
|
|
|
int OptRating = -1;
|
|
|
|
std::vector<std::pair<int, int> >& group = CommonPackageManager::ArmRating;
|
|
|
|
|
|
|
|
if ((cpu_id & ARCH_X86) || (cpu_id & ARCH_X64))
|
|
|
|
group = CommonPackageManager::IntelRating;
|
|
|
|
|
|
|
|
int HardwareRating = GetHardwareRating(platform, cpu_id, group);
|
|
|
|
LOGD("Current hardware platform %d, %d", platform, cpu_id);
|
|
|
|
|
|
|
|
if (-1 == HardwareRating)
|
|
|
|
{
|
|
|
|
LOGE("Cannot calculate rating for current hardware platform!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (vector<PackageInfo>::iterator it = packages.begin(); it != packages.end(); ++it)
|
|
|
|
{
|
|
|
|
int PackageRating = GetHardwareRating(it->GetPlatform(), it->GetCpuID(), group);
|
|
|
|
if (PackageRating >= 0)
|
|
|
|
{
|
|
|
|
if ((PackageRating <= HardwareRating) && (PackageRating > OptRating))
|
|
|
|
{
|
|
|
|
OptRating = PackageRating;
|
|
|
|
found = it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((-1 != OptRating) && (packages.end() != found))
|
|
|
|
{
|
|
|
|
result = found->GetInstalationPath();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOGI("Found package is incompatible with current hardware platform");
|
|
|
|
}
|
|
|
|
}
|
2012-10-17 07:18:30 +08:00
|
|
|
}
|
|
|
|
}
|
2012-09-14 21:20:59 +08:00
|
|
|
|
2012-06-21 22:50:05 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CommonPackageManager::IsVersionCompatible(const std::string& target_version, const std::string& package_version)
|
|
|
|
{
|
|
|
|
assert (target_version.size() == 3);
|
|
|
|
assert (package_version.size() == 3);
|
2012-09-14 21:20:59 +08:00
|
|
|
|
2012-06-21 22:50:05 +08:00
|
|
|
bool result = false;
|
2012-09-14 21:20:59 +08:00
|
|
|
|
2012-06-21 22:50:05 +08:00
|
|
|
// major version is the same and minor package version is above or the same as target.
|
|
|
|
if ((package_version[0] == target_version[0]) && (package_version[1] == target_version[1]) && (package_version[2] >= target_version[2]))
|
|
|
|
{
|
2012-10-17 07:18:30 +08:00
|
|
|
result = true;
|
2012-06-21 22:50:05 +08:00
|
|
|
}
|
2012-09-14 21:20:59 +08:00
|
|
|
|
2012-06-21 22:50:05 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CommonPackageManager::GetHardwareRating(int platform, int cpu_id, const std::vector<std::pair<int, int> >& group)
|
|
|
|
{
|
|
|
|
int result = -1;
|
2012-09-14 21:20:59 +08:00
|
|
|
|
2012-06-21 22:50:05 +08:00
|
|
|
for (size_t i = 0; i < group.size(); i++)
|
|
|
|
{
|
2012-10-17 07:18:30 +08:00
|
|
|
if (group[i] == std::pair<int, int>(platform, cpu_id))
|
|
|
|
{
|
|
|
|
result = i;
|
|
|
|
break;
|
|
|
|
}
|
2012-06-21 22:50:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::pair<int, int> > CommonPackageManager::InitArmRating()
|
|
|
|
{
|
|
|
|
std::vector<std::pair<int, int> > result;
|
2012-09-14 21:20:59 +08:00
|
|
|
|
2012-06-21 22:50:05 +08:00
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv5));
|
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv6));
|
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv6 | FEATURES_HAS_VFPv3d16));
|
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv6 | FEATURES_HAS_VFPv3));
|
2012-09-14 21:20:59 +08:00
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv6 | FEATURES_HAS_VFPv3 | FEATURES_HAS_VFPv3d16));
|
2012-06-21 22:50:05 +08:00
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7));
|
2012-09-14 21:20:59 +08:00
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3d16));
|
2012-06-21 22:50:05 +08:00
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3));
|
2012-09-14 21:20:59 +08:00
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3d16 | FEATURES_HAS_VFPv3));
|
2012-07-12 21:12:16 +08:00
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_NEON));
|
2012-09-14 21:20:59 +08:00
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3d16 | FEATURES_HAS_NEON));
|
2012-06-21 22:50:05 +08:00
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON));
|
2012-09-14 21:20:59 +08:00
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_VFPv3d16 | FEATURES_HAS_NEON));
|
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_TEGRA2, ARCH_ARMv7 | FEATURES_HAS_VFPv3d16));
|
2012-06-21 22:50:05 +08:00
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON));
|
2012-09-14 21:20:59 +08:00
|
|
|
|
2012-06-21 22:50:05 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::pair<int, int> > CommonPackageManager::InitIntelRating()
|
|
|
|
{
|
|
|
|
std::vector<std::pair<int, int> > result;
|
2012-10-17 07:18:30 +08:00
|
|
|
|
2012-06-21 22:50:05 +08:00
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_X64));
|
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_X86 | FEATURES_HAS_SSSE3));
|
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_X86 | FEATURES_HAS_SSE2));
|
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_X86 | FEATURES_HAS_SSE));
|
|
|
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_X86));
|
2012-10-17 07:18:30 +08:00
|
|
|
|
2012-06-21 22:50:05 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::pair<int, int> > CommonPackageManager::IntelRating = CommonPackageManager::InitIntelRating();
|
|
|
|
std::vector<std::pair<int, int> > CommonPackageManager::ArmRating = InitArmRating();
|
|
|
|
|
|
|
|
CommonPackageManager::~CommonPackageManager()
|
|
|
|
{
|
|
|
|
}
|