#include <unistd.h>
#include <string>
#include <cstring>
+#include <app.h>
#include <aul.h>
#include <Ecore_X.h>
#include <provider.h>
#define MASTER_PROVIDER_PING_TIME 120.0f
+// These are string for handling application service from app
+static const std::string BOX_SERVICE_SCHEME("box-service://");
+static const std::string OPERATION_UPDATE_BOX(
+ "http://tizen.org/appcontrol/operation/dynamicbox/web/update");
+static const std::string CONTENT_INFO_KEY("content-info");
+
BoxDaemonImpl::BoxDaemonImpl()
: m_pluginConnector(BoxPluginConnector::create())
{
return true;
}
+bool BoxDaemonImpl::handleAppService(service_h service)
+{
+ LogD("enter");
+ int ret;
+ bool result = false;
+ Ecore_Job* jobResult = NULL;
+ char* operation;
+
+ ret = service_get_operation(service, &operation);
+ if (ret != SERVICE_ERROR_NONE) {
+ LogD("no operation");
+ return false;
+ }
+
+ if (OPERATION_UPDATE_BOX == operation) {
+ BoxInfoPtr info = handleOperationUpdate(service);
+ if (info) {
+ JobInfo* jobInfo = new JobInfo(REQUEST_CMD_UPDATE_BOX, info, this);
+ jobResult = ecore_job_add(requestBoxJobCallback, jobInfo);
+ if (jobResult) {
+ result = true;
+ }
+ }
+ } else {
+ LogD("unknown operation: %s", operation);
+ }
+
+ delete[] operation;
+ return result;
+}
+
int BoxDaemonImpl::connectedCallback(ProviderEventArgPtr arg, void* data)
{
LogD("enter");
if (arg->info.pd_create.w == 0 || arg->info.pd_create.h == 0) {
return -1;
}
-
- info->pdWidth = arg->info.pd_create.w;
+ //Use the screen width to fix the device width
+ ecore_x_window_size_get(0, &info->pdWidth, NULL);
info->pdHeight = arg->info.pd_create.h;
info->pdX = arg->info.pd_create.x;
info->pdY = arg->info.pd_create.y;
if (!type) {
return BoxInfoPtr();
}
-
BoxInfoPtr infoPtr = BoxInfoPtr(new BoxInfo(type, arg->pkgname, arg->id));
delete[] type;
return infoPtr;
}
+std::string BoxDaemonImpl::getBoxIdFromService(service_h service)
+{
+ LogD("enter");
+
+ int ret;
+ char* serviceUri = NULL;
+ ret = service_get_uri(service, &serviceUri);
+ if (ret != SERVICE_ERROR_NONE) {
+ LogD("no box uri");
+ return std::string();
+ }
+
+ std::string uri(serviceUri);
+ delete[] serviceUri;
+
+ if(uri.compare(0, BOX_SERVICE_SCHEME.size(), BOX_SERVICE_SCHEME)) {
+ // uri is not box-service scheme
+ return std::string();
+ }
+
+ std::string boxId = uri.substr(BOX_SERVICE_SCHEME.size());
+ return boxId;
+}
+
+bool BoxDaemonImpl::isServiceCallerBoxOwner(service_h service)
+{
+ LogD("enter");
+
+ int ret;
+
+ std::string boxId = getBoxIdFromService(service);
+ if (boxId.empty()) {
+ LogD("error box-id");
+ return false;
+ }
+
+ // check if caller is owner of this box
+ const char* appId = web_provider_livebox_get_app_id(boxId.c_str());
+ if (!appId) {
+ return false;
+ }
+ std::string ownerAppId(appId);
+ delete[] appId;
+
+ char* caller = NULL;
+ ret = service_get_caller(service, &caller);
+ if (ret != SERVICE_ERROR_NONE) {
+ return false;
+ }
+ std::string callerAppId(caller);
+
+ // release strings
+ delete[] caller;
+
+ if (ownerAppId != callerAppId) {
+ LogD("caller is not matched with owner of requested box");
+ return false;
+ }
+
+ return true;
+}
+
+BoxInfoPtr BoxDaemonImpl::handleOperationUpdate(service_h service)
+{
+ LogD("enter");
+
+ int ret;
+
+ if (!isServiceCallerBoxOwner(service)) {
+ return BoxInfoPtr();
+ }
+
+ std::string boxId = getBoxIdFromService(service);
+ if (boxId.empty()) {
+ LogD("error box-id");
+ return BoxInfoPtr();
+ }
+
+ char* contentInfo = NULL;
+ service_get_extra_data(service, CONTENT_INFO_KEY.c_str(), &contentInfo);
+
+ std::string type(getBoxType(boxId.c_str()));
+ if (type.empty()) {
+ LogD("no type for this box");
+ delete[] contentInfo;
+ return BoxInfoPtr();
+ }
+ BoxInfoPtr info = BoxInfoPtr(new BoxInfo(type, boxId, ""));
+ if (contentInfo) {
+ info->contentInfo = std::string(contentInfo);
+ }
+
+ // release string
+ delete[] contentInfo;
+
+ return info;
+}
+
Eina_Bool BoxDaemonImpl::pingToMasterCallback(void* data)
{
LogD("enter");