414 lines
17 KiB
Java
414 lines
17 KiB
Java
package com.gh.common.util;
|
|
|
|
import android.app.Application;
|
|
import android.content.Context;
|
|
import android.os.Build;
|
|
import android.provider.Settings;
|
|
import android.text.TextUtils;
|
|
|
|
import com.gh.common.exposure.ExposureSource;
|
|
import com.gh.common.exposure.meta.Meta;
|
|
import com.gh.common.exposure.meta.MetaUtil;
|
|
import com.gh.download.DownloadDataHelper;
|
|
import com.gh.gamecenter.BuildConfig;
|
|
import com.gh.gamecenter.entity.CommunityEntity;
|
|
import com.gh.gamecenter.entity.GameEntity;
|
|
import com.gh.gamecenter.entity.SpecialColumn;
|
|
import com.gh.gamecenter.manager.UserManager;
|
|
import com.gh.gamecenter.qa.entity.Questions;
|
|
import com.gh.loghub.LoghubUtils;
|
|
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.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Created by khy on 2/01/18.
|
|
*/
|
|
public class LogUtils {
|
|
|
|
public static void logVideoStreamingUpload(String action, String entrance, String entranceDetail, String videoId) {
|
|
JSONObject object = new JSONObject();
|
|
JSONObject payloadObject = new JSONObject();
|
|
|
|
try {
|
|
object.put("event", "UPLOAD_VIDEO_STEAMING");
|
|
object.put("action", action);
|
|
payloadObject.put("entrance", entrance);
|
|
payloadObject.put("entrance_detail", entranceDetail);
|
|
payloadObject.put("video_id", videoId);
|
|
object.put("payload", payloadObject);
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
uploadVideoStreaming(object);
|
|
}
|
|
|
|
public static void uploadDownloadEvent(DownloadEntity downloadEntity) {
|
|
Context context = HaloApp.getInstance().getApplication();
|
|
Meta meta = MetaUtil.INSTANCE.getMeta();
|
|
JSONObject object = new JSONObject();
|
|
|
|
try {
|
|
object.put("event", DownloadDataHelper.getDownloadStatusAlias(downloadEntity));
|
|
object.put("msg", downloadEntity.getError());
|
|
object.put("status", downloadEntity.getStatus().getStatus());
|
|
|
|
// payload
|
|
JSONObject payloadObject = new JSONObject();
|
|
payloadObject.put("game_id", downloadEntity.getGameId());
|
|
payloadObject.put("gameName", downloadEntity.getName());
|
|
payloadObject.put("platform", downloadEntity.getPlatform());
|
|
payloadObject.put("package", downloadEntity.getPackageName());
|
|
payloadObject.put("filename", downloadEntity.getPath().substring(downloadEntity.getPath().lastIndexOf("/") + 1));
|
|
payloadObject.put("total_size", (downloadEntity.getSize() / 1024 / 1024));
|
|
payloadObject.put("completed_size", (downloadEntity.getProgress() / 1024 / 1024));
|
|
|
|
object.put("payload", payloadObject);
|
|
|
|
// meta
|
|
JSONObject metaObject = new JSONObject();
|
|
metaObject.put("android_id", meta.getAndroid_id());
|
|
metaObject.put("android_sdk", meta.getAndroid_sdk());
|
|
metaObject.put("android_version", meta.getAndroid_version());
|
|
metaObject.put("appVersion", meta.getAppVersion());
|
|
metaObject.put("channel", meta.getChannel());
|
|
metaObject.put("gid", meta.getGid());
|
|
metaObject.put("imei", meta.getImei());
|
|
metaObject.put("mac", meta.getMac());
|
|
metaObject.put("manufacturer", meta.getManufacturer());
|
|
metaObject.put("model", meta.getModel());
|
|
metaObject.put("network", DeviceUtils.getNetwork(context));
|
|
metaObject.put("os", meta.getOs());
|
|
metaObject.put("userId", meta.getUserId());
|
|
|
|
object.put("meta", metaObject);
|
|
object.put("timestamp", System.currentTimeMillis() / 1000);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
if (BuildConfig.DEBUG) {
|
|
Utils.log("LogUtils->" + object.toString());
|
|
}
|
|
LoghubUtils.log(object, "download_debug", false);
|
|
}
|
|
|
|
public static void uploadCommunityArticle(String tracers, String articleId, String articleTitle, int readTime, CommunityEntity community, SpecialColumn specialColumn) {
|
|
JSONObject object = new JSONObject();
|
|
try {
|
|
object.put("subject", "community_article");
|
|
object.put("community_id", community.getId());
|
|
object.put("community_name", community.getName());
|
|
object.put("article_id", articleId);
|
|
object.put("article_name", articleTitle);
|
|
object.put("tracers", tracers);
|
|
object.put("read", readTime);
|
|
JSONObject columnObject = new JSONObject();
|
|
if (specialColumn != null) {
|
|
columnObject.put("type", specialColumn.getType());
|
|
columnObject.put("name", specialColumn.getName());
|
|
columnObject.put("tab", specialColumn.getTab());
|
|
} else {
|
|
columnObject.put("type", "");
|
|
columnObject.put("name", "");
|
|
columnObject.put("tab", "");
|
|
}
|
|
object.put("special_column", columnObject);
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
uploadToCommunity(object);
|
|
}
|
|
|
|
public static void uploadDevice(LunchType launchType) {
|
|
JSONObject object = new JSONObject();
|
|
Application application = HaloApp.getInstance().getApplication();
|
|
try {
|
|
object.put("subject", "halo_device");
|
|
object.put("launch_time", Utils.getTime(application));
|
|
object.put("launch_type", launchType.name());
|
|
object.put("manufacture", Build.MANUFACTURER);
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
uploadToCommunity(object);
|
|
}
|
|
|
|
public static void uploadAnswerReadTime(String tracers, int readTime, String answerId, Questions questions, String communityId, String CommunityName, SpecialColumn specialColumn) {
|
|
JSONObject object = new JSONObject();
|
|
try {
|
|
object.put("subject", "answer");
|
|
object.put("community_id", communityId);
|
|
object.put("community_name", CommunityName);
|
|
object.put("question_id", questions.getId());
|
|
object.put("question_name", questions.getTitle());
|
|
object.put("tracers", tracers);
|
|
object.put("answer_id", answerId);
|
|
object.put("read", readTime);
|
|
JSONObject columnObject = new JSONObject();
|
|
if (specialColumn != null) {
|
|
columnObject.put("type", specialColumn.getType());
|
|
columnObject.put("name", specialColumn.getName());
|
|
columnObject.put("tab", specialColumn.getTab());
|
|
} else {
|
|
columnObject.put("type", "");
|
|
columnObject.put("name", "");
|
|
columnObject.put("tab", "");
|
|
}
|
|
object.put("special_column", columnObject);
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
uploadToCommunity(object);
|
|
}
|
|
|
|
public static void uploadQuestionReadTime(String tracers, int readTime, Questions questions, String communityId, String communityName, SpecialColumn specialColumn) {
|
|
JSONObject object = new JSONObject();
|
|
try {
|
|
object.put("subject", "question");
|
|
object.put("community_id", communityId);
|
|
object.put("community_name", communityName);
|
|
object.put("question_id", questions.getId());
|
|
object.put("question_name", questions.getTitle());
|
|
object.put("tracers", tracers);
|
|
object.put("read", readTime);
|
|
JSONObject columnObject = new JSONObject();
|
|
if (specialColumn != null) {
|
|
columnObject.put("type", specialColumn.getType());
|
|
columnObject.put("name", specialColumn.getName());
|
|
columnObject.put("tab", specialColumn.getTab());
|
|
} else {
|
|
columnObject.put("type", "");
|
|
columnObject.put("name", "");
|
|
columnObject.put("tab", "");
|
|
}
|
|
object.put("special_column", columnObject);
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
uploadToCommunity(object);
|
|
}
|
|
|
|
public static void uploadSearch(String searchKey) {
|
|
if (TextUtils.isEmpty(searchKey)) return;
|
|
|
|
JSONObject object = new JSONObject();
|
|
try {
|
|
object.put("community_id", UserManager.getInstance().getCommunity().getId());
|
|
object.put("community_name", UserManager.getInstance().getCommunity().getName());
|
|
object.put("keyword", searchKey);
|
|
object.put("subject", "search");
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
uploadToCommunity(object);
|
|
}
|
|
|
|
public static void communityRefresh(int dataCount, boolean manualRefresh) {
|
|
JSONObject object = new JSONObject();
|
|
try {
|
|
object.put("subject", "community_refresh");
|
|
object.put("community_id", UserManager.getInstance().getCommunity().getId());
|
|
object.put("refresh_type", "recommend");
|
|
object.put("refresh_way", manualRefresh ? "manual" : "auto");
|
|
object.put("data_count", dataCount);
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
uploadToCommunity(object);
|
|
}
|
|
|
|
public static void login(String loginStep, String loginType, String entrance) {
|
|
JSONObject object = new JSONObject();
|
|
try {
|
|
object.put("entrance", entrance);
|
|
object.put("subject", "login");
|
|
object.put("step", loginStep);
|
|
object.put("login_type", loginType);
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
uploadToCommunity(object);
|
|
}
|
|
|
|
public static void qaAccess(String access, CommunityEntity communityEntity) {
|
|
JSONObject object = new JSONObject();
|
|
try {
|
|
object.put("subject", "qa_access");
|
|
object.put("access", access);
|
|
object.put("community_id", communityEntity.getId());
|
|
object.put("community_name", communityEntity.getName());
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
uploadToCommunity(object);
|
|
}
|
|
|
|
public static void logReservation(GameEntity gameEntity, List<ExposureSource> exposureSourceList) {
|
|
JSONObject object = new JSONObject();
|
|
|
|
if (exposureSourceList == null) {
|
|
exposureSourceList = new ArrayList<>();
|
|
exposureSourceList.add(new ExposureSource("其它", ""));
|
|
}
|
|
|
|
try {
|
|
object.put("source", GsonUtils.toJson(exposureSourceList));
|
|
object.put("game_name", gameEntity.getName());
|
|
object.put("game_id", gameEntity.getId());
|
|
object.put("game_platform", gameEntity.getPlatform());
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
uploadToReservation(object);
|
|
}
|
|
|
|
private static void uploadToCommunity(JSONObject object) {
|
|
if (BuildConfig.DEBUG) {
|
|
Utils.log("LogUtils->" + object.toString());
|
|
}
|
|
|
|
Context context = HaloApp.getInstance().getApplication();
|
|
try {
|
|
object.put("version", PackageUtils.getVersionName());
|
|
object.put("channel", HaloApp.getInstance().getChannel());
|
|
object.put("android_id", Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID));
|
|
object.put("time", Utils.getTime(context));
|
|
object.put("network", DeviceUtils.getNetwork(context));
|
|
object.put("user_id", UserManager.getInstance().getUserId());
|
|
object.put("device_system", android.os.Build.VERSION.RELEASE);
|
|
object.put("device_model", android.os.Build.MODEL);
|
|
object.put("imei", Util_System_Phone_State.getImei(HaloApp.getInstance()
|
|
.getApplication()));
|
|
object.put("G_ID", UserManager.getInstance().getDeviceId());
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// 暂时除了曝光外的数据都是扔到 community 这个库的,要是不是这个这个库的话这里要改一下
|
|
LoghubUtils.log(object, "community", true);
|
|
}
|
|
|
|
/**
|
|
* 上传数据到“预约”的 logStore
|
|
*/
|
|
private static void uploadToReservation(JSONObject object) {
|
|
Context context = HaloApp.getInstance().getApplication();
|
|
try {
|
|
object.put("version", PackageUtils.getVersionName());
|
|
object.put("channel", HaloApp.getInstance().getChannel());
|
|
object.put("android_id", Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID));
|
|
object.put("time", Utils.getTime(context));
|
|
object.put("network", DeviceUtils.getNetwork(context));
|
|
object.put("user_id", UserManager.getInstance().getUserId());
|
|
object.put("device_system", android.os.Build.VERSION.RELEASE);
|
|
object.put("device_model", android.os.Build.MODEL);
|
|
object.put("imei", Util_System_Phone_State.getImei(HaloApp.getInstance()
|
|
.getApplication()));
|
|
object.put("G_ID", UserManager.getInstance().getDeviceId());
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
LoghubUtils.log(object, "appointment", false);
|
|
}
|
|
|
|
private static void uploadVideoStreaming(JSONObject object) {
|
|
Context context = HaloApp.getInstance().getApplication();
|
|
Meta meta = MetaUtil.INSTANCE.getMeta();
|
|
JSONObject metaObject = new JSONObject();
|
|
try {
|
|
metaObject.put("android_id", meta.getAndroid_id());
|
|
metaObject.put("android_sdk", meta.getAndroid_sdk());
|
|
metaObject.put("android_version", meta.getAndroid_version());
|
|
metaObject.put("appVersion", meta.getAppVersion());
|
|
metaObject.put("channel", meta.getChannel());
|
|
metaObject.put("gid", meta.getGid());
|
|
metaObject.put("imei", meta.getImei());
|
|
metaObject.put("mac", meta.getMac());
|
|
metaObject.put("manufacturer", meta.getManufacturer());
|
|
metaObject.put("model", meta.getModel());
|
|
metaObject.put("network", meta.getNetwork());
|
|
metaObject.put("os", meta.getOs());
|
|
metaObject.put("userId", meta.getUserId());
|
|
|
|
object.put("meta", metaObject);
|
|
object.put("timestamp", System.currentTimeMillis() / 1000);
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
if (BuildConfig.DEBUG) {
|
|
Utils.log("LogUtils->" + object.toString());
|
|
}
|
|
|
|
LoghubUtils.log(object, "video_streaming", false);
|
|
}
|
|
|
|
public static void uploadVideoStreamingEnter(String entrance, String entranceDetail, String videoId, String streamingId) {
|
|
JSONObject object = new JSONObject();
|
|
JSONObject payloadObject = new JSONObject();
|
|
|
|
try {
|
|
object.put("event", "ENTERING_VIDEO_STEAMING");
|
|
payloadObject.put("entrance", entrance);
|
|
if (!TextUtils.isEmpty(entranceDetail)) {
|
|
payloadObject.put("entrance_detail", entranceDetail);
|
|
}
|
|
payloadObject.put("video_id", videoId);
|
|
payloadObject.put("streaming_id", streamingId);
|
|
object.put("payload", payloadObject);
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
uploadVideoStreaming(object);
|
|
}
|
|
|
|
public static void uploadVideoStreamingPlaying(String action, String msg, String entrance, String entranceDetail, String videoId, String streamingId, double videoSize, int videoTotalTime, int progress, String videoPlayStatus) {
|
|
JSONObject object = new JSONObject();
|
|
JSONObject payloadObject = new JSONObject();
|
|
|
|
try {
|
|
object.put("event", "VIDEO_PLAYING");
|
|
object.put("action", action);
|
|
if (!TextUtils.isEmpty(msg)) {
|
|
object.put("msg", msg);
|
|
}
|
|
|
|
payloadObject.put("entrance", entrance);
|
|
if (!TextUtils.isEmpty(entranceDetail)) {
|
|
payloadObject.put("entrance_detail", entranceDetail);
|
|
}
|
|
payloadObject.put("video_id", videoId);
|
|
payloadObject.put("streaming_id", streamingId);
|
|
if (videoSize > 0) {
|
|
payloadObject.put("video_size", videoSize);
|
|
}
|
|
if (videoTotalTime > 0) {
|
|
payloadObject.put("video_total_time", videoTotalTime);
|
|
}
|
|
payloadObject.put("progress", progress);
|
|
payloadObject.put("video_play_status", videoPlayStatus);
|
|
|
|
object.put("payload", payloadObject);
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
uploadVideoStreaming(object);
|
|
}
|
|
}
|