[new downloader][android] add: Downloader statistics.

This commit is contained in:
Alexander Marchuk 2016-03-01 13:58:51 +03:00 committed by Sergey Yershov
parent 41fcaa3192
commit b9c8583a94
14 changed files with 153 additions and 41 deletions

View file

@ -104,7 +104,8 @@ static void MigrationStatusChangedCallback(TCountryId const & countryId, bool ke
case NodeStatus::Undefined:
case NodeStatus::Error:
OnMigrationError(attrs.m_error);
if (attrs.m_mwmCounter == 1)
OnMigrationError(attrs.m_error);
break;
}
}
@ -356,8 +357,8 @@ static void StatusChangedCallback(shared_ptr<jobject> const & listenerRef, TCoun
NodeAttrs attrs;
GetStorage().GetNodeAttrs(countryId, attrs);
jmethodID const methodID = jni::GetMethodID(env, *listenerRef, "onStatusChanged", "(Ljava/lang/String;I)V");
env->CallVoidMethod(*listenerRef, methodID, jni::ToJavaString(env, countryId), attrs.m_status);
jmethodID const methodID = jni::GetMethodID(env, *listenerRef, "onStatusChanged", "(Ljava/lang/String;IZ)V");
env->CallVoidMethod(*listenerRef, methodID, jni::ToJavaString(env, countryId), attrs.m_status, (attrs.m_mwmCounter == 1);
}
static void ProgressChangedCallback(shared_ptr<jobject> const & listenerRef, TCountryId const & countryId, TLocalAndRemoteSize const & sizes)

View file

@ -69,7 +69,7 @@ jobject ToJavaResult(Result result, bool hasPosition, double lat, double lon)
auto const address = g_framework->NativeFramework()->GetSearchResultAddress(result);
jni::TScopedLocalRef featureType (env, jni::ToJavaString(env, result.GetFeatureType()));
jni::TScopedLocalRef featureType(env, jni::ToJavaString(env, result.GetFeatureType()));
jni::TScopedLocalRef region(env, jni::ToJavaString(env, address.FormatAddress(search::AddressInfo::SEARCH_RESULT)));
jni::TScopedLocalRef dist(env, jni::ToJavaString(env, distance));
jni::TScopedLocalRef cuisine(env, jni::ToJavaString(env, result.GetCuisine()));

View file

@ -178,9 +178,9 @@ public class DownloadResourcesActivity extends BaseMwmFragmentActivity
private final MapManager.StorageCallback mCountryDownloadListener = new MapManager.StorageCallback()
{
@Override
public void onStatusChanged(String countryId, int newStatus)
public void onStatusChanged(String countryId, int newStatus, boolean isLeafNode)
{
if (newStatus == CountryItem.STATUS_DONE)
if (newStatus == CountryItem.STATUS_DONE && isLeafNode)
{
mAreResourcesDownloaded = true;
showMap();

View file

@ -25,6 +25,7 @@ import com.mapswithme.util.ThemeSwitcher;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Yota;
import com.mapswithme.util.statistics.AlohaHelper;
import com.mapswithme.util.statistics.Statistics;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseInstallation;
@ -51,11 +52,15 @@ public class MwmApplication extends Application
private final MapManager.StorageCallback mStorageCallbacks = new MapManager.StorageCallback()
{
@Override
public void onStatusChanged(String countryId, int newStatus)
public void onStatusChanged(String countryId, int newStatus, boolean isLeafNode)
{
Notifier.cancelDownloadSuggest();
if (newStatus == CountryItem.STATUS_FAILED)
Notifier.notifyDownloadFailed(countryId);
if (newStatus == CountryItem.STATUS_FAILED && isLeafNode)
{
CountryItem country = CountryItem.fill(countryId);
Notifier.notifyDownloadFailed(country);
MapManager.sendErrorStat(Statistics.EventName.DOWNLOADER_ERROR, country.errorCode);
}
}
@Override

View file

@ -34,14 +34,12 @@ public final class Notifier
placeNotification(title, countryName, pi, ID_UPDATE_AVAILABLE);
}
public static void notifyDownloadFailed(String countryId)
public static void notifyDownloadFailed(CountryItem country)
{
CountryItem item = CountryItem.fill(countryId);
String title = APP.getString(R.string.app_name);
String content = APP.getString(R.string.download_country_failed, item.name);
String content = APP.getString(R.string.download_country_failed, country.name);
PendingIntent pi = PendingIntent.getActivity(APP, 0, MwmActivity.createShowMapIntent(APP, countryId, false)
PendingIntent pi = PendingIntent.getActivity(APP, 0, MwmActivity.createShowMapIntent(APP, country.id, false)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
PendingIntent.FLAG_UPDATE_CURRENT);

View file

@ -18,6 +18,7 @@ import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.widget.WheelProgressView;
import com.mapswithme.util.StringUtils;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.statistics.Statistics;
public class CountrySuggestFragment extends BaseMwmFragment implements View.OnClickListener
{
@ -50,9 +51,9 @@ public class CountrySuggestFragment extends BaseMwmFragment implements View.OnCl
mListenerSlot = MapManager.nativeSubscribe(new MapManager.StorageCallback()
{
@Override
public void onStatusChanged(String countryId, int newStatus)
public void onStatusChanged(String countryId, int newStatus, boolean isLeafNode)
{
if (!isAdded())
if (!isLeafNode || !isAdded())
return;
refreshViews();
@ -191,6 +192,9 @@ public class CountrySuggestFragment extends BaseMwmFragment implements View.OnCl
case R.id.wpv__download_progress:
MapManager.nativeCancel(mDownloadingCountry.id);
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_CANCEL,
Statistics.params().add(Statistics.EventParam.FROM, "search"));
break;
}
}

View file

@ -31,6 +31,7 @@ import com.mapswithme.util.BottomSheetHelper;
import com.mapswithme.util.StringUtils;
import com.mapswithme.util.ThemeUtils;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.statistics.Statistics;
import com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersAdapter;
import com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration;
@ -62,8 +63,14 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
@Override
void invoke(CountryItem item, DownloaderAdapter adapter)
{
CANCEL.invoke(item, adapter);
MapManager.nativeCancel(item.id);
MapManager.nativeDelete(item.id);
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_ACTION,
Statistics.params().add(Statistics.EventParam.ACTION, "delete")
.add(Statistics.EventParam.FROM, "downloader")
.add("scenario", (item.isExpandable() ? "delete_group"
: "delete")));
}
},
@ -73,6 +80,8 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
void invoke(CountryItem item, DownloaderAdapter adapter)
{
MapManager.nativeCancel(item.id);
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_CANCEL,
Statistics.params().add(Statistics.EventParam.FROM, "downloader"));
}
},
@ -84,6 +93,10 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
// TODO: Jump to country
if (adapter.mActivity instanceof MwmActivity)
adapter.mActivity.finish();
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_ACTION,
Statistics.params().add(Statistics.EventParam.ACTION, "explore")
.add(Statistics.EventParam.FROM, "downloader"));
}
},
@ -96,6 +109,13 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
if (item.status == CountryItem.STATUS_UPDATABLE)
MapManager.nativeUpdate(item.id);
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_ACTION,
Statistics.params().add(Statistics.EventParam.ACTION, "update")
.add(Statistics.EventParam.FROM, "downloader")
.add("is_auto", "false")
.add("scenario", (item.isExpandable() ? "update_group"
: "update")));
}
};
@ -130,7 +150,7 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
private final MapManager.StorageCallback mStorageCallback = new MapManager.StorageCallback()
{
@Override
public void onStatusChanged(String countryId, int newStatus)
public void onStatusChanged(String countryId, int newStatus, boolean isLeafNode)
{
if (mSearchResultsMode)
updateItem(countryId);
@ -166,6 +186,13 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
case CountryItem.STATUS_DOWNLOADABLE:
MapManager.nativeDownload(mItem.id);
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_ACTION,
Statistics.params().add(Statistics.EventParam.ACTION, "download")
.add(Statistics.EventParam.FROM, "downloader")
.add("is_auto", "false")
.add("scenario", (mItem.isExpandable() ? "download_group"
: "download")));
break;
case CountryItem.STATUS_FAILED:
@ -175,10 +202,19 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
case CountryItem.STATUS_PROGRESS:
case CountryItem.STATUS_ENQUEUED:
MapManager.nativeCancel(mItem.id);
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_CANCEL,
Statistics.params().add(Statistics.EventParam.FROM, "downloader"));
break;
case CountryItem.STATUS_UPDATABLE:
MapManager.nativeUpdate(mItem.id);
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_ACTION,
Statistics.params().add(Statistics.EventParam.ACTION, "update")
.add(Statistics.EventParam.FROM, "downloader")
.add("is_auto", "false")
.add("scenario", (mItem.isExpandable() ? "update_group"
: "update")));
break;
default:
@ -286,6 +322,8 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
public void onClick(View v)
{
MapManager.nativeCancel(mItem.id);
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_CANCEL,
Statistics.params().add(Statistics.EventParam.FROM, "downloader"));
}
});
}

