void aul_launch_worker_fini(void);
/**
- * @brief Called when the application ID is delivered.
+ * @brief Called when the ID is delivered.
* @since_tizen 8.0
* @param[in] result The result
* @param[in] pid The process ID
- * @param[in] appid The application ID
+ * @param[in] id The ID
* @param[in] user_data The user data passed from the regitration function
* @remarks This function is only for App Framework internally.
* @see aul_app_get_appid_bypid_async()
+ * @see aul_app_get_pkgid_bypid_async()
*/
-typedef void (*aul_appid_cb)(int result, pid_t pid, const char *appid, void *user_data);
+typedef void (*aul_get_id_cb)(int result, pid_t pid, const char *appid, void *user_data);
/**
* @brief Gets the application ID from the process ID.
* @retval #AUL_R_ENOMEM Out of memory
* @retval #AUL_R_ERROR Internal I/O error
* @remarks This function is only for App Framework internally.
- * @see aul_appid_cb()
+ * @see aul_get_id_cb()
*/
-int aul_app_get_appid_bypid_async(pid_t pid, aul_appid_cb callback, void *user_data);
+int aul_app_get_appid_bypid_async(pid_t pid, aul_get_id_cb callback, void *user_data);
/**
* @brief Called when the result is delivered.
*/
int aul_restart_loader_for_uid(const char *loader_name, uid_t uid);
+/**
+ * @brief Gets the package ID from the process ID.
+ * @since_tizen 8.0
+ * @param[in] pid The process ID
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callaback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ENOMEM Out of memory
+ * @retval #AUL_R_ERROR Internal I/O error
+ * @remarks This function is only for App Framework internally.
+ * @see aul_get_id_cb()
+ */
+int aul_app_get_pkgid_bypid_async(pid_t pid, aul_get_id_cb callback, void *user_data);
+
#ifdef __cplusplus
}
#endif
class ResultInfo {
public:
- ResultInfo(pid_t pid, int fd, aul_appid_cb callback, void* user_data)
+ ResultInfo(pid_t pid, int fd, aul_get_id_cb callback, void* user_data)
: pid_(pid), fd_(fd), callback_(callback), user_data_(user_data) {}
ResultInfo(const ResultInfo&) = delete;
return;
}
- char appid[256] = { 0, };
- snprintf(appid, sizeof(appid), "%s", pkt->data);
- SECURE_LOGD("pid: %d, appid: %s", pid_, appid);
- callback_(AUL_R_OK, pid_, appid, user_data_);
+ char buf[256] = { 0, };
+ snprintf(buf, sizeof(buf), "%s", pkt->data);
+ SECURE_LOGD("pid: %d, id: %s", pid_, buf);
+ callback_(AUL_R_OK, pid_, buf, user_data_);
}
void ProcessErrorEvent() {
private:
pid_t pid_;
int fd_;
- aul_appid_cb callback_;
+ aul_get_id_cb callback_;
void* user_data_;
guint source_ = 0;
};
}
extern "C" API int aul_app_get_appid_bypid_async(pid_t pid,
- aul_appid_cb callback, void* user_data) {
+ aul_get_id_cb callback, void* user_data) {
if (pid < 1 || callback == nullptr) {
_E("Invalid parameter");
return AUL_R_EINVAL;
return AUL_R_OK;
}
+
+extern "C" API int aul_app_get_pkgid_bypid_async(pid_t pid,
+ aul_get_id_cb callback, void* user_data) {
+ if (pid < 1 || callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (getpid() == pid || getpgid(getpid()) == pid) {
+ context.Initialize();
+ const auto& preinit_pkgid = context.GetPreInitPkgId();
+ if (!preinit_pkgid.empty()) {
+ callback(AUL_R_OK, pid, preinit_pkgid.c_str(), user_data);
+ return AUL_R_OK;
+ }
+ }
+
+ int fd = AppRequest(APP_GET_PKGID_BYPID, getuid())
+ .SetPid(pid)
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ return AUL_R_ERROR;
+
+ try {
+ auto* result_info = new ResultInfo(pid, fd, callback, user_data);
+ result_info->Watch();
+ } catch (const std::exception& e) {
+ _E("Exception occurs. error: %s", e.what());
+ close(fd);
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppGetPkgIdBypidAsyncTest : public AulTest {
+ public:
+ AulAppGetPkgIdBypidAsyncTest()
+ : AulTest("get_pkgid_bypid_async", "aul_app_get_pkgid_bypid_async",
+ "get_pkgid_bypid_async <pid>", false) {}
+
+ virtual ~AulAppGetPkgIdBypidAsyncTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_app_get_pkgid_bypid_async test] %s", argv[2]);
+ return aul_app_get_pkgid_bypid_async(atoi(argv[2]), AulPkgIdCb, this);
+ }
+
+ private:
+ static void AulPkgIdCb(int result, pid_t pid, const char* pkgid,
+ void* user_data) {
+ _D("Result: %d, pkgid: %s", result, pkgid);
+ }
+};
+
+AUL_TEST_REGISTER(AulAppGetPkgIdBypidAsyncTest, get_pkgid_bypid_async_test);
+
+} // namespace aul_test