X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fapp%2FFApp_Aul.cpp;h=6abde095beaf7b44a5fe4b3ec95230126b990732;hb=bee4a804e683c1b893a099838f520ac0463c2d7b;hp=fe69d21d0003ac889650486ecd610e7bac57b978;hpb=27f1388665067f69d5eb64e0cae6bb5f4250beec;p=platform%2Fframework%2Fnative%2Fappfw.git diff --git a/src/app/FApp_Aul.cpp b/src/app/FApp_Aul.cpp index fe69d21..6abde09 100644 --- a/src/app/FApp_Aul.cpp +++ b/src/app/FApp_Aul.cpp @@ -29,8 +29,8 @@ #include #include #include -#include -#include +#include +#include #include #include @@ -44,15 +44,9 @@ #include "FAppPkg_PackageManagerImpl.h" #include "FApp_Types.h" #include "FApp_Aul.h" +#include "FApp_AppArg.h" #include "FApp_TemplateUtil.h" -#ifdef __cplusplus -extern "C" { -#endif -extern int aul_listen_app_dead_signal(int (* func)(int, void*), void* data); -#ifdef __cplusplus -} -#endif using namespace Tizen::App::Package; using namespace Tizen::Base; @@ -62,15 +56,7 @@ using namespace Tizen::Base::Utility; namespace { - -const char _DESKTOP_FILE_PATH[] = "/opt/share/applications"; -const char _DESKTOP_FILE_PATH_FORMAT[] = "%s/%s.desktop"; - -const char _X_TIZEN_SVC[] = "x-tizen-svc"; //X-TIZEN-SVC=[operation1] | [URI1] | [MIME1] ; [operation2] | [URI2] | [MIME2] -const int _MAX_TIZEN_SVC_DESC_LEN = 1024; - -const int _MAX_CATEGORY = 12; -const int _MAX_PACKAGE_ID_LENGTH = 10; +const int _MAX_CATEGORY = 34; // borrowed from app-svc/include/pri_key.h #define APP_SVC_K_RES_VAL "__APP_SVC_K_RES_VAL__" @@ -83,7 +69,7 @@ namespace Tizen { namespace App struct _CategoryList { const char category[_MAX_CATEGORY]; - _AppType type; + const _AppType type; }; static const _CategoryList _CATEGORY_LIST[] = @@ -91,6 +77,9 @@ static const _CategoryList _CATEGORY_LIST[] = {"home-screen", _APP_TYPE_HOME_APP}, {"lock-screen", _APP_TYPE_LOCK_APP}, {"ime", _APP_TYPE_IME_APP}, + {"http://tizen.org/category/homeapp", _APP_TYPE_HOME_APP}, + {"http://tizen.org/category/lockapp", _APP_TYPE_LOCK_APP}, + {"http://tizen.org/category/ime", _APP_TYPE_IME_APP}, }; static const int _NUM_CATEGORY = sizeof(_CATEGORY_LIST) / sizeof(_CategoryList); @@ -126,7 +115,7 @@ _Aul::GetConvertedResult(const int aul_ret, const char* pFunctionName) } result -_Aul::SendResult(bundle* b, appsvc_result_val res) +_Aul::SendResult(bundle* b, appsvc_result_val res, bool isSubMode, bool isServiceApp) { // to skip error handling, of appsvc_send_result, use aul_send_service_result() directly. //int ret = appsvc_send_result(b, res); @@ -135,55 +124,44 @@ _Aul::SendResult(bundle* b, appsvc_result_val res) snprintf(tmp, 32, "%d", static_cast(res)); appsvc_add_data(b, APP_SVC_K_RES_VAL, tmp); - int aul_ret = aul_send_service_result(b); - - return GetConvertedResult(aul_ret, "SendResult"); -} - - -bool -_Aul::IsRunning(const AppId& appId, const String& exeName) -{ - char slpPackageName[MAX_SLP_PACKAGE_ID] = {0, }; - bool isRunning = false; - - _PackageManagerImpl* pPackageManagerImpl = _PackageManagerImpl::GetInstance(); - SysTryReturn(NID_APP, pPackageManagerImpl != null, false, E_INVALID_STATE, "[E_INVALID_STATE] Invalid package instance."); - - pPackageManagerImpl->GetPackageName(appId, &exeName, slpPackageName, MAX_SLP_PACKAGE_ID); + if (isSubMode) + { + _AppArg::UpdateSubMode(b); + } - app_manager_is_running(slpPackageName, &isRunning); + if (isServiceApp) + { + _AppArg::UpdateServiceApp(b); + } - SysLog(NID_APP, "'%s' %s running now.", slpPackageName, (isRunning == true) ? "is" : "is NOT"); + const int aul_ret = aul_send_service_result(b); - return isRunning; + result r = GetConvertedResult(aul_ret, "SendResult"); + if (r == E_INVALID_ARG) + { + SysLog(NID_APP, "Converting internal exception to E_MAX_EXCEEDED."); + r = E_MAX_EXCEEDED; + } + return r; } + bool -_Aul::IsRunning(const String& packageName) +_Aul::IsRunning(const String& appId) { - bool isRunning = false; - std::unique_ptr pSlpPackageName(_StringConverter::CopyToCharArrayN(packageName)); + std::unique_ptr pPackageId(_StringConverter::CopyToCharArrayN(appId)); - app_manager_is_running(pSlpPackageName.get(), &isRunning); + const bool isRunning = (aul_app_is_running(pPackageId.get()) > 0); - SysLog(NID_APP, "'%ls' %s running now.", packageName.GetPointer(), (isRunning) ? "is" : "is NOT"); + SysLog(NID_APP, "'%ls' %s running now.", appId.GetPointer(), (isRunning) ? "is" : "is NOT"); return isRunning; } -void -_Aul::SetOnAppTerminatedCb(int (* pf_app_dead_handler)(int pid, void* pData), void* pData) -{ - aul_listen_app_dead_signal(pf_app_dead_handler, pData); - SysLog(NID_APP, "'app_dead_handler is set."); -} - - result _Aul::TerminateApplicationByPid(int pid) { - int ret_aul = aul_terminate_pid(pid); + int ret_aul = aul_subapp_terminate_request_pid(pid); return GetConvertedResult(ret_aul, "TerminateApplicationByPid"); } @@ -231,9 +209,16 @@ _Aul::SetOomAdj(int pid, int adj) return r; } +typedef void (* cbForVconf)(keynode_t* node, void *pData); + result -_Aul::SetPowerOffNotiListener( void (*powerOffCb)(void *pData), void *pData) +_Aul::SetPowerOffNotiListener( void (*powerOffCb)(void* node, void *pData), void *pData) { + +#if 1 + int ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, (cbForVconf)powerOffCb, pData); + SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It failed to set power off"); +#else int heyFd = heynoti_init(); SysTryReturnResult(NID_APP, heyFd >= 0, E_SYSTEM, "heynoti_init failed."); @@ -242,10 +227,13 @@ _Aul::SetPowerOffNotiListener( void (*powerOffCb)(void *pData), void *pData) ret = heynoti_attach_handler(heyFd); SysTryReturnResult(NID_APP, ret >= 0, E_SYSTEM, "heynoti_attach_handler failed."); +#endif return E_SUCCESS; } + +// _Aul::GetAppType is provided for installer usage int _Aul::GetAppType(const String& category) { @@ -284,7 +272,9 @@ _Aul::GetAppType(const String& category) return ret; } -bool _Aul::IsInstalled(const AppId& appId) + +bool +_Aul::IsInstalled(const AppId& appId) { String packageId; packageId = _PackageManagerImpl::GetPackageIdByAppId(appId); @@ -292,288 +282,44 @@ bool _Aul::IsInstalled(const AppId& appId) return _PackageManagerImpl::GetInstance()->IsPackageInstalled(packageId); } -result -_Aul::_DesktopFile::MakePath(const AppId& appId, char* path, int size) -{ - SysTryReturnResult(NID_APP, path != null, E_INVALID_ARG, ""); - - std::unique_ptr pAppId(_StringConverter::CopyToCharArrayN(appId)); - SysTryReturnResult(NID_APP, pAppId != null, E_OUT_OF_MEMORY, "Failed to allocate memory for 'pAppId'"); - - snprintf(path, size, _DESKTOP_FILE_PATH_FORMAT, _DESKTOP_FILE_PATH, pAppId.get()); - - return E_SUCCESS; -} - -result -_Aul::_DesktopFile::UpdateService(const AppId& appId, const char* value) -{ - char path[FILENAME_MAX] = {0, }; - MakePath(appId, path, FILENAME_MAX); - - return UpdateField(path, _X_TIZEN_SVC, value); -} - -result -_Aul::_DesktopFile::RemoveService(const AppId& appId, const char* operationOnlyValue) +String +_Aul::GetMainAppId(const char* appid) { - char path[FILENAME_MAX] = {0, }; - MakePath(appId, path, FILENAME_MAX); - - return UpdateField(path, _X_TIZEN_SVC, operationOnlyValue, true); -} - -// -// Update value of specified field. -// currently only "x-slp-svc" field is supported. -// -#define BUFFER_SIZE 1024 -result -_Aul::_DesktopFile::UpdateField(const char* path, const char* fieldName, const char* value, bool isRemove) -{ - SysTryReturnResult(NID_APP, path != null, E_INVALID_ARG, "path should not be null."); - SysTryReturnResult(NID_APP, fieldName != null, E_INVALID_ARG, "fieldName should not be null."); - SysTryReturnResult(NID_APP, value != null, E_INVALID_ARG, "value should not be null."); - - FILE* fp = fopen(path, "r+"); - SysTryReturnResult(NID_APP, fp != null, E_SYSTEM, "falied to open '%s' due to %s", path, strerror(errno)); - - char buffer[BUFFER_SIZE] = {0, }; - bool found = false; - int len = 0; - int pos = 0; - int foundpos = 0; - result r = E_SUCCESS; - int remains = 0; - - ArrayListT buffers; - buffers.Construct(); - - char* pCurrent = null; - - while (fgets(buffer, BUFFER_SIZE, fp) != NULL) - { - len = strlen(buffer); - SysTryCatch(NID_APP, len < BUFFER_SIZE, , r = E_INVALID_ARG, "strlen returns invalid value. (%d)", len ); - - if (found) - { - pCurrent = new (std::nothrow) char[len + 1]; - SysTryCatch(NID_APP, pCurrent != null, , r = E_OUT_OF_MEMORY, "failed to allocate mem pCurrent"); - - strncpy(pCurrent, buffer, len); - buffers.Add(pCurrent); - } - else - { - if (strncmp(buffer, fieldName, len) == 0) - { - int fieldNameLen = strlen(fieldName); - SysTryCatch(NID_APP, len > fieldNameLen, , E_INVALID_ARG, "[E_INVALID_ARG] fieldName(%s)", fieldName); - - pCurrent = UpdateServiceValueN(buffer + fieldNameLen, value, isRemove); - SysTryCatch(NID_APP, pCurrent != null, , r = GetLastResult(), "[%s] UpdateServiceValue failed", GetErrorMessage(GetLastResult())); - - buffers.Add(pCurrent); - - foundpos = pos; - found = true; - } - } - - pos += len; - } - - if (found) - { - fsetpos(fp, (fpos_t*) &foundpos); - - remains = buffers.GetCount(); // prevent infinite loop - while (buffers.GetCount() > 0 && remains-- > 0) - { - pCurrent = null; - buffers.GetAt(0, pCurrent); - buffers.RemoveAt(0); - SysTryCatch(NID_APP, pCurrent != null, , r = E_INVALID_STATE, ""); - - fputs(pCurrent, fp); - len = strlen(pCurrent); - pos += len; - delete[] pCurrent; - } - - int ret = truncate(path, pos); - SysTryLog(NID_APP, ret == 0, "Truncate failure (%s).", strerror(errno)); - } - else - { - char svctext[_MAX_TIZEN_SVC_DESC_LEN] = {0, }; - snprintf(svctext, _MAX_TIZEN_SVC_DESC_LEN, "%s=%s\n", fieldName, value); - fputs(svctext, fp); - } - fclose(fp); - - return E_SUCCESS; - -CATCH: - - remains = buffers.GetCount(); // prevent infinite loop - while (buffers.GetCount() > 0 && remains-- > 0) + pkgmgrinfo_appinfo_h handle = NULL; + int ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle); + if (ret != PMINFO_R_OK) { - pCurrent = null; - buffers.GetAt(0, pCurrent); - buffers.RemoveAt(0); - if (pCurrent != null) - { - delete[] pCurrent; - } + return String(); } - fclose(fp); + char* mainid = NULL; + ret = pkgmgrinfo_appinfo_get_submode_mainid(handle, &mainid); + SysTryLog(NID_APP, ret == PMINFO_R_OK, "Cannot get main id for %s.", appid); - return r; + const String tmp = String(mainid); + pkgmgrinfo_appinfo_destroy_appinfo(handle); + return tmp; } -// -// Tizen service string example -// X-TIZEN-SVC= http://tizen.org/appcontrol/operation/pick|NULL|image/jpge; http://tizen.org/appcontrol/operation/pick|NULL|video/mp4; http://tizen.org/appcontrol/operation/pick|NULL|NULL; http://tizen.org/appcontrol/operation/pview|NULL|NULL -// -char* -_Aul::_DesktopFile::UpdateServiceValueN(char* buffer, const char* newValue, bool isRemove) -{ - SysTryReturn(NID_APP, buffer != null, null, E_INVALID_ARG, ""); - SysTryReturn(NID_APP, newValue != null, null, E_INVALID_ARG, ""); - - SysLog(NID_APP, "current(%s), new(%s), isRemove(%s)", buffer, newValue, (isRemove) ? "true" : "false"); - - String buf(buffer); - bool found = false; - - const String& servicePattern(L"([A-Za-z&=:/\\.\\-]*);?"); - ArrayList services; - String resultString; - - Utility::RegularExpression regex; - result r = regex.Construct(servicePattern); - SysTryReturn(NID_APP, !IsFailed(r), null, r, ""); - - String newOperation; - String newUrl; - String newMimeType; - String newService(newValue); - - if (isRemove == false) - { - ParseService(newService, newOperation, newUrl, newMimeType); - } - else - { - newOperation = newValue; - } - - services.Construct(); - - while (regex.Consume(buf, &services) == true) +AppId +_Aul::GetRealAppId(const AppId& appId) +{ + String temp; + appId.SubString(11, temp); + if (temp == String(SUBMODE_NAME)) { - String* pCurrentService = (String*) services.GetAt(1); - services.RemoveAll(false); - - String operation; - String url; - String mimeType; - - ParseService(*pCurrentService, operation, url, mimeType); - - if (operation == newOperation) - { - if (isRemove == true) - { - SysLog(NID_APP, "opreration '%ls' will be removed", operation.GetPointer()); - } - else - { - SysAssertf(found == false, "It's assumed that service doesn't have duplicated operation in tizen desktop file. But it isn't, so now we have to check this case."); - // replace operation. - if (found == false) // ( if duplicated operation is already exist, It will be keeped. - { - // update value - AppendServiceValueToString(resultString, newService); - SysLog(NID_APP, "opreration '%ls;%ls;%ls' will be updated to ;%ls;%ls", operation.GetPointer(), url.GetPointer(), mimeType.GetPointer(), newUrl.GetPointer(), mimeType.GetPointer()); - } - } - found = true; - } - else + std::unique_ptr pAppId(_StringConverter::CopyToCharArrayN(appId)); + const String& main = GetMainAppId(pAppId.get()); + if (!main.IsEmpty()) { - // add not specified service. - AppendServiceValueToString(resultString, *pCurrentService); + SysLog(NID_APP, "main Id is %ls", main.GetPointer()); + return main; } - - delete pCurrentService; - } - - if (found == false && isRemove == false) - { - AppendServiceValueToString(resultString, newService); - SysLog(NID_APP, "opreration '%ls;%ls;%ls' will be added", newOperation.GetPointer(), newUrl.GetPointer(), newMimeType.GetPointer()); - } - - SysLog(NID_APP, "updated string is '%ls'", resultString.GetPointer()); - return _StringConverter::CopyToCharArrayN(resultString); -} - - -void -_Aul::_DesktopFile::AppendServiceValueToString(String& serviceString, const String& newVaue) -{ - if (serviceString.GetLength() > 0) - { - serviceString += ";"; } - serviceString += newVaue; -} - - -result -_Aul::_DesktopFile::ParseService(const String& service, String& operation, String& url, String& mimeType) -{ - SysLog(NID_APP, "service(%ls)", service.GetPointer()); - - const String& serviceDetailPattern(L"([A-Za-z&=/\\.\\-]*):(.*://[A-Za-z&=/\\.\\-]*|[A-Za-z&=/\\.\\-]*):([A-Za-z&=/\\.\\-]*)"); - - Utility::RegularExpression regexDetail; - result r = regexDetail.Construct(serviceDetailPattern); - SysTryReturn(NID_APP, !IsFailed(r), null, r, "[%s] RegularExpression::Construct(L\"%ls\") failed.", GetErrorMessage(r), serviceDetailPattern.GetPointer()); - - ArrayList matchedItems; - matchedItems.Construct(); - regexDetail.Match(service, true, &matchedItems); - - int matchedCount = matchedItems.GetCount(); - SysTryLog(NID_APP, matchedCount == 4, "It's assumed that x-slp-svc value always have operation:url:mime in tizen desktop file. But it isn't or our parser is invalid. so now we have to check this case. %d", matchedItems.GetCount()); - - if (matchedCount > 1) - { - operation = *(String*) matchedItems.GetAt(1); - } - - if (matchedCount > 2) - { - url = *(String*) matchedItems.GetAt(2); - } - - if (matchedCount > 3) - { - mimeType = *(String*) matchedItems.GetAt(3); - } - - SysLog(NID_APP, "matched(%d) : (%ls;%ls;%ls)", matchedItems.GetCount(), operation.GetPointer(), url.GetPointer(), mimeType.GetPointer()); - matchedItems.RemoveAll(true); - - return E_SUCCESS; + return appId; } } } // Tizen::App