View file

@ -131,12 +131,10 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment
mSubscriberSlot = MapManager.nativeSubscribe(new MapManager.StorageCallback()
{
@Override
public void onStatusChanged(String countryId, int newStatus)
public void onStatusChanged(String countryId, int newStatus, boolean isLeafNode)
{
if (!isAdded())
return;
update();
if (isAdded())
update();
}
@Override

View file

@ -8,6 +8,7 @@ import android.view.View;
import com.mapswithme.maps.R;
import com.mapswithme.maps.widget.SearchToolbarController;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.statistics.Statistics;
class DownloaderToolbarController extends SearchToolbarController
{
@ -32,6 +33,12 @@ class DownloaderToolbarController extends SearchToolbarController
public void onClick(View v)
{
MapManager.nativeDownload(mFragment.getAdapter().getCurrentParent());
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_ACTION,
Statistics.params().add(Statistics.EventParam.ACTION, "download")
.add(Statistics.EventParam.FROM, "downloader")
.add("is_auto", "false")
.add("scenario", "download_group"));
}
});
@ -41,6 +48,12 @@ class DownloaderToolbarController extends SearchToolbarController
public void onClick(View v)
{
MapManager.nativeUpdate(mFragment.getAdapter().getCurrentParent());
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_ACTION,
Statistics.params().add(Statistics.EventParam.ACTION, "update")
.add(Statistics.EventParam.FROM, "downloader")
.add("is_auto", "false")
.add("scenario", "update_all"));
}
});
@ -50,6 +63,9 @@ class DownloaderToolbarController extends SearchToolbarController
public void onClick(View v)
{
MapManager.nativeCancel(mFragment.getAdapter().getCurrentParent());
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_CANCEL,
Statistics.params().add(Statistics.EventParam.FROM, "downloader"));
}
});
}

