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"
30 using namespace Tizen::Base;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::Security;
34 namespace Tizen { namespace App
37 AppResource::AppResource(void)
38 : __pAppResourceImpl(null)
43 AppResource::~AppResource(void)
45 delete __pAppResourceImpl;
49 AppResource::GetString(const String& resourceId, String& loadedString) const
51 SysAssertf(__pAppResourceImpl != null, "Not yet constructed. Construct() should be called before use.");
52 return __pAppResourceImpl->GetString(resourceId, loadedString);
57 AppResource::GetBitmapN(const String& imgFilePath, BitmapPixelFormat pixelFormat) const
59 SysAssertf(__pAppResourceImpl != null, "Not yet constructed. Construct() should be called before use.");
60 return __pAppResourceImpl->GetBitmapN(imgFilePath, pixelFormat);
65 AppResource::GetBitmapN(const String& imgFilePath) const
67 SysAssertf(__pAppResourceImpl != null, "Not yet constructed. Construct() should be called before use.");
68 return __pAppResourceImpl->GetBitmapN(imgFilePath);
73 AppResource::GetInstance(void)
75 static AppResource* pSelfAppResource = null;
76 if (pSelfAppResource == null)
78 pSelfAppResource = _AppResourceImpl::GetInstanceN(APP_RESOURCE_DEFAULT);
81 // ClearLastResult(); // as this method does not register any exception.
82 return pSelfAppResource;
86 AppResource::LoadAppResource(const Tizen::Base::String& resourcePath)
88 SysTryReturn(NID_APP, !resourcePath.IsEmpty(), null, E_INVALID_ARG, "Resource path is empty");
90 AppResource* pAppResource = _AppResourceImpl::GetInstanceN(APP_RESOURCE_BY_LIBRARY_NAME, resourcePath);
91 if (GetLastResult() == E_DATA_NOT_FOUND)
93 SetLastResult(E_FILE_NOT_FOUND);
100 AppResource::GetInstanceByAppId(const AppId& appId)
102 result r = E_SUCCESS;
104 r = _AccessController::CheckUserPrivilege(_PRV_APPSETTING);
105 SysTryReturn(NID_APP, r == E_SUCCESS, null, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
107 SysTryReturn(NID_APP, !appId.IsEmpty(), null, E_APP_NOT_INSTALLED, "Invalid app id");
110 r = appId.SubString(0, 10, packageId);
111 SysTryReturn(NID_APP, !IsFailed(r), null,
112 E_APP_NOT_INSTALLED, "[%s] Failed to get the package info", GetErrorMessage(E_APP_NOT_INSTALLED));
113 return _AppResourceImpl::GetInstanceN(APP_RESOURCE_BY_APP_ID, packageId);
117 AppResource::ReleaseInstanceByAppId(const AppId& appId)
119 result r = E_SUCCESS;
121 r = _AccessController::CheckUserPrivilege(_PRV_APPSETTING);
122 SysTryReturnResult(NID_APP, r == E_SUCCESS, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
124 if (appId == _AppInfo::GetApplicationId() || appId == _AppInfo::GetPackageId())
126 SysLog(NID_APP, "Ignoring key[%ls] with current instance", appId.GetPointer());
131 r = appId.SubString(0, 10, packageId);
132 SysTryReturn(NID_APP, !IsFailed(r), null,
133 E_OBJ_NOT_FOUND, "[%s] Failed to get the package info", GetErrorMessage(E_OBJ_NOT_FOUND));
134 return _AppResourceImpl::ReleaseInstance(packageId);