add certification check for AddAppWidget, RequestUpdate. apply changed exception...
authorjungmin76.park <jungmin76.park@samsung.com>
Tue, 16 Apr 2013 05:33:26 +0000 (14:33 +0900)
committerjungmin76.park <jungmin76.park@samsung.com>
Tue, 16 Apr 2013 05:33:26 +0000 (14:33 +0900)
Change-Id: I3776757593a482d4971ec34ef4ec1874f3c27acf
Signed-off-by: jungmin76.park <jungmin76.park@samsung.com>
inc/FShellShortcutManager.h
packaging/osp-shell.spec
src/CMakeLists.txt
src/FShell_AppWidgetProviderManagerImpl.cpp
src/core/FShellShortcutManager.cpp
src/inc/FShell_AppWidgetProviderManagerImpl.h

index 64313a3..4bd5ea9 100644 (file)
@@ -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 );
index 4196485..f4004cc 100755 (executable)
@@ -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)
index 2ef4194..f0b394f 100644 (file)
@@ -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" )
index 141ffc4..a6526ce 100644 (file)
@@ -23,6 +23,7 @@
 #include <unique_ptr.h>
 #include <errno.h>
 #include <string.h>
+#include <package_manager.h>
 #include <shortcut.h>
 
 #include <FBaseSysLog.h>
 #include <FShellAppWidgetPopupProvider.h>
 #include <FShellAppWidgetFrame.h>
 #include <FShellAppWidgetPopup.h>
-
 #include <FShellIAppWidgetProviderFactory.h>
 #include <FShellIAppWidgetPopupProviderFactory.h>
 
-#include <FShell_IAppWidgetTouchEventListener.h>
 #include <FShell_TemplateUtil.h>
-
+#include <FShell_IAppWidgetTouchEventListener.h>
 #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<char[]> pLocalAppId(_StringConverter::CopyToCharArrayN(localAppId));
+       std::unique_ptr<char[]> 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<char[]> 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<const String*>(pArgs->GetValue(ARG_KEY_INSTANCE_ID));
@@ -391,29 +414,6 @@ _AppWidgetProviderManagerImpl::HandleAppWidgetRequest(const Tizen::Base::String&
        const String* pInstanceId = dynamic_cast<const String*>(pArgs->GetValue(ARG_KEY_INSTANCE_ID));
        SysTryReturnResult(NID_SHELL, pInstanceId, E_FAILURE, "[E_FAILURE] pId is null.");
 
-       /*String *pName =  dynamic_cast<String*>(pArgs->GetAt(1));
-       SysTryReturnResult(NID_SHELL, pInstanceId, E_FAILURE, "[E_FAILURE] pName is null");
-
-       String *pParam =  dynamic_cast<String*>(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<String*>(pArgs->GetAt(2));
-               SysTryReturnResult(NID_SHELL, pValue, E_FAILURE, "[E_FAILURE]");
-               Integer::Parse(*pValue, w);
-
-               pValue =  dynamic_cast<String*>(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;
index 06763a4..dc46571 100644 (file)
  */
 
 #include <unique_ptr.h>
+
 #include <shortcut.h>
+
 #include <FBaseSysLog.h>
 #include <FShellShortcutManager.h>
 #include <FShellIShortcutRequestListener.h>
+
 #include <FApp_Types.h>
 #include <FApp_AppInfo.h>
 #include <FBase_StringConverter.h>
@@ -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<char[]> 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
index 0d28d60..fafc148 100644 (file)
@@ -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;