1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

AndroidGCS: Dynamic loading works. Currently won't work out of the box though.

From the build/uavobjects-synth/java:

1. mkdir -p src/org/openpilot/uavtalk/uavobjects
2. javac *.java ../../../androidgcs/src/org/openpilot/uavtalk/UAVDataObject.java \
   ../../../androidgcs/src/org/openpilot/uavtalk/UAVObject*.java \
   ../../../androidgcs/src/org/openpilot/uavtalk/UAVMetaObject.java \
   -d .
3. rm org/openpilot/uavtalk/*.class
4. jar cf tmp_org.openpilot.uavtalk.uavobjects.jar org
5. dx --dex --output org.openpilot.uavtalk.uavobjects.jar tmp_org.openpilot.uavtalk.uavobjects.jar
6. adb push org.openpilot.uavtalk.uavobjects.jar /data/org.openpilot.uavtalk.uavobjects.jar
This commit is contained in:
James Cotton 2012-10-06 00:37:43 -05:00
parent c6341139c2
commit 76785cad57
4 changed files with 30 additions and 14 deletions

View File

@ -276,6 +276,24 @@ public class OPTelemetryService extends Service {
public UAVObjectManager getObjectManager();
};
/**
* Delete the files in a directories
* @param directory
*/
private static void deleteDirectoryContents(File directory)
{
File contents[] = directory.listFiles();
if (contents != null)
{
for (File file : contents)
{
if (file.isDirectory())
deleteDirectoryContents(file);
file.delete();
}
}
}
/**
* Load the UAVObjects from a JAR file. This method must be called in the
* service context.
@ -289,25 +307,24 @@ public class OPTelemetryService extends Service {
File dexDir = getDir(DEX_DIR, Context.MODE_WORLD_READABLE);
// Necessary to get dexOpt to run
//if (dexDir.exists())
// deleteDirectoryContents(dexDir);
if (dexDir.exists())
deleteDirectoryContents(dexDir);
File jarsDir = getDir(JAR_DIR, MODE_WORLD_READABLE);
String classpath = new File(jarsDir, jar).getAbsolutePath();
//File jarsDir = getDir(JAR_DIR, MODE_WORLD_READABLE);
//String classpath = new File(jarsDir, jar).getAbsolutePath();
String classpath = "/data/org.openpilot.uavtalk.uavobjects.jar";
DexClassLoader loader = new DexClassLoader(classpath, dexDir.getAbsolutePath(), null, getClassLoader());
Object initInstance = null;
try {
Class<?> initClass = loader.loadClass("org.openpilot.uavtalk.uavobjects.UAVObjectsInitialize");
initInstance = initClass.newInstance();
Log.d(TAG, "Got the initClass: " + initClass);
Method initMethod = initClass.getMethod("register", UAVObjectManager.class);
initMethod.invoke(initInstance, objMngr);
Log.d(TAG, "Got the method: " + initMethod);
initMethod.invoke(null, objMngr);
Log.d(TAG, "Invoked");
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InstantiationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();

View File

@ -11,7 +11,7 @@ import org.openpilot.uavtalk.TelemetryMonitor;
import org.openpilot.uavtalk.UAVObject;
import org.openpilot.uavtalk.UAVObjectManager;
import org.openpilot.uavtalk.UAVTalk;
import org.openpilot.uavtalk.uavobjects.UAVObjectsInitialize;
import org.openpilot.uavtalk.uavobjects.TelemObjectsInitialize;
import android.content.Intent;
import android.os.Handler;
@ -115,7 +115,7 @@ public abstract class TelemetryTask implements Runnable {
// be dependent on what is connected (e.g. board and
// version number).
objMngr = new UAVObjectManager();
UAVObjectsInitialize.register(objMngr);
TelemObjectsInitialize.register(objMngr);
// Register to get an update from FirmwareIAP in order to register
// the appropriate objects

View File

@ -70,7 +70,6 @@ public class UAVObjectManager {
*/
public synchronized boolean registerObject(UAVDataObject obj) throws Exception
{
// QMutexLocker locker(mutex);
ListIterator<List<UAVObject>> objIt = objects.listIterator(0);

View File

@ -30,7 +30,7 @@ package org.openpilot.uavtalk.uavobjects;
import org.openpilot.uavtalk.UAVObjectManager;
public class UAVObjectsInitialize {
public class TelemObjectsInitialize {
public static void register(UAVObjectManager objMngr) {
try {