Register application info when ping delivered 72/303572/3
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 2 Jan 2024 08:08:52 +0000 (17:08 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 2 Jan 2024 10:01:06 +0000 (19:01 +0900)
If the application is executed using fast launch option of the
app_launcher tool, there is a timing issue.
When the app process is slow to enter the main function, amd does not
know the process existence. To prevent the timing issue, launchpad sends
the launches process list to amd when ping request is received.

Change-Id: If7dea099493e0442b2a09137467238682c63d66e
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/launchpad-process-pool/launchpad.cc
src/launchpad-process-pool/launchpad.hh
src/lib/launchpad-common/types.hh
src/lib/launchpad-glib/app_info.cc
src/lib/launchpad-glib/app_info.hh
src/lib/launchpad-glib/util.cc
src/lib/launchpad-glib/util.hh

index c12f04a4631f80464dca6e6203151fdf46c02de3..8b822677944f584f55d4ef9733cc4c6471dada87 100644 (file)
@@ -364,6 +364,19 @@ void Launchpad::HandleDemandRequest(std::shared_ptr<Request> request) {
 
 void Launchpad::HandlePingRequest(std::shared_ptr<Request> request) {
   request->SendResult(getpid());
+  ping_received_ = true;
+  for (auto& iter : fast_launches_) {
+    pid_t pid = iter.first;
+    auto& appid = iter.second;
+    tizen_base::Bundle b = {
+      { kAulAppId, appid },
+      { kAulPid, std::to_string(pid) }
+    };
+
+    Util::SendCmdToAmd(AmdCmd::AppRegisterPid, b.GetHandle(),
+        static_cast<int>(AmdSocketOption::NoReply | AmdSocketOption::Bundle));
+  }
+  fast_launches_.clear();
   _W("[PAD_CMD_PING]");
 }
 
@@ -559,6 +572,20 @@ void Launchpad::LaunchRequestComplete(std::shared_ptr<Request> request) {
     pid_map_[request->GetPid()] = app_info->GetAppId();
     launchpad::Log::Print("[LAUNCH]", "pid(%7d) | appid(%s)",
         request->GetPid(), app_info->GetAppId().c_str());
+    if (app_info->IsFastLaunch()) {
+      if (ping_received_) {
+        tizen_base::Bundle b = {
+          { kAulAppId, app_info->GetAppId() },
+          { kAulPid, std::to_string(request->GetPid()) }
+        };
+
+        Util::SendCmdToAmd(AmdCmd::AppRegisterPid, b.GetHandle(),
+            static_cast<int>(
+              AmdSocketOption::NoReply | AmdSocketOption::Bundle));
+      } else {
+        fast_launches_[request->GetPid()] = app_info->GetAppId();
+      }
+    }
   }
 }
 
@@ -662,6 +689,7 @@ void Launchpad::OnIOEventReceived(int fd, int condition) {
 }
 
 void Launchpad::OnSigchldReceived(pid_t pid) {
+  fast_launches_.erase(pid);
   auto found = pid_map_.find(pid);
   if (found != pid_map_.end()) {
     auto appid = found->second;
index 4e6cb016662a9b5d2dc9138603c6aeed0d1cb307..40d20aec2deaffd9fb10c897b37b66a98a6b71e8 100644 (file)
@@ -107,6 +107,8 @@ class Launchpad : public IOChannel::IEvent,
   std::unique_ptr<Worker> cleaner_;
   std::vector<std::shared_ptr<Request>> pending_requests_;
   Config::LaunchMode::Mode mode_;
+  bool ping_received_ = false;
+  std::unordered_map<pid_t, std::string> fast_launches_;
 };
 
 }  // namespace launchpad
index 5b7eada4b6d98bba3b20dbb3445dd5ae78380e03..c65e1cc826899da0d10b04766ec1427824490570 100644 (file)
@@ -69,11 +69,20 @@ enum PadLoaderId {
 };
 
 enum AmdCmd {
+  AppRegisterPid = 57,
   LaunchpadDeadSignal = 61,
   LaunchpadLaunchSignal = 83,
   AppStartupSignal = 89,
 };
 
+enum class AmdSocketOption : int {
+  None = 0x0,
+  NoReply = 0x1,
+  Async = 0x2,
+  Queue = 0x4,
+  Bundle = 0x8
+};
+
 }  // namespace launchpad
 
 #endif  // LIB_LAUNCHPAD_COMMON_TYPES_HH_
index c286f6b0fd34d0bfd1dd300fbbc140f42bb4922e..7e95f694fb17ad1dee3de58c7b478353c5cfaea4 100644 (file)
@@ -86,6 +86,15 @@ AppInfo::Builder& AppInfo::Builder::SetLoaderName(const tizen_base::Bundle& b) {
   return *this;
 }
 
