Review fixes.

This commit is contained in:
Daria Volvenkova 2018-10-24 16:09:34 +03:00 committed by Aleksandr Zatsepin
parent 8ab3a1f5bf
commit 83ad7eacd0
8 changed files with 118 additions and 73 deletions

View file

@ -22,20 +22,24 @@ Java_com_mapswithme_maps_LightFramework_nativeGetNumberUnsentUGC(JNIEnv * env, j
}
JNIEXPORT jobjectArray JNICALL
Java_com_mapswithme_maps_LightFramework_nativeGetLocalAdsFeatures(JNIEnv * env, jclass clazz, jdouble lat, jdouble lon,
jdouble radiusInMeters, jint maxCount)
Java_com_mapswithme_maps_LightFramework_nativeGetLocalAdsFeatures(JNIEnv * env, jclass clazz,
jdouble lat, jdouble lon,
jdouble radiusInMeters,
jint maxCount)
{
Framework framework(REQUEST_TYPE_LOCAL_ADS_FEATURES);
auto const features = framework.Get<REQUEST_TYPE_LOCAL_ADS_FEATURES>(lat, lon, radiusInMeters, maxCount);
auto const features = framework.Get<REQUEST_TYPE_LOCAL_ADS_FEATURES>(lat, lon, radiusInMeters,
maxCount);
static jclass const geoFenceFeatureClazz = jni::GetGlobalClassRef(env,
"com/mapswithme/maps/api/GeoFenceFeature");
static jclass const geoFenceFeatureClazz =
jni::GetGlobalClassRef(env, "com/mapswithme/maps/geofence/GeoFenceFeature");
// Java signature : GeoFenceFeature(long mwmVersion, String countryId, int featureIndex,
// double latitude, double longitude)
static jmethodID const geoFenceFeatureConstructor =
jni::GetConstructorID(env, geoFenceFeatureClazz, "(JLjava/lang/String;IDD)V");
return jni::ToJavaArray(env, geoFenceFeatureClazz, features, [&](JNIEnv * jEnv, CampaignFeature const & data)
return jni::ToJavaArray(env, geoFenceFeatureClazz, features, [&](JNIEnv * jEnv,
CampaignFeature const & data)
{
jni::TScopedLocalRef const countryId(env, jni::ToJavaString(env, data.m_countryId));
return env->NewObject(geoFenceFeatureClazz, geoFenceFeatureConstructor,
@ -48,14 +52,16 @@ Java_com_mapswithme_maps_LightFramework_nativeGetLocalAdsFeatures(JNIEnv * env,
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_LightFramework_nativeLogLocalAdsEvent(JNIEnv * env, jclass clazz, jint type,
jdouble lat, jdouble lon, jint accuracyInMeters,
jlong mwmVersion, jstring countryId, jint featureIndex)
Java_com_mapswithme_maps_LightFramework_nativeLogLocalAdsEvent(JNIEnv * env, jclass clazz,
jint type, jdouble lat, jdouble lon,
jint accuracyInMeters,
jlong mwmVersion, jstring countryId,
jint featureIndex)
{
Framework framework(REQUEST_TYPE_LOCAL_ADS_STATISTICS);
local_ads::Event event(static_cast<local_ads::EventType>(type), static_cast<long>(mwmVersion),
jni::ToNativeString(env, countryId), static_cast<uint32_t>(featureIndex),
static_cast<uint8_t>(1) /* zoom level*/, local_ads::Clock::now(),
static_cast<uint8_t>(1) /* zoom level */, local_ads::Clock::now(),
static_cast<double>(lat), static_cast<double>(lon),
static_cast<uint16_t>(accuracyInMeters));
framework.Get<REQUEST_TYPE_LOCAL_ADS_STATISTICS>()->RegisterEvent(std::move(event));

View file

@ -2,14 +2,17 @@ package com.mapswithme.maps;
import android.support.annotation.NonNull;
import com.mapswithme.maps.api.GeoFenceFeature;
import com.mapswithme.maps.geofence.GeoFenceFeature;
public class LightFramework
{
public static native boolean nativeIsAuthenticated();
public static native int nativeGetNumberUnsentUGC();
@NonNull
public static native GeoFenceFeature[] nativeGetLocalAdsFeatures(double lat, double lon,
double radiusInMeters, int maxCount);
public static native void nativeLogLocalAdsEvent(int type, double lat, double lon, int accuracyInMeters,
long mwmVersion, @NonNull String countryId, int featureIndex);
double radiusInMeters,
int maxCount);
public static native void nativeLogLocalAdsEvent(int type, double lat, double lon,
int accuracyInMeters, long mwmVersion,
@NonNull String countryId, int featureIndex);
}

View file

@ -1,23 +0,0 @@
package com.mapswithme.maps.api;
/**
* Represents CampaignFeature from core.
*/
public class GeoFenceFeature
{
public final long mwmVersion;
public final String countryId;
public final int featureIndex;
public final double latitude;
public final double longitude;
public GeoFenceFeature(long mwmVersion, String countryId, int featureIndex,
double latitude, double longitude)
{
this.mwmVersion = mwmVersion;
this.countryId = countryId;
this.featureIndex = featureIndex;
this.latitude = latitude;
this.longitude = longitude;
}
}

View file

@ -44,19 +44,16 @@ public class NotificationService extends JobIntentService
private boolean notifyIsNotAuthenticated()
{
final boolean isAuthenticated = LightFramework.nativeIsAuthenticated();
final int numberUnsentUgc = LightFramework.nativeGetNumberUnsentUGC();
if (!PermissionsUtils.isExternalStorageGranted() ||
!NetworkPolicy.getCurrentNetworkUsageStatus() ||
isAuthenticated ||
numberUnsentUgc < MIN_COUNT_UNSENT_UGC)
LightFramework.nativeIsAuthenticated() ||
LightFramework.nativeGetNumberUnsentUGC() < MIN_COUNT_UNSENT_UGC)
{
LOGGER.d(TAG, "Authentication notification is rejected. External storage granted: " +
PermissionsUtils.isExternalStorageGranted() + ". Is user authenticated: " +
isAuthenticated + ". Current network usage status: " +
LightFramework.nativeIsAuthenticated() + ". Current network usage status: " +
NetworkPolicy.getCurrentNetworkUsageStatus() + ". Number of unsent UGC: " +
numberUnsentUgc);
LightFramework.nativeGetNumberUnsentUGC());
return false;
}

View file

@ -0,0 +1,52 @@
package com.mapswithme.maps.geofence;
import android.support.annotation.NonNull;
/**
* Represents CampaignFeature from core.
*/
public class GeoFenceFeature
{
private final long mwmVersion;
@NonNull
private final String countryId;
private final int featureIndex;
private final double latitude;
private final double longitude;
public GeoFenceFeature(long mwmVersion, @NonNull String countryId, int featureIndex,
double latitude, double longitude)
{
this.mwmVersion = mwmVersion;
this.countryId = countryId;
this.featureIndex = featureIndex;
this.latitude = latitude;
this.longitude = longitude;
}
public long getMwmVersion()
{
return mwmVersion;
}
@NonNull
public String getCountryId()
{
return countryId;
}
public int getFeatureIndex()
{
return featureIndex;
}
public double getLatitude()
{
return latitude;
}
public double getLongitude()
{
return longitude;
}
}

View file

@ -198,8 +198,6 @@ std::vector<uint8_t> SerializeForServer(std::list<local_ads::Event> const & even
ASSERT(!events.empty(), ());
auto root = base::NewJSONObject();
ToJSONObject(*root, "userId", userId);
static std::string offlineId = GetPlatform().MacAddress(true /* md5Decoded */);
ToJSONObject(*root, "offlineId", offlineId);
ToJSONObject(*root, "countryId", events.front().m_countryId);
ToJSONObject(*root, "mwmVersion", events.front().m_mwmVersion);
auto eventsNode = base::NewJSONArray();

View file

@ -52,10 +52,11 @@ auto constexpr kMaxDownloadingAttempts = 5;
auto constexpr kHiddenFeaturePriority = 1;
double constexpr kMinCheckDistanceInMeters = 10.0;
auto constexpr kMinCheckInterval = std::chrono::minutes(1);
double constexpr kMinCheckDistanceInMeters = 5.0;
double constexpr kMinSearchRadiusInMeters = 20.0;
double constexpr kMaxAllowableAccuracyInMeters = 20.0;
uint32_t constexpr kMaxHitCount = 3;
auto const kMinCheckInterval = std::chrono::minutes(1);
void SerializeCampaign(FileWriter & writer, std::string const & countryName,
LocalAdsManager::Timestamp const & ts,
@ -270,7 +271,7 @@ void LocalAdsManager::Start()
// Read persistence data.
ReadCampaignFile(campaignFile);
Invalidate();
InvalidateImpl();
});
m_statistics.Startup();
@ -588,26 +589,32 @@ void LocalAdsManager::WriteFeaturesFile(std::string const & featuresFile)
void LocalAdsManager::Invalidate()
{
m_lastMwms.clear();
GetPlatform().RunTask(Platform::Thread::File, [this]
{
DeleteAllLocalAdsMarks();
m_drapeEngine.SafeCall(&df::DrapeEngine::RemoveAllCustomFeatures);
CampaignData campaignData;
{
std::lock_guard<std::mutex> lock(m_campaignsMutex);
for (auto const & info : m_info)
{
auto data = ParseCampaign(info.second.m_data, m_getMwmIdByNameFn(info.first),
info.second.m_created, m_getFeatureByIdFn);
campaignData.insert(data.begin(), data.end());
}
}
UpdateFeaturesCache(ReadCampaignFeatures(campaignData));
CreateLocalAdsMarks(std::move(campaignData));
InvalidateImpl();
});
}
void LocalAdsManager::InvalidateImpl()
{
DeleteAllLocalAdsMarks();
m_drapeEngine.SafeCall(&df::DrapeEngine::RemoveAllCustomFeatures);
CampaignData campaignData;
{
std::lock_guard<std::mutex> lock(m_campaignsMutex);
for (auto const & info : m_info)
{
auto data = ParseCampaign(info.second.m_data, m_getMwmIdByNameFn(info.first),
info.second.m_created, m_getFeatureByIdFn);
campaignData.insert(data.begin(), data.end());
}
}
UpdateFeaturesCache(ReadCampaignFeatures(campaignData));
CreateLocalAdsMarks(std::move(campaignData));
}
LocalAdsManager::CampaignData LocalAdsManager::ParseCampaign(std::vector<uint8_t> const & rawData,
MwmSet::MwmId const & mwmId,
Timestamp timestamp,
@ -652,12 +659,12 @@ LocalAdsManager::CampaignData LocalAdsManager::ParseCampaign(std::vector<uint8_t
void LocalAdsManager::CreateLocalAdsMarks(CampaignData && campaignData)
{
if (m_bmManager == nullptr)
return;
// Here we copy campaign data, because we can create user marks only from UI thread.
GetPlatform().RunTask(Platform::Thread::Gui, [this, campaignData = std::move(campaignData)]()
{
if (m_bmManager == nullptr)
return;
auto editSession = m_bmManager->GetEditSession();
for (auto const & data : campaignData)
{
@ -673,11 +680,11 @@ void LocalAdsManager::CreateLocalAdsMarks(CampaignData && campaignData)
void LocalAdsManager::DeleteLocalAdsMarks(MwmSet::MwmId const & mwmId)
{
if (m_bmManager == nullptr)
return;
GetPlatform().RunTask(Platform::Thread::Gui, [this, mwmId]()
{
if (m_bmManager == nullptr)
return;
m_bmManager->GetEditSession().DeleteUserMarks<LocalAdsMark>(UserMark::Type::LOCAL_ADS,
[&mwmId](LocalAdsMark const * mark)
{
@ -688,11 +695,11 @@ void LocalAdsManager::DeleteLocalAdsMarks(MwmSet::MwmId const & mwmId)
void LocalAdsManager::DeleteAllLocalAdsMarks()
{
if (m_bmManager == nullptr)
return;
GetPlatform().RunTask(Platform::Thread::Gui, [this]()
{
if (m_bmManager == nullptr)
return;
m_bmManager->GetEditSession().ClearGroup(UserMark::Type::LOCAL_ADS);
});
}
@ -830,6 +837,9 @@ void LocalAdsManager::OnLocationUpdate(location::GpsInfo const & info, int zoomL
if (!m_isEnabled)
return;
if (info.m_horizontalAccuracy > kMaxAllowableAccuracyInMeters)
return;
if (std::chrono::steady_clock::now() < (m_lastCheckTime + kMinCheckInterval))
return;

View file

@ -104,6 +104,8 @@ private:
void Start();
void InvalidateImpl();
void ProcessRequests(std::set<Request> && campaignMwms);
void ReadCampaignFile(std::string const & campaignFile);