Geo-fencing optimization
[platform/framework/native/locations.git] / src / FLoc_LocationManager.cpp
index 51928cf..394590e 100644 (file)
@@ -264,43 +264,6 @@ _LocationManager::GetAccuracyLevel(double horAcc) const
        }
 }
 
-bool
-_LocationManager::IsAppEnabled(void)
-{
-       Boolean enable(false);
-       Monitor synchronizer;
-       result r = synchronizer.Construct();
-       SysTryReturn(NID_LOC, r == E_SUCCESS, false, r, "[%s] Propogating.", GetErrorMessage(r));
-
-       std::unique_ptr< Tizen::Base::Collection::ArrayList > pArgList(new (std::nothrow) ArrayList());
-       SysTryReturn(NID_LOC, pArgList, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       r = pArgList->Construct();
-       SysTryReturn(NID_LOC, r == E_SUCCESS, false, r, "[%s] Propogating.", GetErrorMessage(r));
-
-       r = pArgList->Add(enable);
-       SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Propogating", GetErrorMessage(r));
-       r = pArgList->Add(synchronizer);
-       SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Propogating", GetErrorMessage(r));
-
-       r = synchronizer.Enter();
-       SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Propogating", GetErrorMessage(r));
-
-       r = SendUserEvent(REQ_ID_GET_APP_ACCESSIBILITY, pArgList.get());
-       SysTryCatch(NID_LOC, r == E_SUCCESS, synchronizer.Exit(), r, "[%s] Propogating", GetErrorMessage(r));
-       pArgList.release();
-
-       SysLog(NID_LOC, "Wait till location manager checks if the app is allowed to use location.");
-       r = synchronizer.Wait();
-       SysTryCatch(NID_LOC, r == E_SUCCESS, synchronizer.Exit(), r, "[%s] Propogating", GetErrorMessage(r));
-       SysLog(NID_LOC, "Application setting state is '%ls'.", enable.ToString().GetPointer());
-       synchronizer.Exit();
-
-       return enable.ToBool();
-
-CATCH:
-       return false;
-}
-
 _LocationManager*
 _LocationManager::GetInstance(void)
 {
@@ -578,7 +541,7 @@ NOTIFY:
 result
 _LocationManager::SetLocationInformation(double latitude, double longitude, double altitude, time_t timestamp, location_method_e locMethod, Location* pLocation)
 {
-       SysLog(NID_LOC, "Location Information is: Latitude (%lf), Longitude (%lf), Altitude (%lf), TimeStamp (%ld), Location method (%d)", latitude, longitude, altitude, timestamp, locMethod);
+       SysSecureLog(NID_LOC, "Location Information is: Latitude (%lf), Longitude (%lf), Altitude (%lf), TimeStamp (%ld), Location method (%d)", latitude, longitude, altitude, timestamp, locMethod);
 
        int res = -1;
        LocationAccuracy requiredAcc;
@@ -691,10 +654,9 @@ _LocationManager::SetLocationInformation(double latitude, double longitude, doub
 void
 _LocationManager::SendLocationCallbacks(void)
 {
-       bool isAllowed = GetAppAccessibility();
        const Location* pBestLocation = FindBestLocation();
 
-       SysLog(NID_LOC, "Send location(validity: %x) and accessibility(%x) through the callback.", pBestLocation->IsValid(), isAllowed);
+       SysLog(NID_LOC, "Send location(validity: %x) through the callback.", pBestLocation->IsValid());
        unique_ptr< Location > pLocation(new (std::nothrow) Location(*pBestLocation));
        SysTryReturnVoidResult(NID_LOC, pLocation != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
@@ -704,10 +666,6 @@ _LocationManager::SendLocationCallbacks(void)
                const _LocationRequestInfo* pLocRequestInfo = static_cast< const _LocationRequestInfo* >(__pLocRequestInfoList->GetAt(i));
                if (interval % pLocRequestInfo->GetInterval() == 0 && pLocRequestInfo->GetListener() != null)
                {
-                       if (!isAllowed)
-                       {
-                               _LocationImpl::GetInstance(*pLocation)->TurnOnDeniedFlag();
-                       }
                        pLocRequestInfo->GetListener()->OnLocationUpdated(pLocRequestInfo->GetRequestId(), *pLocation.get());
                }
        }
@@ -767,7 +725,7 @@ _LocationManager::GetLastKnownLocation(location_method_e nativeLocMethod)
 
                int res = location_manager_get_last_position(nativeHandle, &altitude, &latitude, &longitude, &timestampPosition);
                SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to fetch last position from nativeHandle(%x).", nativeHandle);
-               SysLog(NID_LOC, "Last position(latitude: %lf, longitude: %lf, altitude: %lf, timestamp: %ld",
+               SysSecureLog(NID_LOC, "Last position(latitude: %lf, longitude: %lf, altitude: %lf, timestamp: %ld",
                        latitude, longitude, altitude, timestampPosition);
 
                Coordinates coord;
@@ -900,11 +858,11 @@ _LocationManager::FindBestLocation(void)
                long long gpsTimestamp = 0;
                long long wpsTimestamp = 0;
 
-               if (__gpsHandler.pLocation->IsValid() && !_LocationImpl::GetInstance(*__gpsHandler.pLocation)->IsDenied())
+               if (__gpsHandler.pLocation->IsValid())
                {
                        gpsTimestamp = _LocationImpl::GetInstance(*__gpsHandler.pLocation)->GetTimestampInMs();
                }
-               if (__wpsHandler.pLocation->IsValid() && !_LocationImpl::GetInstance(*__wpsHandler.pLocation)->IsDenied())
+               if (__wpsHandler.pLocation->IsValid())
                {
                        wpsTimestamp = _LocationImpl::GetInstance(*__wpsHandler.pLocation)->GetTimestampInMs();
                }
@@ -985,7 +943,7 @@ _LocationManager::GetLocation(location_method_e nativeLocMethod)
        }
 
        res = location_manager_get_position(nativeHandle, &altitude, &latitude, &longitude, &timestamp);
-       SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM,  "[E_SYSTEM] Failed to obtain the natvie location information for the method (%x)", nativeLocMethod);
+       SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM,  "Failed to obtain the natvie location information for the method (%x)", nativeLocMethod);
 
        if (res == 0)
        {
@@ -1056,6 +1014,7 @@ _LocationManager::OnStart(void)
        __gpsHandler.pLocation= std::move(pGpsLocation);
        __wpsHandler.pLocation= std::move(pWpsLocation);
 
+       __waitLoopListener.SetValue(true);
        SysLog(NID_LOC, "All the resources for location manager successfully created.");
        return true;
 
@@ -1075,6 +1034,8 @@ CATCH:
 void
 _LocationManager::OnStop(void)
 {
+       __waitLoopListener.SetValue(false);
+
        if (__gpsHandler.handle)
        {
                location_manager_destroy(__gpsHandler.handle);
@@ -1155,29 +1116,6 @@ _LocationManager::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
        }
        break;
 
-       case REQ_ID_GET_APP_ACCESSIBILITY:
-       {
-               SysLog(NID_LOC, "REQ_ID_GET_APP_ACCESSIBILITY");
-               SysTryReturnVoidResult(NID_LOC, pArgs, E_INVALID_ARG, "[E_INVALID_ARG] Null argument encountered. Ignored.");
-
-               Boolean* pEnabled = static_cast< Boolean* >(pArgs->GetAt(0));
-               Monitor* pMonitor = static_cast< Monitor* >(pArgs->GetAt(1));
-               SysAssertf(pEnabled != null && pMonitor != null, "Invalid request has been made on the location manager.");
-               if (pMonitor != null)
-               {
-                       pMonitor->Enter();
-                       if (pEnabled != null)
-                       {
-                               pEnabled->value = GetAppAccessibility();
-                       }
-                       pMonitor->Notify();
-                       pMonitor->Exit();
-               }
-               pArgs->RemoveAt(1);
-               pArgs->RemoveAt(0);
-       }
-       break;
-
        case REQ_ID_GET_LAST_LOCATION:
        {
                SysLog(NID_LOC, "REQ_ID_GET_LAST_LOCATION");
@@ -1374,6 +1312,8 @@ _LocationManager::InitLocationManager(void)
        r = pLocMgr->Start();
        SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Falied to start the Location Manager. Propagating.", GetErrorMessage(r));
 
+       WaitingLoop::GetInstance()->Wait(*pLocMgr->GetWaitLoopListener());
+
        __pUniqueInstance = pLocMgr.release();
        std::atexit(DestroyLocationManager);
 }
@@ -1384,31 +1324,4 @@ _LocationManager::DestroyLocationManager(void)
        delete __pUniqueInstance;
 }
 
-bool
-_LocationManager::GetAppAccessibility(void)
-{
-       int res = 0;
-       static bool appRegistered = false;
-       if (!appRegistered)
-       {
-               static const char COMMAND_REGISTER_APP[] = "ADD_APPLIST";
-               if (location_manager_send_command(COMMAND_REGISTER_APP) == LOCATIONS_ERROR_NONE)
-               {
-#ifdef _OSP_EMUL_
-                       static const char COMMAND_ENABLE_APP[] = "ACCESSIBILITY:1";
-                       res = location_manager_send_command(COMMAND_ENABLE_APP);
-                       SysTryReturn(NID_LOC, res == 0, false, E_SYSTEM,
-                                                "[%s] Failed to register the application.", GetErrorMessage(E_SYSTEM));
-#endif
-                       appRegistered = true;
-               }
-       }
-
-       location_accessibility_state_e accessState;
-       res = location_manager_get_accessibility_state(&accessState);
-       SysTryReturn(NID_LOC, res == 0, false, E_SYSTEM,
-                                "[%s] Failed to get the application location setting.", GetErrorMessage(E_SYSTEM));
-
-       return (accessState == LOCATIONS_ACCESS_STATE_ALLOWED) ? true : false;
-}
 }}