Removal of core locations accessibility usage
[platform/framework/native/locations.git] / src / FLocLocationProvider.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file        FLocLocationProvider.cpp
20  * @brief       This is the implementation file for the %LocationProvider class.
21  *
22  * This header file contains the definitions of the %LocationProvider class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FLocLocation.h>
27 #include <FLocLocationProvider.h>
28 #include <FSec_AccessController.h>
29 #include <FSec_AccessControlTypes.h>
30 #include "FLoc_LocationImpl.h"
31 #include "FLoc_LocationProviderImpl.h"
32
33
34 using namespace Tizen::Security;
35
36 namespace Tizen { namespace Locations
37 {
38
39 LocationProvider::LocationProvider(void)
40         : Tizen::Base::Object()
41         , __pImpl(null)
42 {
43 }
44
45 LocationProvider::~LocationProvider(void)
46 {
47         delete __pImpl;
48 }
49
50 result
51 LocationProvider::Construct(const LocationCriteria& criteria, ILocationProviderListener& listener)
52 {
53         SysAssertf(__pImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
54
55         __pImpl = new (std::nothrow) _LocationProviderImpl();
56         SysTryReturnResult(NID_LOC, __pImpl, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
57         result r = __pImpl->Construct(criteria, listener);
58         SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to construct location Provider.", GetErrorMessage(r));
59
60         return E_SUCCESS;
61
62 CATCH:
63         delete __pImpl;
64         __pImpl = null;
65         return r;
66 }
67
68 result
69 LocationProvider::StartLocationUpdatesByInterval(int interval)
70 {
71         result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION);
72         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
73         SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "The application is not permitted to call this method.");
74         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
75
76         r = __pImpl->StartLocationUpdatesByInterval(interval);
77         SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the location updates by interval.", GetErrorMessage(r));
78
79         return E_SUCCESS;
80 }
81
82 result
83 LocationProvider::StartLocationUpdatesByDistance(double distance)
84 {
85         result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION);
86         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
87         SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "The application is not permitted to call this method.");
88         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
89
90         r = __pImpl->StartLocationUpdatesByDistance(distance);
91         SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the location updates by distance.", GetErrorMessage(r));
92
93         return E_SUCCESS;
94 }
95
96 result
97 LocationProvider::StopLocationUpdates(void)
98 {
99         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
100
101         result r = __pImpl->StopLocationUpdates();
102         SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to stop the location updates.", GetErrorMessage(r));
103
104         return E_SUCCESS;
105 }
106
107 result
108 LocationProvider::KeepLocationUpdateAwake(bool enable)
109 {
110         result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION);
111         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
112         SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "[%s] The application is not permitted to call this method.",GetErrorMessage(r));
113
114         r = _AccessController::CheckUserPrivilege(_PRV_POWER);
115         SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
116         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
117
118         __pImpl->KeepLocationUpdateAwake(enable);
119         return E_SUCCESS;
120 }
121
122 result
123 LocationProvider::AddMonitoringRegion(const Coordinates& regionCenter, double radius, RegionId& regionId)
124 {
125         result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION);
126         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
127         SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "[%s] The application is not permitted to call this method.",GetErrorMessage(r));
128         r = _AccessController::CheckUserPrivilege(_PRV_POWER);
129         SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
130         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
131
132         r = __pImpl->AddMonitoringRegion(regionCenter, radius, regionId);
133         SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to add monitoring region.", GetErrorMessage(r));
134
135         return E_SUCCESS;
136 }
137
138 result
139 LocationProvider::RemoveMonitoringRegion(RegionId regionId)
140 {
141         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
142
143         result r = __pImpl->RemoveMonitoringRegion(regionId);
144         SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to remove monitoring region with Id (%d).", GetErrorMessage(r), regionId);
145
146         return E_SUCCESS;
147 }
148
149 void
150 LocationProvider::RemoveAllMonitoringRegions(void)
151 {
152         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
153
154         return __pImpl->RemoveAllMonitoringRegions();
155 }
156
157 LocationServiceStatus
158 LocationProvider::GetLocationUpdateStatus(void) const
159 {
160         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
161
162         return __pImpl->GetLocationUpdateStatus();
163 }
164
165 LocationServiceStatus
166 LocationProvider::GetRegionMonitoringStatus(void) const
167 {
168         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
169
170         return __pImpl->GetRegionMonitoringStatus();
171 }
172
173 LocationAccuracy
174 LocationProvider::GetCurrentAccuracy(void) const
175 {
176         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
177
178         return __pImpl->GetCurrentAccuracy();
179 }
180
181 Location
182 LocationProvider::GetLocation(const LocationCriteria& criteria)
183 {
184         result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION);
185         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
186         SysTryReturn(NID_LOC, r == E_SUCCESS, _LocationImpl::GetLocationInstance(), r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
187
188         return _LocationProviderImpl::GetLocation(criteria);
189 }
190
191 Location
192 LocationProvider::GetLastKnownLocation(void)
193 {
194         result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION);
195         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
196         SysTryReturn(NID_LOC, r == E_SUCCESS, _LocationImpl::GetLocationInstance(), r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
197
198         return _LocationProviderImpl::GetLastKnownLocation();
199 }
200 }}