2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FAppAppResource.cpp
19 * @brief This is the implementation for the AppResource class.
22 #include <FBaseResult.h>
23 #include <FBaseSysLog.h>
24 #include <FAppAppResource.h>
26 #include <FSec_AccessController.h>
27 #include "FApp_AppResourceImpl.h"
28 #include "FApp_AppInfo.h"
29 #ifdef _SINGLETON_CLEANUP
30 #include "FApp_LongevityManager.h"
33 using namespace Tizen::Base;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Security;
37 namespace Tizen { namespace App
40 AppResource::AppResource(void)
41 : __pAppResourceImpl(null)
46 AppResource::~AppResource(void)
48 delete __pAppResourceImpl;
52 AppResource::GetString(const String& resourceId, String& loadedString) const
54 SysAssertf(__pAppResourceImpl != null, "Not yet constructed. Construct() should be called before use.");
55 return __pAppResourceImpl->GetString(resourceId, loadedString);
60 AppResource::GetBitmapN(const String& imgFilePath, BitmapPixelFormat pixelFormat) const
62 SysAssertf(__pAppResourceImpl != null, "Not yet constructed. Construct() should be called before use.");
63 return __pAppResourceImpl->GetBitmapN(imgFilePath, pixelFormat);
68 AppResource::GetBitmapN(const String& imgFilePath) const
70 SysAssertf(__pAppResourceImpl != null, "Not yet constructed. Construct() should be called before use.");
71 return __pAppResourceImpl->GetBitmapN(imgFilePath);
76 AppResource::GetInstance(void)
78 static AppResource* pSelfAppResource = null;
79 if (pSelfAppResource == null)
81 pSelfAppResource = _AppResourceImpl::GetInstanceN(APP_RESOURCE_DEFAULT);
83 #ifdef _SINGLETON_CLEANUP
84 _LongevityManager::GetInstance().RegisterOwnership(*pSelfAppResource);
88 // ClearLastResult(); // as this method does not register any exception.
89 return pSelfAppResource;
93 AppResource::LoadAppResource(const Tizen::Base::String& resourcePath)
95 SysTryReturn(NID_APP, !resourcePath.IsEmpty(), null, E_INVALID_ARG, "Resource path is empty");
97 AppResource* pAppResource = _AppResourceImpl::GetInstanceN(APP_RESOURCE_BY_LIBRARY_NAME, resourcePath);
98 if (GetLastResult() == E_DATA_NOT_FOUND)
100 SetLastResult(E_FILE_NOT_FOUND);
107 AppResource::GetInstanceByAppId(const AppId& appId)
109 result r = E_SUCCESS;
111 r = _AccessController::CheckUserPrivilege(_PRV_APPSETTING);
112 SysTryReturn(NID_APP, r == E_SUCCESS, null, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
114 SysTryReturn(NID_APP, !appId.IsEmpty(), null, E_APP_NOT_INSTALLED, "Invalid app id");
117 r = appId.SubString(0, 10, packageId);
118 SysTryReturn(NID_APP, !IsFailed(r), null,
119 E_APP_NOT_INSTALLED, "[%s] Failed to get the package info", GetErrorMessage(E_APP_NOT_INSTALLED));
120 return _AppResourceImpl::GetInstanceN(APP_RESOURCE_BY_APP_ID, packageId);
124 AppResource::ReleaseInstanceByAppId(const AppId& appId)
126 result r = E_SUCCESS;
128 r = _AccessController::CheckUserPrivilege(_PRV_APPSETTING);
129 SysTryReturnResult(NID_APP, r == E_SUCCESS, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
131 if (appId == _AppInfo::GetApplicationId() || appId == _AppInfo::GetPackageId())
133 SysLog(NID_APP, "Ignoring key[%ls] with current instance", appId.GetPointer());
138 r = appId.SubString(0, 10, packageId);
139 SysTryReturn(NID_APP, !IsFailed(r), null,
140 E_OBJ_NOT_FOUND, "[%s] Failed to get the package info", GetErrorMessage(E_OBJ_NOT_FOUND));
141 return _AppResourceImpl::ReleaseInstance(packageId);