Merge remote-tracking branch 'origin/2.4'
Pull requests: #943 from jet47:cuda-5.5-support #944 from jet47:cmake-2.8.11-cuda-fix #912 from SpecLad:contributing #934 from SpecLad:parallel-for #931 from jet47:gpu-test-fixes #932 from bitwangyaoyao:2.4_fixBFM #918 from bitwangyaoyao:2.4_samples #924 from pengx17:2.4_arithm_fix #925 from pengx17:2.4_canny_tmp_fix #927 from bitwangyaoyao:2.4_perf #930 from pengx17:2.4_haar_ext #928 from apavlenko:bugfix_3027 #920 from asmorkalov:android_move #910 from pengx17:2.4_oclgfft #913 from janm399:2.4 #916 from bitwangyaoyao:2.4_fixPyrLK #919 from abidrahmank:2.4 #923 from pengx17:2.4_macfix Conflicts: modules/calib3d/src/stereobm.cpp modules/features2d/src/detectors.cpp modules/gpu/src/error.cpp modules/gpu/src/precomp.hpp modules/imgproc/src/distransform.cpp modules/imgproc/src/morph.cpp modules/ocl/include/opencv2/ocl/ocl.hpp modules/ocl/perf/perf_color.cpp modules/ocl/perf/perf_imgproc.cpp modules/ocl/perf/perf_match_template.cpp modules/ocl/perf/precomp.cpp modules/ocl/perf/precomp.hpp modules/ocl/src/arithm.cpp modules/ocl/src/canny.cpp modules/ocl/src/filtering.cpp modules/ocl/src/haar.cpp modules/ocl/src/hog.cpp modules/ocl/src/imgproc.cpp modules/ocl/src/opencl/haarobjectdetect.cl modules/ocl/src/pyrlk.cpp modules/video/src/bgfg_gaussmix2.cpp modules/video/src/lkpyramid.cpp platforms/linux/scripts/cmake_arm_gnueabi_hardfp.sh platforms/linux/scripts/cmake_arm_gnueabi_softfp.sh platforms/scripts/ABI_compat_generator.py samples/ocl/facedetect.cpp
1
platforms/android/README.android
Normal file
@@ -0,0 +1 @@
|
||||
See http://opencv.org/android
|
1632
platforms/android/android.toolchain.cmake
Normal file
6
platforms/android/java.rst
Normal file
@@ -0,0 +1,6 @@
|
||||
********
|
||||
Java API
|
||||
********
|
||||
|
||||
|
||||
Java API reference (JavaDoc): external `link <http://docs.opencv.org/java/>`_.
|
39
platforms/android/libinfo/CMakeLists.txt
Normal file
@@ -0,0 +1,39 @@
|
||||
project(libopencv_info)
|
||||
if(NOT ANDROID_PACKAGE_RELEASE)
|
||||
set(ANDROID_PACKAGE_RELEASE 1)
|
||||
endif()
|
||||
|
||||
if(NOT ANDROID_PACKAGE_PLATFORM)
|
||||
if(ARMEABI_V7A)
|
||||
if(NEON)
|
||||
set(ANDROID_PACKAGE_PLATFORM armv7a_neon)
|
||||
else()
|
||||
set(ANDROID_PACKAGE_PLATFORM armv7a)
|
||||
endif()
|
||||
elseif(ARMEABI_V6)
|
||||
set(ANDROID_PACKAGE_PLATFORM armv6)
|
||||
elseif(ARMEABI)
|
||||
set(ANDROID_PACKAGE_PLATFORM armv5)
|
||||
elseif(X86)
|
||||
set(ANDROID_PACKAGE_PLATFORM x86)
|
||||
elseif(MIPS)
|
||||
set(ANDROID_PACKAGE_PLATFORM mips)
|
||||
else()
|
||||
message(ERROR "Can not automatically determine the value for ANDROID_PACKAGE_PLATFORM")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_definitions(-DANDROID_PACKAGE_RELEASE=${ANDROID_PACKAGE_RELEASE} -DANDROID_PACKAGE_PLATFORM="${ANDROID_PACKAGE_PLATFORM}")
|
||||
|
||||
include_directories(jni/BinderComponent jni/include "${OpenCV_SOURCE_DIR}/modules/core/include")
|
||||
|
||||
add_library(opencv_info SHARED info.c)
|
||||
|
||||
set_target_properties(${the_module} PROPERTIES
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
|
||||
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
|
||||
INSTALL_NAME_DIR lib
|
||||
)
|
||||
|
||||
get_filename_component(lib_name "libopencv_info.so" NAME)
|
||||
install(FILES "${LIBRARY_OUTPUT_PATH}/${lib_name}" DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main)
|
31
platforms/android/libinfo/info.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "opencv2/core/version.hpp"
|
||||
#include <jni.h>
|
||||
|
||||
const char* GetPackageName(void);
|
||||
const char* GetRevision(void);
|
||||
const char* GetLibraryList(void);
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_android_StaticHelper_getLibraryList(JNIEnv *, jclass);
|
||||
|
||||
#define PACKAGE_NAME "org.opencv.lib_v" CVAUX_STR(CV_VERSION_EPOCH) CVAUX_STR(CV_VERSION_MAJOR) "_" ANDROID_PACKAGE_PLATFORM
|
||||
#define PACKAGE_REVISION CVAUX_STR(CV_VERSION_MINOR) "." CVAUX_STR(CV_VERSION_REVISION) "." CVAUX_STR(ANDROID_PACKAGE_RELEASE)
|
||||
|
||||
const char* GetPackageName(void)
|
||||
{
|
||||
return PACKAGE_NAME;
|
||||
}
|
||||
|
||||
const char* GetRevision(void)
|
||||
{
|
||||
return PACKAGE_REVISION;
|
||||
}
|
||||
|
||||
const char* GetLibraryList(void)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_android_StaticHelper_getLibraryList(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
(void)clazz;
|
||||
return (*env)->NewStringUTF(env, GetLibraryList());
|
||||
}
|
15
platforms/android/package/AndroidManifest.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.opencv.lib_v@OPENCV_VERSION_MAJOR@@OPENCV_VERSION_MINOR@_@ANDROID_PACKAGE_PLATFORM@"
|
||||
android:versionCode="@OPENCV_VERSION_PATCH@@OPENCV_VERSION_TWEAK@@ANDROID_PACKAGE_RELEASE@"
|
||||
android:versionName="@OPENCV_VERSION_PATCH@.@OPENCV_VERSION_TWEAK@.@ANDROID_PACKAGE_RELEASE@" >
|
||||
|
||||
<uses-sdk android:minSdkVersion="@ANDROID_SDK_VERSION@" />
|
||||
<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
|
||||
|
||||
<application
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name" >
|
||||
</application>
|
||||
|
||||
</manifest>
|
94
platforms/android/package/CMakeLists.txt
Normal file
@@ -0,0 +1,94 @@
|
||||
if(NOT ANDROID_PACKAGE_RELEASE)
|
||||
set(ANDROID_PACKAGE_RELEASE 1)
|
||||
endif()
|
||||
|
||||
if(NOT ANDROID_PACKAGE_PLATFORM)
|
||||
if(ARMEABI_V7A)
|
||||
if(NEON)
|
||||
set(ANDROID_PACKAGE_PLATFORM armv7a_neon)
|
||||
else()
|
||||
set(ANDROID_PACKAGE_PLATFORM armv7a)
|
||||
endif()
|
||||
elseif(ARMEABI_V6)
|
||||
set(ANDROID_PACKAGE_PLATFORM armv6)
|
||||
elseif(ARMEABI)
|
||||
set(ANDROID_PACKAGE_PLATFORM armv5)
|
||||
elseif(X86)
|
||||
set(ANDROID_PACKAGE_PLATFORM x86)
|
||||
elseif(MIPS)
|
||||
set(ANDROID_PACKAGE_PLATFORM mips)
|
||||
else()
|
||||
message(ERROR "Can not automatically determine the value for ANDROID_PACKAGE_PLATFORM")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT ANDROID_PACKAGE_PLATFORM_NAME)
|
||||
if(ARMEABI_V7A)
|
||||
if(NEON)
|
||||
set(ANDROID_PACKAGE_PLATFORM_NAME "armeabi-v7a with NEON")
|
||||
else()
|
||||
set(ANDROID_PACKAGE_PLATFORM_NAME "armeabi-v7a")
|
||||
endif()
|
||||
elseif(ARMEABI_V6)
|
||||
set(ANDROID_PACKAGE_PLATFORM_NAME "armeabi-v6")
|
||||
elseif(ARMEABI)
|
||||
set(ANDROID_PACKAGE_PLATFORM_NAME "armeabi")
|
||||
elseif(X86)
|
||||
set(ANDROID_PACKAGE_PLATFORM_NAME "x86")
|
||||
elseif(MIPS)
|
||||
set(ANDROID_PACKAGE_PLATFORM_NAME "mips")
|
||||
else()
|
||||
message(ERROR "Can not automatically determine the value for ANDROID_PACKAGE_PLATFORM_NAME")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if("${ANDROID_NATIVE_API_LEVEL}" MATCHES "[1-9][0-9]*$")
|
||||
set(ANDROID_SDK_VERSION ${CMAKE_MATCH_0})
|
||||
endif()
|
||||
|
||||
if(NOT ANDROID_SDK_VERSION GREATER 7)
|
||||
set(ANDROID_SDK_VERSION 8)
|
||||
endif()
|
||||
|
||||
set(PACKAGE_DIR "${OpenCV_BINARY_DIR}/package")
|
||||
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${ANDROID_MANIFEST_FILE}" "${PACKAGE_DIR}/${ANDROID_MANIFEST_FILE}" @ONLY)
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/res/values/strings.xml" "${PACKAGE_DIR}/res/values/strings.xml" @ONLY)
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/res/drawable/icon.png" "${PACKAGE_DIR}/res/drawable/icon.png" COPYONLY)
|
||||
|
||||
set(target_name "OpenCV_${OPENCV_VERSION}_binary_pack_${ANDROID_PACKAGE_PLATFORM}")
|
||||
get_target_property(opencv_java_location opencv_java LOCATION)
|
||||
|
||||
set(android_proj_target_files ${ANDROID_PROJECT_FILES})
|
||||
ocv_list_add_prefix(android_proj_target_files "${PACKAGE_DIR}/")
|
||||
android_get_compatible_target(android_proj_sdk_target ${ANDROID_SDK_VERSION})
|
||||
set(APK_NAME "${PACKAGE_DIR}/bin/${target_name}-release-unsigned.apk")
|
||||
|
||||
file(GLOB camera_wrappers "${OpenCV_SOURCE_DIR}/3rdparty/lib/${ANDROID_NDK_ABI_NAME}/libnative_camera_r*.so")
|
||||
set(CAMERA_LIB_COMMANDS "")
|
||||
|
||||
foreach(wrapper ${camera_wrappers})
|
||||
list(APPEND CAMERA_LIB_COMMANDS COMMAND ${CMAKE_COMMAND} -E copy "${wrapper}" "${PACKAGE_DIR}/libs/${ANDROID_NDK_ABI_NAME}/")
|
||||
endforeach()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${APK_NAME}"
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory "${PACKAGE_DIR}/libs"
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory "${PACKAGE_DIR}/bin"
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory "${PACKAGE_DIR}/gen"
|
||||
COMMAND ${CMAKE_COMMAND} -E remove ${android_proj_target_files}
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${PACKAGE_DIR}/src"
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${PACKAGE_DIR}/libs/${ANDROID_NDK_ABI_NAME}/"
|
||||
${CAMERA_LIB_COMMANDS}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${opencv_java_location}" "${PACKAGE_DIR}/libs/${ANDROID_NDK_ABI_NAME}/"
|
||||
COMMAND ${ANDROID_EXECUTABLE} --silent update project --path "${PACKAGE_DIR}" --target "${android_proj_sdk_target}" --name "${target_name}"
|
||||
COMMAND ${ANT_EXECUTABLE} -q -noinput -k release
|
||||
COMMAND ${CMAKE_COMMAND} -E touch "${APK_NAME}"
|
||||
WORKING_DIRECTORY "${PACKAGE_DIR}"
|
||||
MAIN_DEPENDENCY "${PACKAGE_DIR}/${ANDROID_MANIFEST_FILE}"
|
||||
DEPENDS "${OpenCV_BINARY_DIR}/bin/classes.jar.dephelper" "${PACKAGE_DIR}/res/values/strings.xml" "${PACKAGE_DIR}/res/drawable/icon.png" ${camera_wrappers} opencv_java
|
||||
)
|
||||
|
||||
install(FILES "${APK_NAME}" DESTINATION "apk/" COMPONENT main)
|
||||
add_custom_target(android_package ALL SOURCES "${APK_NAME}" )
|
||||
add_dependencies(android_package opencv_java)
|
BIN
platforms/android/package/res/drawable/icon.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
6
platforms/android/package/res/values/strings.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">OCV @OPENCV_VERSION_MAJOR@.@OPENCV_VERSION_MINOR@ pack @ANDROID_PACKAGE_PLATFORM_NAME@</string>
|
||||
|
||||
</resources>
|
9
platforms/android/refman.rst
Normal file
@@ -0,0 +1,9 @@
|
||||
############################
|
||||
OpenCV4Android Reference
|
||||
############################
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
service/doc/index.rst
|
||||
java.rst
|
6
platforms/android/service/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
if(BUILD_ANDROID_SERVICE)
|
||||
add_subdirectory(engine)
|
||||
#add_subdirectory(engine_test)
|
||||
endif()
|
||||
|
||||
install(FILES "readme.txt" DESTINATION "apk/" COMPONENT main)
|
43
platforms/android/service/all.py
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
|
||||
LOCAL_LOG_PATH = os.path.join(os.getcwd(), "logs")
|
||||
|
||||
if (__name__ == "__main__"):
|
||||
if (not os.path.exists(LOCAL_LOG_PATH)):
|
||||
os.makedirs(LOCAL_LOG_PATH)
|
||||
|
||||
print("Building native part of OpenCV Manager...")
|
||||
HomeDir = os.getcwd()
|
||||
os.chdir(os.path.join(HomeDir, "engine"))
|
||||
shutil.rmtree(os.path.join(HomeDir, "engine", "libs"), ignore_errors=True)
|
||||
shutil.rmtree(os.path.join(HomeDir, "engine", "obj"), ignore_errors=True)
|
||||
BuildCommand = "ndk-build V=1 > \"%s\" 2>&1" % os.path.join(LOCAL_LOG_PATH, "build.log")
|
||||
#print(BuildCommand)
|
||||
res = os.system(BuildCommand)
|
||||
if (0 == res):
|
||||
print("Build\t[OK]")
|
||||
else:
|
||||
print("Build\t[FAILED]")
|
||||
sys.exit(-1)
|
||||
|
||||
os.chdir(HomeDir)
|
||||
ConfFile = open("device.conf", "rt")
|
||||
|
||||
for s in ConfFile.readlines():
|
||||
keys = s.split(";")
|
||||
if (len(keys) < 2):
|
||||
print("Error: invalid config line: \"%s\"" % s)
|
||||
continue
|
||||
Arch = keys[0]
|
||||
Name = keys[1]
|
||||
print("testing \"%s\" arch" % Arch)
|
||||
print("Pushing to device \"%s\"" % Name)
|
||||
PushCommand = "%s \"%s\" \"%s\" 2>&1" % (os.path.join(HomeDir, "push_native.py"), Arch, Name)
|
||||
os.system(PushCommand)
|
||||
print("Testing on device \"%s\"" % Name)
|
||||
TestCommand = "%s \"%s\" \"%s\" 2>&1" % (os.path.join(HomeDir, "test_native.py"), Arch, Name)
|
||||
os.system(TestCommand)
|
3
platforms/android/service/device.conf
Normal file
@@ -0,0 +1,3 @@
|
||||
armeabi;15c000000581404;
|
||||
x86;0123456789ABCDEF;
|
||||
mips;Novo7 Basic;
|
BIN
platforms/android/service/doc/AndroidAppUsageModel.dia
Normal file
63
platforms/android/service/doc/BaseLoaderCallback.rst
Normal file
@@ -0,0 +1,63 @@
|
||||
*********************************************
|
||||
Base Loader Callback Interface Implementation
|
||||
*********************************************
|
||||
|
||||
.. highlight:: java
|
||||
.. class:: BaseLoaderCallback
|
||||
|
||||
Basic implementation of ``LoaderCallbackInterface``. Logic of this implementation is
|
||||
well-described by the following scheme:
|
||||
|
||||
.. image:: img/AndroidAppUsageModel.png
|
||||
|
||||
Using in Java Activity
|
||||
----------------------
|
||||
|
||||
There is a very base code snippet implementing the async initialization with ``BaseLoaderCallback``.
|
||||
See the "15-puzzle" OpenCV sample for details.
|
||||
|
||||
.. code-block:: java
|
||||
:linenos:
|
||||
|
||||
public class MyActivity extends Activity implements HelperCallbackInterface
|
||||
{
|
||||
private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
|
||||
@Override
|
||||
public void onManagerConnected(int status) {
|
||||
switch (status) {
|
||||
case LoaderCallbackInterface.SUCCESS:
|
||||
{
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
// Create and set View
|
||||
mView = new puzzle15View(mAppContext);
|
||||
setContentView(mView);
|
||||
} break;
|
||||
default:
|
||||
{
|
||||
super.onManagerConnected(status);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** Call on every application resume **/
|
||||
@Override
|
||||
protected void onResume()
|
||||
{
|
||||
Log.i(TAG, "Called onResume");
|
||||
super.onResume();
|
||||
|
||||
Log.i(TAG, "Trying to load OpenCV library");
|
||||
if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_4, this, mOpenCVCallBack))
|
||||
{
|
||||
Log.e(TAG, "Cannot connect to OpenCV Manager");
|
||||
}
|
||||
}
|
||||
|
||||
Using in Service
|
||||
----------------
|
||||
|
||||
Default ``BaseLoaderCallback`` implementation treats application context as ``Activity`` and calls
|
||||
``Activity.finish()`` method to exit in case of initialization failure.
|
||||
To override this behavior you need to override ``finish()`` method of ``BaseLoaderCallback`` class
|
||||
and implement your own finalization method.
|
38
platforms/android/service/doc/InstallCallbackInterface.rst
Normal file
@@ -0,0 +1,38 @@
|
||||
**************************
|
||||
Install Callback Interface
|
||||
**************************
|
||||
.. highlight:: java
|
||||
.. class:: InstallCallbackInterface
|
||||
|
||||
Callback interface for package installation or update.
|
||||
|
||||
String getPackageName()
|
||||
-----------------------
|
||||
|
||||
.. method:: String getPackageName()
|
||||
|
||||
Get name of a package to be installed.
|
||||
|
||||
:rtype: string;
|
||||
:return: returns package name, i.e. "OpenCV Manager Service" or "OpenCV library".
|
||||
|
||||
void install()
|
||||
--------------
|
||||
|
||||
.. method:: void install()
|
||||
|
||||
Installation of package has been approved.
|
||||
|
||||
void cancel()
|
||||
-------------
|
||||
|
||||
.. method:: void cancel()
|
||||
|
||||
Installation of package has been cancelled.
|
||||
|
||||
void wait_install()
|
||||
-------------------
|
||||
|
||||
.. method:: void wait_install()
|
||||
|
||||
Wait for package installation.
|
44
platforms/android/service/doc/Intro.rst
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
.. _Android_OpenCV_Manager_Intro:
|
||||
|
||||
************
|
||||
Introduction
|
||||
************
|
||||
|
||||
.. highlight:: java
|
||||
|
||||
OpenCV Manager is an Android service targeted to manage OpenCV library binaries on end users devices.
|
||||
It allows sharing the OpenCV dynamic libraries between applications on the same device. The Manager
|
||||
provides the following benefits\:
|
||||
|
||||
#. Less memory usage. All apps use the same binaries from service and do not keep native libs inside themselves;
|
||||
#. Hardware specific optimizations for all supported platforms;
|
||||
#. Trusted OpenCV library source. All packages with OpenCV are published on Google Play market;
|
||||
#. Regular updates and bug fixes;
|
||||
|
||||
Usage model for end user
|
||||
------------------------
|
||||
|
||||
.. image:: img/AndroidAppUsageModel.png
|
||||
|
||||
First OpenCV app\:
|
||||
|
||||
#. Any OpenCV-dependent app is installed from Google Play marketplace or manually;
|
||||
#. At the first launch, it suggests installation of OpenCV Manager;
|
||||
#. Then OpenCV Manager is downloaded and installed, using the Google Play application.
|
||||
#. When Manager has been started, the application suggests installation of OpenCV library for the
|
||||
target device architecture if it is necessary;
|
||||
#. After the installation is finished, the app may be launched.
|
||||
|
||||
Subsequent launches of OpenCV apps\:
|
||||
|
||||
#. Any OpenCV-dependent app is installed from Google Play market or manually;
|
||||
#. At the first launch, the app starts as usually;
|
||||
#. If the selected OpenCV version is not installed, OpenCV Manager suggests installing OpenCV
|
||||
library for the target device through Google Play marketplace;
|
||||
#. After the installation is finished, the app may be launched.
|
||||
|
||||
Architecture of OpenCV Manager
|
||||
------------------------------
|
||||
|
||||
.. image:: img/Structure.png
|
57
platforms/android/service/doc/JavaHelper.rst
Normal file
@@ -0,0 +1,57 @@
|
||||
******************
|
||||
Java OpenCV Loader
|
||||
******************
|
||||
|
||||
.. highlight:: java
|
||||
.. Class:: OpenCVLoader
|
||||
|
||||
Helper class provides common initialization methods for OpenCV library.
|
||||
|
||||
boolean initDebug()
|
||||
-------------------
|
||||
|
||||
.. method:: static boolean initDebug()
|
||||
|
||||
Loads and initializes OpenCV library from within current application package. Roughly it is
|
||||
analog of ``system.loadLibrary("opencv_java")``.
|
||||
|
||||
:rtype: boolean;
|
||||
:return: returns true if initialization of OpenCV was successful.
|
||||
|
||||
.. note:: This method is deprecated for production code. It is designed for experimental and local
|
||||
development purposes only. If you want to publish your app use approach with async
|
||||
initialization.
|
||||
|
||||
boolean initAsync()
|
||||
-------------------
|
||||
|
||||
.. method:: static boolean initAsync(String Version, Context AppContext, LoaderCallbackInterface Callback)
|
||||
|
||||
Loads and initializes OpenCV library using OpenCV Manager.
|
||||
|
||||
:param Version: OpenCV Library version.
|
||||
:param AppContext: application context for connecting to the service.
|
||||
:param Callback: object, that implements ``LoaderCallbackInterface`` for handling connection
|
||||
status (see ``BaseLoaderCallback``).
|
||||
|
||||
:rtype: boolean;
|
||||
:return: returns true if initialization of OpenCV starts successfully.
|
||||
|
||||
OpenCV version constants
|
||||
-------------------------
|
||||
|
||||
.. data:: OPENCV_VERSION_2_4_2
|
||||
|
||||
OpenCV Library version 2.4.2
|
||||
|
||||
.. data:: OPENCV_VERSION_2_4_3
|
||||
|
||||
OpenCV Library version 2.4.3
|
||||
|
||||
.. data:: OPENCV_VERSION_2_4_4
|
||||
|
||||
OpenCV Library version 2.4.4
|
||||
|
||||
.. data:: OPENCV_VERSION_2_4_5
|
||||
|
||||
OpenCV Library version 2.4.5
|
BIN
platforms/android/service/doc/LibInstallAproved.dia
Normal file
BIN
platforms/android/service/doc/LibInstallCanceled.dia
Normal file
BIN
platforms/android/service/doc/LibInstalled.dia
Normal file
49
platforms/android/service/doc/LoaderCallbackInterface.rst
Normal file
@@ -0,0 +1,49 @@
|
||||
*************************
|
||||
Loader Callback Interface
|
||||
*************************
|
||||
|
||||
.. highlight:: java
|
||||
.. class:: LoaderCallbackInterface
|
||||
|
||||
Interface for a callback object in case of asynchronous initialization of OpenCV.
|
||||
|
||||
void onManagerConnected()
|
||||
-------------------------
|
||||
|
||||
.. method:: void onManagerConnected(int status)
|
||||
|
||||
Callback method that is called after OpenCV library initialization.
|
||||
|
||||
:param status: status of initialization (see "Initialization Status Constants" section below).
|
||||
|
||||
void onPackageInstall()
|
||||
-----------------------
|
||||
|
||||
.. method:: void onPackageInstall(InstallCallbackInterface Callback)
|
||||
|
||||
Callback method that is called in case when package installation is needed.
|
||||
|
||||
:param callback: answer object with ``install`` and ``cancel`` methods and package description.
|
||||
|
||||
Initialization status constants
|
||||
-------------------------------
|
||||
|
||||
.. data:: SUCCESS
|
||||
|
||||
OpenCV initialization finished successfully
|
||||
|
||||
.. data:: MARKET_ERROR
|
||||
|
||||
Google Play (Android Market) application cannot be invoked
|
||||
|
||||
.. data:: INSTALL_CANCELED
|
||||
|
||||
OpenCV library installation was cancelled by user
|
||||
|
||||
.. data:: INCOMPATIBLE_MANAGER_VERSION
|
||||
|
||||
Version of OpenCV Manager is incompatible with this app. Manager update is needed.
|
||||
|
||||
.. data:: INIT_FAILED
|
||||
|
||||
OpenCV library initialization failed
|
BIN
platforms/android/service/doc/NoService.dia
Normal file
BIN
platforms/android/service/doc/Structure.dia
Normal file
32
platforms/android/service/doc/UseCases.rst
Normal file
@@ -0,0 +1,32 @@
|
||||
Manager Workflow
|
||||
****************
|
||||
|
||||
.. _manager_selection:
|
||||
|
||||
.. include:: ../readme.txt
|
||||
|
||||
First application start
|
||||
-----------------------
|
||||
|
||||
There is no OpenCV Manager or OpenCV libraries:
|
||||
|
||||
.. image:: img/NoService.png
|
||||
|
||||
Additional library package installation
|
||||
---------------------------------------
|
||||
|
||||
There is an OpenCV Manager service, but it does not contain appropriate OpenCV library.
|
||||
If OpenCV library installation has been approved\:
|
||||
|
||||
.. image:: img/LibInstallAproved.png
|
||||
|
||||
If OpenCV library installation has been cancelled\:
|
||||
|
||||
.. image:: img/LibInstallCanceled.png
|
||||
|
||||
Regular application start
|
||||
-------------------------
|
||||
|
||||
OpenCV Manager and OpenCV library has been already installed.
|
||||
|
||||
.. image:: img/LibInstalled.png
|
23
platforms/android/service/doc/build_uml.py
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import os
|
||||
|
||||
TARGET_PATH = "img"
|
||||
|
||||
pipe = os.popen("which dia")
|
||||
DiaPath = pipe.readline()
|
||||
DiaPath = DiaPath.strip("\n");
|
||||
pipe.close()
|
||||
|
||||
if ("" == DiaPath):
|
||||
print("Error: Dia tool was not found")
|
||||
exit(-1)
|
||||
|
||||
print("Dia tool: \"%s\"" % DiaPath)
|
||||
|
||||
if (not os.path.exists(TARGET_PATH)):
|
||||
os.mkdir("img")
|
||||
|
||||
for filename in os.listdir("."):
|
||||
if ("dia" == filename[-3:]):
|
||||
os.system("%s --export %s %s" % (DiaPath, os.path.join(TARGET_PATH, filename[0:len(filename)-4] + ".png"), filename))
|
BIN
platforms/android/service/doc/img/AndroidAppUsageModel.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
platforms/android/service/doc/img/LibInstallAproved.png
Normal file
After Width: | Height: | Size: 41 KiB |
BIN
platforms/android/service/doc/img/LibInstallCanceled.png
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
platforms/android/service/doc/img/LibInstalled.png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
platforms/android/service/doc/img/NoService.png
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
platforms/android/service/doc/img/Structure.png
Normal file
After Width: | Height: | Size: 35 KiB |
18
platforms/android/service/doc/index.rst
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
.. _Android_OpenCV_Manager:
|
||||
|
||||
***********************
|
||||
Android OpenCV Manager
|
||||
***********************
|
||||
|
||||
Contents:
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
Intro
|
||||
UseCases
|
||||
JavaHelper
|
||||
BaseLoaderCallback
|
||||
LoaderCallbackInterface
|
||||
InstallCallbackInterface
|
8
platforms/android/service/engine/.classpath
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
33
platforms/android/service/engine/.project
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>OpenCVEngineService</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
30
platforms/android/service/engine/AndroidManifest.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.opencv.engine"
|
||||
android:versionCode="27@ANDROID_PLATFORM_VERSION_CODE@"
|
||||
android:versionName="2.7" >
|
||||
|
||||
<uses-sdk android:minSdkVersion="@ANDROID_NATIVE_API_LEVEL@" />
|
||||
<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
|
||||
|
||||
<application
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name" >
|
||||
|
||||
<service android:exported="true" android:name="OpenCVEngineService" android:process=":OpenCVEngineProcess">
|
||||
<intent-filter>
|
||||
<action android:name="org.opencv.engine.BIND"></action>
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<activity
|
||||
android:name="org.opencv.engine.manager.ManagerActivity"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="portrait">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
74
platforms/android/service/engine/CMakeLists.txt
Normal file
@@ -0,0 +1,74 @@
|
||||
set(engine OpenCVEngine)
|
||||
set(JNI_LIB_NAME ${engine} ${engine}_jni)
|
||||
|
||||
unset(__android_project_chain CACHE)
|
||||
add_android_project(opencv_engine "${CMAKE_CURRENT_SOURCE_DIR}" SDK_TARGET 9 ${ANDROID_SDK_TARGET} IGNORE_JAVA ON IGNORE_MANIFEST ON )
|
||||
|
||||
set(ANDROID_PLATFORM_VERSION_CODE "0")
|
||||
|
||||
if(ARMEABI_V7A)
|
||||
if (ANDROID_NATIVE_API_LEVEL LESS 9)
|
||||
set(ANDROID_PLATFORM_VERSION_CODE "2")
|
||||
else()
|
||||
set(ANDROID_PLATFORM_VERSION_CODE "3")
|
||||
endif()
|
||||
elseif(ARMEABI_V6)
|
||||
set(ANDROID_PLATFORM_VERSION_CODE "1")
|
||||
elseif(ARMEABI)
|
||||
set(ANDROID_PLATFORM_VERSION_CODE "1")
|
||||
elseif(X86)
|
||||
set(ANDROID_PLATFORM_VERSION_CODE "4")
|
||||
elseif(MIPS)
|
||||
set(ANDROID_PLATFORM_VERSION_CODE "5")
|
||||
else()
|
||||
message(WARNING "Can not automatically determine the value for ANDROID_PLATFORM_VERSION_CODE")
|
||||
endif()
|
||||
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${ANDROID_MANIFEST_FILE}" "${OpenCV_BINARY_DIR}/platforms/android/service/engine/.build/${ANDROID_MANIFEST_FILE}" @ONLY)
|
||||
|
||||
link_directories("${ANDROID_SOURCE_TREE}/out/target/product/generic/system/lib" "${ANDROID_SOURCE_TREE}/out/target/product/${ANDROID_PRODUCT}/system/lib" "${ANDROID_SOURCE_TREE}/bin/${ANDROID_ARCH_NAME}")
|
||||
|
||||
# -D__SUPPORT_ARMEABI_FEATURES key is also available
|
||||
add_definitions(-DPLATFORM_ANDROID -D__SUPPORT_ARMEABI_V7A_FEATURES -D__SUPPORT_TEGRA3 -D__SUPPORT_MIPS)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
|
||||
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-allow-shlib-undefined")
|
||||
file(GLOB engine_files "jni/BinderComponent/*.cpp" "jni/BinderComponent/*.h" "jni/include/*.h")
|
||||
|
||||
include_directories(jni/BinderComponent jni/include)
|
||||
include_directories(SYSTEM "${ANDROID_SOURCE_TREE}/frameworks/base/include" "${ANDROID_SOURCE_TREE}/system/core/include")
|
||||
add_library(${engine} SHARED ${engine_files})
|
||||
target_link_libraries(${engine} z binder log utils)
|
||||
|
||||
set_target_properties(${engine} PROPERTIES
|
||||
OUTPUT_NAME ${engine}
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/.build/libs/${ANDROID_NDK_ABI_NAME}"
|
||||
)
|
||||
|
||||
get_target_property(engine_lib_location ${engine} LOCATION)
|
||||
add_custom_command(TARGET ${engine} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${engine_lib_location}")
|
||||
|
||||
file(GLOB engine_jni_files "jni/JNIWrapper/*.cpp" "jni/JNIWrapper/*.h" "jni/include/*.h")
|
||||
list(APPEND engine_jni_files jni/NativeService/CommonPackageManager.cpp jni/NativeService/PackageInfo.cpp)
|
||||
|
||||
include_directories(jni/include jni/JNIWrapper jni/NativeService jni/BinderComponent "${ANDROID_SOURCE_TREE}/frameworks/base/include" "${ANDROID_SOURCE_TREE}/system/core/include" "${ANDROID_SOURCE_TREE}/frameworks/base/core/jni")
|
||||
add_library(${engine}_jni SHARED ${engine_jni_files})
|
||||
target_link_libraries(${engine}_jni z binder log utils android_runtime ${engine})
|
||||
|
||||
set_target_properties(${engine}_jni PROPERTIES
|
||||
OUTPUT_NAME ${engine}_jni
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/.build/libs/${ANDROID_NDK_ABI_NAME}"
|
||||
)
|
||||
|
||||
get_target_property(engine_lib_location ${engine}_jni LOCATION)
|
||||
add_custom_command(TARGET ${engine}_jni POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${engine_lib_location}")
|
||||
|
||||
# native tests
|
||||
add_definitions(-DGTEST_HAS_CLONE=0 -DANDROID -DGTEST_HAS_TR1_TUPLE=0)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined")
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/jni/Tests)
|
||||
file(GLOB engine_test_files "jni/Tests/*.cpp")
|
||||
|
||||
add_executable(opencv_test_engine ${engine_test_files} jni/Tests/gtest/gtest-all.cpp)
|
||||
target_link_libraries(opencv_test_engine z binder log utils android_runtime ${engine} ${engine}_jni)
|
92
platforms/android/service/engine/build.xml
Normal file
@@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="OpenCV Manager" default="help">
|
||||
|
||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||
It contains the path to the SDK. It should *NOT* be checked into
|
||||
Version Control Systems. -->
|
||||
<property file="local.properties" />
|
||||
|
||||
<!-- The ant.properties file can be created by you. It is only edited by the
|
||||
'android' tool to add properties to it.
|
||||
This is the place to change some Ant specific build properties.
|
||||
Here are some properties you may want to change/update:
|
||||
|
||||
source.dir
|
||||
The name of the source directory. Default is 'src'.
|
||||
out.dir
|
||||
The name of the output directory. Default is 'bin'.
|
||||
|
||||
For other overridable properties, look at the beginning of the rules
|
||||
files in the SDK, at tools/ant/build.xml
|
||||
|
||||
Properties related to the SDK location or the project target should
|
||||
be updated using the 'android' tool with the 'update' action.
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems.
|
||||
|
||||
-->
|
||||
<property file="ant.properties" />
|
||||
|
||||
<!-- if sdk.dir was not set from one of the property file, then
|
||||
get it from the ANDROID_HOME env var.
|
||||
This must be done before we load project.properties since
|
||||
the proguard config can use sdk.dir -->
|
||||
<property environment="env" />
|
||||
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
|
||||
<isset property="env.ANDROID_HOME" />
|
||||
</condition>
|
||||
|
||||
<!-- The project.properties file is created and updated by the 'android'
|
||||
tool, as well as ADT.
|
||||
|
||||
This contains project specific properties such as project target, and library
|
||||
dependencies. Lower level build properties are stored in ant.properties
|
||||
(or in .classpath for Eclipse projects).
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems. -->
|
||||
<loadproperties srcFile="project.properties" />
|
||||
|
||||
<!-- quick check on sdk.dir -->
|
||||
<fail
|
||||
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
|
||||
unless="sdk.dir"
|
||||
/>
|
||||
|
||||
<!--
|
||||
Import per project custom build rules if present at the root of the project.
|
||||
This is the place to put custom intermediary targets such as:
|
||||
-pre-build
|
||||
-pre-compile
|
||||
-post-compile (This is typically used for code obfuscation.
|
||||
Compiled code location: ${out.classes.absolute.dir}
|
||||
If this is not done in place, override ${out.dex.input.absolute.dir})
|
||||
-post-package
|
||||
-post-build
|
||||
-pre-clean
|
||||
-->
|
||||
<import file="custom_rules.xml" optional="true" />
|
||||
|
||||
<!-- Import the actual build file.
|
||||
|
||||
To customize existing targets, there are two options:
|
||||
- Customize only one target:
|
||||
- copy/paste the target into this file, *before* the
|
||||
<import> task.
|
||||
- customize it to your needs.
|
||||
- Customize the whole content of build.xml
|
||||
- copy/paste the content of the rules files (minus the top node)
|
||||
into this file, replacing the <import> task.
|
||||
- customize to your needs.
|
||||
|
||||
***********************
|
||||
****** IMPORTANT ******
|
||||
***********************
|
||||
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
|
||||
in order to avoid having your file be overridden by tools such as "android update project"
|
||||
-->
|
||||
<!-- version-tag: 1 -->
|
||||
<import file="${sdk.dir}/tools/ant/build.xml" />
|
||||
|
||||
</project>
|
86
platforms/android/service/engine/jni/Android.mk
Normal file
@@ -0,0 +1,86 @@
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Binder component library
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
BinderComponent/OpenCVEngine.cpp \
|
||||
BinderComponent/BnOpenCVEngine.cpp \
|
||||
BinderComponent/BpOpenCVEngine.cpp \
|
||||
BinderComponent/ProcReader.cpp \
|
||||
BinderComponent/TegraDetector.cpp \
|
||||
BinderComponent/StringUtils.cpp \
|
||||
BinderComponent/HardwareDetector.cpp
|
||||
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/include \
|
||||
$(LOCAL_PATH)/BinderComponent \
|
||||
$(TOP)/frameworks/base/include \
|
||||
$(TOP)/system/core/include
|
||||
|
||||
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
|
||||
|
||||
LOCAL_MODULE := libOpenCVEngine
|
||||
|
||||
LOCAL_LDLIBS += -lz -lbinder -llog -lutils
|
||||
|
||||
LOCAL_LDFLAGS += -Wl,-allow-shlib-undefined
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# JNI library for Java service
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
JNIWrapper/OpenCVEngine_jni.cpp \
|
||||
NativeService/CommonPackageManager.cpp \
|
||||
JNIWrapper/JavaBasedPackageManager.cpp \
|
||||
NativeService/PackageInfo.cpp \
|
||||
JNIWrapper/HardwareDetector_jni.cpp \
|
||||
JNIWrapper/OpenCVLibraryInfo.cpp
|
||||
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/include \
|
||||
$(LOCAL_PATH)/JNIWrapper \
|
||||
$(LOCAL_PATH)/NativeService \
|
||||
$(LOCAL_PATH)/BinderComponent \
|
||||
$(TOP)/frameworks/base/include \
|
||||
$(TOP)/system/core/include \
|
||||
$(TOP)/frameworks/base/core/jni
|
||||
|
||||
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
|
||||
|
||||
LOCAL_LDLIBS += -lz -lbinder -llog -lutils -landroid_runtime
|
||||
LOCAL_SHARED_LIBRARIES = libOpenCVEngine
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Native test application
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
#include $(LOCAL_PATH)/Tests/Tests.mk
|
6
platforms/android/service/engine/jni/Application.mk
Normal file
@@ -0,0 +1,6 @@
|
||||
APP_ABI := armeabi x86 mips
|
||||
APP_PLATFORM := android-8
|
||||
APP_STL := stlport_static
|
||||
APP_CPPFLAGS := -fno-rtti -fno-exceptions
|
||||
NDK_TOOLCHAIN_VERSION=4.4.3
|
||||
#APP_OPTIM := debug
|
@@ -0,0 +1,72 @@
|
||||
#include "EngineCommon.h"
|
||||
#include "IOpenCVEngine.h"
|
||||
#include "BnOpenCVEngine.h"
|
||||
#include <utils/Log.h>
|
||||
#include <utils/String8.h>
|
||||
#include <utils/String16.h>
|
||||
|
||||
using namespace android;
|
||||
|
||||
BnOpenCVEngine::~BnOpenCVEngine()
|
||||
{
|
||||
}
|
||||
|
||||
// Notes about data transaction:
|
||||
// Java Binder Wrapper call readInt32 before reading return data
|
||||
// It treet this in value as exception code
|
||||
// OnTransact method support this feature
|
||||
status_t BnOpenCVEngine::onTransact(uint32_t code, const Parcel& data, android::Parcel* reply, uint32_t flags)
|
||||
{
|
||||
LOGD("OpenCVEngine::OnTransact(%u,%u)", code, flags);
|
||||
|
||||
switch(code)
|
||||
{
|
||||
case OCVE_GET_ENGINE_VERSION:
|
||||
{
|
||||
LOGD("OpenCVEngine OCVE_GET_ENGINE_VERSION request");
|
||||
CHECK_INTERFACE(IOpenCVEngine, data, reply);
|
||||
LOGD("OpenCVEngine::GetVersion()");
|
||||
reply->writeInt32(0);
|
||||
return reply->writeInt32(GetVersion());
|
||||
} break;
|
||||
case OCVE_GET_LIB_PATH_BY_VERSION:
|
||||
{
|
||||
LOGD("OpenCVEngine OCVE_GET_LIB_PATH_BY_VERSION request");
|
||||
CHECK_INTERFACE(IOpenCVEngine, data, reply);
|
||||
const String16 version = data.readString16();
|
||||
LOGD("OpenCVEngine::GetLibPathByVersion(%s)", String8(version).string());
|
||||
String16 path = GetLibPathByVersion(version);
|
||||
reply->writeInt32(0);
|
||||
return reply->writeString16(path);
|
||||
} break;
|
||||
case OCVE_GET_LIB_LIST:
|
||||
{
|
||||
LOGD("OpenCVEngine OCVE_GET_LIB_LIST request");
|
||||
CHECK_INTERFACE(IOpenCVEngine, data, reply);
|
||||
const String16 version = data.readString16();
|
||||
LOGD("OpenCVEngine::GetLibraryList(%s)", String8(version).string());
|
||||
String16 path = GetLibraryList(version);
|
||||
reply->writeInt32(0);
|
||||
return reply->writeString16(path);
|
||||
} break;
|
||||
case OCVE_INSTALL_VERSION:
|
||||
{
|
||||
LOGD("OpenCVEngine OCVE_INSTALL_VERSION request");
|
||||
CHECK_INTERFACE(IOpenCVEngine, data, reply);
|
||||
const String16 version = data.readString16();
|
||||
LOGD("OpenCVEngine::InstallVersion(%s)", String8(version).string());
|
||||
bool result = InstallVersion(version);
|
||||
reply->writeInt32(0);
|
||||
int res = reply->writeInt32(static_cast<int32_t>(result));
|
||||
LOGD("InstallVersion call to Binder finished with res %d", res);
|
||||
return res;
|
||||
} break;
|
||||
default:
|
||||
{
|
||||
LOGD("OpenCVEngine unknown request");
|
||||
return BBinder::onTransact(code, data, reply, flags);
|
||||
}
|
||||
}
|
||||
|
||||
return android::NO_ERROR;
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
#ifndef __BP_OPENCV_ENGINE_H__
|
||||
#define __BP_OPENCV_ENGINE_H__
|
||||
|
||||
#include "EngineCommon.h"
|
||||
#include "IOpenCVEngine.h"
|
||||
#include <binder/IInterface.h>
|
||||
#include <binder/Parcel.h>
|
||||
#include <utils/String16.h>
|
||||
|
||||
class BnOpenCVEngine: public android::BnInterface<IOpenCVEngine>
|
||||
{
|
||||
public:
|
||||
android::status_t onTransact(uint32_t code,
|
||||
const android::Parcel &data,
|
||||
android::Parcel *reply,
|
||||
uint32_t flags);
|
||||
virtual ~BnOpenCVEngine();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@@ -0,0 +1,71 @@
|
||||
#include "IOpenCVEngine.h"
|
||||
#include "BpOpenCVEngine.h"
|
||||
|
||||
using namespace android;
|
||||
|
||||
BpOpenCVEngine::BpOpenCVEngine(const sp<IBinder>& impl):
|
||||
BpInterface<IOpenCVEngine>(impl)
|
||||
{
|
||||
}
|
||||
|
||||
BpOpenCVEngine::~BpOpenCVEngine()
|
||||
{
|
||||
}
|
||||
|
||||
// Notes about data transaction:
|
||||
// Java Binder Wrapper call readInt32 before reading return data
|
||||
// It treet this in value as exception code
|
||||
// This implementation support this feature
|
||||
|
||||
int BpOpenCVEngine::GetVersion()
|
||||
{
|
||||
Parcel data, reply;
|
||||
|
||||
data.writeInterfaceToken(IOpenCVEngine::descriptor);
|
||||
remote()->transact(OCVE_GET_ENGINE_VERSION, data, &reply, 0);
|
||||
// read exception code
|
||||
reply.readInt32();
|
||||
|
||||
return reply.readInt32();
|
||||
}
|
||||
|
||||
String16 BpOpenCVEngine::GetLibPathByVersion(String16 version)
|
||||
{
|
||||
Parcel data, reply;
|
||||
|
||||
data.writeInterfaceToken(IOpenCVEngine::descriptor);
|
||||
data.writeString16(version);
|
||||
remote()->transact(OCVE_GET_LIB_PATH_BY_VERSION, data, &reply, 0);
|
||||
// read exception code
|
||||
reply.readInt32();
|
||||
|
||||
return reply.readString16();
|
||||
}
|
||||
|
||||
android::String16 BpOpenCVEngine::GetLibraryList(String16 version)
|
||||
{
|
||||
Parcel data, reply;
|
||||
|
||||
data.writeInterfaceToken(IOpenCVEngine::descriptor);
|
||||
data.writeString16(version);
|
||||
remote()->transact(OCVE_GET_LIB_LIST, data, &reply, 0);
|
||||
// read exception code
|
||||
reply.readInt32();
|
||||
|
||||
return reply.readString16();
|
||||
}
|
||||
|
||||
bool BpOpenCVEngine::InstallVersion(String16 version)
|
||||
{
|
||||
Parcel data, reply;
|
||||
|
||||
data.writeInterfaceToken(IOpenCVEngine::descriptor);
|
||||
data.writeString16(version);
|
||||
remote()->transact(OCVE_INSTALL_VERSION, data, &reply, 0);
|
||||
// read exception code
|
||||
reply.readInt32();
|
||||
|
||||
return static_cast<bool>(reply.readInt32());
|
||||
}
|
||||
|
||||
IMPLEMENT_META_INTERFACE(OpenCVEngine, OPECV_ENGINE_CLASSNAME)
|
@@ -0,0 +1,20 @@
|
||||
#ifndef __BP_OPENCV_ENGINE_H__
|
||||
#define __BP_OPENCV_ENGINE_H__
|
||||
|
||||
#include "IOpenCVEngine.h"
|
||||
#include <binder/IInterface.h>
|
||||
#include <binder/Parcel.h>
|
||||
#include <utils/String16.h>
|
||||
|
||||
class BpOpenCVEngine: public android::BpInterface<IOpenCVEngine>
|
||||
{
|
||||
public:
|
||||
BpOpenCVEngine(const android::sp<android::IBinder>& impl);
|
||||
virtual ~BpOpenCVEngine();
|
||||
virtual int GetVersion();
|
||||
virtual android::String16 GetLibPathByVersion(android::String16 version);
|
||||
virtual android::String16 GetLibraryList(android::String16 version);
|
||||
virtual bool InstallVersion(android::String16 version);
|
||||
};
|
||||
|
||||
#endif
|
@@ -0,0 +1,175 @@
|
||||
#include "HardwareDetector.h"
|
||||
#include "TegraDetector.h"
|
||||
#include "ProcReader.h"
|
||||
#include "EngineCommon.h"
|
||||
#include "StringUtils.h"
|
||||
#include <utils/Log.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int GetCpuID()
|
||||
{
|
||||
int result = 0;
|
||||
map<string, string> cpu_info = GetCpuInfo();
|
||||
map<string, string>::const_iterator it;
|
||||
|
||||
#if defined(__i386__)
|
||||
LOGD("Using X86 HW detector");
|
||||
result |= ARCH_X86;
|
||||
it = cpu_info.find("flags");
|
||||
if (cpu_info.end() != it)
|
||||
{
|
||||
set<string> features = SplitString(it->second, ' ');
|
||||
if (features.end() != features.find(CPU_INFO_SSE_STR))
|
||||
{
|
||||
result |= FEATURES_HAS_SSE;
|
||||
}
|
||||
if (features.end() != features.find(CPU_INFO_SSE2_STR))
|
||||
{
|
||||
result |= FEATURES_HAS_SSE2;
|
||||
}
|
||||
if (features.end() != features.find(CPU_INFO_SSSE3_STR))
|
||||
{
|
||||
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");
|
||||
|
||||
if (cpu_info.end() != it)
|
||||
{
|
||||
size_t proc_name_pos = it->second.find(CPU_INFO_ARCH_X86_STR);
|
||||
if (string::npos != proc_name_pos)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
proc_name_pos = it->second.find(CPU_INFO_ARCH_ARMV7_STR);
|
||||
if (string::npos != proc_name_pos)
|
||||
{
|
||||
result |= ARCH_ARMv7;
|
||||
}
|
||||
else
|
||||
{
|
||||
proc_name_pos = it->second.find(CPU_INFO_ARCH_ARMV6_STR);
|
||||
if (string::npos != proc_name_pos)
|
||||
{
|
||||
result |= ARCH_ARMv6;
|
||||
}
|
||||
else
|
||||
{
|
||||
proc_name_pos = it->second.find(CPU_INFO_ARCH_ARMV5_STR);
|
||||
if (string::npos != proc_name_pos)
|
||||
{
|
||||
result |= ARCH_ARMv5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return ARCH_UNKNOWN;
|
||||
}
|
||||
|
||||
it = cpu_info.find("Features");
|
||||
if (cpu_info.end() != it)
|
||||
{
|
||||
set<string> features = SplitString(it->second, ' ');
|
||||
if (features.end() != features.find(CPU_INFO_NEON_STR))
|
||||
{
|
||||
result |= FEATURES_HAS_NEON;
|
||||
}
|
||||
if (features.end() != features.find(CPU_INFO_NEON2_STR))
|
||||
{
|
||||
result |= FEATURES_HAS_NEON2;
|
||||
}
|
||||
if (features.end() != features.find(CPU_INFO_VFPV3_STR))
|
||||
{
|
||||
if (features.end () != features.find(CPU_INFO_VFPV3D16_STR))
|
||||
{
|
||||
result |= FEATURES_HAS_VFPv3d16;
|
||||
}
|
||||
else
|
||||
{
|
||||
result |= FEATURES_HAS_VFPv3;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
string GetPlatformName()
|
||||
{
|
||||
map<string, string> cpu_info = GetCpuInfo();
|
||||
string hardware_name = "";
|
||||
map<string, string>::const_iterator hw_iterator = cpu_info.find("Hardware");
|
||||
|
||||
if (cpu_info.end() != hw_iterator)
|
||||
{
|
||||
hardware_name = hw_iterator->second;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
while(*pbuf)
|
||||
{
|
||||
const char* pos = pbuf;
|
||||
bool range = false;
|
||||
while(*pbuf && *pbuf != ',')
|
||||
{
|
||||
if(*pbuf == '-') range = true;
|
||||
++pbuf;
|
||||
}
|
||||
if(*pbuf) *pbuf++ = 0;
|
||||
if(!range)
|
||||
++cpusAvailable;
|
||||
else
|
||||
{
|
||||
int rstart = 0, rend = 0;
|
||||
sscanf(pos, "%d-%d", &rstart, &rend);
|
||||
cpusAvailable += rend - rstart + 1;
|
||||
}
|
||||
}
|
||||
return cpusAvailable ? cpusAvailable : 1;
|
||||
}
|
||||
|
||||
int DetectKnownPlatforms()
|
||||
{
|
||||
int tegra_status = DetectTegra();
|
||||
|
||||
// All Tegra platforms since Tegra3
|
||||
if (2 < tegra_status)
|
||||
{
|
||||
return PLATFORM_TEGRA + tegra_status - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return PLATFORM_UNKNOWN;
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
#ifndef __HARDWARE_DETECTOR_H__
|
||||
#define __HARDWARE_DETECTOR_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
#define ARCH_UNKNOWN 0L
|
||||
#define ARCH_X86 16777216L
|
||||
#define ARCH_X64 33554432L
|
||||
#define ARCH_ARMv5 67108864L
|
||||
#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
|
||||
#define FEATURES_HAS_NEON 4L
|
||||
#define FEATURES_HAS_NEON2 8L
|
||||
#define FEATURES_HAS_SSE 1L
|
||||
#define FEATURES_HAS_SSE2 2L
|
||||
#define FEATURES_HAS_SSSE3 4L
|
||||
#define FEATURES_HAS_GPU 65536L
|
||||
|
||||
// TODO: Do not forget to add Platrfom name to PackageInfo::PlatformNameMap
|
||||
// in method PackageInfo::InitPlatformNameMap()
|
||||
#define PLATFORM_UNKNOWN 0L
|
||||
#define PLATFORM_TEGRA 1L
|
||||
#define PLATFORM_TEGRA2 2L
|
||||
#define PLATFORM_TEGRA3 3L
|
||||
#define PLATFORM_TEGRA4 4L
|
||||
|
||||
int DetectKnownPlatforms();
|
||||
int GetProcessorCount();
|
||||
std::string GetPlatformName();
|
||||
int GetCpuID();
|
||||
|
||||
#endif
|
@@ -0,0 +1,202 @@
|
||||
#include "EngineCommon.h"
|
||||
#include "OpenCVEngine.h"
|
||||
#include "HardwareDetector.h"
|
||||
#include "StringUtils.h"
|
||||
#include <utils/Log.h>
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
using namespace android;
|
||||
|
||||
const int OpenCVEngine::Platform = DetectKnownPlatforms();
|
||||
const int OpenCVEngine::CpuID = GetCpuID();
|
||||
const int OpenCVEngine::KnownVersions[] = {2040000, 2040100, 2040200, 2040300, 2040301, 2040302, 2040400, 2040500};
|
||||
|
||||
bool OpenCVEngine::ValidateVersion(int version)
|
||||
{
|
||||
for (size_t i = 0; i < sizeof(KnownVersions)/sizeof(int); i++)
|
||||
if (KnownVersions[i] == version)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int OpenCVEngine::NormalizeVersionString(std::string version)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (version.empty())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> parts = SplitStringVector(version, '.');
|
||||
|
||||
// Use only 4 digits of the version, i.e. 1.2.3.4.
|
||||
// Other digits will be ignored.
|
||||
if (parts.size() > 4)
|
||||
parts.erase(parts.begin()+4, parts.end());
|
||||
|
||||
int multiplyer = 1000000;
|
||||
for (std::vector<std::string>::const_iterator it = parts.begin(); it != parts.end(); ++it)
|
||||
{
|
||||
int digit = atoi(it->c_str());
|
||||
result += multiplyer*digit;
|
||||
multiplyer /= 100;
|
||||
}
|
||||
|
||||
if (!ValidateVersion(result))
|
||||
result = 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
OpenCVEngine::OpenCVEngine(IPackageManager* PkgManager):
|
||||
PackageManager(PkgManager)
|
||||
{
|
||||
assert(PkgManager);
|
||||
}
|
||||
|
||||
int32_t OpenCVEngine::GetVersion()
|
||||
{
|
||||
return OPEN_CV_ENGINE_VERSION;
|
||||
}
|
||||
|
||||
String16 OpenCVEngine::GetLibPathByVersion(android::String16 version)
|
||||
{
|
||||
std::string std_version(String8(version).string());
|
||||
int norm_version;
|
||||
std::string path;
|
||||
|
||||
LOGD("OpenCVEngine::GetLibPathByVersion(%s) impl", String8(version).string());
|
||||
|
||||
norm_version = NormalizeVersionString(std_version);
|
||||
|
||||
if (0 != norm_version)
|
||||
{
|
||||
path = PackageManager->GetPackagePathByVersion(norm_version, Platform, CpuID);
|
||||
if (path.empty())
|
||||
{
|
||||
LOGI("Package OpenCV of version \"%s\" (%d) is not installed. Try to install it :)", String8(version).string(), norm_version);
|
||||
}
|
||||
else
|
||||
{
|
||||
FixPermissions(path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGE("OpenCV version \"%s\" (%d) is not supported", String8(version).string(), norm_version);
|
||||
}
|
||||
|
||||
return String16(path.c_str());
|
||||
}
|
||||
|
||||
android::String16 OpenCVEngine::GetLibraryList(android::String16 version)
|
||||
{
|
||||
std::string std_version = String8(version).string();
|
||||
int norm_version;
|
||||
String16 result;
|
||||
norm_version = NormalizeVersionString(std_version);
|
||||
|
||||
if (0 != norm_version)
|
||||
{
|
||||
std::string tmp = PackageManager->GetPackagePathByVersion(norm_version, Platform, CpuID);
|
||||
if (!tmp.empty())
|
||||
{
|
||||
tmp += (std::string("/") + LIB_OPENCV_INFO_NAME);
|
||||
|
||||
LOGD("Trying to load info library \"%s\"", tmp.c_str());
|
||||
|
||||
void* handle;
|
||||
InfoFunctionType info_func;
|
||||
|
||||
handle = dlopen(tmp.c_str(), RTLD_LAZY);
|
||||
if (handle)
|
||||
{
|
||||
const char* error;
|
||||
|
||||
dlerror();
|
||||
info_func = (InfoFunctionType)dlsym(handle, "GetLibraryList");
|
||||
if ((error = dlerror()) == NULL)
|
||||
{
|
||||
result = String16((*info_func)());
|
||||
dlclose(handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGE("Library loading error: \"%s\"", error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGI("Info library not found in package");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGI("Package OpenCV of version \"%s\" (%d) is not installed. Try to install it :)", std_version.c_str(), norm_version);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGE("OpenCV version \"%s\" is not supported", std_version.c_str());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool OpenCVEngine::InstallVersion(android::String16 version)
|
||||
{
|
||||
std::string std_version = String8(version).string();
|
||||
int norm_version;
|
||||
bool result = false;
|
||||
|
||||
LOGD("OpenCVEngine::InstallVersion() begin");
|
||||
|
||||
norm_version = NormalizeVersionString(std_version);
|
||||
|
||||
if (0 != norm_version)
|
||||
{
|
||||
LOGD("PackageManager->InstallVersion call");
|
||||
result = PackageManager->InstallVersion(norm_version, Platform, CpuID);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGE("OpenCV version \"%s\" (%d) is not supported", std_version.c_str(), norm_version);
|
||||
}
|
||||
|
||||
LOGD("OpenCVEngine::InstallVersion() end");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool OpenCVEngine::FixPermissions(const std::string& path)
|
||||
{
|
||||
LOGD("Fixing permissions for folder: \"%s\"", path.c_str());
|
||||
chmod(path.c_str(), S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
|
||||
|
||||
DIR* dir = opendir(path.c_str());
|
||||
if (!dir)
|
||||
{
|
||||
LOGD("Fixing permissions error");
|
||||
return false;
|
||||
}
|
||||
|
||||
dirent* files = readdir(dir);
|
||||
while (files)
|
||||
{
|
||||
LOGD("Fix permissions for \"%s\"", files->d_name);
|
||||
chmod((path + std::string("/") + std::string(files->d_name)).c_str(), S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
|
||||
files = readdir(dir);
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
|
||||
return true;
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
#ifndef __OPEN_CV_ENGINE_H__
|
||||
#define __OPEN_CV_ENGINE_H__
|
||||
|
||||
#include "EngineCommon.h"
|
||||
#include "IOpenCVEngine.h"
|
||||
#include "BnOpenCVEngine.h"
|
||||
#include "IPackageManager.h"
|
||||
#include <binder/IInterface.h>
|
||||
#include <binder/Parcel.h>
|
||||
#include <utils/String8.h>
|
||||
#include <utils/String16.h>
|
||||
#include <string>
|
||||
#include <set>
|
||||
|
||||
class OpenCVEngine: public BnOpenCVEngine
|
||||
{
|
||||
public:
|
||||
OpenCVEngine(IPackageManager* PkgManager);
|
||||
int32_t GetVersion();
|
||||
android::String16 GetLibPathByVersion(android::String16 version);
|
||||
virtual android::String16 GetLibraryList(android::String16 version);
|
||||
bool InstallVersion(android::String16 version);
|
||||
|
||||
protected:
|
||||
IPackageManager* PackageManager;
|
||||
static const int KnownVersions[];
|
||||
|
||||
OpenCVEngine();
|
||||
bool ValidateVersion(int version);
|
||||
int NormalizeVersionString(std::string version);
|
||||
bool FixPermissions(const std::string& path);
|
||||
|
||||
static const int Platform;
|
||||
static const int CpuID;
|
||||
};
|
||||
|
||||
#endif
|
@@ -0,0 +1,31 @@
|
||||
#include "ProcReader.h"
|
||||
#include "StringUtils.h"
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
map<string, string> GetCpuInfo()
|
||||
{
|
||||
map<string, string> result;
|
||||
ifstream f;
|
||||
|
||||
f.open("/proc/cpuinfo");
|
||||
if (f.is_open())
|
||||
{
|
||||
while (!f.eof())
|
||||
{
|
||||
string tmp;
|
||||
string key;
|
||||
string value;
|
||||
getline(f, tmp);
|
||||
if (ParseString(tmp, key, value))
|
||||
{
|
||||
result[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
f.close();
|
||||
|
||||
return result;
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
#ifndef __PROC_READER_H__
|
||||
#define __PROC_READER_H__
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#define CPU_INFO_NEON_STR "neon"
|
||||
#define CPU_INFO_NEON2_STR "neon2"
|
||||
#define CPU_INFO_VFPV3_STR "vfpv3"
|
||||
#define CPU_INFO_VFPV3D16_STR "vfpv3d16"
|
||||
|
||||
#define CPU_INFO_SSE_STR "sse"
|
||||
#define CPU_INFO_SSE2_STR "sse2"
|
||||
#define CPU_INFO_SSSE3_STR "ssse3"
|
||||
|
||||
#define CPU_INFO_ARCH_ARMV7_STR "(v7l)"
|
||||
#define CPU_INFO_ARCH_ARMV6_STR "(v6l)"
|
||||
#define CPU_INFO_ARCH_ARMV5_STR "(v5l)"
|
||||
|
||||
#define CPU_INFO_ARCH_X86_STR "x86"
|
||||
|
||||
#define CPU_INFO_ARCH_MIPS_STR "MIPS"
|
||||
|
||||
|
||||
// public part
|
||||
std::map<std::string, std::string> GetCpuInfo();
|
||||
|
||||
#endif
|
@@ -0,0 +1,92 @@
|
||||
#include "StringUtils.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool StripString(string& src)
|
||||
{
|
||||
size_t pos = 0;
|
||||
|
||||
if (src.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
while ((pos < src.length()) && (' ' == src[pos])) pos++;
|
||||
src.erase(0, pos);
|
||||
|
||||
pos = 0;
|
||||
while ((pos < src.length()) && ('\t' == src[pos])) pos++;
|
||||
src.erase(0, pos);
|
||||
|
||||
pos = src.length() - 1;
|
||||
while (pos && (' ' == src[pos])) pos--;
|
||||
src.erase(pos+1);
|
||||
|
||||
pos = src.length() - 1;
|
||||
while (pos && ('\t' == src[pos])) pos--;
|
||||
src.erase(pos+1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ParseString(const string& src, string& key, string& value)
|
||||
{
|
||||
if (src.empty())
|
||||
return false;
|
||||
|
||||
// find seporator ":"
|
||||
size_t seporator_pos = src.find(":");
|
||||
if (string::npos != seporator_pos)
|
||||
{
|
||||
key = src.substr(0, seporator_pos);
|
||||
StripString(key);
|
||||
value = src.substr(seporator_pos+1);
|
||||
StripString(value);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
set<string> SplitString(const string& src, const char seporator)
|
||||
{
|
||||
set<string> result;
|
||||
|
||||
if (!src.empty())
|
||||
{
|
||||
size_t seporator_pos;
|
||||
size_t prev_pos = 0;
|
||||
do
|
||||
{
|
||||
seporator_pos = src.find(seporator, prev_pos);
|
||||
result.insert(src.substr(prev_pos, seporator_pos - prev_pos));
|
||||
prev_pos = seporator_pos + 1;
|
||||
}
|
||||
while (string::npos != seporator_pos);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
vector<string> SplitStringVector(const string& src, const char seporator)
|
||||
{
|
||||
vector<string> result;
|
||||
|
||||
if (!src.empty())
|
||||
{
|
||||
size_t seporator_pos;
|
||||
size_t prev_pos = 0;
|
||||
do
|
||||
{
|
||||
seporator_pos = src.find(seporator, prev_pos);
|
||||
string tmp = src.substr(prev_pos, seporator_pos - prev_pos);
|
||||
result.push_back(tmp);
|
||||
prev_pos = seporator_pos + 1;
|
||||
}
|
||||
while (string::npos != seporator_pos);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
#ifndef __STRING_UTILS_H__
|
||||
#define __STRING_UTILS_H__
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
bool StripString(std::string& src);
|
||||
std::set<std::string> SplitString(const std::string& src, const char seporator);
|
||||
bool ParseString(const std::string& src, std::string& key, std::string& value);
|
||||
std::vector<std::string> SplitStringVector(const std::string& src, const char seporator);
|
||||
|
||||
#endif
|
@@ -0,0 +1,61 @@
|
||||
#include "TegraDetector.h"
|
||||
#include <zlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define KERNEL_CONFIG "/proc/config.gz"
|
||||
#define KERNEL_CONFIG_MAX_LINE_WIDTH 512
|
||||
#define KERNEL_CONFIG_TEGRA_MAGIC "CONFIG_ARCH_TEGRA=y"
|
||||
#define KERNEL_CONFIG_TEGRA2_MAGIC "CONFIG_ARCH_TEGRA_2x_SOC=y"
|
||||
#define KERNEL_CONFIG_TEGRA3_MAGIC "CONFIG_ARCH_TEGRA_3x_SOC=y"
|
||||
#define KERNEL_CONFIG_TEGRA4_MAGIC "CONFIG_ARCH_TEGRA_11x_SOC=y"
|
||||
#define MAX_DATA_LEN 4096
|
||||
|
||||
int DetectTegra()
|
||||
{
|
||||
int result = TEGRA_NOT_TEGRA;
|
||||
gzFile kernelConfig = gzopen(KERNEL_CONFIG, "r");
|
||||
if (kernelConfig != 0)
|
||||
{
|
||||
char tmpbuf[KERNEL_CONFIG_MAX_LINE_WIDTH];
|
||||
const char *tegra_config = KERNEL_CONFIG_TEGRA_MAGIC;
|
||||
const char *tegra2_config = KERNEL_CONFIG_TEGRA2_MAGIC;
|
||||
const char *tegra3_config = KERNEL_CONFIG_TEGRA3_MAGIC;
|
||||
const char *tegra4_config = KERNEL_CONFIG_TEGRA4_MAGIC;
|
||||
int len = strlen(tegra_config);
|
||||
int len2 = strlen(tegra2_config);
|
||||
int len3 = strlen(tegra3_config);
|
||||
int len4 = strlen(tegra4_config);
|
||||
while (0 != gzgets(kernelConfig, tmpbuf, KERNEL_CONFIG_MAX_LINE_WIDTH))
|
||||
{
|
||||
if (0 == strncmp(tmpbuf, tegra_config, len))
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
|
||||
if (0 == strncmp(tmpbuf, tegra2_config, len2))
|
||||
{
|
||||
result = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
if (0 == strncmp(tmpbuf, tegra3_config, len3))
|
||||
{
|
||||
result = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
if (0 == strncmp(tmpbuf, tegra4_config, len4))
|
||||
{
|
||||
result = 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
gzclose(kernelConfig);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = TEGRA_DETECTOR_ERROR;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
#ifndef __TEGRA_DETECTOR_H__
|
||||
#define __TEGRA_DETECTOR_H__
|
||||
|
||||
#define TEGRA_DETECTOR_ERROR -2
|
||||
#define TEGRA_NOT_TEGRA -1
|
||||
|
||||
int DetectTegra();
|
||||
|
||||
#endif
|
@@ -0,0 +1,25 @@
|
||||
#include "HardwareDetector_jni.h"
|
||||
#include "HardwareDetector.h"
|
||||
#include <jni.h>
|
||||
#include <string>
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_opencv_engine_HardwareDetector_GetCpuID(JNIEnv* , jclass)
|
||||
{
|
||||
return GetCpuID();
|
||||
}
|
||||
|
||||
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_HardwareDetector_GetProcessorCount(JNIEnv* , jclass)
|
||||
{
|
||||
return GetProcessorCount();
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_opencv_engine_HardwareDetector_DetectKnownPlatforms(JNIEnv* , jclass)
|
||||
{
|
||||
return DetectKnownPlatforms();
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class HardwareDetector */
|
||||
|
||||
#ifndef _Included_HardwareDetector
|
||||
#define _Included_HardwareDetector
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Class: org_opencv_engine_HardwareDetector
|
||||
* Method: GetCpuID
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_opencv_engine_HardwareDetector_GetCpuID
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: org_opencv_engine_HardwareDetector
|
||||
* Method: GetPlatformName
|
||||
* Signature: ()Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_engine_HardwareDetector_GetPlatformName
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: org_opencv_engine_HardwareDetector
|
||||
* Method: GetProcessorCount
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_opencv_engine_HardwareDetector_GetProcessorCount
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: org_opencv_engine_HardwareDetector
|
||||
* Method: DetectKnownPlatforms
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_opencv_engine_HardwareDetector_DetectKnownPlatforms
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@@ -0,0 +1,202 @@
|
||||
#include "JavaBasedPackageManager.h"
|
||||
#include <utils/Log.h>
|
||||
#include <assert.h>
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "JavaBasedPackageManager"
|
||||
|
||||
using namespace std;
|
||||
|
||||
JavaBasedPackageManager::JavaBasedPackageManager(JavaVM* JavaMashine, jobject MarketConnector):
|
||||
JavaContext(JavaMashine),
|
||||
JavaPackageManager(MarketConnector)
|
||||
{
|
||||
assert(JavaContext);
|
||||
assert(JavaPackageManager);
|
||||
}
|
||||
|
||||
bool JavaBasedPackageManager::InstallPackage(const PackageInfo& package)
|
||||
{
|
||||
JNIEnv* jenv;
|
||||
bool self_attached;
|
||||
LOGD("JavaBasedPackageManager::InstallPackage() begin\n");
|
||||
|
||||
self_attached = (JNI_EDETACHED == JavaContext->GetEnv((void**)&jenv, JNI_VERSION_1_6));
|
||||
if (self_attached)
|
||||
{
|
||||
JavaContext->AttachCurrentThread(&jenv, NULL);
|
||||
}
|
||||
|
||||
LOGD("GetObjectClass call\n");
|
||||
jclass jclazz = jenv->GetObjectClass(JavaPackageManager);
|
||||
if (!jclazz)
|
||||
{
|
||||
LOGE("MarketConnector class was not found!");
|
||||
return false;
|
||||
}
|
||||
|
||||
LOGD("GetMethodID call\n");
|
||||
jmethodID jmethod = jenv->GetMethodID(jclazz, "InstallAppFromMarket", "(Ljava/lang/String;)Z");
|
||||
if (!jmethod)
|
||||
{
|
||||
LOGE("MarketConnector::GetAppFormMarket method was not found!");
|
||||
jenv->DeleteLocalRef(jclazz);
|
||||
return false;
|
||||
}
|
||||
|
||||
LOGD("Calling java package manager with package name %s\n", package.GetFullName().c_str());
|
||||
jobject jpkgname = jenv->NewStringUTF(package.GetFullName().c_str());
|
||||
bool result = jenv->CallNonvirtualBooleanMethod(JavaPackageManager, jclazz, jmethod, jpkgname);
|
||||
|
||||
jenv->DeleteLocalRef(jpkgname);
|
||||
jenv->DeleteLocalRef(jclazz);
|
||||
|
||||
if (self_attached)
|
||||
{
|
||||
JavaContext->DetachCurrentThread();
|
||||
}
|
||||
|
||||
LOGD("JavaBasedPackageManager::InstallPackage() end\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
vector<PackageInfo> JavaBasedPackageManager::GetInstalledPackages()
|
||||
{
|
||||
vector<PackageInfo> result;
|
||||
JNIEnv* jenv;
|
||||
bool self_attached;
|
||||
|
||||
LOGD("JavaBasedPackageManager::GetInstalledPackages() begin");
|
||||
|
||||
self_attached = (JNI_EDETACHED == JavaContext->GetEnv((void**)&jenv, JNI_VERSION_1_6));
|
||||
if (self_attached)
|
||||
{
|
||||
JavaContext->AttachCurrentThread(&jenv, NULL);
|
||||
}
|
||||
|
||||
jclass jclazz = jenv->GetObjectClass(JavaPackageManager);
|
||||
if (!jclazz)
|
||||
{
|
||||
LOGE("MarketConnector class was not found!");
|
||||
return result;
|
||||
}
|
||||
|
||||
jmethodID jmethod = jenv->GetMethodID(jclazz, "GetInstalledOpenCVPackages", "()[Landroid/content/pm/PackageInfo;");
|
||||
if (!jmethod)
|
||||
{
|
||||
LOGE("MarketConnector::GetInstalledOpenCVPackages method was not found!");
|
||||
jenv->DeleteLocalRef(jclazz);
|
||||
return result;
|
||||
}
|
||||
|
||||
jobjectArray jpkgs = static_cast<jobjectArray>(jenv->CallNonvirtualObjectMethod(JavaPackageManager, jclazz, jmethod));
|
||||
jsize size = jenv->GetArrayLength(jpkgs);
|
||||
|
||||
LOGD("Package info conversion");
|
||||
|
||||
result.reserve(size);
|
||||
|
||||
for (jsize i = 0; i < size; i++)
|
||||
{
|
||||
jobject jtmp = jenv->GetObjectArrayElement(jpkgs, i);
|
||||
PackageInfo tmp = ConvertPackageFromJava(jtmp, jenv);
|
||||
|
||||
if (tmp.IsValid())
|
||||
result.push_back(tmp);
|
||||
|
||||
jenv->DeleteLocalRef(jtmp);
|
||||
}
|
||||
|
||||
jenv->DeleteLocalRef(jpkgs);
|
||||
jenv->DeleteLocalRef(jclazz);
|
||||
|
||||
if (self_attached)
|
||||
{
|
||||
JavaContext->DetachCurrentThread();
|
||||
}
|
||||
|
||||
LOGD("JavaBasedPackageManager::GetInstalledPackages() end");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static jint GetAndroidVersion(JNIEnv* jenv)
|
||||
{
|
||||
jclass jclazz = jenv->FindClass("android/os/Build$VERSION");
|
||||
jfieldID jfield = jenv->GetStaticFieldID(jclazz, "SDK_INT", "I");
|
||||
jint api_level = jenv->GetStaticIntField(jclazz, jfield);
|
||||
jenv->DeleteLocalRef(jclazz);
|
||||
|
||||
return api_level;
|
||||
}
|
||||
|
||||
// IMPORTANT: This method can be called only if thread is attached to Dalvik
|
||||
PackageInfo JavaBasedPackageManager::ConvertPackageFromJava(jobject package, JNIEnv* jenv)
|
||||
{
|
||||
jclass jclazz = jenv->GetObjectClass(package);
|
||||
|
||||
jfieldID jfield = jenv->GetFieldID(jclazz, "packageName", "Ljava/lang/String;");
|
||||
jstring jnameobj = static_cast<jstring>(jenv->GetObjectField(package, jfield));
|
||||
const char* jnamestr = jenv->GetStringUTFChars(jnameobj, NULL);
|
||||
string name(jnamestr);
|
||||
jenv->DeleteLocalRef(jnameobj);
|
||||
|
||||
jfield = jenv->GetFieldID(jclazz, "versionName", "Ljava/lang/String;");
|
||||
jstring jversionobj = static_cast<jstring>(jenv->GetObjectField(package, jfield));
|
||||
const char* jversionstr = jenv->GetStringUTFChars(jversionobj, NULL);
|
||||
string verison(jversionstr);
|
||||
jenv->DeleteLocalRef(jversionobj);
|
||||
|
||||
jenv->DeleteLocalRef(jclazz);
|
||||
|
||||
static const jint api_level = GetAndroidVersion(jenv);
|
||||
string path;
|
||||
if (api_level > 8)
|
||||
{
|
||||
jclazz = jenv->GetObjectClass(package);
|
||||
jfield = jenv->GetFieldID(jclazz, "applicationInfo", "Landroid/content/pm/ApplicationInfo;");
|
||||
jobject japp_info = jenv->GetObjectField(package, jfield);
|
||||
jenv->DeleteLocalRef(jclazz);
|
||||
|
||||
jclazz = jenv->GetObjectClass(japp_info);
|
||||
jfield = jenv->GetFieldID(jclazz, "nativeLibraryDir", "Ljava/lang/String;");
|
||||
jstring jpathobj = static_cast<jstring>(jenv->GetObjectField(japp_info, jfield));
|
||||
const char* jpathstr = jenv->GetStringUTFChars(jpathobj, NULL);
|
||||
path = string(jpathstr);
|
||||
jenv->ReleaseStringUTFChars(jpathobj, jpathstr);
|
||||
|
||||
jenv->DeleteLocalRef(japp_info);
|
||||
jenv->DeleteLocalRef(jpathobj);
|
||||
jenv->DeleteLocalRef(jclazz);
|
||||
}
|
||||
else
|
||||
{
|
||||
path = "/data/data/" + name + "/lib";
|
||||
}
|
||||
|
||||
return PackageInfo(name, path, verison);
|
||||
}
|
||||
|
||||
JavaBasedPackageManager::~JavaBasedPackageManager()
|
||||
{
|
||||
JNIEnv* jenv;
|
||||
bool self_attached;
|
||||
|
||||
LOGD("JavaBasedPackageManager::~JavaBasedPackageManager() begin");
|
||||
|
||||
JavaContext->GetEnv((void**)&jenv, JNI_VERSION_1_6);
|
||||
self_attached = (JNI_EDETACHED == JavaContext->GetEnv((void**)&jenv, JNI_VERSION_1_6));
|
||||
if (self_attached)
|
||||
{
|
||||
JavaContext->AttachCurrentThread(&jenv, NULL);
|
||||
}
|
||||
|
||||
jenv->DeleteGlobalRef(JavaPackageManager);
|
||||
|
||||
if (self_attached)
|
||||
{
|
||||
JavaContext->DetachCurrentThread();
|
||||
}
|
||||
LOGD("JavaBasedPackageManager::~JavaBasedPackageManager() end");
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
#include "IPackageManager.h"
|
||||
#include "CommonPackageManager.h"
|
||||
#include <jni.h>
|
||||
#include <vector>
|
||||
|
||||
class JavaBasedPackageManager: public CommonPackageManager
|
||||
{
|
||||
public:
|
||||
JavaBasedPackageManager(JavaVM* JavaMashine, jobject MarketConector);
|
||||
virtual ~JavaBasedPackageManager();
|
||||
|
||||
protected:
|
||||
virtual bool InstallPackage(const PackageInfo& package);
|
||||
virtual std::vector<PackageInfo> GetInstalledPackages();
|
||||
|
||||
private:
|
||||
JavaVM* JavaContext;
|
||||
jobject JavaPackageManager;
|
||||
|
||||
JavaBasedPackageManager();
|
||||
PackageInfo ConvertPackageFromJava(jobject package, JNIEnv* jenv);
|
||||
};
|
@@ -0,0 +1,69 @@
|
||||
#include "OpenCVEngine_jni.h"
|
||||
#include "EngineCommon.h"
|
||||
#include "IOpenCVEngine.h"
|
||||
#include "OpenCVEngine.h"
|
||||
#include "IPackageManager.h"
|
||||
#include "JavaBasedPackageManager.h"
|
||||
#include <utils/Log.h>
|
||||
#include <android_util_Binder.h>
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "OpenCVEngine/JNI"
|
||||
|
||||
using namespace android;
|
||||
|
||||
sp<IBinder> OpenCVEngineBinder = NULL;
|
||||
IPackageManager* PackageManager = NULL;
|
||||
|
||||
JNIEXPORT jobject JNICALL Java_org_opencv_engine_BinderConnector_Connect(JNIEnv* env, jobject)
|
||||
{
|
||||
LOGI("Creating new component");
|
||||
if (NULL != OpenCVEngineBinder.get())
|
||||
{
|
||||
LOGI("New component created successfully");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGE("OpenCV Engine component was not created!");
|
||||
}
|
||||
|
||||
return javaObjectForIBinder(env, OpenCVEngineBinder);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_engine_BinderConnector_Init(JNIEnv* env, jobject , jobject market)
|
||||
{
|
||||
LOGD("Java_org_opencv_engine_BinderConnector_Init");
|
||||
|
||||
if (NULL == PackageManager)
|
||||
{
|
||||
JavaVM* jvm;
|
||||
env->GetJavaVM(&jvm);
|
||||
PackageManager = new JavaBasedPackageManager(jvm, env->NewGlobalRef(market));
|
||||
}
|
||||
if (PackageManager)
|
||||
{
|
||||
if (!OpenCVEngineBinder.get())
|
||||
{
|
||||
OpenCVEngineBinder = new OpenCVEngine(PackageManager);
|
||||
return (NULL != OpenCVEngineBinder.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_engine_BinderConnector_Final(JNIEnv *, jobject)
|
||||
{
|
||||
LOGD("Java_org_opencv_engine_BinderConnector_Final");
|
||||
|
||||
OpenCVEngineBinder = NULL;
|
||||
|
||||
delete PackageManager;
|
||||
PackageManager = NULL;
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_opencv_engine_BinderConnector */
|
||||
|
||||
#ifndef _Included_org_opencv_engine_BinderConnector
|
||||
#define _Included_org_opencv_engine_BinderConnector
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_opencv_engine_BinderConnector
|
||||
* Method: Connect
|
||||
* Signature: ()Landroid/os/IBinder;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_org_opencv_engine_BinderConnector_Connect
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: org_opencv_engine_BinderConnector
|
||||
* Method: Init
|
||||
* Signature: (Lorg/opencv/engine/MarketConnector;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_engine_BinderConnector_Init
|
||||
(JNIEnv *, jobject, jobject);
|
||||
|
||||
/*
|
||||
* Class: org_opencv_engine_BinderConnector
|
||||
* Method: Final
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_opencv_engine_BinderConnector_Final
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
@@ -0,0 +1,88 @@
|
||||
#include "OpenCVLibraryInfo.h"
|
||||
#include "EngineCommon.h"
|
||||
#include <utils/Log.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_open
|
||||
(JNIEnv * env, jobject, jstring str)
|
||||
{
|
||||
const char* infoLibPath = env->GetStringUTFChars(str, NULL);
|
||||
if (infoLibPath == NULL)
|
||||
return 0;
|
||||
|
||||
LOGD("Trying to load info library \"%s\"", infoLibPath);
|
||||
|
||||
void* handle;
|
||||
|
||||
handle = dlopen(infoLibPath, RTLD_LAZY);
|
||||
if (handle == NULL)
|
||||
LOGI("Info library not found by path \"%s\"", infoLibPath);
|
||||
|
||||
return (jlong)handle;
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_getPackageName
|
||||
(JNIEnv* env, jobject, jlong handle)
|
||||
{
|
||||
InfoFunctionType info_func;
|
||||
const char* result;
|
||||
const char* error;
|
||||
|
||||
dlerror();
|
||||
info_func = (InfoFunctionType)dlsym((void*)handle, "GetPackageName");
|
||||
if ((error = dlerror()) == NULL)
|
||||
result = (*info_func)();
|
||||
else
|
||||
{
|
||||
LOGE("dlsym error: \"%s\"", error);
|
||||
result = "unknown";
|
||||
}
|
||||
|
||||
return env->NewStringUTF(result);
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_getLibraryList
|
||||
(JNIEnv* env, jobject, jlong handle)
|
||||
{
|
||||
InfoFunctionType info_func;
|
||||
const char* result;
|
||||
const char* error;
|
||||
|
||||
dlerror();
|
||||
info_func = (InfoFunctionType)dlsym((void*)handle, "GetLibraryList");
|
||||
if ((error = dlerror()) == NULL)
|
||||
result = (*info_func)();
|
||||
else
|
||||
{
|
||||
LOGE("dlsym error: \"%s\"", error);
|
||||
result = "unknown";
|
||||
}
|
||||
|
||||
return env->NewStringUTF(result);
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_getVersionName
|
||||
(JNIEnv* env, jobject, jlong handle)
|
||||
{
|
||||
InfoFunctionType info_func;
|
||||
const char* result;
|
||||
const char* error;
|
||||
|
||||
dlerror();
|
||||
info_func = (InfoFunctionType)dlsym((void*)handle, "GetRevision");
|
||||
if ((error = dlerror()) == NULL)
|
||||
result = (*info_func)();
|
||||
else
|
||||
{
|
||||
LOGE("dlsym error: \"%s\"", error);
|
||||
result = "unknown";
|
||||
}
|
||||
|
||||
return env->NewStringUTF(result);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_close
|
||||
(JNIEnv*, jobject, jlong handle)
|
||||
{
|
||||
dlclose((void*)handle);
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
#include <jni.h>
|
||||
|
||||
#ifndef _Included_org_opencv_engine_OpenCVLibraryInfo
|
||||
#define _Included_org_opencv_engine_OpenCVLibraryInfo
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_open
|
||||
(JNIEnv *, jobject, jstring);
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_getPackageName
|
||||
(JNIEnv *, jobject, jlong);
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_getLibraryList
|
||||
(JNIEnv *, jobject, jlong);
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_getVersionName
|
||||
(JNIEnv *, jobject, jlong);
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_close
|
||||
(JNIEnv *, jobject, jlong);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
@@ -0,0 +1,42 @@
|
||||
#include "EngineCommon.h"
|
||||
#include "IOpenCVEngine.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <grp.h>
|
||||
|
||||
#include <binder/IPCThreadState.h>
|
||||
#include <binder/ProcessState.h>
|
||||
#include <binder/IServiceManager.h>
|
||||
#include <utils/Log.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace android;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
LOGI("OpenCVEngine client is now starting");
|
||||
|
||||
sp<IServiceManager> ServiceManager = defaultServiceManager();
|
||||
sp<IBinder> EngineService;
|
||||
sp<IOpenCVEngine> Engine;
|
||||
|
||||
LOGI("Trying to contect to service");
|
||||
|
||||
do {
|
||||
EngineService = ServiceManager->getService(IOpenCVEngine::descriptor);
|
||||
if (EngineService != 0) break;
|
||||
LOGW("OpenCVEngine not published, waiting...");
|
||||
usleep(500000); // 0.5 s
|
||||
} while(true);
|
||||
|
||||
LOGI("Connection established");
|
||||
|
||||
Engine = interface_cast<IOpenCVEngine>(EngineService);
|
||||
int32_t EngineVersion = Engine->GetVersion();
|
||||
|
||||
printf("OpenCVEngine version %d started", EngineVersion);
|
||||
|
||||
return 0;
|
||||
}
|
@@ -0,0 +1,229 @@
|
||||
#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;
|
||||
|
||||
vector<int> CommonPackageManager::GetInstalledVersions()
|
||||
{
|
||||
vector<int> result;
|
||||
vector<PackageInfo> installed_packages = GetInstalledPackages();
|
||||
|
||||
result.resize(installed_packages.size());
|
||||
|
||||
for (size_t i = 0; i < installed_packages.size(); i++)
|
||||
{
|
||||
int version = installed_packages[i].GetVersion();
|
||||
assert(version);
|
||||
result[i] = version;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CommonPackageManager::CheckVersionInstalled(int 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();
|
||||
|
||||
for (vector<PackageInfo>::const_iterator it = packages.begin(); it != packages.end(); ++it)
|
||||
{
|
||||
LOGD("Found package: \"%s\"", it->GetFullName().c_str());
|
||||
}
|
||||
|
||||
if (!packages.empty())
|
||||
{
|
||||
vector<PackageInfo>::const_iterator it = find(packages.begin(), packages.end(), target_package);
|
||||
result = (it != packages.end());
|
||||
}
|
||||
LOGD("CommonPackageManager::CheckVersionInstalled() end");
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CommonPackageManager::InstallVersion(int version, int platform, int cpu_id)
|
||||
{
|
||||
LOGD("CommonPackageManager::InstallVersion() begin");
|
||||
PackageInfo package(version, platform, cpu_id);
|
||||
return InstallPackage(package);
|
||||
}
|
||||
|
||||
string CommonPackageManager::GetPackagePathByVersion(int version, int platform, int cpu_id)
|
||||
{
|
||||
string result;
|
||||
PackageInfo target_package(version, platform, cpu_id);
|
||||
vector<PackageInfo> all_packages = GetInstalledPackages();
|
||||
vector<PackageInfo> packages;
|
||||
|
||||
for (vector<PackageInfo>::iterator it = all_packages.begin(); it != all_packages.end(); ++it)
|
||||
{
|
||||
LOGD("Check version \"%d\" compatibility with \"%d\"\n", version, it->GetVersion());
|
||||
if (IsVersionCompatible(version, it->GetVersion()))
|
||||
{
|
||||
LOGD("Compatible");
|
||||
packages.push_back(*it);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGD("NOT Compatible");
|
||||
}
|
||||
}
|
||||
|
||||
if (!packages.empty())
|
||||
{
|
||||
int platform_group = 0;
|
||||
|
||||
if ((cpu_id & ARCH_X86) || (cpu_id & ARCH_X64))
|
||||
platform_group = 1;
|
||||
|
||||
if (cpu_id & ARCH_MIPS)
|
||||
platform_group = 2;
|
||||
|
||||
int opt_rating = -1;
|
||||
int opt_version = 0;
|
||||
|
||||
const int hardware_rating = GetHardwareRating(platform, cpu_id, ArchRatings[platform_group]);
|
||||
LOGD("Current hardware platform rating %d for (%d,%d)", hardware_rating, platform, cpu_id);
|
||||
|
||||
if (-1 == hardware_rating)
|
||||
{
|
||||
LOGE("Cannot calculate rating for current hardware platform!");
|
||||
}
|
||||
else
|
||||
{
|
||||
vector<PackageInfo>::iterator found = packages.end();
|
||||
for (vector<PackageInfo>::iterator it = packages.begin(); it != packages.end(); ++it)
|
||||
{
|
||||
int package_group = 0;
|
||||
|
||||
if ((it->GetCpuID() & ARCH_X86) || (it->GetCpuID() & ARCH_X64))
|
||||
package_group = 1;
|
||||
|
||||
if (it->GetCpuID() & ARCH_MIPS)
|
||||
package_group = 2;
|
||||
|
||||
if (package_group != platform_group)
|
||||
continue;
|
||||
|
||||
const int package_rating = GetHardwareRating(it->GetPlatform(), it->GetCpuID(), ArchRatings[package_group]);
|
||||
|
||||
LOGD("Package \"%s\" rating %d for (%d,%d)", it->GetFullName().c_str(), package_rating, it->GetPlatform(), it->GetCpuID());
|
||||
if ((package_rating >= 0) && (package_rating <= hardware_rating))
|
||||
{
|
||||
if (((it->GetVersion() >= opt_version) && (package_rating >= opt_rating)) || (it->GetVersion() > opt_version))
|
||||
{
|
||||
opt_rating = package_rating;
|
||||
opt_version = it->GetVersion();
|
||||
found = it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((-1 != opt_rating) && (packages.end() != found))
|
||||
{
|
||||
result = found->GetInstalationPath();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGI("No compatible packages found!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CommonPackageManager::IsVersionCompatible(int target_version, int package_version)
|
||||
{
|
||||
assert(target_version);
|
||||
assert(package_version);
|
||||
|
||||
// major version is the same and minor package version is above or the same as target.
|
||||
return ( (package_version/10000 == target_version/10000) && (package_version%10000 >= target_version%10000) );
|
||||
}
|
||||
|
||||
int CommonPackageManager::GetHardwareRating(int platform, int cpu_id, const std::vector<std::pair<int, int> >& group)
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
if ((cpu_id & ARCH_X86) || (cpu_id & ARCH_X64) || (cpu_id & ARCH_MIPS))
|
||||
// Note: No raiting for x86, x64 and MIPS
|
||||
// only one package is used
|
||||
result = 0;
|
||||
else
|
||||
{
|
||||
// Calculate rating for Arm
|
||||
LOGD("!!! Calculating rating for ARM\n");
|
||||
for (size_t i = 0; i < group.size(); i++)
|
||||
{
|
||||
LOGD("Checking (%d, %d) against (%d,%d)\n", group[i].first, group[i].second, platform, cpu_id);
|
||||
if (group[i] == std::pair<int, int>(platform, cpu_id))
|
||||
{
|
||||
LOGD("Rating found: %d\n", i);
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::pair<int, int> > CommonPackageManager::InitArmRating()
|
||||
{
|
||||
std::vector<std::pair<int, int> > result;
|
||||
|
||||
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));
|
||||
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv6 | FEATURES_HAS_VFPv3 | FEATURES_HAS_VFPv3d16));
|
||||
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7));
|
||||
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3d16));
|
||||
result.push_back(std::pair<int, int>(PLATFORM_TEGRA2, ARCH_ARMv7 | FEATURES_HAS_VFPv3d16));
|
||||
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3));
|
||||
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3d16 | FEATURES_HAS_VFPv3));
|
||||
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_NEON));
|
||||
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3d16 | FEATURES_HAS_NEON));
|
||||
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON));
|
||||
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_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON));
|
||||
result.push_back(std::pair<int, int>(PLATFORM_TEGRA4, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Stub for Intel platforms rating initialization. Common package for all Intel based devices is used now
|
||||
std::vector<std::pair<int, int> > CommonPackageManager::InitIntelRating()
|
||||
{
|
||||
std::vector<std::pair<int, int> > result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Stub for MIPS platforms rating initialization. Common package for all MIPS based devices is used now
|
||||
std::vector<std::pair<int, int> > CommonPackageManager::InitMipsRating()
|
||||
{
|
||||
std::vector<std::pair<int, int> > result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const std::vector<std::pair<int, int> > CommonPackageManager::ArchRatings[] = {
|
||||
CommonPackageManager::InitArmRating(),
|
||||
CommonPackageManager::InitIntelRating(),
|
||||
CommonPackageManager::InitMipsRating()
|
||||
};
|
||||
|
||||
CommonPackageManager::~CommonPackageManager()
|
||||
{
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
#ifndef __COMMON_PACKAGE_MANAGER_H__
|
||||
#define __COMMON_PACKAGE_MANAGER_H__
|
||||
|
||||
#include "IPackageManager.h"
|
||||
#include "PackageInfo.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class CommonPackageManager: public IPackageManager
|
||||
{
|
||||
public:
|
||||
std::vector<int> GetInstalledVersions();
|
||||
bool CheckVersionInstalled(int version, int platform, int cpu_id);
|
||||
bool InstallVersion(int version, int platform, int cpu_id);
|
||||
std::string GetPackagePathByVersion(int version, int platform, int cpu_id);
|
||||
virtual ~CommonPackageManager();
|
||||
|
||||
protected:
|
||||
static const std::vector<std::pair<int, int> > ArchRatings[];
|
||||
|
||||
static std::vector<std::pair<int, int> > InitArmRating();
|
||||
static std::vector<std::pair<int, int> > InitIntelRating();
|
||||
static std::vector<std::pair<int, int> > InitMipsRating();
|
||||
|
||||
bool IsVersionCompatible(int target_version, int package_version);
|
||||
int GetHardwareRating(int platform, int cpu_id, const std::vector<std::pair<int, int> >& group);
|
||||
|
||||
virtual bool InstallPackage(const PackageInfo& package) = 0;
|
||||
virtual std::vector<PackageInfo> GetInstalledPackages() = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@@ -0,0 +1,19 @@
|
||||
#include "NativePackageManager.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool NativePackageManager::InstallPackage(const PackageInfo& package)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
vector<PackageInfo> NativePackageManager::GetInstalledPackages()
|
||||
{
|
||||
vector<PackageInfo> result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NativePackageManager::~NativePackageManager()
|
||||
{
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
#ifndef __NATIVE_PACKAGE_MANAGER_STUB_H__
|
||||
#define __NATIVE_PACKAGE_MANAGER_STUB_H__
|
||||
|
||||
#include "IPackageManager.h"
|
||||
#include "CommonPackageManager.h"
|
||||
|
||||
class NativePackageManager: public CommonPackageManager
|
||||
{
|
||||
public:
|
||||
virtual ~NativePackageManager();
|
||||
protected:
|
||||
virtual bool InstallPackage(const PackageInfo& package);
|
||||
virtual std::vector<PackageInfo> GetInstalledPackages();
|
||||
};
|
||||
|
||||
#endif
|
@@ -0,0 +1,528 @@
|
||||
#include "EngineCommon.h"
|
||||
#include "PackageInfo.h"
|
||||
#include "HardwareDetector.h"
|
||||
#include "IOpenCVEngine.h"
|
||||
#include "StringUtils.h"
|
||||
#include <assert.h>
|
||||
#include <vector>
|
||||
#include <utils/Log.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
map<int, string> PackageInfo::InitPlatformNameMap()
|
||||
{
|
||||
map<int, string> 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;
|
||||
result[PLATFORM_TEGRA4] = PLATFORM_TEGRA4_NAME;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const map<int, string> 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)
|
||||
{
|
||||
string result;
|
||||
|
||||
if (FEATURES_HAS_NEON2 & 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)))
|
||||
result = string(FEATURES_HAS_NEON_NAME);
|
||||
}
|
||||
else if (FEATURES_HAS_VFPv3 & cpu_id)
|
||||
{
|
||||
if ((ARCH_ARMv5 & cpu_id) || (ARCH_ARMv6 & cpu_id))
|
||||
result = string(FEATURES_HAS_VFPv3_NAME);
|
||||
}
|
||||
else if (FEATURES_HAS_VFPv3d16 & cpu_id)
|
||||
{
|
||||
if ((ARCH_ARMv5 & cpu_id) || (ARCH_ARMv6 & cpu_id))
|
||||
result = string(FEATURES_HAS_VFPv3d16_NAME);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
inline int SplitARMFeatures(const vector<string>& features)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
for (size_t i = 3; i < features.size(); i++)
|
||||
{
|
||||
if (FEATURES_HAS_VFPv3_NAME == features[i])
|
||||
{
|
||||
result |= FEATURES_HAS_VFPv3;
|
||||
}
|
||||
else if (FEATURES_HAS_VFPv3d16_NAME == features[i])
|
||||
{
|
||||
result |= FEATURES_HAS_VFPv3d16;
|
||||
}
|
||||
else if (FEATURES_HAS_NEON_NAME == features[i])
|
||||
{
|
||||
result |= FEATURES_HAS_NEON;
|
||||
}
|
||||
else if (FEATURES_HAS_NEON2_NAME == features[i])
|
||||
{
|
||||
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;
|
||||
}
|
||||
else if (FEATURES_HAS_SSE2 & cpu_id)
|
||||
{
|
||||
result = FEATURES_HAS_SSE2_NAME;
|
||||
}
|
||||
else if (FEATURES_HAS_SSE & cpu_id)
|
||||
{
|
||||
result = FEATURES_HAS_SSE_NAME;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
inline int SplitIntelFeatures(const vector<string>& features)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
for (size_t i = 3; i < features.size(); i++)
|
||||
{
|
||||
if (FEATURES_HAS_SSSE3_NAME == features[i])
|
||||
{
|
||||
result |= FEATURES_HAS_SSSE3;
|
||||
}
|
||||
else if (FEATURES_HAS_SSE2_NAME == features[i])
|
||||
{
|
||||
result |= FEATURES_HAS_SSE2;
|
||||
}
|
||||
else if (FEATURES_HAS_SSE_NAME == features[i])
|
||||
{
|
||||
result |= FEATURES_HAS_SSE;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
inline int SplitVersion(const vector<string>& features, const string& package_version)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if ((features.size() > 1) && ('v' == features[1][0]))
|
||||
{
|
||||
// Taking major and minor mart of library version from package name
|
||||
string tmp1 = features[1].substr(1);
|
||||
result += atoi(tmp1.substr(0,1).c_str())*1000000 + atoi(tmp1.substr(1,1).c_str())*10000;
|
||||
|
||||
// Taking release and build number from package revision
|
||||
vector<string> tmp2 = SplitStringVector(package_version, '.');
|
||||
if (tmp2.size() == 2)
|
||||
{
|
||||
// the 2nd digit is revision
|
||||
result += atoi(tmp2[0].c_str())*100 + 00;
|
||||
}
|
||||
else
|
||||
{
|
||||
// the 2nd digit is part of library version
|
||||
// the 3rd digit is revision
|
||||
result += atoi(tmp2[0].c_str())*100 + atoi(tmp2[1].c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Report package name format error
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
inline string JoinPlatform(int platform)
|
||||
{
|
||||
string result;
|
||||
map<int, string>::const_iterator it = PackageInfo::PlatformNameMap.find(platform);
|
||||
|
||||
assert(PackageInfo::PlatformNameMap.end() != it);
|
||||
result = it->second;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
inline int SplitPlatfrom(const vector<string>& features)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (features.size() > 2)
|
||||
{
|
||||
string tmp = features[2];
|
||||
if (PLATFORM_TEGRA_NAME == tmp)
|
||||
{
|
||||
result = PLATFORM_TEGRA;
|
||||
}
|
||||
else if (PLATFORM_TEGRA2_NAME == tmp)
|
||||
{
|
||||
result = PLATFORM_TEGRA2;
|
||||
}
|
||||
else if (PLATFORM_TEGRA3_NAME == tmp)
|
||||
{
|
||||
result = PLATFORM_TEGRA3;
|
||||
}
|
||||
else if (PLATFORM_TEGRA4_NAME == tmp)
|
||||
{
|
||||
result = PLATFORM_TEGRA4;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Report package name format error
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Package naming convention
|
||||
* All parts of package name seporated by "_" symbol
|
||||
* First part is base namespace.
|
||||
* Second part is version. Version starts from "v" symbol. After "v" symbol version nomber without dot symbol added.
|
||||
* If platform is known third part is platform name
|
||||
* If platform is unknown it is defined by hardware capabilities using pattern: <arch>_<floating point and vectorization features>_<other features>
|
||||
* Example: armv7_neon
|
||||
*/
|
||||
PackageInfo::PackageInfo(int version, int platform, int cpu_id, std::string install_path):
|
||||
Version(version),
|
||||
Platform(platform),
|
||||
CpuID(cpu_id),
|
||||
InstallPath("")
|
||||
{
|
||||
#ifndef __SUPPORT_TEGRA3
|
||||
Platform = PLATFORM_UNKNOWN;
|
||||
#endif
|
||||
|
||||
int major_version = version/1000000;
|
||||
int minor_version = version/10000 - major_version*100;
|
||||
|
||||
char tmp[32];
|
||||
|
||||
sprintf(tmp, "%d%d", major_version, minor_version);
|
||||
|
||||
FullName = BasePackageName + std::string("_v") + std::string(tmp);
|
||||
if (PLATFORM_UNKNOWN != Platform)
|
||||
{
|
||||
FullName += string("_") + JoinPlatform(platform);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ARCH_UNKNOWN != CpuID)
|
||||
{
|
||||
if (ARCH_X86 & CpuID)
|
||||
{
|
||||
LOGD("PackageInfo::PackageInfo: package arch x86");
|
||||
FullName += string("_") + ARCH_X86_NAME;
|
||||
#ifdef __SUPPORT_INTEL_FEATURES
|
||||
string features = JoinIntelFeatures(CpuID);
|
||||
if (!features.empty())
|
||||
{
|
||||
FullName += string("_") + features;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (ARCH_X64 & CpuID)
|
||||
{
|
||||
LOGD("PackageInfo::PackageInfo: package arch x64");
|
||||
#ifdef __SUPPORT_INTEL_x64
|
||||
FullName += string("_") + ARCH_X64_NAME;
|
||||
#else
|
||||
FullName += string("_") + ARCH_X86_NAME;
|
||||
#endif
|
||||
#ifdef __SUPPORT_INTEL_FEATURES
|
||||
string features = JoinIntelFeatures(CpuID);
|
||||
if (!features.empty())
|
||||
{
|
||||
FullName += string("_") + features;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (ARCH_ARMv5 & CpuID)
|
||||
{
|
||||
LOGD("PackageInfo::PackageInfo: package arch ARMv5");
|
||||
FullName += string("_") + ARCH_ARMv5_NAME;
|
||||
#ifdef __SUPPORT_ARMEABI_FEATURES
|
||||
string features = JoinARMFeatures(CpuID);
|
||||
if (!features.empty())
|
||||
{
|
||||
FullName += string("_") + features;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (ARCH_ARMv6 & CpuID)
|
||||
{
|
||||
LOGD("PackageInfo::PackageInfo: package arch ARMv6");
|
||||
// NOTE: ARM v5 used instead ARM v6
|
||||
//FullName += string("_") + ARCH_ARMv6_NAME;
|
||||
FullName += string("_") + ARCH_ARMv5_NAME;
|
||||
#ifdef __SUPPORT_ARMEABI_FEATURES
|
||||
string features = JoinARMFeatures(CpuID);
|
||||
if (!features.empty())
|
||||
{
|
||||
FullName += string("_") + features;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (ARCH_ARMv7 & CpuID)
|
||||
{
|
||||
LOGD("PackageInfo::PackageInfo: package arch ARMv7");
|
||||
FullName += string("_") + ARCH_ARMv7_NAME;
|
||||
#ifdef __SUPPORT_ARMEABI_V7A_FEATURES
|
||||
string features = JoinARMFeatures(CpuID);
|
||||
if (!features.empty())
|
||||
{
|
||||
FullName += string("_") + features;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (ARCH_ARMv8 & CpuID)
|
||||
{
|
||||
LOGD("PackageInfo::PackageInfo: package arch ARMv8");
|
||||
#ifdef __SUPPORT_ARMEABI_V8
|
||||
FullName += string("_") + ARCH_ARMv8_NAME;
|
||||
#else
|
||||
FullName += string("_") + ARCH_ARMv7_NAME;
|
||||
#endif
|
||||
//string features = JoinARMFeatures(CpuID);
|
||||
//if (!features.empty())
|
||||
//{
|
||||
// FullName += string("_") + features;
|
||||
//}
|
||||
}
|
||||
#ifdef __SUPPORT_MIPS
|
||||
else if (ARCH_MIPS & CpuID)
|
||||
{
|
||||
FullName += string("_") + ARCH_MIPS_NAME;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
LOGD("PackageInfo::PackageInfo: package arch unknown");
|
||||
Version = 0;
|
||||
CpuID = ARCH_UNKNOWN;
|
||||
Platform = PLATFORM_UNKNOWN;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGD("PackageInfo::PackageInfo: package arch unknown");
|
||||
Version = 0;
|
||||
CpuID = ARCH_UNKNOWN;
|
||||
Platform = PLATFORM_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
if (!FullName.empty())
|
||||
{
|
||||
InstallPath = install_path + FullName + "/lib";
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
InfoFunctionType name_func;
|
||||
InfoFunctionType revision_func;
|
||||
|
||||
handle = dlopen(tmp.c_str(), RTLD_LAZY);
|
||||
if (handle)
|
||||
{
|
||||
const char* error;
|
||||
|
||||
dlerror();
|
||||
name_func = (InfoFunctionType)dlsym(handle, "GetPackageName");
|
||||
revision_func = (InfoFunctionType)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 (%p, %p): \"%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 = 0;
|
||||
CpuID = ARCH_UNKNOWN;
|
||||
Platform = PLATFORM_UNKNOWN;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
vector<string> features = SplitStringVector(FullName, '_');
|
||||
|
||||
if (!features.empty() && (BasePackageName == features[0]))
|
||||
{
|
||||
Version = SplitVersion(features, package_version);
|
||||
if (0 == Version)
|
||||
{
|
||||
CpuID = ARCH_UNKNOWN;
|
||||
Platform = PLATFORM_UNKNOWN;
|
||||
return;
|
||||
}
|
||||
|
||||
Platform = SplitPlatfrom(features);
|
||||
if (PLATFORM_UNKNOWN != Platform)
|
||||
{
|
||||
switch (Platform)
|
||||
{
|
||||
case PLATFORM_TEGRA2:
|
||||
{
|
||||
CpuID = ARCH_ARMv7 | FEATURES_HAS_VFPv3d16;
|
||||
} break;
|
||||
case PLATFORM_TEGRA3:
|
||||
{
|
||||
CpuID = ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON;
|
||||
} break;
|
||||
case PLATFORM_TEGRA4:
|
||||
{
|
||||
CpuID = ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (features.size() < 3)
|
||||
{
|
||||
LOGD("It is not OpenCV library package for this platform");
|
||||
Version = 0;
|
||||
CpuID = ARCH_UNKNOWN;
|
||||
Platform = PLATFORM_UNKNOWN;
|
||||
return;
|
||||
}
|
||||
else if (ARCH_ARMv5_NAME == features[2])
|
||||
{
|
||||
CpuID = ARCH_ARMv5 | SplitARMFeatures(features);
|
||||
}
|
||||
else if (ARCH_ARMv6_NAME == features[2])
|
||||
{
|
||||
CpuID = ARCH_ARMv6 | SplitARMFeatures(features);
|
||||
}
|
||||
else if (ARCH_ARMv7_NAME == features[2])
|
||||
{
|
||||
CpuID = ARCH_ARMv7 | SplitARMFeatures(features);
|
||||
}
|
||||
else if (ARCH_X86_NAME == features[2])
|
||||
{
|
||||
CpuID = ARCH_X86 | SplitIntelFeatures(features);
|
||||
}
|
||||
else if (ARCH_X64_NAME == features[2])
|
||||
{
|
||||
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");
|
||||
Version = 0;
|
||||
CpuID = ARCH_UNKNOWN;
|
||||
Platform = PLATFORM_UNKNOWN;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGD("It is not OpenCV library package for this platform");
|
||||
Version = 0;
|
||||
CpuID = ARCH_UNKNOWN;
|
||||
Platform = PLATFORM_UNKNOWN;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool PackageInfo::IsValid() const
|
||||
{
|
||||
return !((0 == Version) && (PLATFORM_UNKNOWN == Platform) && (ARCH_UNKNOWN == CpuID));
|
||||
}
|
||||
|
||||
int PackageInfo::GetPlatform() const
|
||||
{
|
||||
return Platform;
|
||||
}
|
||||
|
||||
int PackageInfo::GetCpuID() const
|
||||
{
|
||||
return CpuID;
|
||||
}
|
||||
|
||||
string PackageInfo::GetFullName() const
|
||||
{
|
||||
return FullName;
|
||||
}
|
||||
|
||||
int PackageInfo::GetVersion() const
|
||||
{
|
||||
return Version;
|
||||
}
|
||||
|
||||
string PackageInfo::GetInstalationPath() const
|
||||
{
|
||||
return InstallPath;
|
||||
}
|
||||
|
||||
bool PackageInfo::operator==(const PackageInfo& package) const
|
||||
{
|
||||
return (package.FullName == FullName);
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
#ifndef __PACKAGE_INFO_H__
|
||||
#define __PACKAGE_INFO_H__
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#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"
|
||||
#define FEATURES_HAS_NEON2_NAME "neon2"
|
||||
#define FEATURES_HAS_SSE_NAME "sse"
|
||||
#define FEATURES_HAS_SSE2_NAME "sse2"
|
||||
#define FEATURES_HAS_SSSE3_NAME "ssse3"
|
||||
#define FEATURES_HAS_GPU_NAME "gpu"
|
||||
|
||||
#define PLATFORM_TEGRA_NAME "tegra"
|
||||
#define PLATFORM_TEGRA2_NAME "tegra2"
|
||||
#define PLATFORM_TEGRA3_NAME "tegra3"
|
||||
#define PLATFORM_TEGRA4_NAME "tegra4"
|
||||
|
||||
class PackageInfo
|
||||
{
|
||||
public:
|
||||
PackageInfo(int version, int platform, int cpu_id, std::string install_path = "/data/data/");
|
||||
PackageInfo(const std::string& fullname, const std::string& install_path, std::string package_version = "0.0");
|
||||
std::string GetFullName() const;
|
||||
int GetVersion() const;
|
||||
int GetPlatform() const;
|
||||
int GetCpuID() const;
|
||||
std::string GetInstalationPath() const;
|
||||
bool operator==(const PackageInfo& package) const;
|
||||
static const std::map<int, std::string> PlatformNameMap;
|
||||
bool IsValid() const;
|
||||
|
||||
protected:
|
||||
static std::map<int, std::string> InitPlatformNameMap();
|
||||
int Version;
|
||||
int Platform;
|
||||
int CpuID;
|
||||
std::string FullName;
|
||||
std::string InstallPath;
|
||||
static const std::string BasePackageName;
|
||||
};
|
||||
|
||||
#endif
|
@@ -0,0 +1,32 @@
|
||||
#include "EngineCommon.h"
|
||||
#include "IOpenCVEngine.h"
|
||||
#include "OpenCVEngine.h"
|
||||
#include "IPackageManager.h"
|
||||
#include "NativePackageManager.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <grp.h>
|
||||
#include <binder/IPCThreadState.h>
|
||||
#include <binder/ProcessState.h>
|
||||
#include <binder/IServiceManager.h>
|
||||
#include <utils/Log.h>
|
||||
|
||||
using namespace android;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
LOGI("OpenCVEngine native service starting");
|
||||
IPackageManager* PackageManager = new NativePackageManager();
|
||||
sp<IBinder> 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;
|
||||
}
|
@@ -0,0 +1,177 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "ProcReader.h"
|
||||
#include "TegraDetector.h"
|
||||
#include "HardwareDetector.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
TEST(Strip, StripEmptyString)
|
||||
{
|
||||
string a = "";
|
||||
EXPECT_FALSE(StripString(a));
|
||||
}
|
||||
|
||||
TEST(Strip, StripClearString)
|
||||
{
|
||||
string a = "qqqwww";
|
||||
EXPECT_TRUE(StripString(a));
|
||||
EXPECT_STREQ("qqqwww", a.c_str());
|
||||
}
|
||||
|
||||
TEST(Strip, StripStringLeft)
|
||||
{
|
||||
string a = " qqqwww";
|
||||
EXPECT_TRUE(StripString(a));
|
||||
EXPECT_STREQ("qqqwww", a.c_str());
|
||||
}
|
||||
|
||||
TEST(Strip, StripStringRight)
|
||||
{
|
||||
string a = "qqqwww ";
|
||||
EXPECT_TRUE(StripString(a));
|
||||
EXPECT_STREQ("qqqwww", a.c_str());
|
||||
}
|
||||
|
||||
TEST(Strip, StripStringLeftRight)
|
||||
{
|
||||
string a = "qqqwww ";
|
||||
EXPECT_TRUE(StripString(a));
|
||||
EXPECT_STREQ("qqqwww", a.c_str());
|
||||
}
|
||||
|
||||
TEST(Strip, StripStringWithSpaces)
|
||||
{
|
||||
string a = " qqq www ";
|
||||
EXPECT_TRUE(StripString(a));
|
||||
EXPECT_STREQ("qqq www", a.c_str());
|
||||
}
|
||||
|
||||
TEST(Parse, ParseEmptyString)
|
||||
{
|
||||
string a = "";
|
||||
string key;
|
||||
string value;
|
||||
EXPECT_FALSE(ParseString(a, key, value));
|
||||
}
|
||||
|
||||
TEST(Parse, ParseStringWithoutSeporator)
|
||||
{
|
||||
string a = "qqqwww";
|
||||
string key;
|
||||
string value;
|
||||
EXPECT_FALSE(ParseString(a, key, value));
|
||||
}
|
||||
|
||||
TEST(Parse, ParseClearString)
|
||||
{
|
||||
string a = "qqq:www";
|
||||
string key;
|
||||
string value;
|
||||
EXPECT_TRUE(ParseString(a, key, value));
|
||||
EXPECT_STREQ("qqq", key.c_str());
|
||||
EXPECT_STREQ("www", value.c_str());
|
||||
}
|
||||
|
||||
TEST(Parse, ParseDirtyString)
|
||||
{
|
||||
string a = "qqq : www";
|
||||
string key;
|
||||
string value;
|
||||
EXPECT_TRUE(ParseString(a, key, value));
|
||||
EXPECT_STREQ("qqq", key.c_str());
|
||||
EXPECT_STREQ("www", value.c_str());
|
||||
}
|
||||
|
||||
TEST(Split, SplitEmptyString)
|
||||
{
|
||||
string a = "";
|
||||
set<string> b = SplitString(a, ' ');
|
||||
EXPECT_EQ(0, b.size());
|
||||
}
|
||||
|
||||
TEST(Split, SplitOneElementString)
|
||||
{
|
||||
string a = "qqq";
|
||||
set<string> b = SplitString(a, ' ');
|
||||
EXPECT_EQ(1, b.size());
|
||||
EXPECT_FALSE(b.find("qqq") == b.end());
|
||||
}
|
||||
|
||||
TEST(Split, SplitMultiElementString)
|
||||
{
|
||||
string a = "qqq www eee";
|
||||
set<string> b = SplitString(a, ' ');
|
||||
EXPECT_EQ(3, b.size());
|
||||
EXPECT_FALSE(b.find("qqq") == b.end());
|
||||
EXPECT_FALSE(b.find("www") == b.end());
|
||||
EXPECT_FALSE(b.find("eee") == b.end());
|
||||
}
|
||||
|
||||
TEST(CpuCount, CheckNonZero)
|
||||
{
|
||||
EXPECT_TRUE(GetProcessorCount() != 0);
|
||||
}
|
||||
|
||||
TEST(GetCpuInfo, GetCpuInfo)
|
||||
{
|
||||
map<string, string> a = GetCpuInfo();
|
||||
EXPECT_FALSE(a.empty());
|
||||
EXPECT_TRUE(a.find("") == a.end());
|
||||
}
|
||||
|
||||
TEST(CpuID, CheckNotEmpy)
|
||||
{
|
||||
int cpu_id = GetCpuID();
|
||||
EXPECT_NE(0, cpu_id);
|
||||
}
|
||||
|
||||
#if defined(__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);
|
||||
}
|
||||
#elif defined(__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();
|
||||
EXPECT_TRUE(cpu_id & ARCH_ARMv7);
|
||||
}
|
||||
|
||||
TEST(CpuID, CheckNeon)
|
||||
{
|
||||
int cpu_id = GetCpuID();
|
||||
EXPECT_TRUE(cpu_id & FEATURES_HAS_NEON);
|
||||
}
|
||||
|
||||
TEST(CpuID, CheckVFPv3)
|
||||
{
|
||||
int cpu_id = GetCpuID();
|
||||
EXPECT_TRUE(cpu_id & FEATURES_HAS_VFPv3);
|
||||
}
|
||||
|
||||
TEST(PlatfromDetector, CheckTegra)
|
||||
{
|
||||
EXPECT_NE(PLATFORM_UNKNOWN, DetectKnownPlatforms());
|
||||
}
|
||||
#endif
|
329
platforms/android/service/engine/jni/Tests/OpenCVEngineTest.cpp
Normal file
@@ -0,0 +1,329 @@
|
||||
#include "IOpenCVEngine.h"
|
||||
#include "EngineCommon.h"
|
||||
#include "OpenCVEngine.h"
|
||||
#include "IPackageManager.h"
|
||||
#include "PackageManagerStub.h"
|
||||
#include "PackageInfo.h"
|
||||
#include "HardwareDetector.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <binder/IPCThreadState.h>
|
||||
#include <binder/ProcessState.h>
|
||||
#include <binder/IServiceManager.h>
|
||||
#include <utils/Log.h>
|
||||
|
||||
using namespace android;
|
||||
|
||||
class ServiceStarter
|
||||
{
|
||||
public:
|
||||
ServiceStarter()
|
||||
{
|
||||
PackageManager = new PackageManagerStub();
|
||||
Engine = new OpenCVEngine(PackageManager);
|
||||
|
||||
defaultServiceManager()->addService(IOpenCVEngine::descriptor, Engine);
|
||||
LOGI("OpenCVEngine native service started successfully");
|
||||
ProcessState::self()->startThreadPool();
|
||||
}
|
||||
~ServiceStarter()
|
||||
{
|
||||
delete PackageManager;
|
||||
}
|
||||
|
||||
PackageManagerStub* PackageManager;
|
||||
sp<IBinder> Engine;
|
||||
};
|
||||
|
||||
static ServiceStarter Starter;
|
||||
|
||||
sp<IOpenCVEngine> InitConnect()
|
||||
{
|
||||
sp<IServiceManager> ServiceManager = defaultServiceManager();
|
||||
sp<IBinder> EngineService;
|
||||
sp<IOpenCVEngine> Engine;
|
||||
|
||||
do
|
||||
{
|
||||
EngineService = ServiceManager->getService(IOpenCVEngine::descriptor);
|
||||
if (EngineService != 0) break;
|
||||
usleep(500000); // 0.5 s
|
||||
} while(true);
|
||||
|
||||
Engine = interface_cast<IOpenCVEngine>(EngineService);
|
||||
|
||||
return Engine;
|
||||
}
|
||||
|
||||
TEST(OpenCVEngineTest, GetVersion)
|
||||
{
|
||||
sp<IOpenCVEngine> Engine = InitConnect();
|
||||
EXPECT_FALSE(NULL == Engine.get());
|
||||
int32_t Version = Engine->GetVersion();
|
||||
EXPECT_EQ(OPEN_CV_ENGINE_VERSION, Version);
|
||||
}
|
||||
|
||||
#if defined(__i386__)
|
||||
TEST(OpenCVEngineTest, GetPathForExecHWExistVersion)
|
||||
{
|
||||
sp<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040000, 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<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040200, 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<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040100, 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<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040000, 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<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040200, 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<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040100, PLATFORM_UNKNOWN, ARCH_MIPS);
|
||||
EXPECT_FALSE(NULL == Engine.get());
|
||||
String16 result = Engine->GetLibPathByVersion(String16("2.4.2"));
|
||||
EXPECT_EQ(0, result.size());
|
||||
}
|
||||
|
||||
#else // armeabi
|
||||
TEST(OpenCVEngineTest, GetPathForExecHWExistVersion)
|
||||
{
|
||||
sp<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040000, PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON);
|
||||
EXPECT_FALSE(NULL == Engine.get());
|
||||
String16 result = Engine->GetLibPathByVersion(String16("2.4"));
|
||||
#ifdef __SUPPORT_TEGRA3
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra3/lib", String8(result).string());
|
||||
#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
|
||||
}
|
||||
|
||||
TEST(OpenCVEngineTest, GetPathForExecHWOldVersion)
|
||||
{
|
||||
sp<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040200, PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON);
|
||||
EXPECT_FALSE(NULL == Engine.get());
|
||||
String16 result = Engine->GetLibPathByVersion(String16("2.4.1"));
|
||||
#ifdef __SUPPORT_TEGRA3
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra3/lib", String8(result).string());
|
||||
#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
|
||||
}
|
||||
|
||||
TEST(OpenCVEngineTest, GetPathForExecHWNewVersion)
|
||||
{
|
||||
sp<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040100, PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_NEON);
|
||||
EXPECT_FALSE(NULL == Engine.get());
|
||||
String16 result = Engine->GetLibPathByVersion(String16("2.4.2"));
|
||||
EXPECT_EQ(0, result.size());
|
||||
}
|
||||
|
||||
TEST(OpenCVEngineTest, GetPathForCompatiblePackage1)
|
||||
{
|
||||
sp<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040200, PLATFORM_UNKNOWN, ARCH_ARMv5);
|
||||
EXPECT_FALSE(NULL == Engine.get());
|
||||
String16 result = Engine->GetLibPathByVersion(String16("2.4"));
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv5/lib", String8(result).string());
|
||||
}
|
||||
|
||||
TEST(OpenCVEngineTest, GetPathForCompatiblePackage2)
|
||||
{
|
||||
sp<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040200, PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON);
|
||||
EXPECT_FALSE(NULL == Engine.get());
|
||||
String16 result = Engine->GetLibPathByVersion(String16("2.4"));
|
||||
#ifdef __SUPPORT_TEGRA3
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra3/lib", String8(result).string());
|
||||
#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
|
||||
}
|
||||
|
||||
TEST(OpenCVEngineTest, GetPathForCompatiblePackage3)
|
||||
{
|
||||
sp<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040400, PLATFORM_TEGRA4, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON);
|
||||
EXPECT_FALSE(NULL == Engine.get());
|
||||
String16 result = Engine->GetLibPathByVersion(String16("2.4"));
|
||||
#ifdef __SUPPORT_TEGRA3
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra4/lib", String8(result).string());
|
||||
#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
|
||||
}
|
||||
|
||||
TEST(OpenCVEngineTest, InstallAndGetVersion)
|
||||
{
|
||||
sp<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
EXPECT_FALSE(NULL == Engine.get());
|
||||
EXPECT_TRUE(Engine->InstallVersion(String16("2.4")));
|
||||
String16 result = Engine->GetLibPathByVersion(String16("2.4"));
|
||||
#ifdef __SUPPORT_TEGRA3
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra3/lib", String8(result).string());
|
||||
#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
|
||||
}
|
||||
|
||||
TEST(OpenCVEngineTest, GetPathFor2_4_2)
|
||||
{
|
||||
sp<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040200, PLATFORM_UNKNOWN, ARCH_ARMv7);
|
||||
EXPECT_FALSE(NULL == Engine.get());
|
||||
String16 result = Engine->GetLibPathByVersion(String16("2.4.2"));
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string());
|
||||
}
|
||||
|
||||
TEST(OpenCVEngineTest, GetPathFor2_4_3)
|
||||
{
|
||||
sp<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040300, PLATFORM_UNKNOWN, ARCH_ARMv7);
|
||||
EXPECT_FALSE(NULL == Engine.get());
|
||||
String16 result = Engine->GetLibPathByVersion(String16("2.4.3"));
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string());
|
||||
}
|
||||
|
||||
TEST(OpenCVEngineTest, GetPathFor2_4_3_1)
|
||||
{
|
||||
sp<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040301, PLATFORM_UNKNOWN, ARCH_ARMv7);
|
||||
EXPECT_FALSE(NULL == Engine.get());
|
||||
String16 result = Engine->GetLibPathByVersion(String16("2.4.3.1"));
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string());
|
||||
}
|
||||
|
||||
TEST(OpenCVEngineTest, GetPathFor2_4_3_2)
|
||||
{
|
||||
sp<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040302, PLATFORM_UNKNOWN, ARCH_ARMv7);
|
||||
EXPECT_FALSE(NULL == Engine.get());
|
||||
String16 result = Engine->GetLibPathByVersion(String16("2.4.3.2"));
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string());
|
||||
}
|
||||
|
||||
TEST(OpenCVEngineTest, GetPathFor2_4_4)
|
||||
{
|
||||
sp<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040400, PLATFORM_UNKNOWN, ARCH_ARMv7);
|
||||
EXPECT_FALSE(NULL == Engine.get());
|
||||
String16 result = Engine->GetLibPathByVersion(String16("2.4.4"));
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string());
|
||||
}
|
||||
|
||||
TEST(OpenCVEngineTest, GetPathFor2_4_5)
|
||||
{
|
||||
sp<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040500, PLATFORM_UNKNOWN, ARCH_ARMv7);
|
||||
EXPECT_FALSE(NULL == Engine.get());
|
||||
String16 result = Engine->GetLibPathByVersion(String16("2.4.5"));
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string());
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __i386__
|
||||
TEST(OpenCVEngineTest, GetPathForInCompatiblePackage1)
|
||||
{
|
||||
sp<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040200, 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<IOpenCVEngine> Engine = InitConnect();
|
||||
Starter.PackageManager->InstalledPackages.clear();
|
||||
Starter.PackageManager->InstallVersion(2040200, 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<IOpenCVEngine> Engine = InitConnect();
|
||||
EXPECT_FALSE(NULL == Engine.get());
|
||||
String16 result = Engine->GetLibPathByVersion(String16("2.5"));
|
||||
EXPECT_EQ(0, result.size());
|
||||
}
|
224
platforms/android/service/engine/jni/Tests/PackageInfoTest.cpp
Normal file
@@ -0,0 +1,224 @@
|
||||
#include "HardwareDetector.h"
|
||||
#include "IPackageManager.h"
|
||||
#include "IOpenCVEngine.h"
|
||||
#include "PackageInfo.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
TEST(PackageInfo, FullNameArmv7)
|
||||
{
|
||||
PackageInfo info(2030000, PLATFORM_UNKNOWN, ARCH_ARMv7);
|
||||
string name = info.GetFullName();
|
||||
EXPECT_STREQ("org.opencv.lib_v23_armv7a", name.c_str());
|
||||
}
|
||||
|
||||
TEST(PackageInfo, FullNameArmv7Neon)
|
||||
{
|
||||
PackageInfo info(2040100, PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_NEON);
|
||||
string name = info.GetFullName();
|
||||
#ifdef __SUPPORT_ARMEABI_V7A_FEATURES
|
||||
EXPECT_STREQ("org.opencv.lib_v24_armv7a_neon", name.c_str());
|
||||
#else
|
||||
EXPECT_STREQ("org.opencv.lib_v24_armv7a", name.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(PackageInfo, FullNameArmv7VFPv3)
|
||||
{
|
||||
PackageInfo info(2030300, PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3);
|
||||
string name = info.GetFullName();
|
||||
EXPECT_STREQ("org.opencv.lib_v23_armv7a", name.c_str());
|
||||
}
|
||||
|
||||
TEST(PackageInfo, FullNameArmv7VFPv3Neon)
|
||||
{
|
||||
PackageInfo info(2030000, PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON);
|
||||
string name = info.GetFullName();
|
||||
#ifdef __SUPPORT_ARMEABI_V7A_FEATURES
|
||||
EXPECT_STREQ("org.opencv.lib_v23_armv7a_neon", name.c_str());
|
||||
#else
|
||||
EXPECT_STREQ("org.opencv.lib_v23_armv7a", name.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(PackageInfo, FullNameArmv5)
|
||||
{
|
||||
PackageInfo info(2030000, PLATFORM_UNKNOWN, ARCH_ARMv5);
|
||||
string name = info.GetFullName();
|
||||
EXPECT_STREQ("org.opencv.lib_v23_armv5", name.c_str());
|
||||
}
|
||||
|
||||
TEST(PackageInfo, FullNameArmv6)
|
||||
{
|
||||
PackageInfo info(2030000, PLATFORM_UNKNOWN, ARCH_ARMv6);
|
||||
string name = info.GetFullName();
|
||||
EXPECT_STREQ("org.opencv.lib_v23_armv5", name.c_str());
|
||||
}
|
||||
|
||||
TEST(PackageInfo, FullNameArmv6VFPv3)
|
||||
{
|
||||
PackageInfo info(2030200, PLATFORM_UNKNOWN, ARCH_ARMv6 | FEATURES_HAS_VFPv3);
|
||||
string name = info.GetFullName();
|
||||
#ifdef __SUPPORT_ARMEABI_FEATURES
|
||||
EXPECT_STREQ("org.opencv.lib_v23_armv5_vfpv3", name.c_str());
|
||||
#else
|
||||
EXPECT_STREQ("org.opencv.lib_v23_armv5", name.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(PackageInfo, FullNameTegra3)
|
||||
{
|
||||
PackageInfo info(2030000, PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_NEON);
|
||||
string name = info.GetFullName();
|
||||
#ifdef __SUPPORT_TEGRA3
|
||||
EXPECT_STREQ("org.opencv.lib_v23_tegra3", name.c_str());
|
||||
#else
|
||||
#ifdef __SUPPORT_ARMEABI_V7A_FEATURES
|
||||
EXPECT_STREQ("org.opencv.lib_v23_armv7a_neon", name.c_str());
|
||||
#else
|
||||
EXPECT_STREQ("org.opencv.lib_v23_armv7a", name.c_str());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(PackageInfo, FullNameTegra4)
|
||||
{
|
||||
PackageInfo info(2040400, PLATFORM_TEGRA4, ARCH_ARMv7 | FEATURES_HAS_NEON);
|
||||
string name = info.GetFullName();
|
||||
#ifdef __SUPPORT_TEGRA3
|
||||
EXPECT_STREQ("org.opencv.lib_v24_tegra4", name.c_str());
|
||||
#else
|
||||
#ifdef __SUPPORT_ARMEABI_V7A_FEATURES
|
||||
EXPECT_STREQ("org.opencv.lib_v24_armv7a_neon", name.c_str());
|
||||
#else
|
||||
EXPECT_STREQ("org.opencv.lib_v24_armv7a", name.c_str());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(PackageInfo, FullNameX86SSE2)
|
||||
{
|
||||
PackageInfo info(2030000, PLATFORM_UNKNOWN, ARCH_X86 | FEATURES_HAS_SSE2);
|
||||
string name = info.GetFullName();
|
||||
#ifdef __SUPPORT_INTEL_FEATURES
|
||||
EXPECT_STREQ("org.opencv.lib_v23_x86_sse2", name.c_str());
|
||||
#else
|
||||
EXPECT_STREQ("org.opencv.lib_v23_x86", name.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __SUPPORT_MIPS
|
||||
TEST(PackageInfo, FullNameMips)
|
||||
{
|
||||
PackageInfo info(2040300, 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");
|
||||
EXPECT_EQ(2030000, info.GetVersion());
|
||||
EXPECT_EQ(ARCH_ARMv7 | FEATURES_HAS_NEON, info.GetCpuID());
|
||||
}
|
||||
|
||||
TEST(PackageInfo, Armv5FromFullName)
|
||||
{
|
||||
PackageInfo info("org.opencv.lib_v23_armv5", "/data/data/org.opencv.lib_v23_armv5");
|
||||
EXPECT_EQ(2030000, info.GetVersion());
|
||||
EXPECT_EQ(ARCH_ARMv5, info.GetCpuID());
|
||||
}
|
||||
|
||||
TEST(PackageInfo, Armv5VFPv3FromFullName)
|
||||
{
|
||||
PackageInfo info("org.opencv.lib_v23_armv5_vfpv3", "/data/data/org.opencv.lib_v23_armv5_vfpv3");
|
||||
EXPECT_EQ(2030000, info.GetVersion());
|
||||
EXPECT_EQ(ARCH_ARMv5 | FEATURES_HAS_VFPv3, info.GetCpuID());
|
||||
}
|
||||
|
||||
TEST(PackageInfo, X86SSE2FromFullName)
|
||||
{
|
||||
PackageInfo info("org.opencv.lib_v24_x86_sse2", "/data/data/org.opencv.lib_v24_x86_sse2");
|
||||
EXPECT_EQ(PLATFORM_UNKNOWN, info.GetPlatform());
|
||||
EXPECT_EQ(ARCH_X86 | FEATURES_HAS_SSE2, info.GetCpuID());
|
||||
EXPECT_EQ(2040000, info.GetVersion());
|
||||
}
|
||||
|
||||
TEST(PackageInfo, Tegra2FromFullName)
|
||||
{
|
||||
PackageInfo info("org.opencv.lib_v23_tegra2", "/data/data/org.opencv.lib_v23_tegra2");
|
||||
EXPECT_EQ(2030000, info.GetVersion());
|
||||
EXPECT_EQ(PLATFORM_TEGRA2, info.GetPlatform());
|
||||
}
|
||||
|
||||
TEST(PackageInfo, Tegra3FromFullName)
|
||||
{
|
||||
PackageInfo info("org.opencv.lib_v24_tegra3", "/data/data/org.opencv.lib_v24_tegra3");
|
||||
EXPECT_EQ(2040000, info.GetVersion());
|
||||
EXPECT_EQ(PLATFORM_TEGRA3, info.GetPlatform());
|
||||
}
|
||||
|
||||
TEST(PackageInfo, Tegra4FromFullName)
|
||||
{
|
||||
PackageInfo info("org.opencv.lib_v24_tegra4", "/data/data/org.opencv.lib_v24_tegra4");
|
||||
EXPECT_EQ(2040000, info.GetVersion());
|
||||
EXPECT_EQ(PLATFORM_TEGRA4, info.GetPlatform());
|
||||
}
|
||||
|
||||
#ifdef __SUPPORT_MIPS
|
||||
TEST(PackageInfo, MipsFromFullName)
|
||||
{
|
||||
PackageInfo info("org.opencv.lib_v24_mips", "/data/data/org.opencv.lib_v24_mips");
|
||||
EXPECT_EQ(2040000, info.GetVersion());
|
||||
EXPECT_EQ(ARCH_MIPS, info.GetCpuID());
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(PackageInfo, Check2DigitRevision)
|
||||
{
|
||||
PackageInfo info("org.opencv.lib_v23_armv7a_neon", "/data/data/org.opencv.lib_v23_armv7_neon", "4.1");
|
||||
EXPECT_EQ(2030400, info.GetVersion());
|
||||
EXPECT_EQ(ARCH_ARMv7 | FEATURES_HAS_NEON, info.GetCpuID());
|
||||
}
|
||||
|
||||
TEST(PackageInfo, Check3DigitRevision)
|
||||
{
|
||||
PackageInfo info("org.opencv.lib_v23_armv7a_neon", "/data/data/org.opencv.lib_v23_armv7_neon", "4.1.5");
|
||||
EXPECT_EQ(2030401, info.GetVersion());
|
||||
EXPECT_EQ(ARCH_ARMv7 | FEATURES_HAS_NEON, info.GetCpuID());
|
||||
}
|
||||
|
||||
TEST(PackageInfo, Comparator1)
|
||||
{
|
||||
PackageInfo info1(2040000, PLATFORM_UNKNOWN, ARCH_X86);
|
||||
PackageInfo info2("org.opencv.lib_v24_x86", "/data/data/org.opencv.lib_v24_x86");
|
||||
EXPECT_STREQ(info1.GetFullName().c_str(), info2.GetFullName().c_str());
|
||||
EXPECT_EQ(info1, info2);
|
||||
}
|
||||
|
||||
TEST(PackageInfo, Comparator2)
|
||||
{
|
||||
PackageInfo info1(2040000, PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_NEON | FEATURES_HAS_VFPv3);
|
||||
#ifdef __SUPPORT_ARMEABI_V7A_FEATURES
|
||||
PackageInfo info2("org.opencv.lib_v24_armv7a_neon", "/data/data/org.opencv.lib_v24_armv7a_neon");
|
||||
#else
|
||||
PackageInfo info2("org.opencv.lib_v24_armv7a", "/data/data/org.opencv.lib_v24_armv7a");
|
||||
#endif
|
||||
EXPECT_STREQ(info1.GetFullName().c_str(), info2.GetFullName().c_str());
|
||||
EXPECT_EQ(info1, info2);
|
||||
}
|
||||
|
||||
#ifdef __SUPPORT_TEGRA3
|
||||
TEST(PackageInfo, Comparator3)
|
||||
{
|
||||
PackageInfo info1(2030000, PLATFORM_TEGRA3, 0);
|
||||
PackageInfo info2("org.opencv.lib_v23_tegra3", "/data/data/org.opencv.lib_v23_tegra3");
|
||||
EXPECT_STREQ(info1.GetFullName().c_str(), info2.GetFullName().c_str());
|
||||
EXPECT_EQ(info1, info2);
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,18 @@
|
||||
#include "PackageManagerStub.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool PackageManagerStub::InstallPackage(const PackageInfo& package)
|
||||
{
|
||||
InstalledPackages.push_back(package);
|
||||
return true;
|
||||
}
|
||||
|
||||
vector<PackageInfo> PackageManagerStub::GetInstalledPackages()
|
||||
{
|
||||
return InstalledPackages;
|
||||
}
|
||||
|
||||
PackageManagerStub::~PackageManagerStub()
|
||||
{
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
#ifndef __PACKAGE_MANAGER_STUB_H__
|
||||
#define __PACKAGE_MANAGER_STUB_H__
|
||||
|
||||
#include "IPackageManager.h"
|
||||
#include "CommonPackageManager.h"
|
||||
|
||||
class PackageManagerStub: public CommonPackageManager
|
||||
{
|
||||
public:
|
||||
std::vector<PackageInfo> InstalledPackages;
|
||||
virtual ~PackageManagerStub();
|
||||
protected:
|
||||
virtual bool InstallPackage(const PackageInfo& package);
|
||||
virtual std::vector<PackageInfo> GetInstalledPackages();
|
||||
};
|
||||
|
||||
#endif
|
@@ -0,0 +1,139 @@
|
||||
#include "HardwareDetector.h"
|
||||
#include "IPackageManager.h"
|
||||
#include "CommonPackageManager.h"
|
||||
#include "PackageManagerStub.h"
|
||||
#include "IOpenCVEngine.h"
|
||||
#include <utils/String16.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
TEST(PackageManager, InstalledVersions)
|
||||
{
|
||||
PackageManagerStub pm;
|
||||
PackageInfo info(2030000, PLATFORM_UNKNOWN, ARCH_ARMv7);
|
||||
pm.InstalledPackages.push_back(info);
|
||||
std::vector<int> versions = pm.GetInstalledVersions();
|
||||
EXPECT_EQ(1, versions.size());
|
||||
EXPECT_EQ(2030000, *versions.begin());
|
||||
}
|
||||
|
||||
TEST(PackageManager, CheckVersionInstalled)
|
||||
{
|
||||
PackageManagerStub pm;
|
||||
PackageInfo info(2030000, PLATFORM_UNKNOWN, ARCH_ARMv7);
|
||||
pm.InstalledPackages.push_back(info);
|
||||
EXPECT_TRUE(pm.CheckVersionInstalled(2030000, PLATFORM_UNKNOWN, ARCH_ARMv7));
|
||||
}
|
||||
|
||||
TEST(PackageManager, InstallVersion)
|
||||
{
|
||||
PackageManagerStub pm;
|
||||
PackageInfo info(2030000, PLATFORM_UNKNOWN, ARCH_ARMv5);
|
||||
pm.InstalledPackages.push_back(info);
|
||||
EXPECT_TRUE(pm.InstallVersion(2040000, PLATFORM_UNKNOWN, ARCH_ARMv5));
|
||||
EXPECT_EQ(2, pm.InstalledPackages.size());
|
||||
EXPECT_TRUE(pm.CheckVersionInstalled(2040000, PLATFORM_UNKNOWN, ARCH_ARMv5));
|
||||
}
|
||||
|
||||
TEST(PackageManager, GetPackagePathForArmv5)
|
||||
{
|
||||
PackageManagerStub pm;
|
||||
EXPECT_TRUE(pm.InstallVersion(2040300, PLATFORM_UNKNOWN, ARCH_ARMv5));
|
||||
string path = pm.GetPackagePathByVersion(2040300, PLATFORM_UNKNOWN, ARCH_ARMv5);
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv5/lib", path.c_str());
|
||||
}
|
||||
|
||||
TEST(PackageManager, GetPackagePathForArmv7)
|
||||
{
|
||||
PackageManagerStub pm;
|
||||
EXPECT_TRUE(pm.InstallVersion(2030000, PLATFORM_UNKNOWN, ARCH_ARMv7));
|
||||
string path = pm.GetPackagePathByVersion(2030000, PLATFORM_UNKNOWN, ARCH_ARMv7);
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v23_armv7a/lib", path.c_str());
|
||||
}
|
||||
|
||||
TEST(PackageManager, GetPackagePathForArmv7Neon)
|
||||
{
|
||||
PackageManagerStub pm;
|
||||
EXPECT_TRUE(pm.InstallVersion(2030000, PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_NEON));
|
||||
string path = pm.GetPackagePathByVersion(2030000, PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_NEON);
|
||||
#ifdef __SUPPORT_ARMEABI_V7A_FEATURES
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v23_armv7a_neon/lib", path.c_str());
|
||||
#else
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v23_armv7a/lib", path.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(PackageManager, GetPackagePathForX86)
|
||||
{
|
||||
PackageManagerStub pm;
|
||||
EXPECT_TRUE(pm.InstallVersion(2030000, PLATFORM_UNKNOWN, ARCH_X86));
|
||||
string path = pm.GetPackagePathByVersion(2030000, PLATFORM_UNKNOWN, ARCH_X86);
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v23_x86/lib", path.c_str());
|
||||
}
|
||||
|
||||
TEST(PackageManager, GetPackagePathForX86SSE2)
|
||||
{
|
||||
PackageManagerStub pm;
|
||||
EXPECT_TRUE(pm.InstallVersion(2030000, PLATFORM_UNKNOWN, ARCH_X86 | FEATURES_HAS_SSE2));
|
||||
string path = pm.GetPackagePathByVersion(2030000, PLATFORM_UNKNOWN, ARCH_X86 | FEATURES_HAS_SSE2);
|
||||
#ifdef __SUPPORT_INTEL_FEATURES
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v23_x86_sse2/lib", path.c_str());
|
||||
#else
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v23_x86/lib", path.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(PackageManager, GetPackagePathForTegra3)
|
||||
{
|
||||
PackageManagerStub pm;
|
||||
EXPECT_TRUE(pm.InstallVersion(2030000, PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON));
|
||||
string path = pm.GetPackagePathByVersion(2030000, PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON);
|
||||
#ifdef __SUPPORT_TEGRA3
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v23_tegra3/lib", path.c_str());
|
||||
#else
|
||||
#ifdef __SUPPORT_ARMEABI_V7A_FEATURES
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v23_armv7a_neon/lib", path.c_str());
|
||||
#else
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v23_armv7a/lib", path.c_str());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(PackageManager, GetPackagePathForTegra4)
|
||||
{
|
||||
PackageManagerStub pm;
|
||||
EXPECT_TRUE(pm.InstallVersion(2040400, PLATFORM_TEGRA4, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON));
|
||||
string path = pm.GetPackagePathByVersion(2040400, PLATFORM_TEGRA4, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON);
|
||||
#ifdef __SUPPORT_TEGRA3
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra4/lib", path.c_str());
|
||||
#else
|
||||
#ifdef __SUPPORT_ARMEABI_V7A_FEATURES
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a_neon/lib", path.c_str());
|
||||
#else
|
||||
EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", path.c_str());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __SUPPORT_MIPS
|
||||
TEST(PackageManager, GetPackagePathForMips)
|
||||
{
|
||||
PackageManagerStub pm;
|
||||
EXPECT_TRUE(pm.InstallVersion(2040000, PLATFORM_UNKNOWN, ARCH_MIPS));
|
||||
string path = pm.GetPackagePathByVersion(2040000, 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)
|
||||
// {
|
||||
// PackageManagerStub pm;
|
||||
// PackageInfo info("240", PLATFORM_TEGRA2, 0);
|
||||
// pm.InstalledPackages.push_back(info);
|
||||
// string path = pm.GetPackagePathByVersion("240", PLATFORM_TEGRA2, 0);
|
||||
// EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra2/lib", path.c_str());
|
||||
// }
|
7
platforms/android/service/engine/jni/Tests/TestMain.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
47
platforms/android/service/engine/jni/Tests/Tests.mk
Normal file
@@ -0,0 +1,47 @@
|
||||
#---------------------------------------------------------------------
|
||||
# Native test application
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
Tests/gtest/gtest-all.cpp \
|
||||
BinderComponent/ProcReader.cpp \
|
||||
BinderComponent/TegraDetector.cpp \
|
||||
BinderComponent/HardwareDetector.cpp \
|
||||
Tests/PackageManagerStub.cpp \
|
||||
NativeService/CommonPackageManager.cpp \
|
||||
NativeService/PackageInfo.cpp \
|
||||
Tests/PackageManagmentTest.cpp \
|
||||
Tests/PackageInfoTest.cpp \
|
||||
Tests/OpenCVEngineTest.cpp \
|
||||
Tests/TestMain.cpp
|
||||
# Tests/HardwareDetectionTest.cpp \
|
||||
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/Tests \
|
||||
$(LOCAL_PATH)/Tests/gtest \
|
||||
$(LOCAL_PATH)/include \
|
||||
$(LOCAL_PATH)/BinderComponent \
|
||||
$(LOCAL_PATH)/NativeService \
|
||||
$(LOCAL_PATH)/Tests/gtest/include \
|
||||
$(TOP)/frameworks/base/include \
|
||||
$(TOP)/system/core/include
|
||||
|
||||
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
|
||||
|
||||
LOCAL_MODULE := OpenCVEngineTestApp
|
||||
|
||||
LOCAL_LDLIBS += -lz -lbinder -llog -lutils
|
||||
|
||||
LOCAL_SHARED_LIBRARIES += libOpenCVEngine
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
9118
platforms/android/service/engine/jni/Tests/gtest/gtest-all.cpp
Normal file
19537
platforms/android/service/engine/jni/Tests/gtest/gtest.h
Normal file
22
platforms/android/service/engine/jni/include/EngineCommon.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef __ENGINE_COMMON_H__
|
||||
#define __ENGINE_COMMON_H__
|
||||
|
||||
// Global tag for Logcat output
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "OpenCVEngine"
|
||||
|
||||
// OpenCV Engine API version
|
||||
#ifndef OPEN_CV_ENGINE_VERSION
|
||||
#define OPEN_CV_ENGINE_VERSION 2
|
||||
#endif
|
||||
|
||||
#define LIB_OPENCV_INFO_NAME "libopencv_info.so"
|
||||
|
||||
// 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"
|
||||
|
||||
typedef const char* (*InfoFunctionType)();
|
||||
|
||||
#endif
|
32
platforms/android/service/engine/jni/include/IOpenCVEngine.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef __IOPENCV_ENGINE_H__
|
||||
#define __IOPENCV_ENGINE_H__
|
||||
|
||||
#include <binder/IInterface.h>
|
||||
#include <binder/Parcel.h>
|
||||
#include <utils/String16.h>
|
||||
#include "EngineCommon.h"
|
||||
|
||||
enum EngineMethonID
|
||||
{
|
||||
OCVE_GET_ENGINE_VERSION = 1,
|
||||
OCVE_GET_LIB_PATH_BY_VERSION = 2,
|
||||
OCVE_INSTALL_VERSION = 3,
|
||||
OCVE_GET_LIB_LIST = 4,
|
||||
};
|
||||
|
||||
using namespace android;
|
||||
|
||||
class IOpenCVEngine: public android::IInterface
|
||||
{
|
||||
public:
|
||||
|
||||
DECLARE_META_INTERFACE(OpenCVEngine)
|
||||
|
||||
public:
|
||||
virtual int GetVersion() = 0;
|
||||
virtual android::String16 GetLibPathByVersion(android::String16 version) = 0;
|
||||
virtual android::String16 GetLibraryList(android::String16 version) = 0;
|
||||
virtual bool InstallVersion(android::String16 version) = 0;
|
||||
};
|
||||
|
||||
#endif
|
@@ -0,0 +1,17 @@
|
||||
#ifndef __IPACKAGE_MANAGER__
|
||||
#define __IPACKAGE_MANAGER__
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class IPackageManager
|
||||
{
|
||||
public:
|
||||
virtual std::vector<int> GetInstalledVersions() = 0;
|
||||
virtual bool CheckVersionInstalled(int version, int platform, int cpu_id) = 0;
|
||||
virtual bool InstallVersion(int version, int platform, int cpu_id) = 0;
|
||||
virtual std::string GetPackagePathByVersion(int version, int platform, int cpu_id) = 0;
|
||||
virtual ~IPackageManager(){};
|
||||
};
|
||||
|
||||
#endif
|
14
platforms/android/service/engine/project.properties
Normal file
@@ -0,0 +1,14 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system edit
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
#
|
||||
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
# Project target.
|
||||
target=android-8
|
BIN
platforms/android/service/engine/res/drawable/icon.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
61
platforms/android/service/engine/res/layout-small/info.xml
Normal file
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:focusable="false"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/InfoName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Large Text"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Version: "
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/InfoVersion"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Small Text"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Target hardware: "
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/InfoHardware"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Small Text"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
123
platforms/android/service/engine/res/layout-small/main.xml
Normal file
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="About"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:autoLink="web"
|
||||
android:clickable="false"
|
||||
android:duplicateParentState="false"
|
||||
android:longClickable="false"
|
||||
android:text="OpenCV is Open Computer Vision library. OpenCV Manager provides the best version of the OpenCV for your hardware. See opencv.org for details."
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/EngineVersionCaption"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Version: "
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/EngineVersionValue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="version"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Device information"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" android:layout_marginTop="15dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/HardwareCaption"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hardware: "
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/HardwareValue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hardware"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/OsVersionCaption"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="OS version: "
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/OsVersionValue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Os Specification"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Installed packages"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" android:layout_marginTop="15dp"/>
|
||||
|
||||
<ListView
|
||||
android:id="@+id/InstalledPackageList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" android:layout_weight="1">
|
||||
</ListView>
|
||||
|
||||
<Button
|
||||
android:id="@+id/CheckEngineUpdate"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Check for update" />
|
||||
|
||||
</LinearLayout>
|
61
platforms/android/service/engine/res/layout/info.xml
Normal file
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:focusable="false"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/InfoName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Large Text"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Library version: "
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/InfoVersion"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Small Text"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Target hardware: "
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/InfoHardware"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Small Text"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
123
platforms/android/service/engine/res/layout/main.xml
Normal file
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="About"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:autoLink="web"
|
||||
android:clickable="false"
|
||||
android:duplicateParentState="false"
|
||||
android:longClickable="false"
|
||||
android:text="OpenCV library is used by other applications for image enhancement, panorama stitching, object detection, recognition and tracking and so on. OpenCV Manager provides the best version of the OpenCV for your hardware. See opencv.org for details."
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/EngineVersionCaption"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="OpenCV Manager version: "
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/EngineVersionValue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="version"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Device information"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" android:layout_marginTop="20dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/HardwareCaption"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hardware: "
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/HardwareValue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hardware"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/OsVersionCaption"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="OS version: "
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/OsVersionValue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Os Specification"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Installed packages"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" android:layout_marginTop="15dp"/>
|
||||
|
||||
<ListView
|
||||
android:id="@+id/InstalledPackageList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" android:layout_weight="1">
|
||||
</ListView>
|
||||
|
||||
<Button
|
||||
android:id="@+id/CheckEngineUpdate"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Check for update" />
|
||||
|
||||
</LinearLayout>
|
4
platforms/android/service/engine/res/values/strings.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">OpenCV Manager</string>
|
||||
</resources>
|
@@ -0,0 +1,46 @@
|
||||
package org.opencv.engine;
|
||||
|
||||
import android.os.IBinder;
|
||||
|
||||
public class BinderConnector
|
||||
{
|
||||
public BinderConnector(MarketConnector Market) {
|
||||
mMarket = Market;
|
||||
}
|
||||
|
||||
public boolean Init() {
|
||||
boolean result = false;
|
||||
if (mIsReady)
|
||||
result = Init(mMarket);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public native IBinder Connect();
|
||||
|
||||
public boolean Disconnect()
|
||||
{
|
||||
if (mIsReady)
|
||||
Final();
|
||||
|
||||
return mIsReady;
|
||||
}
|
||||
|
||||
private native boolean Init(MarketConnector Market);
|
||||
private native void Final();
|
||||
private static boolean mIsReady = false;
|
||||
private MarketConnector mMarket;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("OpenCVEngine");
|
||||
System.loadLibrary("OpenCVEngine_jni");
|
||||
mIsReady = true;
|
||||
}
|
||||
catch(UnsatisfiedLinkError e) {
|
||||
mIsReady = false;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
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_TEGRA4 = 4;
|
||||
|
||||
|
||||
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();
|
||||
|
||||
public static boolean mIsReady = false;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("OpenCVEngine");
|
||||
System.loadLibrary("OpenCVEngine_jni");
|
||||
mIsReady = true;
|
||||
}
|
||||
catch(UnsatisfiedLinkError e) {
|
||||
mIsReady = false;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,130 @@
|
||||
package org.opencv.engine;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
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 MarketConnector(Context context)
|
||||
{
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public String GetApplicationName(ApplicationInfo info)
|
||||
{
|
||||
return (String) info.loadLabel(mContext.getPackageManager());
|
||||
}
|
||||
|
||||
public boolean InstallAppFromMarket(String AppID)
|
||||
{
|
||||
boolean result = true;
|
||||
try
|
||||
{
|
||||
Intent intent = new Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
Uri.parse("market://details?id=" + AppID)
|
||||
);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean RemoveAppFromMarket(String AppID, boolean wait)
|
||||
{
|
||||
boolean result = true;
|
||||
try
|
||||
{
|
||||
Intent intent = new Intent(
|
||||
Intent.ACTION_DELETE,
|
||||
Uri.parse("package:" + AppID)
|
||||
);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
if (wait)
|
||||
{
|
||||
((Activity)mContext).startActivityForResult(intent, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean CheckPackageInstalled(String AppID)
|
||||
{
|
||||
List<PackageInfo> Packages = mContext.getPackageManager().getInstalledPackages(PackageManager.GET_CONFIGURATIONS);
|
||||
Iterator<PackageInfo> it = Packages.iterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
PackageInfo CurrentPack = it.next();
|
||||
if (CurrentPack.packageName == AppID)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public PackageInfo[] GetInstalledOpenCVPackages()
|
||||
{
|
||||
List<PackageInfo> AllPackages = mContext.getPackageManager().getInstalledPackages(PackageManager.GET_CONFIGURATIONS);
|
||||
List<PackageInfo> OpenCVPackages = new ArrayList<PackageInfo>();
|
||||
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<PackageInfo> it = AllPackages.iterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
PackageInfo CurrentPack = it.next();
|
||||
if (CurrentPack.packageName.contains(OpenCVPackageNamePreffix))
|
||||
{
|
||||
OpenCVPackages.add(CurrentPack);
|
||||
}
|
||||
}
|
||||
|
||||
PackageInfo[] OpenCVPackagesArray = new PackageInfo[OpenCVPackages.size()];
|
||||
|
||||
it = OpenCVPackages.iterator();
|
||||
int idx = 0;
|
||||
while(it.hasNext())
|
||||
{
|
||||
OpenCVPackagesArray[idx] = it.next();
|
||||
idx++;
|
||||
}
|
||||
|
||||
return OpenCVPackagesArray;
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package org.opencv.engine;
|
||||
|
||||
/**
|
||||
* Class provides Java interface to OpenCV Engine Service. Is synchronious with native OpenCVEngine class.
|
||||
*/
|
||||
interface OpenCVEngineInterface
|
||||
{
|
||||
/**
|
||||
* @return Return service version
|
||||
*/
|
||||
int getEngineVersion();
|
||||
|
||||
/**
|
||||
* Find installed OpenCV library
|
||||
* @param OpenCV version
|
||||
* @return Returns path to OpenCV native libs or empty string if OpenCV was not found
|
||||
*/
|
||||
String getLibPathByVersion(String version);
|
||||
|
||||
/**
|
||||
* Try to install defined version of OpenCV from Google Play (Android Market).
|
||||
* @param OpenCV version
|
||||
* @return Returns true if installation was successful or OpenCV package has been already installed
|
||||
*/
|
||||
boolean installVersion(String version);
|
||||
|
||||
/**
|
||||
* Return list of libraries in loading order seporated by ";" symbol
|
||||
* @param OpenCV version
|
||||
* @return Returns OpenCV libraries names seporated by symbol ";" in loading order
|
||||
*/
|
||||
String getLibraryList(String version);
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
package org.opencv.engine;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
public class OpenCVEngineService extends Service
|
||||
{
|
||||
private static final String TAG = "OpenCVEngine/Service";
|
||||
private IBinder mEngineInterface = null;
|
||||
private MarketConnector mMarket;
|
||||
private BinderConnector mNativeBinder;
|
||||
|
||||
public void onCreate() {
|
||||
Log.i(TAG, "Service starting");
|
||||
super.onCreate();
|
||||
Log.i(TAG, "Engine binder component creating");
|
||||
mMarket = new MarketConnector(getBaseContext());
|
||||
mNativeBinder = new BinderConnector(mMarket);
|
||||
if (mNativeBinder.Init()) {
|
||||
mEngineInterface = mNativeBinder.Connect();
|
||||
Log.i(TAG, "Service started successfully");
|
||||
} else {
|
||||
Log.e(TAG, "Cannot initialize native part of OpenCV Manager!");
|
||||
Log.e(TAG, "Using stub instead");
|
||||
|
||||
mEngineInterface = new OpenCVEngineInterface.Stub() {
|
||||
|
||||
@Override
|
||||
public boolean installVersion(String version) throws RemoteException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLibraryList(String version) throws RemoteException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLibPathByVersion(String version) throws RemoteException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEngineVersion() throws RemoteException {
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public IBinder onBind(Intent intent) {
|
||||
Log.i(TAG, "Service onBind called for intent " + intent.toString());
|
||||
return mEngineInterface;
|
||||
}
|
||||
|
||||
public boolean onUnbind(Intent intent)
|
||||
{
|
||||
Log.i(TAG, "Service onUnbind called for intent " + intent.toString());
|
||||
return true;
|
||||
}
|
||||
public void OnDestroy()
|
||||
{
|
||||
Log.i(TAG, "OpenCV Engine service destruction");
|
||||
mNativeBinder.Disconnect();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
package org.opencv.engine;
|
||||
|
||||
public class OpenCVLibraryInfo {
|
||||
public OpenCVLibraryInfo(String packagePath) {
|
||||
mNativeObj = open(packagePath + "/libopencv_info.so");
|
||||
if (mNativeObj != 0) {
|
||||
mPackageName = getPackageName(mNativeObj);
|
||||
mLibraryList = getLibraryList(mNativeObj);
|
||||
mVersionName = getVersionName(mNativeObj);
|
||||
close(mNativeObj);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean status() {
|
||||
return (mNativeObj != 0);
|
||||
}
|
||||
|
||||
public String packageName() {
|
||||
return mPackageName;
|
||||
}
|
||||
|
||||
public String libraryList() {
|
||||
return mLibraryList;
|
||||
}
|
||||
|
||||
public String versionName() {
|
||||
return mVersionName;
|
||||
}
|
||||
|
||||
private long mNativeObj;
|
||||
private String mPackageName;
|
||||
private String mLibraryList;
|
||||
private String mVersionName;
|
||||
|
||||
private native long open(String packagePath);
|
||||
private native String getPackageName(long obj);
|
||||
private native String getLibraryList(long obj);
|
||||
private native String getVersionName(long obj);
|
||||
private native void close(long obj);
|
||||
}
|
@@ -0,0 +1,492 @@
|
||||
package org.opencv.engine.manager;
|
||||
|
||||
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.OpenCVLibraryInfo;
|
||||
import org.opencv.engine.R;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SimpleAdapter;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class ManagerActivity extends Activity
|
||||
{
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (!HardwareDetector.mIsReady) {
|
||||
Log.e(TAG, "Cannot initialize native part of OpenCV Manager!");
|
||||
|
||||
AlertDialog dialog = new AlertDialog.Builder(this).create();
|
||||
|
||||
dialog.setTitle("OpenCV Manager Error");
|
||||
dialog.setMessage("OpenCV Manager is incompatible with this device. Please replace it with an appropriate package.");
|
||||
dialog.setCancelable(false);
|
||||
dialog.setButton("OK", new DialogInterface.OnClickListener() {
|
||||
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
return;
|
||||
}
|
||||
|
||||
setContentView(R.layout.main);
|
||||
|
||||
TextView OsVersionView = (TextView)findViewById(R.id.OsVersionValue);
|
||||
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) {
|
||||
ManagerVersion = "N/A";
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
mInstalledPackageView = (ListView)findViewById(R.id.InstalledPackageList);
|
||||
|
||||
mMarket = new MarketConnector(this);
|
||||
|
||||
mInstalledPacksAdapter = new PackageListAdapter(
|
||||
this,
|
||||
mListViewItems,
|
||||
R.layout.info,
|
||||
new String[] {"Name", "Version", "Hardware", "Activity"},
|
||||
new int[] {R.id.InfoName,R.id.InfoVersion, R.id.InfoHardware}
|
||||
);
|
||||
|
||||
mInstalledPackageView.setAdapter(mInstalledPacksAdapter);
|
||||
|
||||
TextView HardwarePlatformView = (TextView)findViewById(R.id.HardwareValue);
|
||||
int Platfrom = HardwareDetector.DetectKnownPlatforms();
|
||||
int CpuId = HardwareDetector.GetCpuID();
|
||||
|
||||
if (HardwareDetector.PLATFORM_UNKNOWN != Platfrom)
|
||||
{
|
||||
if (HardwareDetector.PLATFORM_TEGRA == Platfrom)
|
||||
{
|
||||
HardwarePlatformView.setText("Tegra");
|
||||
}
|
||||
else if (HardwareDetector.PLATFORM_TEGRA2 == Platfrom)
|
||||
{
|
||||
HardwarePlatformView.setText("Tegra 2");
|
||||
}
|
||||
else if (HardwareDetector.PLATFORM_TEGRA3 == Platfrom)
|
||||
{
|
||||
HardwarePlatformView.setText("Tegra 3");
|
||||
}
|
||||
else
|
||||
{
|
||||
HardwarePlatformView.setText("Tegra 4");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((CpuId & HardwareDetector.ARCH_X86) == HardwareDetector.ARCH_X86)
|
||||
{
|
||||
HardwarePlatformView.setText("x86 " + JoinIntelFeatures(CpuId));
|
||||
}
|
||||
else if ((CpuId & HardwareDetector.ARCH_X64) == HardwareDetector.ARCH_X64)
|
||||
{
|
||||
HardwarePlatformView.setText("x64 " + JoinIntelFeatures(CpuId));
|
||||
}
|
||||
else if ((CpuId & HardwareDetector.ARCH_ARMv5) == HardwareDetector.ARCH_ARMv5)
|
||||
{
|
||||
HardwarePlatformView.setText("ARM v5 " + JoinArmFeatures(CpuId));
|
||||
}
|
||||
else if ((CpuId & HardwareDetector.ARCH_ARMv6) == HardwareDetector.ARCH_ARMv6)
|
||||
{
|
||||
HardwarePlatformView.setText("ARM v6 " + JoinArmFeatures(CpuId));
|
||||
}
|
||||
else if ((CpuId & HardwareDetector.ARCH_ARMv7) == HardwareDetector.ARCH_ARMv7)
|
||||
{
|
||||
HardwarePlatformView.setText("ARM v7 " + JoinArmFeatures(CpuId));
|
||||
}
|
||||
else if ((CpuId & HardwareDetector.ARCH_ARMv8) == HardwareDetector.ARCH_ARMv8)
|
||||
{
|
||||
HardwarePlatformView.setText("ARM v8 " + JoinArmFeatures(CpuId));
|
||||
}
|
||||
else if ((CpuId & HardwareDetector.ARCH_MIPS) == HardwareDetector.ARCH_MIPS)
|
||||
{
|
||||
HardwarePlatformView.setText("MIPS");
|
||||
}
|
||||
else
|
||||
{
|
||||
HardwarePlatformView.setText("not detected");
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mActionDialog.setButton2("Return", new DialogInterface.OnClickListener() {
|
||||
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// nothing
|
||||
}
|
||||
});
|
||||
|
||||
mInstalledPackageView.setOnItemClickListener(new OnItemClickListener() {
|
||||
|
||||
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
|
||||
//if (!mListViewItems.get((int) id).get("Name").equals("Built-in OpenCV library"));
|
||||
if (!mInstalledPackageInfo[(int) id].packageName.equals("org.opencv.engine"))
|
||||
{
|
||||
mInstalledPackageView.setTag(Integer.valueOf((int)id));
|
||||
mActionDialog.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mPackageChangeReciever = new BroadcastReceiver() {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d("OpenCVManager/Reciever", "Bradcast message " + intent.getAction() + " reciever");
|
||||
Log.d("OpenCVManager/Reciever", "Filling package list on broadcast message");
|
||||
if (!bindService(new Intent("org.opencv.engine.BIND"), new OpenCVEngineServiceConnection(), 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mPackageChangeReciever != null)
|
||||
unregisterReceiver(mPackageChangeReciever);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (HardwareDetector.mIsReady) {
|
||||
Log.d(TAG, "Filling package list on resume");
|
||||
OpenCVEngineServiceConnection connection = new OpenCVEngineServiceConnection();
|
||||
if (!bindService(new Intent("org.opencv.engine.BIND"), connection, Context.BIND_AUTO_CREATE)) {
|
||||
Log.e(TAG, "Cannot bind to OpenCV Manager service!");
|
||||
TextView EngineVersionView = (TextView)findViewById(R.id.EngineVersionValue);
|
||||
if (EngineVersionView != null)
|
||||
EngineVersionView.setText("not avaliable");
|
||||
unbindService(connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected SimpleAdapter mInstalledPacksAdapter;
|
||||
protected ListView mInstalledPackageView;
|
||||
protected Button mUpdateEngineButton;
|
||||
protected PackageInfo[] mInstalledPackageInfo;
|
||||
protected final ArrayList<HashMap<String,String>> mListViewItems = new ArrayList<HashMap<String,String>>();
|
||||
protected static final String TAG = "OpenCV_Manager/Activity";
|
||||
protected MarketConnector mMarket;
|
||||
protected AlertDialog mActionDialog;
|
||||
protected HashMap<String,String> mActivePackageMap = new HashMap<String, String>();
|
||||
protected int ManagerApiLevel = 0;
|
||||
protected String ManagerVersion;
|
||||
|
||||
protected BroadcastReceiver mPackageChangeReciever = null;
|
||||
|
||||
protected class OpenCVEngineServiceConnection implements ServiceConnection
|
||||
{
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
}
|
||||
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
OpenCVEngineInterface EngineService = OpenCVEngineInterface.Stub.asInterface(service);
|
||||
if (EngineService == null) {
|
||||
Log.e(TAG, "Cannot connect to OpenCV Manager Service!");
|
||||
unbindService(this);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
ManagerApiLevel = EngineService.getEngineVersion();
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
TextView EngineVersionView = (TextView)findViewById(R.id.EngineVersionValue);
|
||||
EngineVersionView.setText(ManagerVersion);
|
||||
|
||||
try {
|
||||
String path = EngineService.getLibPathByVersion("2.4");
|
||||
Log.d(TAG, "2.4 -> " + path);
|
||||
mActivePackageMap.put("24", path);
|
||||
path = EngineService.getLibPathByVersion("2.5");
|
||||
Log.d(TAG, "2.5 -> " + path);
|
||||
mActivePackageMap.put("25", path);
|
||||
} catch (RemoteException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Log.d(TAG, "Filling package list on service connection");
|
||||
FillPackageList();
|
||||
|
||||
unbindService(this);
|
||||
}
|
||||
};
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
|
||||
synchronized protected void FillPackageList()
|
||||
{
|
||||
synchronized (mListViewItems) {
|
||||
mInstalledPackageInfo = mMarket.GetInstalledOpenCVPackages();
|
||||
mListViewItems.clear();
|
||||
|
||||
int RealPackageCount = mInstalledPackageInfo.length;
|
||||
for (int i = 0; i < RealPackageCount; i++)
|
||||
{
|
||||
if (mInstalledPackageInfo[i] == null)
|
||||
break;
|
||||
|
||||
// Convert to Items for package list view
|
||||
HashMap<String,String> temp = new HashMap<String,String>();
|
||||
|
||||
String HardwareName = "";
|
||||
String NativeLibDir = "";
|
||||
String OpenCVersion = "";
|
||||
|
||||
String PublicName = mMarket.GetApplicationName(mInstalledPackageInfo[i].applicationInfo);
|
||||
String PackageName = mInstalledPackageInfo[i].packageName;
|
||||
String VersionName = mInstalledPackageInfo[i].versionName;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD)
|
||||
NativeLibDir = mInstalledPackageInfo[i].applicationInfo.nativeLibraryDir;
|
||||
else
|
||||
NativeLibDir = "/data/data/" + mInstalledPackageInfo[i].packageName + "/lib";
|
||||
|
||||
if (PackageName.equals("org.opencv.engine"))
|
||||
{
|
||||
OpenCVLibraryInfo NativeInfo = new OpenCVLibraryInfo(NativeLibDir);
|
||||
if (NativeInfo.status())
|
||||
{
|
||||
PublicName = "Built-in OpenCV library";
|
||||
PackageName = NativeInfo.packageName();
|
||||
VersionName = NativeInfo.versionName();
|
||||
}
|
||||
else
|
||||
{
|
||||
mInstalledPackageInfo[i] = mInstalledPackageInfo[RealPackageCount-1];
|
||||
mInstalledPackageInfo[RealPackageCount-1] = null;
|
||||
RealPackageCount--;
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int idx = 0;
|
||||
Log.d(TAG, PackageName);
|
||||
StringTokenizer tokenizer = new StringTokenizer(PackageName, "_");
|
||||
while (tokenizer.hasMoreTokens())
|
||||
{
|
||||
if (idx == 1)
|
||||
{
|
||||
// version of OpenCV
|
||||
OpenCVersion = tokenizer.nextToken().substring(1);
|
||||
}
|
||||
else if (idx >= 2)
|
||||
{
|
||||
// hardware options
|
||||
HardwareName += tokenizer.nextToken() + " ";
|
||||
}
|
||||
else
|
||||
{
|
||||
tokenizer.nextToken();
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
|
||||
String ActivePackagePath;
|
||||
String Tags = null;
|
||||
ActivePackagePath = mActivePackageMap.get(OpenCVersion);
|
||||
Log.d(TAG, OpenCVersion + " -> " + ActivePackagePath);
|
||||
|
||||
if (null != ActivePackagePath)
|
||||
{
|
||||
if (ActivePackagePath.equals(NativeLibDir))
|
||||
{
|
||||
temp.put("Activity", "y");
|
||||
Tags = "active";
|
||||
}
|
||||
else
|
||||
{
|
||||
temp.put("Activity", "n");
|
||||
if (!PublicName.equals("Built-in OpenCV library"))
|
||||
Tags = "safe to remove";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
temp.put("Activity", "n");
|
||||
}
|
||||
|
||||
temp.put("Version", NormalizeVersion(OpenCVersion, VersionName));
|
||||
// HACK: OpenCV Manager for Armv7-a Neon already has Tegra3 optimizations
|
||||
// that is enabled on proper hardware
|
||||
if (HardwareDetector.DetectKnownPlatforms() >= HardwareDetector.PLATFORM_TEGRA3 &&
|
||||
HardwareName.equals("armv7a neon ") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD)
|
||||
{
|
||||
temp.put("Hardware", "Tegra");
|
||||
if (Tags == null)
|
||||
{
|
||||
Tags = "optimized";
|
||||
}
|
||||
else
|
||||
{
|
||||
Tags = Tags + ", optimized";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
temp.put("Hardware", HardwareName);
|
||||
}
|
||||
|
||||
if (Tags != null)
|
||||
PublicName = PublicName + " (" + Tags + ")";
|
||||
|
||||
temp.put("Name", PublicName);
|
||||
|
||||
mListViewItems.add(temp);
|
||||
}
|
||||
|
||||
mInstalledPacksAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected String NormalizeVersion(String OpenCVersion, String PackageVersion)
|
||||
{
|
||||
if (OpenCVersion == null || PackageVersion == null)
|
||||
return "unknown";
|
||||
|
||||
String[] revisions = PackageVersion.split("\\.");
|
||||
|
||||
if (revisions.length <= 1 || OpenCVersion.length() == 0)
|
||||
return "unknown";
|
||||
else
|
||||
if (revisions.length == 2)
|
||||
// the 2nd digit is revision
|
||||
return OpenCVersion.substring(0, OpenCVersion.length()-1) + "." +
|
||||
OpenCVersion.toCharArray()[OpenCVersion.length()-1] + "." +
|
||||
revisions[0] + " rev " + revisions[1];
|
||||
else
|
||||
// the 2nd digit is part of library version
|
||||
// the 3rd digit is revision
|
||||
return OpenCVersion.substring(0, OpenCVersion.length()-1) + "." +
|
||||
OpenCVersion.toCharArray()[OpenCVersion.length()-1] + "." +
|
||||
revisions[0] + "." + revisions[1] + " rev " + revisions[2];
|
||||
}
|
||||
|
||||
protected String ConvertPackageName(String Name, String Version)
|
||||
{
|
||||
return Name + " rev " + Version;
|
||||
}
|
||||
|
||||
protected String JoinIntelFeatures(int features)
|
||||
{
|
||||
// TODO: update if package will be published
|
||||
return "";
|
||||
}
|
||||
|
||||
protected String JoinArmFeatures(int features)
|
||||
{
|
||||
// TODO: update if package will be published
|
||||
if ((features & HardwareDetector.FEATURES_HAS_NEON) == HardwareDetector.FEATURES_HAS_NEON)
|
||||
{
|
||||
return "with Neon";
|
||||
}
|
||||
else if ((features & HardwareDetector.FEATURES_HAS_VFPv3) == HardwareDetector.FEATURES_HAS_VFPv3)
|
||||
{
|
||||
return "with VFP v3";
|
||||
}
|
||||
else if ((features & HardwareDetector.FEATURES_HAS_VFPv3d16) == HardwareDetector.FEATURES_HAS_VFPv3d16)
|
||||
{
|
||||
return "with VFP v3d16";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
package org.opencv.engine.manager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.SimpleAdapter;
|
||||
|
||||
public class PackageListAdapter extends SimpleAdapter {
|
||||
|
||||
public PackageListAdapter(Context context,
|
||||
List<? extends Map<String, ?>> data, int resource, String[] from,
|
||||
int[] to) {
|
||||
super(context, data, resource, from, to);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view = super.getView(position, convertView, parent);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> item = (Map<String, String>)getItem(position);
|
||||
if (item.get("Activity") == "y")
|
||||
{
|
||||
view.setBackgroundColor(0x50ffffff);
|
||||
}
|
||||
else
|
||||
{
|
||||
view.setBackgroundColor(0xff000000);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
10
platforms/android/service/engine_test/.classpath
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/OpenCVEngineService"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|