View file

@ -4,12 +4,14 @@ import android.support.annotation.Nullable;
import java.util.List;
import com.mapswithme.util.statistics.Statistics;
public final class MapManager
{
@SuppressWarnings("unused")
public interface StorageCallback
{
void onStatusChanged(String countryId, int newStatus);
void onStatusChanged(String countryId, int newStatus, boolean isLeafNode);
void onProgress(String countryId, long localSize, long remoteSize);
}
@ -29,6 +31,26 @@ public final class MapManager
private MapManager() {}
public static void sendErrorStat(String event, int code)
{
String text;
switch (code)
{
case CountryItem.ERROR_NO_INTERNET:
text = "no_connection";
break;
case CountryItem.ERROR_OOM:
text = "no_space";
break;
default:
text = "unknown_error";
}
Statistics.INSTANCE.trackEvent(event, Statistics.params().add(Statistics.EventParam.TYPE, text));
}
/**
* Moves a file from one place to another.
*/

View file

@ -3,6 +3,7 @@ package com.mapswithme.maps.downloader;
import android.location.Location;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.util.statistics.Statistics;
@android.support.annotation.UiThread
final class MigrationController
@ -54,6 +55,8 @@ final class MigrationController
mState = State.ERROR;
mError = code;
callStateError();
MapManager.sendErrorStat(Statistics.EventName.DOWNLOADER_MIGRATION_ERROR, code);
}
};

View file

@ -16,6 +16,7 @@ import com.mapswithme.maps.base.OnBackPressListener;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.widget.WheelProgressView;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.statistics.Statistics;
public class MigrationFragment extends BaseMwmFragment
implements OnBackPressListener,
@ -32,7 +33,12 @@ public class MigrationFragment extends BaseMwmFragment
@Override
public void onClick(View v)
{
MigrationController.get().start(v == mButtonPrimary);
boolean keepOld = (v == mButtonPrimary);
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_MIGRATION_STARTED,
Statistics.params().add(Statistics.EventParam.TYPE, keepOld ? "all_maps"
: "current_map"));
MigrationController.get().start(keepOld);
}
};
@ -67,6 +73,8 @@ public class MigrationFragment extends BaseMwmFragment
});
MigrationController.get().attach(this);
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_MIGRATION_DIALOG_SEEN);
}
@Override
@ -132,7 +140,7 @@ public class MigrationFragment extends BaseMwmFragment
@Override
public void onComplete()
{
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_MIGRATION_COMPLETE);
}
@Override

