Merge pull request #204 from asmorkalov/manager_internal_lib

Feature #2565 implementation
This commit is contained in:
Andrey Kamaev 2012-12-10 08:07:39 -08:00
commit 2bf56961c0
9 changed files with 243 additions and 28 deletions

View File

@ -2,7 +2,7 @@ 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 8 ${ANDROID_SDK_TARGET} IGNORE_JAVA ON IGNORE_MANIFEST ON )
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")

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="ManagerActivity" default="help">
<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

View File

@ -52,7 +52,8 @@ LOCAL_SRC_FILES := \
NativeService/CommonPackageManager.cpp \
JNIWrapper/JavaBasedPackageManager.cpp \
NativeService/PackageInfo.cpp \
JNIWrapper/HardwareDetector_jni.cpp
JNIWrapper/HardwareDetector_jni.cpp \
JNIWrapper/OpenCVLibraryInfo.cpp
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/include \

View File

@ -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)
{
const char* (*info_func)();
const char* result;
const char* error;
dlerror();
*(void **) (&info_func) = 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)
{
const char* (*info_func)();
const char* result;
const char* error;
dlerror();
*(void **) (&info_func) = 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)
{
const char* (*info_func)();
const char* result;
const char* error;
dlerror();
*(void **) (&info_func) = 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);
}

View File

@ -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

View File

@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-8
target=android-9

View File

@ -20,8 +20,6 @@ public class MarketConnector
private static final String TAG = "OpenCVEngine/MarketConnector";
protected Context mContext;
public boolean mIncludeManager = true;
public MarketConnector(Context context)
{
mContext = context;
@ -100,15 +98,13 @@ public class MarketConnector
{
List<PackageInfo> AllPackages = mContext.getPackageManager().getInstalledPackages(PackageManager.GET_CONFIGURATIONS);
List<PackageInfo> OpenCVPackages = new ArrayList<PackageInfo>();
if (mIncludeManager)
{
try {
OpenCVPackages.add(mContext.getPackageManager().getPackageInfo("org.opencv.engine", PackageManager.GET_CONFIGURATIONS));
} catch (NameNotFoundException e) {
Log.e(TAG, "OpenCV Manager package info was not found!");
e.printStackTrace();
}
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())
{

View File

@ -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);
}

View File

@ -7,7 +7,9 @@ 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;
@ -77,7 +79,7 @@ public class ManagerActivity extends Activity
{
HardwarePlatformView.setText("Tegra");
}
else if (HardwareDetector.PLATFORM_TEGRA == Platfrom)
else if (HardwareDetector.PLATFORM_TEGRA2 == Platfrom)
{
HardwarePlatformView.setText("Tegra 2");
}
@ -170,9 +172,13 @@ public class ManagerActivity extends Activity
mInstalledPackageView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long id) {
mInstalledPackageView.setTag(Integer.valueOf((int)id));
mActionDialog.show();
public void onItemClick(AdapterView<?> 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();
}
}
});
@ -232,8 +238,6 @@ public class ManagerActivity extends Activity
protected class OpenCVEngineServiceConnection implements ServiceConnection
{
public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
}
public void onServiceConnected(ComponentName name, IBinder service) {
@ -266,23 +270,58 @@ public class ManagerActivity extends Activity
}
};
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
synchronized protected void FillPackageList()
{
synchronized (mListViewItems) {
mMarket.mIncludeManager = false;
mInstalledPackageInfo = mMarket.GetInstalledOpenCVPackages();
mListViewItems.clear();
for (int i = 0; i < mInstalledPackageInfo.length; i++)
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";
OpenCVLibraryInfo NativeInfo = new OpenCVLibraryInfo(NativeLibDir);
if (PackageName.equals("org.opencv.engine"))
{
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;
String OpenCVersion = "unknown";
String HardwareName = "";
StringTokenizer tokenizer = new StringTokenizer(mInstalledPackageInfo[i].packageName, "_");
Log.d(TAG, PackageName);
StringTokenizer tokenizer = new StringTokenizer(PackageName, "_");
while (tokenizer.hasMoreTokens())
{
if (idx == 1)
@ -303,6 +342,7 @@ public class ManagerActivity extends Activity
}
String ActivePackagePath;
String Tags = null;
ActivePackagePath = mActivePackageMap.get(OpenCVersion);
Log.d(TAG, OpenCVersion + " -> " + ActivePackagePath);
@ -313,7 +353,7 @@ public class ManagerActivity extends Activity
if (start >= 0 && ActivePackagePath.charAt(stop) == '/')
{
temp.put("Activity", "y");
PublicName += " (in use)";
Tags = "active";
}
else
{
@ -325,9 +365,32 @@ public class ManagerActivity extends Activity
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 3");
if (Tags == null)
{
Tags = "optimized";
}
else
{
Tags = Tags + ", optimized";
}
}
else
{
temp.put("Hardware", HardwareName);
}
if (Tags != null)
PublicName = PublicName + " (" + Tags + ")";
temp.put("Name", PublicName);
temp.put("Version", NormalizeVersion(OpenCVersion, mInstalledPackageInfo[i].versionName));
temp.put("Hardware", HardwareName);
mListViewItems.add(temp);
}