From 9dff899c91f44c740fc80cb7bc44cd512f84179a Mon Sep 17 00:00:00 2001 From: "jungmin76.park" Date: Tue, 16 Apr 2013 14:33:26 +0900 Subject: [PATCH] add certification check for AddAppWidget, RequestUpdate. apply changed exception value for libshortcut Change-Id: I3776757593a482d4971ec34ef4ec1874f3c27acf Signed-off-by: jungmin76.park --- inc/FShellShortcutManager.h | 7 +- packaging/osp-shell.spec | 1 + src/CMakeLists.txt | 1 + src/FShell_AppWidgetProviderManagerImpl.cpp | 96 +++++++++++++-------------- src/core/FShellShortcutManager.cpp | 12 +++- src/inc/FShell_AppWidgetProviderManagerImpl.h | 3 + 6 files changed, 67 insertions(+), 53 deletions(-) diff --git a/inc/FShellShortcutManager.h b/inc/FShellShortcutManager.h index 64313a3..4bd5ea9 100644 --- a/inc/FShellShortcutManager.h +++ b/inc/FShellShortcutManager.h @@ -103,9 +103,10 @@ public: * using namespace Tizen::App; * using namespace Tizen::Shell; * - * String appId = App::GetInstance()->GetAppId(); - * String iconPath = AppManager::GetInstance()->GetAppSharedPath(appId) + L"res/my_icons/my_icon.png"; - * ShortcutManager::GetInstance()->AddShortcut(appId, L"MyApp", iconPath , L"myapp://mydata/myitem"); + * String displayName = L"Shortcut to my app"; + * String iconPath = App::GetInstance()->GetAppSharedPath() + L"res/screen-density-xhigh/mainmenu.png"; + * String uriData = L"myapp://mydata/myitem"; + * ShortcutManager::GetInstance()->AddShortcut(App::GetInstance()->GetAppId(), displayName, iconPath , uriData); * @endcode */ result AddShortcut(const Tizen::App::AppId& appId, const Tizen::Base::String& displayName, const Tizen::Base::String& iconPath, const Tizen::Base::String& uriData, bool allowDuplication = true ); diff --git a/packaging/osp-shell.spec b/packaging/osp-shell.spec index 4196485..f4004cc 100755 --- a/packaging/osp-shell.spec +++ b/packaging/osp-shell.spec @@ -11,6 +11,7 @@ Source0: %{name}-%{version}.tar.gz BuildRequires: cmake BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(capi-appfw-app-manager) +BuildRequires: pkgconfig(capi-appfw-package-manager) BuildRequires: pkgconfig(chromium) BuildRequires: pkgconfig(osp-appfw) BuildRequires: pkgconfig(osp-uifw) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2ef4194..f0b394f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -118,6 +118,7 @@ TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp -losp-image-core" ) TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp -losp-shell-core" ) TARGET_LINK_LIBRARIES(${this_target} "-lcapi-appfw-application" ) TARGET_LINK_LIBRARIES(${this_target} "-lcapi-appfw-app-manager" ) +TARGET_LINK_LIBRARIES(${this_target} "-lcapi-appfw-package-manager" ) TARGET_LINK_LIBRARIES(${this_target} "-lnotification" ) TARGET_LINK_LIBRARIES(${this_target} "-lecore" ) TARGET_LINK_LIBRARIES(${this_target} "-levas" ) diff --git a/src/FShell_AppWidgetProviderManagerImpl.cpp b/src/FShell_AppWidgetProviderManagerImpl.cpp index 141ffc4..a6526ce 100644 --- a/src/FShell_AppWidgetProviderManagerImpl.cpp +++ b/src/FShell_AppWidgetProviderManagerImpl.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -43,16 +44,13 @@ #include #include #include - #include #include -#include #include - +#include #include "FShell_AppWidgetManagerProxy.h" #include "FShell_AppWidgetProviderManagerImpl.h" - #include "FShell_AppWidgetProviderInfoImpl.h" namespace Tizen { namespace Shell @@ -204,6 +202,10 @@ _AppWidgetProviderManagerImpl::RequestUpdate(const Tizen::App::AppId& appId, con { SysLog(NID_SHELL, "Enter."); + + result r = CheckCertificate(Tizen::App::App::GetInstance()->GetAppId(), appId); + SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "[%s] VerifyCertification is failed.", GetErrorMessage(r)); + // if( appId == App::App::GetInstance()->GetAppId()) // { // //TODO: optimizing for local request @@ -255,16 +257,55 @@ int AddAppWidgetCallback(int ret, int pid, void *data) } } +bool +_AppWidgetProviderManagerImpl::IsSamePackage(const Tizen::App::AppId& appId1, const Tizen::App::AppId& appId2) +{ + String PackageId1 = _PackageManagerImpl::GetPackageIdByAppId(appId1); + String PackageId2 = _PackageManagerImpl::GetPackageIdByAppId(appId2); + + return ( PackageId1 == PackageId2); +} + +result +_AppWidgetProviderManagerImpl::CheckCertificate(const Tizen::App::AppId& localAppId, const Tizen::App::AppId& remoteAppId) +{ + if( IsSamePackage( localAppId, remoteAppId)) + { + return E_SUCCESS; + } + + // for FtApp + static const String PKGID_FTAPP = L"2s4jm6firv"; + if( _PackageManagerImpl::GetPackageIdByAppId(localAppId) == PKGID_FTAPP ) + { + return E_SUCCESS; + } + + package_manager_compare_result_type_e res; + + std::unique_ptr pLocalAppId(_StringConverter::CopyToCharArrayN(localAppId)); + std::unique_ptr pRemoteAppId(_StringConverter::CopyToCharArrayN(remoteAppId)); + + int ret = package_manager_compare_app_cert_info(pLocalAppId.get(), pRemoteAppId.get(), &res); + SysTryReturnResult(NID_SHELL, ret == 0, E_SYSTEM, "Failed to check the certificate: %d", ret); + SysTryReturnResult(NID_SHELL, res == PACAKGE_MANAGER_COMPARE_MATCH, E_CERTIFICATE_VERIFICATION_FAILED, "Both applications are not signed with the same certificate: %d", res); + + return E_SUCCESS; +} + result _AppWidgetProviderManagerImpl::AddAppWidget(const Tizen::App::AppId& providerAppId, const Tizen::Base::String& providerName, const Tizen::Base::String& text, const Tizen::Base::String& userInfo) { - result r = _AccessController::CheckUserPrivilege(_PRV_APPWIDGETPROVIDER_INSTALL); + result r = _AccessController::CheckUserPrivilege(_PRV_SHORTCUT_INSTALL); SysTryReturnResult(NID_SHELL, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method."); SysTryReturnResult(NID_SHELL, providerAppId.IsEmpty()==false, E_INVALID_ARG, "The providerAppId is empty."); SysTryReturnResult(NID_SHELL, providerAppId.GetLength() < NATIVE_APP_MAX_APPID_LENGTH, E_INVALID_ARG, "The providerAppId is too long (Maximum %d bytes).", NATIVE_APP_MAX_APPID_LENGTH); SysTryReturnResult(NID_SHELL, Tizen::App::_Aul::IsInstalled(providerAppId) == true, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", providerAppId.GetPointer()); + r = CheckCertificate(Tizen::App::App::GetInstance()->GetAppId(), providerAppId); + SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "[%s] VerifyCertification is failed.", GetErrorMessage(r)); + String providerId; if( providerAppId.StartsWith(L"com.samsung", 0) == true ) { @@ -274,13 +315,6 @@ _AppWidgetProviderManagerImpl::AddAppWidget(const Tizen::App::AppId& providerApp } else { - String localPackageId = _PackageManagerImpl::GetPackageIdByAppId(Tizen::App::App::GetInstance()->GetAppId()); - String appwidgetProviderPackageId = _PackageManagerImpl::GetPackageIdByAppId(providerAppId); - if( localPackageId != appwidgetProviderPackageId) - { - SysLog(NID_SHELL, "[E_INVALID_OPERATION] but allowed to test"); - //TODO:return E_INVALID_OPERATION - } providerId = providerAppId + "." + providerName; } @@ -296,8 +330,8 @@ _AppWidgetProviderManagerImpl::AddAppWidget(const Tizen::App::AppId& providerApp std::unique_ptr pIcon(_StringConverter::CopyToCharArrayN(iconPath)); int ret = add_to_home_livebox(pProviderId.get(), pName.get(), LIVEBOX_TYPE_DEFAULT, pContent.get(), pIcon.get(), -1.0l, true, AddAppWidgetCallback, this); - SysTryReturnResult(NID_SHELL, ret != -ENOTCONN, E_CONNECTION_FAILED, "[E_CONNECTION_FAILED] failed to add_to_home_livebox"); - SysTryReturnResult(NID_SHELL, ret == 0, E_SYSTEM, "[E_SYSTEM] failed to add_to_home_livebox (%s)", strerror(r)); + SysTryReturnResult(NID_SHELL, ret != SHORTCUT_ERROR_COMM, E_CONNECTION_FAILED, "[E_CONNECTION_FAILED] failed to add_to_home_livebox"); + SysTryReturnResult(NID_SHELL, ret == SHORTCUT_SUCCESS, E_SYSTEM, "[E_SYSTEM] failed to add_to_home_livebox (%s)", strerror(r)); return E_SUCCESS; } @@ -311,23 +345,12 @@ _AppWidgetProviderManagerImpl::ContainsAppWidget(const String& instanceId) const return contains; } -//void -//_AppWidgetProviderManagerImpl::TerminateAppIfInvalidState() -//{ -// if( __messageReceived == false ) -// { -// Tizen::App::App::GetInstance()->Terminate(); -// } -//} - void _AppWidgetProviderManagerImpl::OnAppControlRequestReceived(RequestId reqId, const String& operationId, const String* pUri, const String* pMimeType, const IMap* pArgs) { SysAssertf( pArgs, "[E_SYSTEN] pArgs should not be null."); SysAssertf( pArgs->GetCount() > 0, "[E_SYSTEN] pArgs should have one more key-values."); -// __messageReceived = true; - SysLog(NID_SHELL, "operationId(%ls), argc(%d)", operationId.GetPointer(), pArgs->GetCount()); const String* pInstanceId = dynamic_cast(pArgs->GetValue(ARG_KEY_INSTANCE_ID)); @@ -391,29 +414,6 @@ _AppWidgetProviderManagerImpl::HandleAppWidgetRequest(const Tizen::Base::String& const String* pInstanceId = dynamic_cast(pArgs->GetValue(ARG_KEY_INSTANCE_ID)); SysTryReturnResult(NID_SHELL, pInstanceId, E_FAILURE, "[E_FAILURE] pId is null."); - /*String *pName = dynamic_cast(pArgs->GetAt(1)); - SysTryReturnResult(NID_SHELL, pInstanceId, E_FAILURE, "[E_FAILURE] pName is null"); - - String *pParam = dynamic_cast(pArgs->GetAt(2)); - SysTryReturnResult(NID_SHELL, pParam, E_FAILURE, "[E_FAILURE] pName is null"); - - SysLog(NID_SHELL, "id(%ls), name(%d)", pInstanceId->GetPointer(), pName->GetPointer());*/ - - /*if( operationId == APPWIDGET_ON_ADD ) - { - int w = 0; - int h = 0; - String* pValue = dynamic_cast(pArgs->GetAt(2)); - SysTryReturnResult(NID_SHELL, pValue, E_FAILURE, "[E_FAILURE]"); - Integer::Parse(*pValue, w); - - pValue = dynamic_cast(pArgs->GetAt(3)); - SysTryReturnResult(NID_SHELL, pValue, E_FAILURE, "[E_FAILURE]"); - Integer::Parse(*pValue, h); - - this->__pAppWidgetEventListener->OnAppWidgetAdded(*pId, width, height, pArgs); - }*/ - if (operationId == APPWIDGET_ON_RESIZE) { int width = 0; diff --git a/src/core/FShellShortcutManager.cpp b/src/core/FShellShortcutManager.cpp index 06763a4..dc46571 100644 --- a/src/core/FShellShortcutManager.cpp +++ b/src/core/FShellShortcutManager.cpp @@ -21,10 +21,13 @@ */ #include + #include + #include #include #include + #include #include #include @@ -84,7 +87,9 @@ ShortcutManager::AddShortcut(const AppId& appId, const String& displayName, cons int type = (uriData.IsEmpty())? LAUNCH_BY_PACKAGE : LAUNCH_BY_URI; int ret = add_to_home_shortcut(pAppId.get(), pName.get(), type, pUriData.get(), pIcon.get(), allowDuplication, NULL, this); - SysTryReturnResult(NID_SHELL, ret == 0, E_SYSTEM, "Failed to add_to_home_shortcut"); + SysTryReturnResult(NID_SHELL, ret != SHORTCUT_ERROR_COMM, E_SUCCESS, "It's failed to add_to_home_shortcut, but regarded as success."); + SysTryReturnResult(NID_SHELL, ret != SHORTCUT_ERROR_MEMORY, E_OUT_OF_MEMORY, "It's failed to add_to_home_shortcut."); + SysTryReturnResult(NID_SHELL, ret == SHORTCUT_SUCCESS, E_SYSTEM, "Failed to add_to_home_shortcut"); return E_SUCCESS; } @@ -99,7 +104,9 @@ ShortcutManager::RemoveShortcut(const Tizen::App::AppId& appId, const Tizen::Bas std::unique_ptr pName(_StringConverter::CopyToCharArrayN(displayName)); int ret = add_to_home_remove_shortcut(pAppId.get(), pName.get(), "", null, this); - SysTryReturnResult(NID_SHELL, ret == 0, E_SYSTEM, "Failed to add_to_home_remove_shortcut"); + SysTryReturnResult(NID_SHELL, ret != SHORTCUT_ERROR_COMM, E_SUCCESS, "It's failed to add_to_home_remove_shortcut, but regarded as success."); + SysTryReturnResult(NID_SHELL, ret != SHORTCUT_ERROR_MEMORY, E_OUT_OF_MEMORY, "It's failed to add_to_home_remove_shortcut."); + SysTryReturnResult(NID_SHELL, ret == SHORTCUT_SUCCESS, E_SYSTEM, "It's failed to add_to_home_remove_shortcut, with reason (%d)"); return E_SUCCESS; } @@ -116,4 +123,5 @@ ShortcutManager::RemoveShortcutRequestListener(IShortcutRequestListener& listene return __pShortcutManagerImpl->RemoveShortcutRequestListener(listener); } + }} // Tizen::Shell diff --git a/src/inc/FShell_AppWidgetProviderManagerImpl.h b/src/inc/FShell_AppWidgetProviderManagerImpl.h index 0d28d60..fafc148 100644 --- a/src/inc/FShell_AppWidgetProviderManagerImpl.h +++ b/src/inc/FShell_AppWidgetProviderManagerImpl.h @@ -101,6 +101,9 @@ private: result HandleAppWidgetRequest(const Tizen::Base::String& operationId, const Tizen::Base::Collection::IMap* pArgs); result HandleAppWidgetPopupRequest(const Tizen::Base::String& operationId, const Tizen::Base::Collection::IMap* pArgs); + static result CheckCertificate(const Tizen::App::AppId& localAppId, const Tizen::App::AppId& remoteAppId); + static bool IsSamePackage(const Tizen::App::AppId& appId1, const Tizen::App::AppId& appId2); + private: // for AppWidget IAppWidgetProviderFactory* __pAppWidgetFactory; -- 2.7.4