Fix update request bug 67/192067/1
authorjusung son <jusung07.son@samsung.com>
Tue, 30 Oct 2018 01:12:45 +0000 (10:12 +0900)
committerjusung son <jusung07.son@samsung.com>
Tue, 30 Oct 2018 01:12:45 +0000 (10:12 +0900)
 - A provider cannot listen to update request signal
   until OnAppear callback is invoked

Change-Id: Id9dcaab063314ad16e7f5bd05158a761e97ce541
Signed-off-by: jusung son <jusung07.son@samsung.com>
watchface-complication/complication-implementation.h
watchface-complication/complication.cc
watchface-complication/complication.h

index 89e38b12a67eba4e814e0acf740a48f3fa2cbb25..16f755f4fefabf78aff44585af0d774a8cb850cf 100644 (file)
@@ -110,6 +110,7 @@ class Complication::Impl : IGDBus::IGDBusEvent, IPackageManager::IPackageEvent {
   int last_data_idx_ = -1;
   std::string name_;
   int subscribe_id_ = -1;
+  int watcher_id_ = -1;
   static const std::string provider_id_key_;
   static const std::string provider_type_key_;
   static const std::string supported_events_error_key_;
@@ -117,7 +118,6 @@ class Complication::Impl : IGDBus::IGDBusEvent, IPackageManager::IPackageEvent {
   static std::list<int> complication_id_list_;
   IEditable::EditableState ed_state_ = Complete;
   guint periodic_timer_ = 0;
-  std::map<std::string, int> sender_info_;
   std::unique_ptr<IGDBus> gdbus_ = nullptr;
   std::unique_ptr<IPackageManager> package_ = nullptr;
   bool mock_ = false;
index 6e6b039c7fa29addfa5d0e408a4af7258676ce77..5adcb1961b6348a3c19bfed60c55ee61641e995e 100644 (file)
@@ -166,43 +166,33 @@ Complication::Impl::~Impl() {
 }
 
 void Complication::Impl::OnVanish(const std::string& name) {
-  auto sender_info = sender_info_.find(name);
-  auto si = sender_info->second;
-
-  if (sender_info == sender_info_.end())
-    return;
-
-  gdbus_.get()->UnWatch(si);
-  sender_info_.erase(name);
+  LOGI("OnVanish %s", name.c_str());
 }
 
 void Complication::Impl::OnAppear(const std::string& name,
     const std::string& name_owner) {
+  LOGI("OnAppear %s  ", name.c_str());
+  parent_->SendDataUpdateRequest(false);
 }
 
 bool Complication::Impl::IsValidSender(GDBusConnection* connection,
                                   const std::string& sender_name) {
+  static std::string prev_sender_name;
+  if (prev_sender_name.compare(sender_name) == 0)
+    return true;
+
   std::string sender_appid = util::GetSenderAppid(connection, sender_name);
   if (sender_appid.empty()) {
     LOGI("invalid sender_appid");
     return false;
   }
 
-  std::string provider_appid =
-      DBManager::GetProviderAppId(cur_provider_id_.c_str());
-  if (provider_appid.empty()) {
-    LOGI("invalid provider_appid");
-    return false;
-  }
-
-  if (provider_appid.compare(sender_appid) != 0) {
+  if (cur_provider_appid_.compare(sender_appid) != 0) {
     LOGI("invalid sender_appid %s", sender_appid.c_str());
     return false;
   }
 
-  int watcher_id = gdbus_.get()->Watch(sender_appid, this);
-  sender_info_[sender_name] = watcher_id;
-
+  prev_sender_name = sender_name;
   return true;
 }
 
@@ -253,9 +243,7 @@ void Complication::Impl::OnSignal(GDBusConnection* connection,
                                   GVariant* parameters) {
   LOGI("signal_name: %s , %s ", signal_name.c_str(), sender_name.c_str());
 
-  auto sender_info = sender_info_.find(sender_name);
-  if (sender_info == sender_info_.end() &&
-      !IsValidSender(connection, sender_name))
+  if (IsValidSender(connection, sender_name) == false)
     return;
 
   if (signal_name.compare(util::GetCmdStr(util::CompUpdated)) == 0) {
@@ -451,7 +439,15 @@ int Complication::Impl::UpdateProviderInfo() {
   if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
     return ret;
 
-  gdbus_.get()->UnSubscribeSignal(subscribe_id_);
+  if (watcher_id_ > 0)
+    gdbus_.get()->UnWatch(watcher_id_);
+  if (cur_type_ == NoData)
+    watcher_id_ = 0;
+  else
+    watcher_id_ = gdbus_.get()->Watch(cur_provider_appid_, this);
+
+  if (subscribe_id_ > 0)
+    gdbus_.get()->UnSubscribeSignal(subscribe_id_);
   if (cur_type_ == NoData) {
     subscribe_id_ = 0;
   } else {
@@ -695,7 +691,7 @@ int Complication::Impl::CheckNotSupported(std::string provider_id) {
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
 
-int Complication::SendDataUpdateRequest() {
+int Complication::SendDataUpdateRequest(bool launch_option) {
   LOGI("emit signal comp_id %d, type %d",
       impl_->complication_id_, impl_->cur_type_);
 
@@ -724,18 +720,20 @@ int Complication::SendDataUpdateRequest() {
     return WATCHFACE_COMPLICATION_ERROR_NONE;
   }
 
-  ret = aul_complication_update_request(
-            util::GetAppId().c_str(),
-            provider_appid.c_str(), getuid());
-  LOGI("Launch the provider app: %d, %s", ret, provider_appid.c_str());
-
-  if (ret != AUL_R_OK) {
-    if (ret == AUL_R_EILLACC)
-      return WATCHFACE_COMPLICATION_ERROR_PERMISSION_DENIED;
-    else if (ret == AUL_R_EINVAL)
-      return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
-    else
-      return WATCHFACE_COMPLICATION_ERROR_IO_ERROR;
+  if (launch_option) {
+    ret = aul_complication_update_request(
+              util::GetAppId().c_str(),
+              provider_appid.c_str(), getuid());
+    LOGI("Launch the provider app: %d, %s", ret, provider_appid.c_str());
+
+    if (ret != AUL_R_OK) {
+      if (ret == AUL_R_EILLACC)
+        return WATCHFACE_COMPLICATION_ERROR_PERMISSION_DENIED;
+      else if (ret == AUL_R_EINVAL)
+        return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+      else
+        return WATCHFACE_COMPLICATION_ERROR_IO_ERROR;
+    }
   }
 
   if (impl_->context_data_ != nullptr)
index baa8c47ec41202d8f222f0afba7040bbd3506f21..117e7bcf4c3e16dc990c7bf31c0d3401435aeccc 100644 (file)
@@ -87,7 +87,7 @@ class EXPORT_API Complication : public IEditable
   std::unique_ptr<Bundle>& GetLastContext() const override;
   const std::string GetSetupAppId() override;
 
-  int SendDataUpdateRequest();
+  int SendDataUpdateRequest(bool launch_option = true);
   const char* GetCurProviderId();
   const char* GetProviderId(const Bundle* candidate_data);
   int GetProviderType(const Bundle* candidate_data);