From 5ffbcf1e1687c3f33931d2f4c9d0ccc9325c2ac7 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 2 Oct 2012 15:02:04 +0400 Subject: [PATCH] MIPS arch support added to OpenCV manager; Internal OpenCV library in OpenCV Manager support added; Unit tests improved, platform specific tests added, MIPS related tests added; Code refactoring done. --- android/service/engine/AndroidManifest.xml | 4 +- android/service/engine/jni/Android.mk | 2 + android/service/engine/jni/Application.mk | 2 +- .../jni/BinderComponent/HardwareDetector.cpp | 25 +-- .../jni/BinderComponent/HardwareDetector.h | 1 + .../jni/BinderComponent/OpenCVEngine.cpp | 8 +- .../engine/jni/BinderComponent/ProcReader.h | 2 + .../jni/BinderComponent/TegraDetector.cpp | 4 +- .../jni/JNIWrapper/HardwareDetector_jni.cpp | 8 +- .../jni/JNIWrapper/HardwareDetector_jni.h | 16 +- .../jni/JNIWrapper/OpenCVEngine_jni.cpp | 2 +- .../jni/NativeService/CommonPackageManager.h | 8 +- .../NativeService/NativePackageManager.cpp | 2 +- .../jni/NativeService/NativePackageManager.h | 2 +- .../engine/jni/NativeService/PackageInfo.cpp | 113 ++++++++++--- .../engine/jni/NativeService/PackageInfo.h | 4 +- .../engine/jni/NativeService/ServiceMain.cpp | 6 +- .../jni/Tests/HardwareDetectionTest.cpp | 45 ++++-- .../engine/jni/Tests/OpenCVEngineTest.cpp | 150 +++++++++++++----- .../engine/jni/Tests/PackageInfoTest.cpp | 21 ++- .../engine/jni/Tests/PackageManagmentTest.cpp | 26 ++- android/service/engine/jni/Tests/TestMain.cpp | 3 +- android/service/engine/jni/Tests/Tests.mk | 1 + .../service/engine/jni/include/EngineCommon.h | 2 + .../engine/jni/include/IOpenCVEngine.h | 2 + .../org/opencv/engine/HardwareDetector.java | 29 ++-- .../org/opencv/engine/MarketConnector.java | 19 ++- .../engine/manager/HardwareDetector.java | 52 ------ .../engine/manager/ManagerActivity.java | 98 ++++++------ .../engine/manager/OpenCVPackageInfo.java | 16 -- 30 files changed, 421 insertions(+), 252 deletions(-) delete mode 100644 android/service/engine/src/org/opencv/engine/manager/HardwareDetector.java delete mode 100644 android/service/engine/src/org/opencv/engine/manager/OpenCVPackageInfo.java diff --git a/android/service/engine/AndroidManifest.xml b/android/service/engine/AndroidManifest.xml index b8aea3ee46..6359fe2371 100644 --- a/android/service/engine/AndroidManifest.xml +++ b/android/service/engine/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="17" + android:versionName="1.7" > diff --git a/android/service/engine/jni/Android.mk b/android/service/engine/jni/Android.mk index 4ba317603d..a33466c5c5 100644 --- a/android/service/engine/jni/Android.mk +++ b/android/service/engine/jni/Android.mk @@ -26,6 +26,7 @@ LOCAL_C_INCLUDES := \ LOCAL_CFLAGS += -DPLATFORM_ANDROID LOCAL_CFLAGS += -D__SUPPORT_ARMEABI_V7A_FEATURES LOCAL_CFLAGS += -D__SUPPORT_TEGRA3 +LOCAL_CFLAGS += -D__SUPPORT_MIPS #LOCAL_CFLAGS += -D__SUPPORT_ARMEABI_FEATURES LOCAL_PRELINK_MODULE := false @@ -67,6 +68,7 @@ LOCAL_PRELINK_MODULE := false LOCAL_CFLAGS += -DPLATFORM_ANDROID LOCAL_CFLAGS += -D__SUPPORT_ARMEABI_V7A_FEATURES LOCAL_CFLAGS += -D__SUPPORT_TEGRA3 +LOCAL_CFLAGS += -D__SUPPORT_MIPS #LOCAL_CFLAGS += -D__SUPPORT_ARMEABI_FEATURES LOCAL_MODULE := libOpenCVEngine_jni diff --git a/android/service/engine/jni/Application.mk b/android/service/engine/jni/Application.mk index e89251573b..4230cd26e0 100644 --- a/android/service/engine/jni/Application.mk +++ b/android/service/engine/jni/Application.mk @@ -1,4 +1,4 @@ -APP_ABI := armeabi x86 +APP_ABI := armeabi x86 mips APP_PLATFORM := android-8 APP_STL := stlport_static APP_CPPFLAGS := -fno-rtti -fno-exceptions diff --git a/android/service/engine/jni/BinderComponent/HardwareDetector.cpp b/android/service/engine/jni/BinderComponent/HardwareDetector.cpp index ccfad3ccf5..ea20431df1 100644 --- a/android/service/engine/jni/BinderComponent/HardwareDetector.cpp +++ b/android/service/engine/jni/BinderComponent/HardwareDetector.cpp @@ -13,7 +13,7 @@ int GetCpuID() map cpu_info = GetCpuInfo(); map::const_iterator it; -#ifdef __i386__ +#if defined(__i386__) LOGD("Using X86 HW detector"); result |= ARCH_X86; it = cpu_info.find("flags"); @@ -33,6 +33,12 @@ int GetCpuID() result |= FEATURES_HAS_SSSE3; } } +#elif defined(__mips) + #ifdef __SUPPORT_MIPS + result |= ARCH_MIPS; + #else + result = ARCH_UNKNOWN; + #endif #else LOGD("Using ARM HW detector"); it = cpu_info.find("Processor"); @@ -64,7 +70,6 @@ int GetCpuID() { result |= ARCH_ARMv5; } - } } } @@ -108,27 +113,27 @@ string GetPlatformName() map cpu_info = GetCpuInfo(); string hardware_name = ""; map::const_iterator hw_iterator = cpu_info.find("Hardware"); - + if (cpu_info.end() != hw_iterator) { hardware_name = hw_iterator->second; } - - return hardware_name; + + return hardware_name; } int GetProcessorCount() -{ +{ FILE* cpuPossible = fopen("/sys/devices/system/cpu/possible", "r"); if(!cpuPossible) return 1; - + char buf[2000]; //big enough for 1000 CPUs in worst possible configuration char* pbuf = fgets(buf, sizeof(buf), cpuPossible); fclose(cpuPossible); if(!pbuf) return 1; - + //parse string of form "0-1,3,5-7,10,13-15" int cpusAvailable = 0; @@ -157,7 +162,7 @@ int GetProcessorCount() int DetectKnownPlatforms() { int tegra_status = DetectTegra(); - + if (3 == tegra_status) { return PLATFORM_TEGRA3; @@ -166,7 +171,7 @@ int DetectKnownPlatforms() { return PLATFORM_UNKNOWN; } - + // NOTE: Uncomment when all Tegras will be supported /*if (tegra_status > 0) { diff --git a/android/service/engine/jni/BinderComponent/HardwareDetector.h b/android/service/engine/jni/BinderComponent/HardwareDetector.h index 9242143bb0..e049db9c5f 100644 --- a/android/service/engine/jni/BinderComponent/HardwareDetector.h +++ b/android/service/engine/jni/BinderComponent/HardwareDetector.h @@ -10,6 +10,7 @@ #define ARCH_ARMv6 134217728L #define ARCH_ARMv7 268435456L #define ARCH_ARMv8 536870912L +#define ARCH_MIPS 1073741824L #define FEATURES_HAS_VFPv3d16 1L #define FEATURES_HAS_VFPv3 2L diff --git a/android/service/engine/jni/BinderComponent/OpenCVEngine.cpp b/android/service/engine/jni/BinderComponent/OpenCVEngine.cpp index b1d0779b0e..7868062d33 100644 --- a/android/service/engine/jni/BinderComponent/OpenCVEngine.cpp +++ b/android/service/engine/jni/BinderComponent/OpenCVEngine.cpp @@ -79,7 +79,7 @@ OpenCVEngine::OpenCVEngine(IPackageManager* PkgManager): int32_t OpenCVEngine::GetVersion() { - return OPEN_CV_ENGINE_VERSION; + return OPEN_CV_ENGINE_VERSION; } String16 OpenCVEngine::GetLibPathByVersion(android::String16 version) @@ -124,17 +124,17 @@ android::String16 OpenCVEngine::GetLibraryList(android::String16 version) std::string tmp = PackageManager->GetPackagePathByVersion(norm_version, Platform, CpuID); if (!tmp.empty()) { - tmp += "/libopencvinfo.so"; + tmp += (std::string("/") + LIB_OPENCV_INFO_NAME); LOGD("Trying to load info library \"%s\"", tmp.c_str()); - void *handle; + void* handle; char* (*info_func)(); handle = dlopen(tmp.c_str(), RTLD_LAZY); if (handle) { - const char *error; + const char* error; dlerror(); *(void **) (&info_func) = dlsym(handle, "GetLibraryList"); diff --git a/android/service/engine/jni/BinderComponent/ProcReader.h b/android/service/engine/jni/BinderComponent/ProcReader.h index 7b50028fc0..333e7c2937 100644 --- a/android/service/engine/jni/BinderComponent/ProcReader.h +++ b/android/service/engine/jni/BinderComponent/ProcReader.h @@ -20,6 +20,8 @@ #define CPU_INFO_ARCH_X86_STR "x86" +#define CPU_INFO_ARCH_MIPS_STR "MIPS" + // public part std::map GetCpuInfo(); diff --git a/android/service/engine/jni/BinderComponent/TegraDetector.cpp b/android/service/engine/jni/BinderComponent/TegraDetector.cpp index 7b383cc24a..18f31dac6f 100644 --- a/android/service/engine/jni/BinderComponent/TegraDetector.cpp +++ b/android/service/engine/jni/BinderComponent/TegraDetector.cpp @@ -34,7 +34,7 @@ int DetectTegra() result = 2; break; } - + if (0 == strncmp(tmpbuf, tegra3_config, len3)) { result = 3; @@ -48,6 +48,6 @@ int DetectTegra() { result = TEGRA_DETECTOR_ERROR; } - + return result; } \ No newline at end of file diff --git a/android/service/engine/jni/JNIWrapper/HardwareDetector_jni.cpp b/android/service/engine/jni/JNIWrapper/HardwareDetector_jni.cpp index 6e80282427..b55c0b8e3d 100644 --- a/android/service/engine/jni/JNIWrapper/HardwareDetector_jni.cpp +++ b/android/service/engine/jni/JNIWrapper/HardwareDetector_jni.cpp @@ -3,23 +3,23 @@ #include #include -JNIEXPORT jint JNICALL Java_org_opencv_engine_manager_HardwareDetector_GetCpuID(JNIEnv* env, jclass) +JNIEXPORT jint JNICALL Java_org_opencv_engine_HardwareDetector_GetCpuID(JNIEnv* env, jclass) { return GetCpuID(); } -JNIEXPORT jstring JNICALL Java_org_opencv_engine_manager_HardwareDetector_GetPlatformName(JNIEnv* env, jclass) +JNIEXPORT jstring JNICALL Java_org_opencv_engine_HardwareDetector_GetPlatformName(JNIEnv* env, jclass) { std::string hardware_name = GetPlatformName(); return env->NewStringUTF(hardware_name.c_str()); } -JNIEXPORT jint JNICALL Java_org_opencv_engine_manager_HardwareDetector_GetProcessorCount(JNIEnv* env, jclass) +JNIEXPORT jint JNICALL Java_org_opencv_engine_HardwareDetector_GetProcessorCount(JNIEnv* env, jclass) { return GetProcessorCount(); } -JNIEXPORT jint JNICALL Java_org_opencv_engine_manager_HardwareDetector_DetectKnownPlatforms(JNIEnv* env, jclass) +JNIEXPORT jint JNICALL Java_org_opencv_engine_HardwareDetector_DetectKnownPlatforms(JNIEnv* env, jclass) { return DetectKnownPlatforms(); } \ No newline at end of file diff --git a/android/service/engine/jni/JNIWrapper/HardwareDetector_jni.h b/android/service/engine/jni/JNIWrapper/HardwareDetector_jni.h index 7dcc0bf953..bd397b2f29 100644 --- a/android/service/engine/jni/JNIWrapper/HardwareDetector_jni.h +++ b/android/service/engine/jni/JNIWrapper/HardwareDetector_jni.h @@ -10,35 +10,35 @@ extern "C" { #endif /* - * Class: org_opencv_engine_manager_HardwareDetector + * Class: org_opencv_engine_HardwareDetector * Method: GetCpuID * Signature: ()I */ -JNIEXPORT jint JNICALL Java_org_opencv_engine_manager_HardwareDetector_GetCpuID +JNIEXPORT jint JNICALL Java_org_opencv_engine_HardwareDetector_GetCpuID (JNIEnv *, jclass); /* - * Class: org_opencv_engine_manager_HardwareDetector + * Class: org_opencv_engine_HardwareDetector * Method: GetPlatformName * Signature: ()Ljava/lang/String; */ -JNIEXPORT jstring JNICALL Java_org_opencv_engine_manager_HardwareDetector_GetPlatformName +JNIEXPORT jstring JNICALL Java_org_opencv_engine_HardwareDetector_GetPlatformName (JNIEnv *, jclass); /* - * Class: org_opencv_engine_manager_HardwareDetector + * Class: org_opencv_engine_HardwareDetector * Method: GetProcessorCount * Signature: ()I */ -JNIEXPORT jint JNICALL Java_org_opencv_engine_manager_HardwareDetector_GetProcessorCount +JNIEXPORT jint JNICALL Java_org_opencv_engine_HardwareDetector_GetProcessorCount (JNIEnv *, jclass); /* - * Class: org_opencv_engine_manager_HardwareDetector + * Class: org_opencv_engine_HardwareDetector * Method: DetectKnownPlatforms * Signature: ()I */ -JNIEXPORT jint JNICALL Java_org_opencv_engine_manager_HardwareDetector_DetectKnownPlatforms +JNIEXPORT jint JNICALL Java_org_opencv_engine_HardwareDetector_DetectKnownPlatforms (JNIEnv *, jclass); #ifdef __cplusplus diff --git a/android/service/engine/jni/JNIWrapper/OpenCVEngine_jni.cpp b/android/service/engine/jni/JNIWrapper/OpenCVEngine_jni.cpp index cd4b38c5b0..a4cfea95ba 100644 --- a/android/service/engine/jni/JNIWrapper/OpenCVEngine_jni.cpp +++ b/android/service/engine/jni/JNIWrapper/OpenCVEngine_jni.cpp @@ -37,7 +37,7 @@ JNIEXPORT jboolean JNICALL Java_org_opencv_engine_BinderConnector_Init(JNIEnv* e if (NULL == PackageManager) { JavaVM* jvm; - env->GetJavaVM(&jvm);; + env->GetJavaVM(&jvm); PackageManager = new JavaBasedPackageManager(jvm, env->NewGlobalRef(market)); } if (PackageManager) diff --git a/android/service/engine/jni/NativeService/CommonPackageManager.h b/android/service/engine/jni/NativeService/CommonPackageManager.h index 1e82a419bd..86f31788a1 100644 --- a/android/service/engine/jni/NativeService/CommonPackageManager.h +++ b/android/service/engine/jni/NativeService/CommonPackageManager.h @@ -19,15 +19,15 @@ public: protected: static std::vector > ArmRating; static std::vector > IntelRating; - + static std::vector > InitArmRating(); static std::vector > InitIntelRating(); - + bool IsVersionCompatible(const std::string& target_version, const std::string& package_version); int GetHardwareRating(int platform, int cpu_id, const std::vector >& group); - + virtual bool InstallPackage(const PackageInfo& package) = 0; - virtual std::vector GetInstalledPackages() = 0; + virtual std::vector GetInstalledPackages() = 0; }; diff --git a/android/service/engine/jni/NativeService/NativePackageManager.cpp b/android/service/engine/jni/NativeService/NativePackageManager.cpp index bbd21760a2..aba13de1e9 100644 --- a/android/service/engine/jni/NativeService/NativePackageManager.cpp +++ b/android/service/engine/jni/NativeService/NativePackageManager.cpp @@ -10,7 +10,7 @@ bool NativePackageManager::InstallPackage(const PackageInfo& package) vector NativePackageManager::GetInstalledPackages() { vector result; - + return result; } diff --git a/android/service/engine/jni/NativeService/NativePackageManager.h b/android/service/engine/jni/NativeService/NativePackageManager.h index 341fe6853a..c74a083598 100644 --- a/android/service/engine/jni/NativeService/NativePackageManager.h +++ b/android/service/engine/jni/NativeService/NativePackageManager.h @@ -10,7 +10,7 @@ public: virtual ~NativePackageManager(); protected: virtual bool InstallPackage(const PackageInfo& package); - virtual std::vector GetInstalledPackages(); + virtual std::vector GetInstalledPackages(); }; #endif \ No newline at end of file diff --git a/android/service/engine/jni/NativeService/PackageInfo.cpp b/android/service/engine/jni/NativeService/PackageInfo.cpp index 65828e7402..1076245661 100644 --- a/android/service/engine/jni/NativeService/PackageInfo.cpp +++ b/android/service/engine/jni/NativeService/PackageInfo.cpp @@ -6,23 +6,25 @@ #include #include #include +#include using namespace std; map PackageInfo::InitPlatformNameMap() { map result; - + // TODO: Do not forget to add Platrfom constant to HardwareDetector.h result[PLATFORM_TEGRA] = PLATFORM_TEGRA_NAME; result[PLATFORM_TEGRA2] = PLATFORM_TEGRA2_NAME; result[PLATFORM_TEGRA3] = PLATFORM_TEGRA3_NAME; - + return result; } const map PackageInfo::PlatformNameMap = InitPlatformNameMap(); const string PackageInfo::BasePackageName = "org.opencv.lib"; +const string DEFAULT_ENGINE_INSTALL_PATH = "/data/data/org.opencv.engine"; inline string JoinARMFeatures(int cpu_id) { @@ -32,7 +34,7 @@ inline string JoinARMFeatures(int cpu_id) { if (!((ARCH_ARMv5 & cpu_id) || (ARCH_ARMv6 & cpu_id) ||(ARCH_ARMv7 & cpu_id))) result = string(FEATURES_HAS_NEON2_NAME); - } + } else if (FEATURES_HAS_NEON & cpu_id) { if (!((ARCH_ARMv5 & cpu_id) || (ARCH_ARMv6 & cpu_id))) @@ -48,14 +50,14 @@ inline string JoinARMFeatures(int cpu_id) if ((ARCH_ARMv5 & cpu_id) || (ARCH_ARMv6 & cpu_id)) result = string(FEATURES_HAS_VFPv3d16_NAME); } - + return result; } inline int SplitARMFeatures(const vector& features) { int result = 0; - + for (size_t i = 3; i < features.size(); i++) { if (FEATURES_HAS_VFPv3_NAME == features[i]) @@ -75,14 +77,14 @@ inline int SplitARMFeatures(const vector& features) result |= FEATURES_HAS_NEON2; } } - + return result; } inline string JoinIntelFeatures(int cpu_id) { string result; - + if (FEATURES_HAS_SSSE3 & cpu_id) { result = FEATURES_HAS_SSSE3_NAME; @@ -95,14 +97,14 @@ inline string JoinIntelFeatures(int cpu_id) { result = FEATURES_HAS_SSE_NAME; } - + return result; } inline int SplitIntelFeatures(const vector& features) { int result = 0; - + for (size_t i = 3; i < features.size(); i++) { if (FEATURES_HAS_SSSE3_NAME == features[i]) @@ -117,15 +119,15 @@ inline int SplitIntelFeatures(const vector& features) { result |= FEATURES_HAS_SSE; } - } - + } + return result; } inline string SplitVersion(const vector& features, const string& package_version) { string result; - + if ((features.size() > 1) && ('v' == features[1][0])) { result = features[1].substr(1); @@ -135,7 +137,7 @@ inline string SplitVersion(const vector& features, const string& package { // TODO: Report package name format error } - + return result; } @@ -143,17 +145,17 @@ inline string JoinPlatform(int platform) { string result; map::const_iterator it = PackageInfo::PlatformNameMap.find(platform); - + assert(PackageInfo::PlatformNameMap.end() != it); result = it->second; - + return result; } inline int SplitPlatfrom(const vector& features) { int result = 0; - + if (features.size() > 2) { string tmp = features[2]; @@ -174,7 +176,7 @@ inline int SplitPlatfrom(const vector& features) { // TODO: Report package name format error } - + return result; } @@ -185,7 +187,7 @@ inline int SplitPlatfrom(const vector& features) * If platform is known third part is platform name * If platform is unknown it is defined by hardware capabilities using pattern: __ * Example: armv7_neon, armv5_vfpv3 - */ + */ PackageInfo::PackageInfo(const string& version, int platform, int cpu_id, std::string install_path): Version(version), Platform(platform), @@ -284,6 +286,12 @@ PackageInfo::PackageInfo(const string& version, int platform, int cpu_id, std::s // FullName += string("_") + features; //} } +#ifdef __SUPPORT_MIPS + else if (ARCH_MIPS & CpuID) + { + FullName += string("_") + ARCH_MIPS_NAME; + } +#endif else { LOGD("PackageInfo::PackageInfo: package arch unknown"); @@ -300,24 +308,77 @@ PackageInfo::PackageInfo(const string& version, int platform, int cpu_id, std::s Platform = PLATFORM_UNKNOWN; } } - + if (!FullName.empty()) { InstallPath = install_path + FullName + "/lib"; } } -PackageInfo::PackageInfo(const string& fullname, const string& install_path, const string& package_version): +PackageInfo::PackageInfo(const string& fullname, const string& install_path, string package_version): FullName(fullname), InstallPath(install_path) { LOGD("PackageInfo::PackageInfo(\"%s\", \"%s\", \"%s\")", fullname.c_str(), install_path.c_str(), package_version.c_str()); - + assert(!fullname.empty()); assert(!install_path.empty()); - + + if (OPENCV_ENGINE_PACKAGE == fullname) + { + // Science version 1.7 OpenCV Manager has it's own version of OpenCV inside + // Load libopencv_info.so to understand OpenCV version, platform and other features + std::string tmp; + if (install_path.empty()) + { + tmp = std::string(DEFAULT_ENGINE_INSTALL_PATH) + "/" + LIB_OPENCV_INFO_NAME; + } + else + { + tmp = install_path + "/" + LIB_OPENCV_INFO_NAME; + } + + LOGD("Trying to load info library \"%s\"", tmp.c_str()); + + void* handle; + const char* (*name_func)(); + const char* (*revision_func)(); + + handle = dlopen(tmp.c_str(), RTLD_LAZY); + if (handle) + { + const char* error; + + dlerror(); + *(void **) (&name_func) = dlsym(handle, "GetPackageName"); + *(void **) (&revision_func) = dlsym(handle, "GetRevision"); + error = dlerror(); + + if (!error && revision_func && name_func) + { + FullName = std::string((*name_func)()); + package_version = std::string((*revision_func)()); + dlclose(handle); + LOGI("OpenCV package \"%s\" revision \"%s\" found", FullName.c_str(), package_version.c_str()); + } + else + { + LOGE("Library loading error (%x, %x): \"%s\"", name_func, revision_func, error); + } + } + else + { + LOGI("Info library not found in package"); + LOGI("OpenCV Manager package does not contain any verison of OpenCV library"); + Version.clear(); + CpuID = ARCH_UNKNOWN; + Platform = PLATFORM_UNKNOWN; + return; + } + } + vector features = SplitStringVector(FullName, '_'); - + if (!features.empty() && (BasePackageName == features[0])) { Version = SplitVersion(features, package_version); @@ -363,6 +424,12 @@ PackageInfo::PackageInfo(const string& fullname, const string& install_path, con { CpuID = ARCH_X64 | SplitIntelFeatures(features); } +#ifdef __SUPPORT_MIPS + else if (ARCH_MIPS_NAME == features[2]) + { + CpuID = ARCH_MIPS; + } +#endif else { LOGD("It is not OpenCV library package for this platform"); diff --git a/android/service/engine/jni/NativeService/PackageInfo.h b/android/service/engine/jni/NativeService/PackageInfo.h index 216ad8f43a..05d9098d6b 100644 --- a/android/service/engine/jni/NativeService/PackageInfo.h +++ b/android/service/engine/jni/NativeService/PackageInfo.h @@ -6,11 +6,13 @@ #define ARCH_X86_NAME "x86" #define ARCH_X64_NAME "x64" +#define ARCH_MIPS_NAME "mips" #define ARCH_ARMv5_NAME "armv5" #define ARCH_ARMv6_NAME "armv6" #define ARCH_ARMv7_NAME "armv7a" #define ARCH_ARMv8_NAME "armv8" + #define FEATURES_HAS_VFPv3d16_NAME "vfpv3d16" #define FEATURES_HAS_VFPv3_NAME "vfpv3" #define FEATURES_HAS_NEON_NAME "neon" @@ -29,7 +31,7 @@ class PackageInfo { public: PackageInfo(const std::string& version, int platform, int cpu_id, std::string install_path = "/data/data/"); - PackageInfo(const std::string& fullname, const std::string& install_path, const std::string& package_version = "0.0"); + PackageInfo(const std::string& fullname, const std::string& install_path, std::string package_version = "0.0"); std::string GetFullName() const; std::string GetVersion() const; int GetPlatform() const; diff --git a/android/service/engine/jni/NativeService/ServiceMain.cpp b/android/service/engine/jni/NativeService/ServiceMain.cpp index abaaca8883..66ea995980 100644 --- a/android/service/engine/jni/NativeService/ServiceMain.cpp +++ b/android/service/engine/jni/NativeService/ServiceMain.cpp @@ -19,14 +19,14 @@ int main(int argc, char *argv[]) LOGI("OpenCVEngine native service starting"); IPackageManager* PackageManager = new NativePackageManager(); sp Engine = new OpenCVEngine(PackageManager); - + defaultServiceManager()->addService(IOpenCVEngine::descriptor, Engine); LOGI("OpenCVEngine native service started successfully"); ProcessState::self()->startThreadPool(); IPCThreadState::self()->joinThreadPool(); LOGI("OpenCVEngine native service finished"); - + delete PackageManager; - + return 0; } \ No newline at end of file diff --git a/android/service/engine/jni/Tests/HardwareDetectionTest.cpp b/android/service/engine/jni/Tests/HardwareDetectionTest.cpp index 7f85c6b8d2..b62e2c994d 100644 --- a/android/service/engine/jni/Tests/HardwareDetectionTest.cpp +++ b/android/service/engine/jni/Tests/HardwareDetectionTest.cpp @@ -108,6 +108,12 @@ TEST(Split, SplitMultiElementString) EXPECT_FALSE(b.find("eee") == b.end()); } +TEST(CpuCount, CheckNonZero) +{ + EXPECT_TRUE(GetProcessorCount() != 0); + EXPECT_TRUE(a.find("") == a.end()); +} + TEST(GetCpuInfo, GetCpuInfo) { map a = GetCpuInfo(); @@ -115,22 +121,38 @@ TEST(GetCpuInfo, GetCpuInfo) EXPECT_TRUE(a.find("") == a.end()); } -TEST(TegraDetector, Detect) -{ - EXPECT_TRUE(DetectTegra() != 0); -} - -TEST(CpuCount, CheckNonZero) -{ - EXPECT_TRUE(GetProcessorCount() != 0); -} - TEST(CpuID, CheckNotEmpy) { int cpu_id = GetCpuID(); EXPECT_NE(0, cpu_id); } +#ifdef __i386__ +TEST(CpuID, CheckX86) +{ + int cpu_id = GetCpuID(); + EXPECT_TRUE(cpu_id & ARCH_X86); +} + +TEST(CpuID, CheckSSE2) +{ + int cpu_id = GetCpuID(); + EXPECT_TRUE(cpu_id & FEATURES_HAS_SSE2); +} +#elseif __mips + #ifdef __SUPPORT_MIPS + TEST(CpuID, CheckMips) + { + int cpu_id = GetCpuID(); + EXPECT_TRUE(cpu_id & ARCH_MIPS); + } + #endif +#else +TEST(TegraDetector, Detect) +{ + EXPECT_TRUE(DetectTegra() != 0); +} + TEST(CpuID, CheckArmV7) { int cpu_id = GetCpuID(); @@ -152,4 +174,5 @@ TEST(CpuID, CheckVFPv3) TEST(PlatfromDetector, CheckTegra) { EXPECT_NE(PLATFORM_UNKNOWN, DetectKnownPlatforms()); -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/android/service/engine/jni/Tests/OpenCVEngineTest.cpp b/android/service/engine/jni/Tests/OpenCVEngineTest.cpp index 4ea8b3d2ea..aabc729b94 100644 --- a/android/service/engine/jni/Tests/OpenCVEngineTest.cpp +++ b/android/service/engine/jni/Tests/OpenCVEngineTest.cpp @@ -20,7 +20,7 @@ class ServiceStarter public: ServiceStarter() { - PackageManager = new PackageManagerStub(); + PackageManager = new PackageManagerStub(); Engine = new OpenCVEngine(PackageManager); defaultServiceManager()->addService(IOpenCVEngine::descriptor, Engine); @@ -36,23 +36,23 @@ public: sp Engine; }; -static ServiceStarter Starter; +static ServiceStarter Starter; sp InitConnect() { sp ServiceManager = defaultServiceManager(); sp EngineService; sp Engine; - + do { EngineService = ServiceManager->getService(IOpenCVEngine::descriptor); if (EngineService != 0) break; usleep(500000); // 0.5 s } while(true); - + Engine = interface_cast(EngineService); - + return Engine; } @@ -64,6 +64,69 @@ TEST(OpenCVEngineTest, GetVersion) EXPECT_EQ(OPEN_CV_ENGINE_VERSION, Version); } +#if defined(__i386__) +TEST(OpenCVEngineTest, GetPathForExecHWExistVersion) +{ + sp Engine = InitConnect(); + Starter.PackageManager->InstalledPackages.clear(); + Starter.PackageManager->InstallVersion("240", PLATFORM_UNKNOWN, ARCH_X86); + EXPECT_FALSE(NULL == Engine.get()); + String16 result = Engine->GetLibPathByVersion(String16("2.4")); + EXPECT_STREQ("/data/data/org.opencv.lib_v24_x86/lib", String8(result).string()); +} + +TEST(OpenCVEngineTest, GetPathForExecHWOldVersion) +{ + sp Engine = InitConnect(); + Starter.PackageManager->InstalledPackages.clear(); + Starter.PackageManager->InstallVersion("242", PLATFORM_UNKNOWN, ARCH_X86); + EXPECT_FALSE(NULL == Engine.get()); + String16 result = Engine->GetLibPathByVersion(String16("2.4.1")); + EXPECT_STREQ("/data/data/org.opencv.lib_v24_x86/lib", String8(result).string()); +} + +TEST(OpenCVEngineTest, GetPathForExecHWNewVersion) +{ + sp Engine = InitConnect(); + Starter.PackageManager->InstalledPackages.clear(); + Starter.PackageManager->InstallVersion("241", PLATFORM_UNKNOWN, ARCH_X86); + EXPECT_FALSE(NULL == Engine.get()); + String16 result = Engine->GetLibPathByVersion(String16("2.4.2")); + EXPECT_EQ(0, result.size()); +} + +#elif defined (__mips) +TEST(OpenCVEngineTest, GetPathForExecHWExistVersion) +{ + sp Engine = InitConnect(); + Starter.PackageManager->InstalledPackages.clear(); + Starter.PackageManager->InstallVersion("240", PLATFORM_UNKNOWN, ARCH_MIPS); + EXPECT_FALSE(NULL == Engine.get()); + String16 result = Engine->GetLibPathByVersion(String16("2.4")); + EXPECT_STREQ("/data/data/org.opencv.lib_v24_mips/lib", String8(result).string()); +} + +TEST(OpenCVEngineTest, GetPathForExecHWOldVersion) +{ + sp Engine = InitConnect(); + Starter.PackageManager->InstalledPackages.clear(); + Starter.PackageManager->InstallVersion("242", PLATFORM_UNKNOWN, ARCH_MIPS); + EXPECT_FALSE(NULL == Engine.get()); + String16 result = Engine->GetLibPathByVersion(String16("2.4.1")); + EXPECT_STREQ("/data/data/org.opencv.lib_v24_mips/lib", String8(result).string()); +} + +TEST(OpenCVEngineTest, GetPathForExecHWNewVersion) +{ + sp Engine = InitConnect(); + Starter.PackageManager->InstalledPackages.clear(); + Starter.PackageManager->InstallVersion("241", PLATFORM_UNKNOWN, ARCH_MIPS); + EXPECT_FALSE(NULL == Engine.get()); + String16 result = Engine->GetLibPathByVersion(String16("2.4.2")); + EXPECT_EQ(0, result.size()); +} + +#else TEST(OpenCVEngineTest, GetPathForExecHWExistVersion) { sp Engine = InitConnect(); @@ -71,15 +134,15 @@ TEST(OpenCVEngineTest, GetPathForExecHWExistVersion) Starter.PackageManager->InstallVersion("240", PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_NEON); EXPECT_FALSE(NULL == Engine.get()); String16 result = Engine->GetLibPathByVersion(String16("2.4")); - #ifdef __SUPPORT_TEGRA3 +#ifdef __SUPPORT_TEGRA3 EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra3/lib", String8(result).string()); - #else +#else #ifdef __SUPPORT_ARMEABI_V7A_FEATURES EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a_neon/lib", String8(result).string()); #else EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string()); #endif - #endif +#endif } TEST(OpenCVEngineTest, GetPathForExecHWOldVersion) @@ -89,15 +152,15 @@ TEST(OpenCVEngineTest, GetPathForExecHWOldVersion) Starter.PackageManager->InstallVersion("242", PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_NEON); EXPECT_FALSE(NULL == Engine.get()); String16 result = Engine->GetLibPathByVersion(String16("2.4.1")); - #ifdef __SUPPORT_TEGRA3 +#ifdef __SUPPORT_TEGRA3 EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra3/lib", String8(result).string()); - #else +#else #ifdef __SUPPORT_ARMEABI_V7A_FEATURES EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a_neon/lib", String8(result).string()); #else EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string()); #endif - #endif +#endif } TEST(OpenCVEngineTest, GetPathForExecHWNewVersion) @@ -110,21 +173,13 @@ TEST(OpenCVEngineTest, GetPathForExecHWNewVersion) EXPECT_EQ(0, result.size()); } -TEST(OpenCVEngineTest, GetPathForUnExistVersion) -{ - sp Engine = InitConnect(); - EXPECT_FALSE(NULL == Engine.get()); - String16 result = Engine->GetLibPathByVersion(String16("2.5")); - EXPECT_EQ(0, result.size()); -} - TEST(OpenCVEngineTest, GetPathForCompatiblePackage1) { sp Engine = InitConnect(); Starter.PackageManager->InstalledPackages.clear(); Starter.PackageManager->InstallVersion("242", PLATFORM_UNKNOWN, ARCH_ARMv5); EXPECT_FALSE(NULL == Engine.get()); - String16 result = Engine->GetLibPathByVersion(String16("2.4")); + String16 result = Engine->GetLibPathByVersion(String16("2.4")); EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv5/lib", String8(result).string()); } @@ -138,22 +193,12 @@ TEST(OpenCVEngineTest, GetPathForCompatiblePackage2) #ifdef __SUPPORT_TEGRA3 EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra3/lib", String8(result).string()); #else -#ifdef __SUPPORT_ARMEABI_V7A_FEATURES + #ifdef __SUPPORT_ARMEABI_V7A_FEATURES EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a_neon/lib", String8(result).string()); -#else + #else EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string()); + #endif #endif -#endif -} - -TEST(OpenCVEngineTest, GetPathForInCompatiblePackage1) -{ - sp Engine = InitConnect(); - Starter.PackageManager->InstalledPackages.clear(); - Starter.PackageManager->InstallVersion("242", PLATFORM_UNKNOWN, ARCH_X64); - EXPECT_FALSE(NULL == Engine.get()); - String16 result = Engine->GetLibPathByVersion(String16("2.4")); - EXPECT_EQ(0, result.size()); } TEST(OpenCVEngineTest, InstallAndGetVersion) @@ -163,13 +208,44 @@ TEST(OpenCVEngineTest, InstallAndGetVersion) EXPECT_FALSE(NULL == Engine.get()); EXPECT_TRUE(Engine->InstallVersion(String16("2.4"))); String16 result = Engine->GetLibPathByVersion(String16("2.4")); -#ifdef __SUPPORT_TEGRA3 + #ifdef __SUPPORT_TEGRA3 EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra3/lib", String8(result).string()); -#else -#ifdef __SUPPORT_ARMEABI_V7A_FEATURES + #else + #ifdef __SUPPORT_ARMEABI_V7A_FEATURES EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a_neon/lib", String8(result).string()); -#else + #else EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string()); + #endif + #endif +} #endif + +#ifndef __i386__ +TEST(OpenCVEngineTest, GetPathForInCompatiblePackage1) +{ + sp Engine = InitConnect(); + Starter.PackageManager->InstalledPackages.clear(); + Starter.PackageManager->InstallVersion("242", PLATFORM_UNKNOWN, ARCH_X64); + EXPECT_FALSE(NULL == Engine.get()); + String16 result = Engine->GetLibPathByVersion(String16("2.4")); + EXPECT_EQ(0, result.size()); +} +#else +TEST(OpenCVEngineTest, GetPathForInCompatiblePackage1) +{ + sp Engine = InitConnect(); + Starter.PackageManager->InstalledPackages.clear(); + Starter.PackageManager->InstallVersion("242", PLATFORM_UNKNOWN, ARCH_ARMv7); + EXPECT_FALSE(NULL == Engine.get()); + String16 result = Engine->GetLibPathByVersion(String16("2.4")); + EXPECT_EQ(0, result.size()); +} #endif + +TEST(OpenCVEngineTest, GetPathForUnExistVersion) +{ + sp Engine = InitConnect(); + EXPECT_FALSE(NULL == Engine.get()); + String16 result = Engine->GetLibPathByVersion(String16("2.5")); + EXPECT_EQ(0, result.size()); } \ No newline at end of file diff --git a/android/service/engine/jni/Tests/PackageInfoTest.cpp b/android/service/engine/jni/Tests/PackageInfoTest.cpp index c8f6c7ceda..bb6b7ee0ed 100644 --- a/android/service/engine/jni/Tests/PackageInfoTest.cpp +++ b/android/service/engine/jni/Tests/PackageInfoTest.cpp @@ -96,6 +96,15 @@ TEST(PackageInfo, FullNameX86SSE2) #endif } +#ifdef __SUPPORT_MIPS +TEST(PackageInfo, FullNameMips) +{ + PackageInfo info("243", PLATFORM_UNKNOWN, ARCH_MIPS); + string name = info.GetFullName(); + EXPECT_STREQ("org.opencv.lib_v24_mips", name.c_str()); +} +#endif + TEST(PackageInfo, Armv7NeonFromFullName) { PackageInfo info("org.opencv.lib_v23_armv7a_neon", "/data/data/org.opencv.lib_v23_armv7_neon"); @@ -139,6 +148,15 @@ TEST(PackageInfo, Tegra3FromFullName) EXPECT_EQ(PLATFORM_TEGRA3, info.GetPlatform()); } +#ifdef __SUPPORT_MIPS +TEST(PackageInfo, MipsFromFullName) +{ + PackageInfo info("org.opencv.lib_v24_mips", "/data/data/org.opencv.lib_v24_mips"); + EXPECT_EQ("240", info.GetVersion()); + EXPECT_EQ(ARCH_MIPS, info.GetCpuID()); +} +#endif + TEST(PackageInfo, Comparator1) { PackageInfo info1("240", PLATFORM_UNKNOWN, ARCH_X86); @@ -167,4 +185,5 @@ TEST(PackageInfo, Comparator3) EXPECT_STREQ(info1.GetFullName().c_str(), info2.GetFullName().c_str()); EXPECT_EQ(info1, info2); } -#endif \ No newline at end of file +#endif + diff --git a/android/service/engine/jni/Tests/PackageManagmentTest.cpp b/android/service/engine/jni/Tests/PackageManagmentTest.cpp index 8d5c43afb6..51401e2e51 100644 --- a/android/service/engine/jni/Tests/PackageManagmentTest.cpp +++ b/android/service/engine/jni/Tests/PackageManagmentTest.cpp @@ -39,6 +39,14 @@ TEST(PackageManager, InstallVersion) EXPECT_TRUE(pm.CheckVersionInstalled("240", PLATFORM_UNKNOWN, ARCH_ARMv5)); } +TEST(PackageManager, GetPackagePathForArmv5) +{ + PackageManagerStub pm; + EXPECT_TRUE(pm.InstallVersion("243", PLATFORM_UNKNOWN, ARCH_ARMv5)); + string path = pm.GetPackagePathByVersion("243", PLATFORM_UNKNOWN, ARCH_ARMv5); + EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv5/lib", path.c_str()); +} + TEST(PackageManager, GetPackagePathForArmv7) { PackageManagerStub pm; @@ -52,9 +60,9 @@ TEST(PackageManager, GetPackagePathForArmv7Neon) PackageManagerStub pm; EXPECT_TRUE(pm.InstallVersion("230", PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_NEON)); string path = pm.GetPackagePathByVersion("230", PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_NEON); -#ifdef __SUPPORT_ARMEABI_V7A_FEATURES +#ifdef __SUPPORT_ARMEABI_V7A_FEATURES EXPECT_STREQ("/data/data/org.opencv.lib_v23_armv7a_neon/lib", path.c_str()); -#else +#else EXPECT_STREQ("/data/data/org.opencv.lib_v23_armv7a/lib", path.c_str()); #endif } @@ -72,9 +80,9 @@ TEST(PackageManager, GetPackagePathForX86SSE2) PackageManagerStub pm; EXPECT_TRUE(pm.InstallVersion("230", PLATFORM_UNKNOWN, ARCH_X86 | FEATURES_HAS_SSE2)); string path = pm.GetPackagePathByVersion("230", PLATFORM_UNKNOWN, ARCH_X86 | FEATURES_HAS_SSE2); -#ifdef __SUPPORT_INTEL_FEATURES +#ifdef __SUPPORT_INTEL_FEATURES EXPECT_STREQ("/data/data/org.opencv.lib_v23_x86_sse2/lib", path.c_str()); -#else +#else EXPECT_STREQ("/data/data/org.opencv.lib_v23_x86/lib", path.c_str()); #endif } @@ -95,6 +103,16 @@ TEST(PackageManager, GetPackagePathForTegra3) #endif } +#ifdef __SUPPORT_MIPS +TEST(PackageManager, GetPackagePathForMips) +{ + PackageManagerStub pm; + EXPECT_TRUE(pm.InstallVersion("243", PLATFORM_UNKNOWN, ARCH_MIPS)); + string path = pm.GetPackagePathByVersion("243", PLATFORM_UNKNOWN, ARCH_MIPS); + EXPECT_STREQ("/data/data/org.opencv.lib_v24_mips/lib", path.c_str()); +} +#endif + // TODO: Enable tests if seporate package will be exists // TEST(PackageManager, GetPackagePathForTegra2) // { diff --git a/android/service/engine/jni/Tests/TestMain.cpp b/android/service/engine/jni/Tests/TestMain.cpp index 14a634fdb6..4c994ef447 100644 --- a/android/service/engine/jni/Tests/TestMain.cpp +++ b/android/service/engine/jni/Tests/TestMain.cpp @@ -2,7 +2,6 @@ int main(int argc, char **argv) { -/* return 0;*/ - ::testing::InitGoogleTest(&argc, argv); + ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } \ No newline at end of file diff --git a/android/service/engine/jni/Tests/Tests.mk b/android/service/engine/jni/Tests/Tests.mk index 935feb323d..a436bc2095 100644 --- a/android/service/engine/jni/Tests/Tests.mk +++ b/android/service/engine/jni/Tests/Tests.mk @@ -33,6 +33,7 @@ LOCAL_C_INCLUDES := \ LOCAL_CFLAGS += -O0 -DGTEST_HAS_CLONE=0 -DGTEST_OS_LINUX_ANDROID=1 -DGTEST_HAS_TR1_TUPLE=0 LOCAL_CFLAGS += -D__SUPPORT_ARMEABI_V7A_FEATURES LOCAL_CFLAGS += -D__SUPPORT_TEGRA3 +LOCAL_CFLAGS += -D__SUPPORT_MIPS #LOCAL_CFLAGS += -D__SUPPORT_ARMEABI_FEATURES LOCAL_LDFLAGS = -Wl,-allow-shlib-undefined diff --git a/android/service/engine/jni/include/EngineCommon.h b/android/service/engine/jni/include/EngineCommon.h index 96f6dee9f7..99b5af30d3 100644 --- a/android/service/engine/jni/include/EngineCommon.h +++ b/android/service/engine/jni/include/EngineCommon.h @@ -9,4 +9,6 @@ #define OPEN_CV_ENGINE_VERSION 1 #endif +#define LIB_OPENCV_INFO_NAME "libopencv_info.so" + #endif \ No newline at end of file diff --git a/android/service/engine/jni/include/IOpenCVEngine.h b/android/service/engine/jni/include/IOpenCVEngine.h index 2cab52e29d..20cb5d537c 100644 --- a/android/service/engine/jni/include/IOpenCVEngine.h +++ b/android/service/engine/jni/include/IOpenCVEngine.h @@ -5,6 +5,8 @@ #include #include +// OpenCV Manager package name +#define OPENCV_ENGINE_PACKAGE "org.opencv.engine" // Class name of OpenCV engine binder object. Is needned for connection to service #define OPECV_ENGINE_CLASSNAME "org.opencv.engine.OpenCVEngineInterface" diff --git a/android/service/engine/src/org/opencv/engine/HardwareDetector.java b/android/service/engine/src/org/opencv/engine/HardwareDetector.java index bc90cf6aa1..841cd10cf7 100644 --- a/android/service/engine/src/org/opencv/engine/HardwareDetector.java +++ b/android/service/engine/src/org/opencv/engine/HardwareDetector.java @@ -3,44 +3,51 @@ package org.opencv.engine; public class HardwareDetector { public static final int ARCH_UNKNOWN = -1; - + public static final int ARCH_X86 = 0x01000000; public static final int ARCH_X64 = 0x02000000; - + public static final int ARCH_ARMv5 = 0x04000000; public static final int ARCH_ARMv6 = 0x08000000; public static final int ARCH_ARMv7 = 0x10000000; public static final int ARCH_ARMv8 = 0x20000000; - + + public static final int ARCH_MIPS = 0x40000000; // Platform specific features // ! Check CPU arch before ! - + // ARM specific features public static final int FEATURES_HAS_VFPv3d16 = 0x01; public static final int FEATURES_HAS_VFPv3 = 0x02; public static final int FEATURES_HAS_NEON = 0x04; public static final int FEATURES_HAS_NEON2 = 0x08; - + // X86 specific features public static final int FEATURES_HAS_SSE = 0x01; public static final int FEATURES_HAS_SSE2 = 0x02; public static final int FEATURES_HAS_SSE3 = 0x04; - + // GPU Acceleration options public static final int FEATURES_HAS_GPU = 0x010000; - + public static final int PLATFORM_TEGRA = 1; public static final int PLATFORM_TEGRA2 = 2; public static final int PLATFORM_TEGRA3 = 3; - - public static final int PLATFORM_UNKNOWN = -1; - + + public static final int PLATFORM_UNKNOWN = 0; + // Return CPU arch and list of supported features public static native int GetCpuID(); // Return hardware platform name public static native String GetPlatformName(); // Return processor count public static native int GetProcessorCount(); - + public static native int DetectKnownPlatforms(); + + static + { + System.loadLibrary("OpenCVEngine"); + System.loadLibrary("OpenCVEngine_jni"); + } } diff --git a/android/service/engine/src/org/opencv/engine/MarketConnector.java b/android/service/engine/src/org/opencv/engine/MarketConnector.java index 45c80a7298..35fbe59b8f 100644 --- a/android/service/engine/src/org/opencv/engine/MarketConnector.java +++ b/android/service/engine/src/org/opencv/engine/MarketConnector.java @@ -10,12 +10,17 @@ import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.net.Uri; +import android.util.Log; public class MarketConnector { protected static final String OpenCVPackageNamePreffix = "org.opencv.lib"; + private static final String TAG = "OpenCVEngine/MarketConnector"; protected Context mContext; + + public boolean mIncludeManager = true; public MarketConnector(Context context) { @@ -26,7 +31,7 @@ public class MarketConnector { return (String) info.loadLabel(mContext.getPackageManager()); } - + public boolean InstallAppFromMarket(String AppID) { boolean result = true; @@ -50,7 +55,7 @@ public class MarketConnector public boolean RemoveAppFromMarket(String AppID, boolean wait) { boolean result = true; - try + try { Intent intent = new Intent( Intent.ACTION_DELETE, @@ -75,7 +80,6 @@ public class MarketConnector return result; } - public boolean CheckPackageInstalled(String AppID) { List Packages = mContext.getPackageManager().getInstalledPackages(PackageManager.GET_CONFIGURATIONS); @@ -96,6 +100,15 @@ public class MarketConnector { List AllPackages = mContext.getPackageManager().getInstalledPackages(PackageManager.GET_CONFIGURATIONS); List OpenCVPackages = new ArrayList(); + if (mIncludeManager) + { + try { + OpenCVPackages.add(mContext.getPackageManager().getPackageInfo("org.opencv.engine", PackageManager.GET_CONFIGURATIONS)); + } catch (NameNotFoundException e) { + Log.e(TAG, "OpenCV Manager package info was not found!"); + e.printStackTrace(); + } + } Iterator it = AllPackages.iterator(); while(it.hasNext()) { diff --git a/android/service/engine/src/org/opencv/engine/manager/HardwareDetector.java b/android/service/engine/src/org/opencv/engine/manager/HardwareDetector.java deleted file mode 100644 index 740a7581e2..0000000000 --- a/android/service/engine/src/org/opencv/engine/manager/HardwareDetector.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.opencv.engine.manager; - -public class HardwareDetector -{ - public static final int ARCH_UNKNOWN = -1; - - public static final int ARCH_X86 = 0x01000000; - public static final int ARCH_X64 = 0x02000000; - - public static final int ARCH_ARMv5 = 0x04000000; - public static final int ARCH_ARMv6 = 0x08000000; - public static final int ARCH_ARMv7 = 0x10000000; - public static final int ARCH_ARMv8 = 0x20000000; - - // Platform specific features - // ! Check CPU arch before ! - - // ARM specific features - public static final int FEATURES_HAS_VFPv3d16 = 0x01; - public static final int FEATURES_HAS_VFPv3 = 0x02; - public static final int FEATURES_HAS_NEON = 0x04; - public static final int FEATURES_HAS_NEON2 = 0x08; - - // X86 specific features - public static final int FEATURES_HAS_SSE = 0x01; - public static final int FEATURES_HAS_SSE2 = 0x02; - public static final int FEATURES_HAS_SSE3 = 0x04; - - // GPU Acceleration options - public static final int FEATURES_HAS_GPU = 0x010000; - - public static final int PLATFORM_TEGRA = 1; - public static final int PLATFORM_TEGRA2 = 2; - public static final int PLATFORM_TEGRA3 = 3; - - public static final int PLATFORM_UNKNOWN = 0; - - // Return CPU arch and list of supported features - public static native int GetCpuID(); - // Return hardware platform name - public static native String GetPlatformName(); - // Return processor count - public static native int GetProcessorCount(); - - public static native int DetectKnownPlatforms(); - - static - { - System.loadLibrary("OpenCVEngine"); - System.loadLibrary("OpenCVEngine_jni"); - } -} diff --git a/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java b/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java index 9295146f8c..b8fc2d9e19 100644 --- a/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java +++ b/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.StringTokenizer; +import org.opencv.engine.HardwareDetector; import org.opencv.engine.MarketConnector; import org.opencv.engine.OpenCVEngineInterface; import org.opencv.engine.R; @@ -45,13 +46,12 @@ public class ManagerActivity extends Activity OsVersionView.setText(Build.VERSION.CODENAME + " (" + Build.VERSION.RELEASE + "), API " + Build.VERSION.SDK_INT); try { - PackageInfo packageInfo = getPackageManager().getPackageInfo(this.getPackageName(), 0); - ManagerVersion = packageInfo.versionName; - } catch (NameNotFoundException e) { - // TODO Auto-generated catch block - ManagerVersion = "N/A"; - e.printStackTrace(); - } + PackageInfo packageInfo = getPackageManager().getPackageInfo(this.getPackageName(), 0); + ManagerVersion = packageInfo.versionName; + } catch (NameNotFoundException e) { + ManagerVersion = "N/A"; + e.printStackTrace(); + } mInstalledPackageView = (ListView)findViewById(R.id.InstalledPackageList); @@ -112,6 +112,10 @@ public class ManagerActivity extends Activity { HardwarePlatformView.setText("ARM v8 " + JoinArmFeatures(CpuId)); } + else if ((CpuId & HardwareDetector.ARCH_MIPS) == HardwareDetector.ARCH_MIPS) + { + HardwarePlatformView.setText("MIPS"); + } else { HardwarePlatformView.setText("not detected"); @@ -120,41 +124,41 @@ public class ManagerActivity extends Activity mUpdateEngineButton = (Button)findViewById(R.id.CheckEngineUpdate); mUpdateEngineButton.setOnClickListener(new OnClickListener() { - - public void onClick(View v) { - if (!mMarket.InstallAppFromMarket("org.opencv.engine")) - { - Toast toast = Toast.makeText(getApplicationContext(), "Google Play is not avaliable", Toast.LENGTH_SHORT); - toast.show(); - } - } - }); + + public void onClick(View v) { + if (!mMarket.InstallAppFromMarket("org.opencv.engine")) + { + Toast toast = Toast.makeText(getApplicationContext(), "Google Play is not avaliable", Toast.LENGTH_SHORT); + toast.show(); + } + } + }); mActionDialog = new AlertDialog.Builder(this).create(); mActionDialog.setTitle("Choose action"); mActionDialog.setButton("Update", new DialogInterface.OnClickListener() { - - public void onClick(DialogInterface dialog, int which) { - int index = (Integer)mInstalledPackageView.getTag(); - if (!mMarket.InstallAppFromMarket(mInstalledPackageInfo[index].packageName)) - { - Toast toast = Toast.makeText(getApplicationContext(), "Google Play is not avaliable", Toast.LENGTH_SHORT); - toast.show(); - } - } - }); + + public void onClick(DialogInterface dialog, int which) { + int index = (Integer)mInstalledPackageView.getTag(); + if (!mMarket.InstallAppFromMarket(mInstalledPackageInfo[index].packageName)) + { + Toast toast = Toast.makeText(getApplicationContext(), "Google Play is not avaliable", Toast.LENGTH_SHORT); + toast.show(); + } + } + }); mActionDialog.setButton3("Remove", new DialogInterface.OnClickListener() { - - public void onClick(DialogInterface dialog, int which) { - int index = (Integer)mInstalledPackageView.getTag(); - if (!mMarket.RemoveAppFromMarket(mInstalledPackageInfo[index].packageName, true)) - { - Toast toast = Toast.makeText(getApplicationContext(), "Google Play is not avaliable", Toast.LENGTH_SHORT); - toast.show(); - } - } + + public void onClick(DialogInterface dialog, int which) { + int index = (Integer)mInstalledPackageView.getTag(); + if (!mMarket.RemoveAppFromMarket(mInstalledPackageInfo[index].packageName, true)) + { + Toast toast = Toast.makeText(getApplicationContext(), "Google Play is not avaliable", Toast.LENGTH_SHORT); + toast.show(); + } + } }); mActionDialog.setButton2("Return", new DialogInterface.OnClickListener() { @@ -165,27 +169,20 @@ public class ManagerActivity extends Activity }); mInstalledPackageView.setOnItemClickListener(new OnItemClickListener() { - - public void onItemClick(AdapterView arg0, View arg1, int arg2, long id) { - - mInstalledPackageView.setTag(Integer.valueOf((int)id)); - mActionDialog.show(); - } + + public void onItemClick(AdapterView arg0, View arg1, int arg2, long id) { + mInstalledPackageView.setTag(Integer.valueOf((int)id)); + mActionDialog.show(); + } }); - if (!bindService(new Intent("org.opencv.engine.BIND"), mServiceConnection, Context.BIND_AUTO_CREATE)) - { - TextView EngineVersionView = (TextView)findViewById(R.id.EngineVersionValue); - EngineVersionView.setText("not avaliable"); - } - IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_PACKAGE_ADDED); filter.addAction(Intent.ACTION_PACKAGE_CHANGED); filter.addAction(Intent.ACTION_PACKAGE_INSTALL); filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addAction(Intent.ACTION_PACKAGE_REPLACED); - + registerReceiver(mPackageChangeReciever, filter); } @@ -272,6 +269,7 @@ public class ManagerActivity extends Activity protected void FillPackageList() { synchronized (mListViewItems) { + mMarket.mIncludeManager = false; mInstalledPackageInfo = mMarket.GetInstalledOpenCVPackages(); mListViewItems.clear(); @@ -328,11 +326,11 @@ public class ManagerActivity extends Activity } temp.put("Name", PublicName); - temp.put("Version", NormalizeVersion(OpenCVersion, mInstalledPackageInfo[i].versionName)); + temp.put("Version", NormalizeVersion(OpenCVersion, mInstalledPackageInfo[i].versionName)); temp.put("Hardware", HardwareName); mListViewItems.add(temp); } - + mInstalledPacksAdapter.notifyDataSetChanged(); } } diff --git a/android/service/engine/src/org/opencv/engine/manager/OpenCVPackageInfo.java b/android/service/engine/src/org/opencv/engine/manager/OpenCVPackageInfo.java deleted file mode 100644 index ba5fcfa9aa..0000000000 --- a/android/service/engine/src/org/opencv/engine/manager/OpenCVPackageInfo.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.opencv.engine.manager; - -public class OpenCVPackageInfo -{ - public OpenCVPackageInfo(String PackageName, String PackageInstallPath, String RevName) - { - - } - - protected long mNativeObject = 0; - - protected static native long nativeConstructor(String PackageName, String PackageInstallPath, String RevName); - protected static native void nativeDestructor(long nativeAddress); - protected static native String nativeGetVersion(long thiz); - protected static native String nativeGetPlatfrom(long thiz); -}