View file

@ -13,6 +13,7 @@ import com.mapswithme.util.Config;
import com.mapswithme.util.ConnectionState;
import com.mapswithme.util.StringUtils;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.statistics.Statistics;
public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
{
@ -30,9 +31,9 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
private final MapManager.StorageCallback mStorageCallback = new MapManager.StorageCallback()
{
@Override
public void onStatusChanged(String countryId, int newStatus)
public void onStatusChanged(String countryId, int newStatus, boolean isLeafNode)
{
if (mCurrentCountry != null && mCurrentCountry.id.equals(countryId))
if (mCurrentCountry != null && isLeafNode && mCurrentCountry.id.equals(countryId))
{
mCurrentCountry.update();
updateState();
@ -90,15 +91,23 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
mProgress.setProgress((int)(mCurrentCountry.progress * 100L / mCurrentCountry.totalSize));
else
{
boolean failed = (mCurrentCountry.status == CountryItem.STATUS_FAILED);
if (!failed &&
boolean success = (mCurrentCountry.status != CountryItem.STATUS_FAILED);
if (success &&
!MapManager.nativeIsLegacyMode() &&
Config.isAutodownloadMaps() &&
ConnectionState.isWifiConnected())
{
MapManager.nativeDownload(mCurrentCountry.id);
mButton.setText(failed ? R.string.downloader_retry
: R.string.download);
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_ACTION,
Statistics.params().add(Statistics.EventParam.ACTION, "download")
.add(Statistics.EventParam.FROM, "map")
.add("is_auto", "true")
.add("scenario", "download"));
}
mButton.setText(success ? R.string.download
: R.string.downloader_retry);
}
}
}
@ -123,6 +132,8 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
public void onClick(View v)
{
MapManager.nativeCancel(mCurrentCountry.id);
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_CANCEL,
Statistics.params().add(Statistics.EventParam.FROM, "map"));
}
});
@ -137,10 +148,17 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
return;
}
if (mCurrentCountry.status == CountryItem.STATUS_FAILED)
boolean retry = (mCurrentCountry.status == CountryItem.STATUS_FAILED);
if (retry)
MapManager.nativeRetry(mCurrentCountry.id);
else
MapManager.nativeDownload(mCurrentCountry.id);
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_ACTION,
Statistics.params().add(Statistics.EventParam.ACTION, (retry ? "retry" : "download"))
.add(Statistics.EventParam.FROM, "map")
.add("is_auto", "false")
.add("scenario", "download"));
}
});

View file

@ -35,14 +35,13 @@ public enum Statistics
public static class EventName
{
// Downloader
public static final String DOWNLOADER_MAP_DOWNLOAD = "Country download";
public static final String DOWNLOADER_MAP_DOWNLOAD_ALL = "Download all country clicks counter";
public static final String DOWNLOADER_MAP_UPDATE = "Country update";
public static final String DOWNLOADER_MAP_DELETE = "Country delete";
public static final String DOWNLOADER_MIGRATE_DIALOG_SEEN = "Big mwms to small mwms dialog appearing counter";
public static final String DOWNLOADER_MIGRATE_PERFORMED = "Big mwms to small mwms migration counter";
public static final String MAP_DOWNLOADED = "DownloadMap";
public static final String MAP_UPDATED = "UpdateMap";
public static final String DOWNLOADER_MIGRATION_DIALOG_SEEN = "Downloader_Migration_dialogue";
public static final String DOWNLOADER_MIGRATION_STARTED = "Downloader_Migration_started";
public static final String DOWNLOADER_MIGRATION_COMPLETE = "Downloader_Migration_completed";
public static final String DOWNLOADER_MIGRATION_ERROR = "Downloader_Migration_error";
public static final String DOWNLOADER_ERROR = "Downloader_Map_error";
public static final String DOWNLOADER_ACTION = "Downloader_Map_action";
public static final String DOWNLOADER_CANCEL = "Downloader_Cancel_downloading";
// bookmarks
public static final String BMK_DESCRIPTION_CHANGED = "Bookmark. Description changed";
public static final String BMK_GROUP_CREATED = "Bookmark. Group created";
@ -148,6 +147,8 @@ public enum Statistics
public static final String POINT = "point";
public static final String LANGUAGE = "language";
public static final String NAME = "Name";
public static final String ACTION = "action";
public static final String TYPE = "type";
private EventParam() {}
}