2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FAppAppResource.cpp
20 * @brief This is the implementation for the AppResource class.
23 #include <FBaseResult.h>
24 #include <FBaseSysLog.h>
25 #include <FAppAppResource.h>
27 #include <FSec_AccessController.h>
28 #include "FApp_AppResourceImpl.h"
29 #include "FApp_AppInfo.h"
31 using namespace Tizen::Base;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Security;
35 namespace Tizen { namespace App
38 AppResource::AppResource(void)
39 : __pAppResourceImpl(null)
44 AppResource::~AppResource(void)
46 delete __pAppResourceImpl;
50 AppResource::GetString(const String& resourceId, String& loadedString) const
52 SysAssertf(__pAppResourceImpl != null, "Not yet constructed. Construct() should be called before use.");
53 return __pAppResourceImpl->GetString(resourceId, loadedString);
58 AppResource::GetBitmapN(const String& imgFilePath, BitmapPixelFormat pixelFormat) const
60 SysAssertf(__pAppResourceImpl != null, "Not yet constructed. Construct() should be called before use.");
61 return __pAppResourceImpl->GetBitmapN(imgFilePath, pixelFormat);
66 AppResource::GetBitmapN(const String& imgFilePath) const
68 SysAssertf(__pAppResourceImpl != null, "Not yet constructed. Construct() should be called before use.");
69 return __pAppResourceImpl->GetBitmapN(imgFilePath);
74 AppResource::GetInstance(void)
76 static AppResource* pSelfAppResource = null;
77 if (pSelfAppResource == null)
79 pSelfAppResource = _AppResourceImpl::GetInstanceN(APP_RESOURCE_DEFAULT);
82 // ClearLastResult(); // as this method does not register any exception.
83 return pSelfAppResource;
87 AppResource::LoadAppResource(const Tizen::Base::String& resourcePath)
89 SysTryReturn(NID_APP, !resourcePath.IsEmpty(), null, E_INVALID_ARG, "Resource path is empty");
91 AppResource* pAppResource = _AppResourceImpl::GetInstanceN(APP_RESOURCE_BY_LIBRARY_NAME, resourcePath);
92 if (GetLastResult() == E_DATA_NOT_FOUND)
94 SetLastResult(E_FILE_NOT_FOUND);
101 AppResource::GetInstanceByAppId(const AppId& appId)
103 result r = E_SUCCESS;
105 r = _AccessController::CheckUserPrivilege(_PRV_APPSETTING);
106 SysTryReturn(NID_APP, r == E_SUCCESS, null, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
108 SysTryReturn(NID_APP, !appId.IsEmpty(), null, E_APP_NOT_INSTALLED, "Invalid app id");
111 r = appId.SubString(0, 10, packageId);
112 SysTryReturn(NID_APP, !IsFailed(r), null,
113 E_APP_NOT_INSTALLED, "[%s] Failed to get the package info", GetErrorMessage(E_APP_NOT_INSTALLED));
114 return _AppResourceImpl::GetInstanceN(APP_RESOURCE_BY_APP_ID, packageId);
118 AppResource::ReleaseInstanceByAppId(const AppId& appId)
120 result r = E_SUCCESS;
122 r = _AccessController::CheckUserPrivilege(_PRV_APPSETTING);
123 SysTryReturnResult(NID_APP, r == E_SUCCESS, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
125 if (appId == _AppInfo::GetApplicationId() || appId == _AppInfo::GetPackageId())
127 SysLog(NID_APP, "Ignoring key[%ls] with current instance", appId.GetPointer());
132 r = appId.SubString(0, 10, packageId);
133 SysTryReturn(NID_APP, !IsFailed(r), null,
134 E_OBJ_NOT_FOUND, "[%s] Failed to get the package info", GetErrorMessage(E_OBJ_NOT_FOUND));
135 return _AppResourceImpl::ReleaseInstance(packageId);