MODES_NAMESPACE_USE;
-const std::string PkgStartSupportMode::NAME = "startSupportMode";
-int PkgStartSupportMode::appModeVal = 0;
+const std::string PkgSupportMode::NAME = "supportMode";
-PkgStartSupportMode::PkgStartSupportMode()
- : PkgAction(NAME)
+PkgSupportMode::PkgSupportMode()
+ : PkgAction(NAME), requestVal(0)
{
}
-int PkgStartSupportMode::app_list_cb(const pkgmgrinfo_appinfo_h handle, void *userData)
-{
- std::list<std::string> *appList = (std::list<std::string>*)userData;
-
- int ret;
- int appSupportMode = 0;
- ret = pkgmgrinfo_appinfo_get_support_mode(handle, &appSupportMode);
- if (PMINFO_R_OK != ret)
- ERR("pkgmgrinfo_appinfo_get_support_mode() Fail");
-
-
- if (appSupportMode != appModeVal) {
- char *appid = NULL;
- ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
- if (PMINFO_R_OK != ret) {
- ERR("pkgmgrinfo_appinfo_get_appid() Fail");
- return 0;
- }
-
- appList->push_back(appid);
- }
- return 0;
-}
-
-int PkgStartSupportMode::set(int val)
+int PkgSupportMode::set(int val)
{
int ret;
pkgmgrinfo_appinfo_filter_h filter;
ret = pkgmgrinfo_appinfo_filter_create(&filter);
- if (ret != PMINFO_R_OK)
- return ret;
+ if (ret != PMINFO_R_OK) {
+ ERR("pkgmgrinfo_appinfo_filter_create() Fail(%d)", ret);
+ return MODES_ERROR_SYSTEM;
+ }
switch (val) {
case ULTRA_POWER_SAVING:
- appModeVal = APP_SUPPORT_MODE_ULTRA_POWER_SAVING_VAL;
- break;
case COOL_DOWN:
- appModeVal = APP_SUPPORT_MODE_COOL_DOWN_VAL;
- break;
case SCREEN_READER:
- appModeVal = APP_SUPPORT_MODE_SCREEN_READER_VAL;
+ requestVal = val;
break;
default:
- ERR("invalid Mode(%d)", val);
+ ERR("Unknown Mode(%d)", val);
return MODES_ERROR_INVALID_PARAMETER;
}
- pkgmgrinfo_appinfo_filter_foreach_appinfo(filter, app_list_cb, &appList);
+ pkgmgrinfo_appinfo_filter_foreach_appinfo(filter, appListCB, this);
pkgmgrinfo_appinfo_filter_destroy(filter);
int nApps = 0;
- const char *appIDs[appList.size()];
- for (auto it = appList.begin(); it != appList.end(); it++, nApps++) {
+ const char *appIDs[inactiveApps.size()];
+ for (auto it = inactiveApps.begin(); it != inactiveApps.end(); it++, nApps++) {
appIDs[nApps] = it->c_str();
- DBG("Deactivate App(%s)", appIDs[nApps]);
+ INFO("Deactivate App(%s)", appIDs[nApps]);
}
pkgmgr_client *pc = pkgmgr_client_new(PC_REQUEST);
int reqId = pkgmgr_client_deactivate_apps(pc, appIDs, nApps, NULL, NULL);
+ if (reqId < 0)
+ ERR("pkgmgr_client_deactivate_apps() Fail(%d)", reqId);
DBG("Request id[%d] count[%d]", reqId, nApps);
pkgmgr_client_free(pc);
return MODES_ERROR_NONE;
}
-int PkgStartSupportMode::get(int *val)
-{
- if (val)
- *val = appModeVal;
-
- return MODES_ERROR_NONE;
-}
-
-
-void PkgStartSupportMode::undo()
+void PkgSupportMode::undo()
{
//If the appList is empty, it will be ignored at subroutines.
-
int nApps = 0;
- const char *appIDs[appList.size()];
- for (auto it = appList.begin(); it != appList.end(); it++, nApps++) {
+ const char *appIDs[inactiveApps.size()];
+ for (auto it = inactiveApps.begin(); it != inactiveApps.end(); it++, nApps++) {
appIDs[nApps] = it->c_str();
- DBG("Activate App(%s)", appIDs[nApps]);
+ INFO("Activate App(%s)", appIDs[nApps]);
}
pkgmgr_client *pc = pkgmgr_client_new(PC_REQUEST);
int reqId = pkgmgr_client_activate_apps(pc, appIDs, nApps, NULL, NULL);
- WARN("Request id[%d] count[%d]", reqId, nApps);
+ if (reqId < 0)
+ ERR("pkgmgr_client_activate_apps() Fail(%d)", reqId);
+ DBG("Request id[%d] count[%d]", reqId, nApps);
pkgmgr_client_free(pc);
//The caller(Plugin undo function) includes destruction of this instance.
- //Therefore, appList will be cleared by the destructor.
+ //Therefore, appList will be automatically cleared by the destructor.
}
-std::string PkgStartSupportMode::serialize()
+std::string PkgSupportMode::serialize()
{
std::ostringstream ostr;
- for (auto it = appList.begin(); it != appList.end(); it++)
+ for (auto it = inactiveApps.begin(); it != inactiveApps.end(); it++)
ostr << *it << delimiter;
return ostr.str();
}
-int PkgStartSupportMode::parse(const std::string &data)
+int PkgSupportMode::parse(const std::string &data)
{
size_t pos;
size_t start = 0;
while ((pos = data.find(delimiter, start)) != std::string::npos) {
- appList.push_back(data.substr(start, pos - start));
+ inactiveApps.push_back(data.substr(start, pos - start));
start = pos + 1;
}
return MODES_ERROR_NONE;
}
+
+int PkgSupportMode::setChangedCallback(valueChangedCB callback, void *userData)
+{
+ ERR("Not Support Changed Callback");
+ return MODES_ERROR_NOT_SUPPORTED;
+}
+
+void PkgSupportMode::unSetChangedCallback(valueChangedCB callback, void *userData)
+{
+ ERR("Not Support Changed Callback");
+}
+
+int PkgSupportMode::appListCB(const pkgmgrinfo_appinfo_h handle, void *userData)
+{
+ PkgSupportMode *action = (PkgSupportMode*)userData;
+
+ RETV_IF(nullptr == userData, 0);
+
+ int appSupportMode = 0;
+ int ret = pkgmgrinfo_appinfo_get_support_mode(handle, &appSupportMode);
+ if (PMINFO_R_OK != ret)
+ ERR("pkgmgrinfo_appinfo_get_support_mode() Fail");
+
+ if (appSupportMode != action->requestVal) {
+ char *appid;
+ ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
+ if (PMINFO_R_OK != ret) {
+ ERR("pkgmgrinfo_appinfo_get_appid() Fail");
+ return 0;
+ }
+ action->inactiveApps.push_back(appid);
+ }
+ return 0;
+}
MODES_NAMESPACE_BEGIN
-class PkgStartSupportMode : public PkgAction {
+class PkgSupportMode : public PkgAction {
public:
- static const std::string NAME;
- PkgStartSupportMode();
+ PkgSupportMode();
int set(int val) override;
- int get(int *val) override;
void undo() override;
std::string serialize() override;
int parse(const std::string &data) override;
+ int setChangedCallback(valueChangedCB callback, void *userData) override;
+ void unSetChangedCallback(valueChangedCB callback, void *userData) override;
+
+ static const std::string NAME;
private:
- enum AppSupportMode {
- ULTRA_POWER_SAVING = 1,
- COOL_DOWN = 2,
- SCREEN_READER = 4
+ enum SupportModeType {
+ ULTRA_POWER_SAVING = APP_SUPPORT_MODE_ULTRA_POWER_SAVING_VAL,
+ COOL_DOWN = APP_SUPPORT_MODE_COOL_DOWN_VAL,
+ SCREEN_READER = APP_SUPPORT_MODE_SCREEN_READER_VAL
};
- const char delimiter = '#';
+ static int appListCB(const pkgmgrinfo_appinfo_h handle, void *userData);
- static int app_list_cb(const pkgmgrinfo_appinfo_h handle, void *user_data);
- static int appModeVal;
- std::list<std::string> appList;
+ const char delimiter = '#';
+ int requestVal;
+ std::list<std::string> inactiveApps;
};
MODES_NAMESPACE_END