import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
+import java.util.Hashtable;
+
// TODO null check for parameters
/**
* This class provides APIs for managing the container and bundles in the
public RcsResourceContainer(Context appContext){
this.appContext = appContext;
}
+
+ private Hashtable<String, BundleActivator> activators = new Hashtable<String, BundleActivator>();
/**
* API for starting the Container
Log.d(TAG, "Loading activator: " + className);
Class activatorClass = df.loadClass(className, cl);
if(activatorClass!= null){
- BundleActivator activator = (BundleActivator) activatorClass.getConstructor(RcsResourceContainerBundleAPI.class, Context.class).newInstance(this, appContext);
+ BundleActivator activator = (BundleActivator) activatorClass.
+ getConstructor(RcsResourceContainerBundleAPI.class, Context.class).
+ newInstance(this, appContext);
activator.activateBundle();
+ activators.put(bundleInfo.getID(), activator);
}else{
Log.e(TAG, "Activator is null.");
}
* API for stopping the Container
*/
public void stopContainer() {
+ // stop all android bundles
+ for(BundleActivator activator :activators.values()){
+ activator.deactivateBundle();
+ }
nativeStopContainer();
}
*
*/
public void removeBundle(String bundleId) {
+ if(activators.contains(bundleId)){
+ // deactivate android bundle
+ activators.get(bundleId).deactivateBundle();
+ }
nativeRemoveBundle(bundleId);
}
public void startBundle(String bundleId) {
Log.d(TAG, "startBundle");
List<RcsBundleInfo> bundles = listBundles();
- boolean androidBundle =false;
- for(RcsBundleInfo bundleInfo : bundles){
+
+ for(RcsBundleInfo bundleInfo : bundles){
if(bundleInfo.getID().equals(bundleId) && bundleInfo.getLibraryPath().endsWith(".apk")){
- androidBundle = true;
Log.d(TAG, "Have to start android bundle");
+ Log.d(TAG, "bundle-id: " + bundleInfo.getID() + ", " + bundleInfo.getPath());
+ if(bundleInfo.getPath().endsWith(".apk")){
+ String packageName = bundleInfo.getPath().replace(".apk", "");
+ try{
+ PackageManager packageManager = appContext.getPackageManager();
+ ApplicationInfo appInfo = packageManager.getApplicationInfo(packageName, 0);
+ DexFile df = new DexFile(appInfo.sourceDir);
+ ClassLoader cl = appContext.getClassLoader();
+ for (Enumeration<String> iter = df.entries(); iter.hasMoreElements(); ) {
+ String classN = iter.nextElement();
+ if (classN.contains(packageName)) {
+ Log.d(TAG,"Class: " + classN);
+ df.loadClass(classN, cl);
+ }
+ }
+
+ String className = bundleInfo.getActivatorName();
+ Log.d(TAG, "Loading activator: " + className);
+ Class activatorClass = df.loadClass(className, cl);
+ if(activatorClass!= null){
+ BundleActivator activator = (BundleActivator) activatorClass.
+ getConstructor(RcsResourceContainerBundleAPI.class,
+ Context.class).
+ newInstance(this, appContext);
+ activator.activateBundle();
+ }else{
+ Log.e(TAG, "Activator is null.");
+ }
+ }
+ catch(Exception e){
+ Log.e(TAG, e.getMessage(), e);
+ }
+ Log.d(TAG, "Have to register android bundle");
+ }
+ }else{
+ nativeStartBundle(bundleId);
}
}
- if(!androidBundle){
- nativeStartBundle(bundleId);
- }
+
}
/**
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "RemoteResourceUnit.h"
+#include "InternalTypes.h"
+
+#include <exception>
using namespace OIC::Service;
{
if(remoteObject->isCaching())
{
- remoteObject->stopCaching();
+ try{
+ remoteObject->stopCaching();
+ }
+ catch(std::exception &e){
+ OC_LOG_V(ERROR, CONTAINER_TAG, "%s", e.what());
+ }
}
if(remoteObject->isMonitoring())
{
- remoteObject->stopMonitoring();
+ try{
+ remoteObject->stopMonitoring();
+ }
+ catch(std::exception &e){
+ OC_LOG_V(ERROR, CONTAINER_TAG, "%s", e.what());
+ }
}
}
}
if (m_config->isHasInput(resource->m_bundleId))
{
+ OC_LOG_V(INFO, CONTAINER_TAG, "Calling undiscover (%s)",
+ std::string(resource->m_uri + ", " +
+ resource->m_resourceType).c_str());
undiscoverInputResource(strUri);
}
if (m_mapServers.find(strUri) != m_mapServers.end())
{
+ OC_LOG_V(INFO, CONTAINER_TAG, "Resetting server (%s)",
+ std::string(resource->m_uri + ", " +
+ resource->m_resourceType).c_str());
m_mapServers[strUri].reset();
m_mapResources.erase(m_mapResources.find(strUri));
+
+ OC_LOG_V(INFO, CONTAINER_TAG, "Remove bundle resource (%s)",
+ std::string(resource->m_uri + ", " +
+ resource->m_resourceType).c_str());
m_mapBundleResources[resource->m_bundleId].remove(strUri);
}
}
auto foundDiscoverResource = m_mapDiscoverResourceUnits.find(outputResourceUri);
if (foundDiscoverResource != m_mapDiscoverResourceUnits.end())
{
+ OC_LOG(DEBUG, CONTAINER_TAG, "Erase discover resource.");
m_mapDiscoverResourceUnits.erase(foundDiscoverResource);
+ OC_LOG(DEBUG, CONTAINER_TAG, "Erase discover resource done.");
}
}