_I(BLUE("Read"));
_J("Option", option);
- Json dataRead = __engine.getPlaces();
+ std::string request;
+ Json dataRead;
+ option.get(NULL, PLACE_DETECTION_REQUEST, &request);
+ if (request == PLACE_DETECTION_REQUEST_CONSENT) {
+ dataRead.set(NULL, PLACE_DETECTION_REQUEST_CONSENT, UserPlaces::getConsent() ? MYPLACE_SETTING_VALUE_TRUE : MYPLACE_SETTING_VALUE_FALSE);
+ } else if (request == PLACE_DETECTION_REQUEST_LIST) {
+ dataRead = UserPlaces::getPlaces();
+ } else {
+ replyToRead(option, ERR_INVALID_PARAMETER, dataRead);
+ return ERR_INVALID_PARAMETER;
+ }
- /*
- * The below function needs to be called once.
- * It does not need to be called within this read() function.
- * In can be called later, in another scope.
- * Please just be sure that, the 2nd input parameter "option" should be the same to the
- * "option" parameter received via ctx::PlaceRecognitionProvider::read().
- */
replyToRead(option, ERR_NONE, dataRead);
-
return ERR_NONE;
}
int ctx::PlaceRecognitionProvider::write(ctx::Json data, ctx::Json* requestResult)
{
- return ERR_NOT_SUPPORTED;
+ _I(BLUE("Write"));
+ _J("Data", data);
+
+ std::string value;
+ IF_FAIL_RETURN_TAG(
+ data.get(NULL, PLACE_DETECTION_REQUEST_CONSENT, &value),
+ ERR_NOT_SUPPORTED,
+ _E,
+ "Invalid write request");
+ if (value == MYPLACE_SETTING_VALUE_TRUE) {
+ UserPlaces::setConsent(true);
+ } else if (value == MYPLACE_SETTING_VALUE_FALSE) {
+ UserPlaces::setConsent(false);
+ } else {
+ _E("Invalid write parameter %s = '%s'", PLACE_DETECTION_REQUEST_CONSENT, value.c_str());
+ return ERR_INVALID_PARAMETER;
+ }
+ return ERR_NONE;
}
bool ctx::PlaceRecognitionProvider::isSupported()
#include <MyPlaceTypes.h>
#include <gmodule.h>
#include <DatabaseManager.h>
+#include <string>
#define SO_PATH "/usr/lib/context-service/libctx-prvd-my-place-places-detector.so"
WIFI_APS_MAP_COLUMN_NETWORK_NAME \
" FROM " WIFI_APS_MAP_TABLE
+#define __MYPLACE_SETTINGS_TABLE_COLUMNS \
+ MYPLACE_SETTINGS_COLUMN_KEY " TEXT NOT NULL UNIQUE, "\
+ MYPLACE_SETTINGS_COLUMN_VALUE " TEXT NOT NULL"\
+
+#define __GET_USER_CONSENT_QUERY "SELECT "\
+ MYPLACE_SETTINGS_COLUMN_VALUE \
+ " FROM " MYPLACE_SETTINGS_TABLE \
+ " WHERE " MYPLACE_SETTINGS_COLUMN_KEY \
+ "='" MYPLACE_SETTING_KEY_USER_CONSENT "';"
+
ctx::UserPlaces::UserPlaces(PlaceRecogMode energyMode):
__visitDetector(nullptr),
__timerId(-1)
{
+ __dbCreateMyPlaceSettingsTable();
+ bool userConsent = getConsent();
time_t now = std::time(nullptr);
__visitDetector = new(std::nothrow) VisitDetector(now, energyMode);
if (__visitDetector == nullptr) {
bool ctx::UserPlaces::onTimerExpired(int timerId)
{
- _D("mmastern try to detect places from UserPlaces");
+ _D("Try to detect places from user visits");
GModule *soHandle = g_module_open(SO_PATH, G_MODULE_BIND_LAZY);
IF_FAIL_RETURN_TAG(soHandle, true, _E, "%s", g_module_error());
gpointer symbol;
if (!g_module_symbol(soHandle, "detectPlaces", &symbol) || symbol == NULL) {
- _E("mmastern %s", g_module_error());
+ _E("%s", g_module_error());
g_module_close(soHandle);
return true;
}
_D("number of all places in vector: %d", places.size());
return places;
}
+
+void ctx::UserPlaces::__dbCreateMyPlaceSettingsTable()
+{
+ DatabaseManager dbManager;
+ bool ret = dbManager.createTable(0, MYPLACE_SETTINGS_TABLE, __MYPLACE_SETTINGS_TABLE_COLUMNS);
+ _D("db: Myplace setting Table Creation Result: %s", ret ? "SUCCESS" : "FAIL");
+}
+
+void ctx::UserPlaces::setConsent(bool consent)
+{
+ DatabaseManager dbManager;
+ std::vector<Json> records;
+ std::stringstream query;
+ query << "REPLACE INTO " MYPLACE_SETTINGS_TABLE \
+ " ( " MYPLACE_SETTINGS_COLUMN_KEY ", " MYPLACE_SETTINGS_COLUMN_VALUE " )" \
+ " VALUES ( '" MYPLACE_SETTING_KEY_USER_CONSENT "', '";
+ if (consent)
+ query << MYPLACE_SETTING_VALUE_TRUE;
+ else
+ query << MYPLACE_SETTING_VALUE_FALSE;
+ query << "' );";
+
+ bool ret = dbManager.executeSync(query.str().c_str(), &records);
+ IF_FAIL_VOID_TAG(ret, _E, "Setting user consent (value = %d) to database failed", consent);
+}
+
+bool ctx::UserPlaces::getConsent()
+{
+ DatabaseManager dbManager;
+ std::vector<Json> records;
+ bool ret = dbManager.executeSync(__GET_USER_CONSENT_QUERY, &records);
+ IF_FAIL_RETURN_TAG(ret, MYPLACE_SETTING_USER_CONSENT_DEFAULT, _E, "Getting user consent from database failed");
+ if (records.size()) {
+ std::string consentStr;
+ records[0].get(NULL, MYPLACE_SETTINGS_COLUMN_VALUE, &consentStr);
+ if (consentStr == MYPLACE_SETTING_VALUE_TRUE) {
+ return true;
+ } else if (consentStr == MYPLACE_SETTING_VALUE_FALSE) {
+ return false;
+ } else {
+ _E("Unknown user consent value \"%s\" from db, it should be \"%s\" or \"%s\"",
+ consentStr.c_str(),
+ MYPLACE_SETTING_VALUE_TRUE,
+ MYPLACE_SETTING_VALUE_FALSE);
+ }
+ }
+ // consent record empty or unknown value
+ setConsent(MYPLACE_SETTING_USER_CONSENT_DEFAULT);
+ return MYPLACE_SETTING_USER_CONSENT_DEFAULT;
+}
std::map<std::string, std::string> &wifiAPsMap);
static std::vector<std::shared_ptr<Place>> __getPlaces();
static Json __composeJson(std::vector<std::shared_ptr<Place>> places);
+ static void __dbCreateMyPlaceSettingsTable();
bool onTimerExpired(int timerId);
void setMode(PlaceRecogMode energyMode);
static ctx::Json getPlaces();
+ static void setConsent(bool consent);
+ static bool getConsent();
}; /* class UserPlaces */
*/
#define PLACES_CATEGER_MIN_VISITS_PER_WORK 2
+/*
+ * Default user consent value for place detection
+ */
+#define MYPLACE_SETTING_USER_CONSENT_DEFAULT false
+
#endif /* End of _CONTEXT_PLACE_RECOGNITION_USER_PLACES_PARAMS_H_ */
#include <ctime>
#include <MyPlaceTypes.h>
-// Context Items
-#define PLACE_PRIV_RECOGNITION "location" // TODO: unused?
-
// Database
-#define VISIT_TABLE "place_status_user_place_visit"
+#define VISIT_TABLE "Log_Myplace_Visit"
#define VISIT_COLUMN_START_TIME "start_time"
#define VISIT_COLUMN_END_TIME "end_time"
#define VISIT_COLUMN_WIFI_APS "wifi_aps"
#define VISIT_COLUMN_CATEG_WORK "categ_work"
#define VISIT_COLUMN_CATEG_OTHER "categ_other"
-#define WIFI_APS_MAP_TABLE "place_status_user_place_wifi_aps_map"
+#define WIFI_APS_MAP_TABLE "Log_Myplace_WifiAPsMap"
#define WIFI_APS_MAP_COLUMN_MAC "mac"
#define WIFI_APS_MAP_COLUMN_NETWORK_NAME "network_name"
#define WIFI_APS_MAP_COLUMN_INSERT_TIME "insert_time"
-#define PLACE_TABLE "place_status_user_place"
+#define PLACE_TABLE "Log_Myplace_Place"
#define PLACE_COLUMN_CATEG_ID "categ_id"
#define PLACE_COLUMN_CATEG_CONFIDENCE "categ_confidence"
#define PLACE_COLUMN_NAME "name"
#define PLACE_COLUMN_WIFI_APS "wifi_aps"
#define PLACE_COLUMN_CREATE_DATE "create_date"
-#define WIFI_TABLE_NAME "place_status_user_place_wifi"
+#define WIFI_TABLE "Log_Myplace_Wifi"
#define WIFI_COLUMN_TIMESTAMP "timestamp"
#define WIFI_COLUMN_BSSID "bssid"
#define WIFI_COLUMN_ESSID "essid"
-#define LOCATION_TABLE_NAME "place_status_user_place_location"
-#define LOCATION_COLUMN_LATITUDE "geo_latitude"
-#define LOCATION_COLUMN_LONGITUDE "geo_longitude"
+#define LOCATION_TABLE "Log_Myplace_Location"
+#define LOCATION_COLUMN_LATITUDE "latitude"
+#define LOCATION_COLUMN_LONGITUDE "longitude"
#define LOCATION_COLUMN_ACCURACY "accuracy"
#define LOCATION_COLUMN_TIMESTAMP "timestamp"
#ifdef TIZEN_ENGINEER_MODE
#define LOCATION_COLUMN_METHOD "method"
#endif /* TIZEN_ENGINEER_MODE */
+#define MYPLACE_SETTINGS_TABLE "Myplace_Settings"
+#define MYPLACE_SETTINGS_COLUMN_KEY "key"
+#define MYPLACE_SETTINGS_COLUMN_VALUE "value"
+#define MYPLACE_SETTING_KEY_USER_CONSENT PLACE_DETECTION_REQUEST_CONSENT
+
enum PlaceRecogMode {
PLACE_RECOG_HIGH_ACCURACY_MODE = 0,
PLACE_RECOG_LOW_POWER_MODE = 1
int ctx::LocationLogger::__dbCreateTable()
{
DatabaseManager dbManager;
- bool ret = dbManager.createTable(0, LOCATION_TABLE_NAME, __LOCATION_CREATE_TABLE_COLUMNS, NULL, NULL);
+ bool ret = dbManager.createTable(0, LOCATION_TABLE, __LOCATION_CREATE_TABLE_COLUMNS, NULL, NULL);
_D("%s -> Table Creation Request", ret ? "SUCCESS" : "FAIL");
return 0;
}
DatabaseManager dbManager;
int64_t rowId;
- bool ret = dbManager.insertSync(LOCATION_TABLE_NAME, data, &rowId);
+ bool ret = dbManager.insertSync(LOCATION_TABLE, data, &rowId);
_D("%s -> DB: location table insert result", ret ? "SUCCESS" : "FAIL");
return ret;
}
int ctx::WifiLogger::__dbCreateTable()
{
DatabaseManager dbManager;
- bool ret = dbManager.createTable(0, WIFI_TABLE_NAME, __WIFI_CREATE_TABLE_COLUMNS, NULL, NULL);
+ bool ret = dbManager.createTable(0, WIFI_TABLE, __WIFI_CREATE_TABLE_COLUMNS, NULL, NULL);
_D("Table Creation Request: %s", ret ? "SUCCESS" : "FAIL");
return ret;
}
std::stringstream query;
const char* separator = " ";
query << "BEGIN TRANSACTION; \
- INSERT INTO " WIFI_TABLE_NAME " \
+ INSERT INTO " WIFI_TABLE " \
( " WIFI_COLUMN_BSSID ", " WIFI_COLUMN_ESSID ", " WIFI_COLUMN_TIMESTAMP " ) \
VALUES";
for (MacEvent mac_event : __logs) {