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

170 lines
6.8 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.gamecenter.entity.CommunityEntity;
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.utils.Util_System_Phone_State;
import com.lightgame.utils.Utils;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Created by khy on 2/01/18.
*/
public class LogUtils {
public static void uploadCommunityArticle(String tracers, String articleId, String articleTitle,
int readTime, CommunityEntity community) {
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);
} catch (JSONException e) {
e.printStackTrace();
}
upload(HaloApp.getInstance().getApplication(), 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("network", DeviceUtils.getNetwork(application));
object.put("device_model", android.os.Build.MODEL);
object.put("manufacture", Build.MANUFACTURER);
object.put("device_system", android.os.Build.VERSION.RELEASE);
} catch (JSONException e) {
e.printStackTrace();
}
upload(application, object);
}
public static void uploadAnswerReadTime(String tracers, int readTime, String answerId, Questions questions) {
JSONObject object = new JSONObject();
try {
object.put("subject", "answer");
object.put("community_id", UserManager.getInstance().getCommunity().getId());
object.put("community_name", UserManager.getInstance().getCommunity().getName());
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);
} catch (JSONException e) {
e.printStackTrace();
}
upload(HaloApp.getInstance().getApplication(), object);
}
public static void uploadQuestionReadTime(String tracers, int readTime, Questions questions) {
JSONObject object = new JSONObject();
try {
object.put("subject", "question");
object.put("community_id", UserManager.getInstance().getCommunity().getId());
object.put("community_name", UserManager.getInstance().getCommunity().getName());
object.put("question_id", questions.getId());
object.put("question_name", questions.getTitle());
object.put("tracers", tracers);
object.put("read", readTime);
} catch (JSONException e) {
e.printStackTrace();
}
upload(HaloApp.getInstance().getApplication(), object);
}
public static void uploadSearch(Context context, String searchKey) {
if (TextUtils.isEmpty(searchKey) || context == null) 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();
}
upload(context, object);
}
public static void communityRefresh(Context context, int dataCount, boolean manualRefresh) {
if (context == null) return;
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);
object.put("user_id", UserManager.getInstance().getUserId());
object.put("network", DeviceUtils.getNetwork(context));
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("imei", Util_System_Phone_State.getDeviceId(context));
object.put("device_system", android.os.Build.VERSION.RELEASE);
object.put("device_model", android.os.Build.MODEL);
object.put("time", Utils.getTime(context));
} catch (JSONException e) {
e.printStackTrace();
}
upload(context, object);
}
public static void login(Context context, String loginStep, String loginType) {
if (context == null) return;
JSONObject object = new JSONObject();
try {
object.put("subject", "login");
object.put("step", loginStep);
object.put("login_type", loginType);
object.put("network", DeviceUtils.getNetwork(context));
} catch (JSONException e) {
e.printStackTrace();
}
upload(context, object);
}
private static void upload(Context context, JSONObject object) {
if (context == null) return;
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("imei", Util_System_Phone_State.getDeviceId(context));
object.put("time", Utils.getTime(context));
} catch (JSONException e) {
e.printStackTrace();
}
// 暂时除了曝光外的数据都是扔到 community 这个库的,要是不是这个这个库的话这里要改一下
LogHubUtils.uploadLog(DeviceUtils.getIPAddress(context), object, "community");
}
}