2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "app-core-ui-cpp/window_position_private.hh"
20 #include <bundle_cpp.h>
27 #include "common/log_private.hh"
32 constexpr const char PATH_AUL[] = "/run/aul/apps/";
33 constexpr uid_t REGULAR_UID_MIN = 5000;
35 std::string WindowPositionToRaw(
36 const std::unique_ptr<WindowPosition>& win_pos) {
37 tizen_base::Bundle b {
38 { AUL_K_HINT_SCREEN_POS_X, std::to_string(win_pos->GetPositionX()) },
39 { AUL_K_HINT_SCREEN_POS_Y, std::to_string(win_pos->GetPositionY()) },
40 { AUL_K_HINT_SCREEN_WIDTH, std::to_string(win_pos->GetScreenWidth()) },
41 { AUL_K_HINT_SCREEN_HEIGHT, std::to_string(win_pos->GetScreenHeight()) },
44 return std::string(reinterpret_cast<char*>(b.ToRaw().first.get()));
47 std::unique_ptr<WindowPosition> WindowPositionFromBundle(
48 const tizen_base::Bundle& b) {
49 auto x_str = b.GetString(AUL_K_HINT_SCREEN_POS_X);
53 auto y_str = b.GetString(AUL_K_HINT_SCREEN_POS_Y);
57 auto w_str = b.GetString(AUL_K_HINT_SCREEN_WIDTH);
61 auto h_str = b.GetString(AUL_K_HINT_SCREEN_HEIGHT);
65 return std::make_unique<WindowPosition>(std::stoi(x_str),
66 std::stoi(y_str), std::stoi(w_str), std::stoi(h_str));
69 std::unique_ptr<WindowPosition> WindowPositionFromRaw(
70 const std::string& raw) {
71 tizen_base::Bundle b(raw);
72 return WindowPositionFromBundle(b);
75 std::string GetAulAppPath() {
76 static std::string path;
78 if (!path.empty() || getuid() < REGULAR_UID_MIN)
81 char appid[256] = { 0, };
82 int ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
83 if (ret != AUL_R_OK) {
84 _E("aul_app_get_appid_bypid() is failed. error(%d)", ret);
88 path = PATH_AUL + std::to_string(getuid()) + "/." + std::string(appid);
94 WindowPosition::WindowPosition(int x, int y, int w, int h)
95 : x_(x), y_(y), w_(w), h_(h) {
98 int WindowPosition::GetPositionX() const {
102 int WindowPosition::GetPositionY() const {
106 int WindowPosition::GetScreenWidth() const {
110 int WindowPosition::GetScreenHeight() const {
114 void WindowPositionManager::WriteToFile(
115 const std::unique_ptr<WindowPosition>& win_pos) {
116 std::string raw = WindowPositionToRaw(win_pos);
117 std::ofstream stream(GetAulAppPath());
122 std::unique_ptr<WindowPosition> WindowPositionManager::ReadFromFile() {
123 std::ifstream stream(GetAulAppPath());
124 if (!stream.good()) {
125 _W("There is no files");
136 return WindowPositionFromRaw(raw);
139 std::unique_ptr<WindowPosition> WindowPositionManager::ReadFromBundle(
140 const tizen_base::Bundle& b) {
141 return WindowPositionFromBundle(b);
144 } // namespace tizen_cpp