Apply secure logs
[platform/framework/native/appfw.git] / src / app / FAppAppResource.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file        FAppAppResource.cpp
19  * @brief       This is the implementation for the AppResource class.
20  */
21
22 #include <FBaseResult.h>
23 #include <FBaseSysLog.h>
24 #include <FAppAppResource.h>
25
26 #include <FSec_AccessController.h>
27 #include "FApp_AppResourceImpl.h"
28 #include "FApp_AppInfo.h"
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::Security;
33
34 namespace Tizen { namespace App
35 {
36
37 AppResource::AppResource(void)
38         : __pAppResourceImpl(null)
39 {
40 }
41
42
43 AppResource::~AppResource(void)
44 {
45         delete __pAppResourceImpl;
46 }
47
48 result
49 AppResource::GetString(const String& resourceId, String& loadedString) const
50 {
51         SysAssertf(__pAppResourceImpl != null, "Not yet constructed. Construct() should be called before use.");
52         return __pAppResourceImpl->GetString(resourceId, loadedString);
53 }
54
55
56 Bitmap*
57 AppResource::GetBitmapN(const String& imgFilePath, BitmapPixelFormat pixelFormat) const
58 {
59         SysAssertf(__pAppResourceImpl != null, "Not yet constructed. Construct() should be called before use.");
60         return __pAppResourceImpl->GetBitmapN(imgFilePath, pixelFormat);
61 }
62
63
64 Bitmap*
65 AppResource::GetBitmapN(const String& imgFilePath) const
66 {
67         SysAssertf(__pAppResourceImpl != null, "Not yet constructed. Construct() should be called before use.");
68         return __pAppResourceImpl->GetBitmapN(imgFilePath);
69 }
70
71
72 AppResource*
73 AppResource::GetInstance(void)
74 {
75         static AppResource* pSelfAppResource = null;
76         if (pSelfAppResource == null)
77         {
78                 pSelfAppResource = _AppResourceImpl::GetInstanceN(APP_RESOURCE_DEFAULT);
79         }
80
81 //      ClearLastResult();      // as this method does not register any exception.
82         return pSelfAppResource;
83 }
84
85 AppResource*
86 AppResource::LoadAppResource(const Tizen::Base::String& resourcePath)
87 {
88         SysTryReturn(NID_APP, !resourcePath.IsEmpty(), null, E_INVALID_ARG, "Resource path is empty");
89
90         AppResource* pAppResource = _AppResourceImpl::GetInstanceN(APP_RESOURCE_BY_LIBRARY_NAME, resourcePath);
91         if (GetLastResult() == E_DATA_NOT_FOUND)
92         {
93                 SetLastResult(E_FILE_NOT_FOUND);
94         }
95
96         return pAppResource;
97 }
98
99 AppResource*
100 AppResource::GetInstanceByAppId(const AppId& appId)
101 {
102         result r = E_SUCCESS;
103
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.");
106
107         SysTryReturn(NID_APP, !appId.IsEmpty(), null, E_APP_NOT_INSTALLED, "Invalid app id");
108
109         String packageId;
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);
114 }
115
116 result
117 AppResource::ReleaseInstanceByAppId(const AppId& appId)
118 {
119         result r = E_SUCCESS;
120
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.");
123
124         if (appId == _AppInfo::GetApplicationId() || appId == _AppInfo::GetPackageId())
125         {
126                 SysLog(NID_APP, "Ignoring key[%ls] with current instance", appId.GetPointer());
127                 return E_SUCCESS;
128         }
129
130         String packageId;
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);
135 }
136
137 } } // Tizen::App