Set indirect request info 22/219122/2
authorJusung Son <jusung07.son@samsung.com>
Mon, 2 Dec 2019 06:48:04 +0000 (15:48 +0900)
committerJusung Son <jusung07.son@samsung.com>
Tue, 3 Dec 2019 00:24:31 +0000 (09:24 +0900)
Requires:
  - https://review.tizen.org/gerrit/#/c/platform/core/api/notification/+/219120/

Change-Id: Ib3d8bee5af78c133e5af67e0c4ae79a457028253
Signed-off-by: Jusung Son <jusung07.son@samsung.com>
src/notification_ex_service.cc

index 5bd97b4ebc569d533efe28a57752dce800869dd2..79199d4b779a69d9f4244c23ffb861fb679f5ef2 100644 (file)
 #include <stdlib.h>
 #include <notification_type.h>
 #include <notification_viewer.h>
+#include <aul.h>
+#include <app_control_internal.h>
+#include <pkgmgr-info.h>
+#include <bundle.h>
+#include <bundle_internal.h>
 
 #include <iostream>
 #include <sstream>
 #include <notification-ex/ievent_info_internal.h>
 #include <notification-ex/iitem_info_internal.h>
 #include <notification-ex/shared_file.h>
+#include <notification-ex/group_item.h>
+#include <notification-ex/app_control_action.h>
 
 #include "debug.h"
 #include "notification_ex_service.h"
 
+#define NORMAL_UID_BASE 5000
+
 using namespace std;
 using namespace notification;
 using namespace notification::item;
@@ -319,6 +328,8 @@ class DPMManager : public Manager {
     DBG("Add !!!");
     int ret;
 
+    SetIndirectRequest(info, addedItem);
+
     ret = DBManager::InsertNotification(addedItem);
     if (ret == ERROR_NONE) {
       facade_->shared_file_.SetPrivateSharing(addedItem,
@@ -337,6 +348,7 @@ class DPMManager : public Manager {
     int ret;
 
     UpdateHideApp(updatedItem);
+    SetIndirectRequest(info, updatedItem);
 
     ret = DBManager::UpdateNotification(updatedItem);
     if (ret == ERROR_NONE) {
@@ -395,6 +407,63 @@ class DPMManager : public Manager {
     }
   }
 
+  void SetIndirectRequest(const IEventInfo& info,
+          list<shared_ptr<AbstractItem>> addedItem) {
+    for (auto& i : addedItem)
+      SetIndirectRequest(info, i);
+  }
+
+  void SetIndirectRequest(const IEventInfo& info,
+          shared_ptr<AbstractItem> addedItem) {
+    SetIndirectRequest(info, addedItem->GetAction());
+
+    if (addedItem->GetType() != AbstractItem::Type::Group)
+      return;
+
+    auto item_group = static_pointer_cast<GroupItem>(addedItem);
+    auto children_list = item_group->GetChildren();
+    for (auto& i : children_list)
+      SetIndirectRequest(info, i);
+  }
+
+  void SetIndirectRequest(const IEventInfo& info, shared_ptr<AbstractAction>action) {
+    if (action == nullptr || action->GetType() != AbstractAction::Type::AppControl)
+      return;
+
+    uid_t uid = static_cast<const IEventInfoInternal&>(info).GetValidatedUid();
+    if (uid < NORMAL_UID_BASE)
+      return;
+
+    string owner = static_cast<const IEventInfoInternal&>(info).GetValidatedOwner();
+    app_control_h appcontrol = static_pointer_cast<AppControlAction>(action)->GetAppControl();
+    bundle* b = nullptr;
+    app_control_export_as_bundle(appcontrol, &b);
+
+    bundle_del(b, AUL_K_REQUEST_TYPE);
+    bundle_add(b, AUL_K_REQUEST_TYPE, "indirect-request");
+
+    bundle_del(b, AUL_K_ORG_CALLER_UID);
+    bundle_add(b, AUL_K_ORG_CALLER_UID, std::to_string(uid).c_str());
+
+    bundle_del(b, AUL_K_ORG_CALLER_APPID);
+    bundle_add(b, AUL_K_ORG_CALLER_APPID, owner.c_str());
+
+    pkgmgrinfo_appinfo_h handle;
+    int r = pkgmgrinfo_appinfo_get_usr_appinfo(owner.c_str(), uid, &handle);
+    if (r == PMINFO_R_OK) {
+      char* pkgid = nullptr;
+      pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
+      if (pkgid) {
+        bundle_del(b, AUL_K_ORG_CALLER_PKGID);
+        bundle_add(b, AUL_K_ORG_CALLER_PKGID, pkgid);
+      }
+      pkgmgrinfo_appinfo_destroy_appinfo(handle);
+    }
+
+    app_control_import_from_bundle(appcontrol, b);
+    bundle_free(b);
+  }
+
  public:
   DPMManager(std::unique_ptr<IEventSender> sender,
       std::unique_ptr<IEventListener> listener)