+AppInfo::Builder& AppInfo::Builder::SetFastLaunch(const tizen_base::Bundle& b) {
+  if (b.GetString(kAulFastLaunch) == "true")
+    fast_launch_ = true;
+  else
+    fast_launch_ = false;
+
+  return *this;
+}
+
 AppInfo::Builder& AppInfo::Builder::SetGlobal(const tizen_base::Bundle& b) {
   if (b.GetString(kAulIsGlobal) == "true")
     global_ = true;
@@ -105,7 +114,7 @@ AppInfo::Builder::operator AppInfo*() {
       std::move(original_app_path_), std::move(pkg_type_), std::move(app_type_),
       std::move(hwacc_), std::move(taskmanage_), std::move(pkg_id_),
       std::move(comp_type_), std::move(internal_pool_), std::move(root_path_),
-      std::move(loader_name_), global_, std::move(b_));
+      std::move(loader_name_), fast_launch_, global_, std::move(b_));
 }
 
 AppInfo* AppInfo::Create(tizen_base::Bundle b) {
@@ -121,6 +130,7 @@ AppInfo* AppInfo::Create(tizen_base::Bundle b) {
       .SetInternalPool(b)
       .SetRootPath(b)
       .SetLoaderName(b)
+      .SetFastLaunch(b)
       .SetGlobal(b)
       .SetBundle(std::move(b));
 }
@@ -173,6 +183,10 @@ const std::string& AppInfo::GetLoaderName() const {
   return loader_name_;
 }
 
+const bool AppInfo::IsFastLaunch() const {
+  return fast_launch_;
+}
+
 const bool AppInfo::IsGlobal() const {
   return global_;
 }
@@ -194,6 +208,7 @@ void AppInfo::WriteToParcel(tizen_base::Parcel* parcel) const {
   parcel->WriteString(internal_pool_);
   parcel->WriteString(root_path_);
   parcel->WriteString(loader_name_);
+  parcel->WriteBool(fast_launch_);
   parcel->WriteBool(global_);
 
   bundle_raw* b_raw = nullptr;
@@ -217,6 +232,7 @@ void AppInfo::ReadFromParcel(tizen_base::Parcel* parcel) {
   internal_pool_ = parcel->ReadString();
   root_path_ = parcel->ReadString();
   loader_name_ = parcel->ReadString();
+  parcel->ReadBool(&fast_launch_);
   parcel->ReadBool(&global_);
 
   auto raw = parcel->ReadString();
@@ -228,7 +244,8 @@ AppInfo::AppInfo(std::string app_id, std::string app_path,
     std::string original_app_path, std::string pkg_type, std::string app_type,
     std::string hwacc, std::string taskmanage, std::string pkg_id,
     std::string comp_type, std::string internal_pool, std::string root_path,
-    std::string loader_name, bool global, tizen_base::Bundle b)
+    std::string loader_name, bool fast_launch, bool global,
+    tizen_base::Bundle b)
     : app_id_(std::move(app_id)),
       app_path_(std::move(app_path)),
       original_app_path_(std::move(original_app_path)),
@@ -241,6 +258,7 @@ AppInfo::AppInfo(std::string app_id, std::string app_path,
       internal_pool_(std::move(internal_pool)),
       root_path_(std::move(root_path)),
       loader_name_(std::move(loader_name)),
+      fast_launch_(fast_launch),
       global_(global),
       b_(std::move(b)) {}
 
index a76a8628c53e1a513d96aeccc84a833d344be828..bfafe73a559402dc58377e3a2640bf8b75f2d870 100644 (file)
@@ -46,6 +46,7 @@ class EXPORT_API AppInfo : public tizen_base::Parcelable {
     Builder& SetInternalPool(const tizen_base::Bundle& b);
     Builder& SetRootPath(const tizen_base::Bundle& b);
     Builder& SetLoaderName(const tizen_base::Bundle& b);
+    Builder& SetFastLaunch(const tizen_base::Bundle& b);
     Builder& SetGlobal(const tizen_base::Bundle& b);
     Builder& SetBundle(tizen_base::Bundle b);
     operator AppInfo*();
@@ -63,7 +64,8 @@ class EXPORT_API AppInfo : public tizen_base::Parcelable {
     std::string internal_pool_;
     std::string root_path_;
     std::string loader_name_;
-    bool global_;
+    bool fast_launch_ = false;
+    bool global_ = true;
     tizen_base::Bundle b_;
   };
 
@@ -84,6 +86,7 @@ class EXPORT_API AppInfo : public tizen_base::Parcelable {
   const std::string& GetInternalPool() const;
   const std::string& GetRootPath() const;
   const std::string& GetLoaderName() const;
+  const bool IsFastLaunch() const;
   const bool IsGlobal() const;
   const tizen_base::Bundle& GetBundle() const;
 
@@ -95,7 +98,8 @@ class EXPORT_API AppInfo : public tizen_base::Parcelable {
       std::string original_app_path, std::string pkg_type, std::string app_type,
       std::string hwacc, std::string taskmanage, std::string pkg_id,
       std::string comp_type, std::string internal_pool, std::string root_path,
-      std::string loader_name, bool global, tizen_base::Bundle b);
+      std::string loader_name, bool fast_launch, bool global,
+      tizen_base::Bundle b);
 
  private:
   std::string app_id_;
@@ -110,6 +114,7 @@ class EXPORT_API AppInfo : public tizen_base::Parcelable {
   std::string internal_pool_;
   std::string root_path_;
   std::string loader_name_;
+  bool fast_launch_ = false;
   bool global_ = true;
   tizen_base::Bundle b_;
 };
index 2e793825f74f8b0d52c6f41bcfb593e51df4dcd1..e13ff466eea28956da003514cd4514d1e6a4bac1 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "launchpad-glib/util.hh"
 
+#include <bundle_internal.h>
 #include <dbus/dbus.h>
 #include <stdlib.h>
 #include <sys/mount.h>
@@ -316,12 +317,23 @@ class ExternalPackage : public DBus {
 
 class AmdPacket : public tizen_base::Parcelable {
  public:
-  explicit AmdPacket(int cmd) : cmd_(cmd) {}
+  explicit AmdPacket(int cmd, bundle* request, int opt)
+      : cmd_(cmd), request_(request), opt_(opt) {}
 
   void WriteToParcel(tizen_base::Parcel* parcel) const {
     parcel->WriteInt32(cmd_);
-    parcel->WriteInt32(0);
-    parcel->WriteInt32(0);
+    if (request_ == nullptr) {
+      parcel->WriteInt32(0);
+      parcel->WriteInt32(opt_);
+    } else {
+      bundle_raw* raw = nullptr;
+      int len = 0;
+      bundle_encode(request_, &raw, &len);
+      parcel->WriteInt32(len);
+      parcel->WriteInt32(opt_);
+      parcel->Write(reinterpret_cast<unsigned char*>(raw), len);
+      bundle_free_encoded_rawdata(&raw);
+    }
   }
 
   void ReadFromParcel(tizen_base::Parcel* parcel) {
@@ -329,7 +341,9 @@ class AmdPacket : public tizen_base::Parcelable {
   }
 
  private:
-  int cmd_;
+  int cmd_ = -1;
+  bundle* request_ = nullptr;
+  int opt_ = 0;
 };
 
 }  // namespace
@@ -548,6 +562,10 @@ int Util::PrepareAppIdFile(const AppInfo* app_info) {
 }
 
 int Util::SendCmdToAmd(enum AmdCmd cmd) {
+  return SendCmdToAmd(cmd, nullptr, static_cast<int>(AmdSocketOption::None));
+}
+
+int Util::SendCmdToAmd(enum AmdCmd cmd, bundle* request, int opt) {
   try {
     std::string endpoint = "/run/aul/daemons/.amd-sock";
     ClientSocket socket;
@@ -555,7 +573,7 @@ int Util::SendCmdToAmd(enum AmdCmd cmd) {
     socket.SetReceiveBufferSize(Socket::kSocketMaxBufferSize);
     socket.SetReceiveTimeout(5000);
 
-    AmdPacket packet(static_cast<int>(cmd));
+    AmdPacket packet(static_cast<int>(cmd), request, opt);
     tizen_base::Parcel parcel;
     parcel.WriteParcelable(packet);
 
index 013581cf994b3596a98bab644625c5c233484bfe..07713ac7c4f8478be63c9536d4c2f2ca02539369 100644 (file)
@@ -17,6 +17,7 @@
 #ifndef LIB_LAUNCHPAD_GLIB_UTIL_HH_
 #define LIB_LAUNCHPAD_GLIB_UTIL_HH_
 
+#include <bundle.h>
 #include <sys/types.h>
 #include <tzplatform_config.h>
 
@@ -46,6 +47,7 @@ class EXPORT_API Util {
   static int PrepareAppSocket();
   static int PrepareAppIdFile(const AppInfo* app_info);
   static int SendCmdToAmd(enum AmdCmd cmd);
+  static int SendCmdToAmd(enum AmdCmd cmd, bundle* request, int opt);
 };
 
 }  // namespace launchpad