2 * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
\r
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.
19 #include "profile_common.h"
\r
20 #include "launcher_env.h"
\r
22 #include <sys/types.h>
\r
24 #include <tzplatform_config.h>
\r
26 static std::vector<uid_t> getUserIds()
\r
28 std::vector<uid_t> list;
31 errno = 0; // so we can distinguish errors from no more entries
32 passwd* entry = getpwent();
35 _SERR("Error while getting userIDs");
41 list.push_back(entry->pw_uid);
48 static std::string getAppDataPath(const std::string& pkgId, uid_t uid)
50 std::string pDataFile;
52 tzplatform_set_user(uid);
54 const char* tzUserApp = tzplatform_getenv(TZ_USER_APP);
55 if (tzUserApp != NULL) {
56 pDataFile = std::string(tzUserApp) + "/" + pkgId + "/data/";
59 tzplatform_reset_user();
64 profile_error_e removeAppProfileData(const std::string& pkgId)
\r
67 return PROFILE_ERROR_INVALID_PARAMETER;
\r
70 std::vector<uid_t> uidList = getUserIds();
71 for (auto& uid : uidList) {
72 // get data path from pkgid
73 std::string dataPath = getAppDataPath(pkgId, uid);
74 if (!dataPath.empty() && exist(dataPath)) {
75 std::string pDataFile = dataPath + PROFILE_BASENAME;
77 if (exist(pDataFile)) {
78 if (!removeFile(pDataFile)) {
79 _SERR("Failed to remove profile data file (%s).", pDataFile.c_str());
\r
80 return PROFILE_ERROR_UNKNOWN;
\r
82 _SOUT("Profile data (%s) is removed successfully", pDataFile.c_str());
87 return PROFILE_ERROR_NONE;
\r
90 static int removeAppProfileListCb(pkgmgrinfo_appinfo_h handle, void *user_data)
\r
93 int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
94 if (ret != PMINFO_R_OK || pkgId == NULL) {
95 _SERR("Failed to get package id");
\r
99 if (removeAppProfileData(pkgId) != PROFILE_ERROR_NONE) {
\r
100 _SERR("Failed to remove profile data for (%s)", pkgId);
\r
106 static void removeAppProfileByAppType(const char* type)
\r
108 pkgmgrinfo_appinfo_filter_h filter;
\r
110 int ret = pkgmgrinfo_appinfo_filter_create(&filter);
\r
111 if (ret != PMINFO_R_OK) {
112 _SERR("Failed to create appinfo filter");
\r
116 ret = pkgmgrinfo_appinfo_filter_add_string(filter, PMINFO_APPINFO_PROP_APP_TYPE, type);
117 if (ret != PMINFO_R_OK) {
118 pkgmgrinfo_appinfo_filter_destroy(filter);
119 _SERR("Failed to add appinfo filter (%s)", type);
\r
123 ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(filter, removeAppProfileListCb, NULL);
\r
124 if (ret != PMINFO_R_OK) {
125 _SERR("Failed to pkgmgrinfo_pkginfo_filter_foreach_pkginfo");
\r
126 pkgmgrinfo_appinfo_filter_destroy(filter);
130 pkgmgrinfo_appinfo_filter_destroy(filter);
135 void removeAllAppProfileData()
137 std::vector<const char*> appTypeList = {"dotnet", "dotnet-nui", "dotnet-inhouse"};
139 for (auto& type : appTypeList) {
140 removeAppProfileByAppType(type);
\r