#include <atomic>
#include <memory>
+#include <mutex>
#include <string>
+#include <unordered_map>
#include <vector>
#include "aul/app_control/resolve_info.hh"
std::string appid_;
};
+class AppSvcAlias {
+ public:
+ AppSvcAlias() = default;
+
+ void Load() {
+ std::lock_guard<std::mutex> lock(mutex_);
+ if (loaded_)
+ return;
+
+ dictionary* dict = iniparser_load("/usr/share/appsvc/alias.ini");
+ if (dict == nullptr) {
+ loaded_ = true;
+ return;
+ }
+
+ std::string delimiter = "Alias:";
+ for (int i = 0; i < dict->n; ++i) {
+ if (dict->key[i] == nullptr || dict->val[i] == nullptr)
+ continue;
+
+ std::string key = dict->key[i];
+ key.erase(0, key.find(delimiter) + delimiter.length() + 1);
+ std::string value = dict->val[i];
+ map_[key] = value;
+ }
+
+ iniparser_freedict(dict);
+ loaded_ = true;
+ }
+
+ std::string GetAliasAppId(const std::string& alias_appid) {
+ auto found = map_.find(alias_appid);
+ if (found == map_.end())
+ return {};
+
+ SECURE_LOGD("alias_appid: %s, appid: %s",
+ alias_appid.c_str(), found->second.c_str());
+ return found->second;
+ }
+
+ private:
+ bool loaded_ = false;
+ std::unordered_map<std::string, std::string> map_;
+ std::mutex mutex_;
+};
+
+AppSvcAlias appsvc_alias;
+
int SetBundle(bundle* b, const char* key, const char* value) {
if (bundle_get_type(b, key) != BUNDLE_TYPE_NONE) {
if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
}
std::string GetAliasAppId(const char* appid) {
- dictionary* dic = iniparser_load("/usr/share/appsvc/alias.ini");
- if (dic == nullptr)
- return {};
-
- auto dic_ptr = std::unique_ptr<dictionary, decltype(iniparser_freedict)*>(
- dic, iniparser_freedict);
-
- std::string key = std::string("Alias:") + appid;
- const char* value = iniparser_getstring(dic, key.c_str(), nullptr);
- SECURE_LOGD("appid(%s), alias_id(%s)", appid, value);
- if (value == nullptr)
- return {};
-
- return std::string(value);
+ appsvc_alias.Load();
+ return appsvc_alias.GetAliasAppId(appid);
}
bool IsSpecialApp(const char* appid) {