Files
assistant-android/app/src/main/java/com/gh/common/util/DataLogUtils.java

109 lines
3.8 KiB
Java

package com.gh.common.util;
import android.content.Context;
import com.gh.gamecenter.retrofit.Response;
import com.gh.gamecenter.retrofit.RetrofitManager;
import com.halo.assistant.HaloApp;
import com.lightgame.download.DownloadEntity;
import com.lightgame.utils.Util_System_Phone_State;
import com.lightgame.utils.Utils;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
/**
* Created by LGT on 2016/12/8.
* 日志上传工具类
*/
public class DataLogUtils {
// 轮播图
public static void uploadLunbotuLog(Context context, String type, String text, String index, String source) {
Map<String, Object> map = new HashMap<>();
map.put("index", index);
map.put("type", type);
map.put("text", text);
map.put("source", source);
uploadLog(context, "slide", map);
}
// 搜索热门标签
public static void uploadHotTagLog(Context context, String tag) {
Map<String, Object> map = new HashMap<>();
map.put("tag", tag);
uploadLog(context, "search-hot-tag", map);
}
// 点击下载按钮或进入游戏详情
public static void uploadGameLog(Context context, String gameId, String gameName, String entrance) {
Map<String, Object> map = new HashMap<>();
map.put("game_id", gameId);
map.put("game_name", gameName);
map.put("entrance", entrance);
uploadLog(context, "game", map);
}
// 上传日志
public static void uploadLog(Context context, String topic, Map<String, Object> map) {
String version = PackageUtils.getVersionName();
String user = Installation.getUUID(context);
String channel = HaloApp.getInstance().getChannel();
map.put("version", version);
map.put("user", user);
map.put("device_id", Util_System_Phone_State.getDeviceId(context));
map.put("channel", channel);
Map<String, String> params = new HashMap<>();
params.put("topic", topic);
params.put("source", "GH-ASSIST-Client");
params.put("time", String.valueOf(Utils.getTime(context)));
params.put("content", new JSONObject(map).toString());
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
new JSONObject(params).toString());
RetrofitManager.getInstance(context).getData().postLog(body)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Response<ResponseBody>());
}
// 网络错误
public static void uploadNeterrorLog(Context context, DownloadEntity downloadEntity) {
Map<String, Object> map = new HashMap<>();
map.put("url", downloadEntity.getUrl());
map.put("game", downloadEntity.getName());
map.put("game_id", downloadEntity.getGameId());
map.put("platform", downloadEntity.getPlatform());
map.put("error", downloadEntity.getError());
uploadLog(context, "neterror", map);
}
// 助手更新
public static void uploadUpgradeLog(Context context, String step) {
Map<String, Object> map = new HashMap<>();
map.put("step", step);
uploadLog(context, "upgrade", map);
}
// 链接劫持
public static void uploadHijack(Context context, DownloadEntity downloadEntity) {
Map<String, Object> map = new HashMap<>();
map.put("url", downloadEntity.getUrl());
map.put("game", downloadEntity.getName());
map.put("game_id", downloadEntity.getGameId());
map.put("platform", downloadEntity.getPlatform());
map.put("hijack_url", downloadEntity.getError());
uploadLog(context, "hijack", map);
}
}