新增上报日志功能

This commit is contained in:
zlzw 2024-06-29 10:11:42 +08:00
parent f1a1aae787
commit e0669e98cf
17 changed files with 301 additions and 110 deletions

View File

@ -13,7 +13,7 @@ import com.google.gson.JsonObject;
import com.yunbao.faceunity.entity.net.FineStickerEntity; import com.yunbao.faceunity.entity.net.FineStickerEntity;
import com.yunbao.faceunity.utils.FaceUnityData; import com.yunbao.faceunity.utils.FaceUnityData;
import com.yunbao.faceunity.utils.FileUtils; import com.yunbao.faceunity.utils.FileUtils;
import com.yunbao.faceunity.utils.ZipUtils; import com.yunbao.common.utils.ZipUtils;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -88,12 +88,12 @@ android {
applicationVariants.all { variant -> applicationVariants.all { variant ->
println "清空build文件夹"; println "清空build文件夹";
/* for (final def project in rootProject.getAllprojects()) { for (final def project in rootProject.getAllprojects()) {
def name = variant.name.replace('Debug', '').replace('Release', '').toLowerCase() def name = variant.name.replace('Debug', '').replace('Release', '').toLowerCase()
delete project.buildDir //delete project.buildDir
delete project.rootDir.absolutePath+File.separator+"app"+File.separator+name delete project.rootDir.absolutePath+File.separator+"app"+File.separator+name
println project.buildDir //println project.buildDir
}*/ }
//delete project.rootDir.absolutePath + File.separator + "outputs" //delete project.rootDir.absolutePath + File.separator + "outputs"
String variantName = variant.name.capitalize() String variantName = variant.name.capitalize()
def processManifestTask = project.tasks.getByName("process${variantName}Manifest") def processManifestTask = project.tasks.getByName("process${variantName}Manifest")

View File

@ -25,7 +25,7 @@ import com.blankj.utilcode.util.Utils;
import com.facebook.appevents.AppEventsLogger; import com.facebook.appevents.AppEventsLogger;
import com.fm.openinstall.OpenInstall; import com.fm.openinstall.OpenInstall;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.shayu.phonelive.utils.LogUtils; import com.yunbao.common.utils.LogUtils;
import com.tencent.imsdk.v2.V2TIMGroupMemberInfo; import com.tencent.imsdk.v2.V2TIMGroupMemberInfo;
import com.tencent.imsdk.v2.V2TIMManager; import com.tencent.imsdk.v2.V2TIMManager;
import com.tencent.imsdk.v2.V2TIMSimpleMsgListener; import com.tencent.imsdk.v2.V2TIMSimpleMsgListener;

View File

@ -235,4 +235,6 @@ dependencies {
//ExoPlayer, //ExoPlayer,
api 'com.google.android.exoplayer:exoplayer:2.18.2' api 'com.google.android.exoplayer:exoplayer:2.18.2'
api 'com.google.android.exoplayer:exoplayer-core:2.18.2@aar' api 'com.google.android.exoplayer:exoplayer-core:2.18.2@aar'
api rootProject.ext.dependencies["blank-utilcode"]
} }

View File

@ -0,0 +1,16 @@
package com.yunbao.common.bean;
import com.alibaba.fastjson.annotation.JSONField;
public class QiniuLog extends BaseModel{
@JSONField(name = "log_type")
private int log_type;
public int getLog_type() {
return log_type;
}
public void setLog_type(int log_type) {
this.log_type = log_type;
}
}

View File

@ -8,6 +8,7 @@ import android.util.Log;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.DeviceUtils;
import com.lzy.okgo.OkGo; import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback; import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response; import com.lzy.okgo.model.Response;
@ -28,6 +29,7 @@ import com.yunbao.common.utils.AppManager;
import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DialogUitl;
import com.yunbao.common.utils.L; import com.yunbao.common.utils.L;
import com.yunbao.common.utils.SpUtil; import com.yunbao.common.utils.SpUtil;
import com.yunbao.common.utils.StringUtil;
import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.VersionUtil; import com.yunbao.common.utils.VersionUtil;
import com.yunbao.common.utils.WordUtil; import com.yunbao.common.utils.WordUtil;
@ -459,6 +461,20 @@ public class CommonHttpUtil {
.params("token", CommonAppConfig.getInstance().getToken()) .params("token", CommonAppConfig.getInstance().getToken())
.params("ext", isImg ? ".jpeg" : ".mp4") .params("ext", isImg ? ".jpeg" : ".mp4")
.execute(callback); .execute(callback);
} /**
* 上传文件 获取七牛云token的接口
*/
public static void getUploadQiNiuTokenLog(HttpCallback callback,String fileName) {
String uid = CommonAppConfig.getInstance().getUid();
if(StringUtil.isEmpty(uid)){
uid="NotLogin_"+ DeviceUtils.getUniqueDeviceId();
}
HttpClient.getInstance().get("Pdluserhome.getQiNiuToken3", "Pdluserhome.getQiNiuToken3")
.params("uid",uid)
.params("token", CommonAppConfig.getInstance().getToken())
.params("file_name", fileName)
.params("ext", ".zip")
.execute(callback);
} }
// //
// //埋点唯一性 // //埋点唯一性

View File

@ -57,6 +57,7 @@ import com.yunbao.common.bean.PrankGiftBean;
import com.yunbao.common.bean.PrankGiftResultBean; import com.yunbao.common.bean.PrankGiftResultBean;
import com.yunbao.common.bean.PrankHttpTurntableBean; import com.yunbao.common.bean.PrankHttpTurntableBean;
import com.yunbao.common.bean.PrankProgressBean; import com.yunbao.common.bean.PrankProgressBean;
import com.yunbao.common.bean.QiniuLog;
import com.yunbao.common.bean.QuickGiftSendGiftModel; import com.yunbao.common.bean.QuickGiftSendGiftModel;
import com.yunbao.common.bean.RandomPkUserBean; import com.yunbao.common.bean.RandomPkUserBean;
import com.yunbao.common.bean.RankPkInfoBean; import com.yunbao.common.bean.RankPkInfoBean;
@ -1261,4 +1262,8 @@ public interface PDLiveApi {
@Query("anchor_id")String anchor_id, @Query("anchor_id")String anchor_id,
@Query("gift_id")String gift_id @Query("gift_id")String gift_id
); );
@GET("/api/public/?service=Tx.androidQiniuLog")
Observable<ResponseModel<QiniuLog>> getPrankList(
@Query("type")String type
);
} }

View File

@ -57,6 +57,7 @@ import com.yunbao.common.bean.PrankGiftBean;
import com.yunbao.common.bean.PrankGiftResultBean; import com.yunbao.common.bean.PrankGiftResultBean;
import com.yunbao.common.bean.PrankHttpTurntableBean; import com.yunbao.common.bean.PrankHttpTurntableBean;
import com.yunbao.common.bean.PrankProgressBean; import com.yunbao.common.bean.PrankProgressBean;
import com.yunbao.common.bean.QiniuLog;
import com.yunbao.common.bean.QuickGiftSendGiftModel; import com.yunbao.common.bean.QuickGiftSendGiftModel;
import com.yunbao.common.bean.RandomPkUserBean; import com.yunbao.common.bean.RandomPkUserBean;
import com.yunbao.common.bean.RankPkInfoBean; import com.yunbao.common.bean.RankPkInfoBean;
@ -3237,6 +3238,31 @@ public class LiveNetManager {
} }
/**
* 上报日志相关
* @param type 1为查询3为删除
* @param callback
*/
public void getLogUpdateStatus(String type, HttpCallback<QiniuLog>callback) {
API.get().pdLiveApi(mContext)
.getPrankList(type)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(listResponseModel -> {
if (callback != null) {
callback.onSuccess(listResponseModel.getData().getInfo());
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
throwable.printStackTrace();
if (callback != null) {
callback.onError(mContext.getString(R.string.net_error));
}
}
}).isDisposed();
}
public void updateFile(File file, HttpCallback<AvatarBean> callback) { public void updateFile(File file, HttpCallback<AvatarBean> callback) {
MultipartBody.Part uploadFile = createUploadFile(file); MultipartBody.Part uploadFile = createUploadFile(file);

View File

@ -11,6 +11,7 @@ public class UploadBean {
public static final int IMG = 0; public static final int IMG = 0;
public static final int VIDEO = 1; public static final int VIDEO = 1;
public static final int VOICE = 2; public static final int VOICE = 2;
public static final int LOG = 3;
private File mOriginFile;//要被上传的源文件 private File mOriginFile;//要被上传的源文件
private File mCompressFile;//压缩后的图片文件 private File mCompressFile;//压缩后的图片文件
private String mRemoteFileName;//上传成功后在云存储上的文件名字 private String mRemoteFileName;//上传成功后在云存储上的文件名字

View File

@ -1,5 +1,7 @@
package com.yunbao.common.upload; package com.yunbao.common.upload;
import static java.text.DateFormat.DEFAULT;
import android.content.Context; import android.content.Context;
import android.text.TextUtils; import android.text.TextUtils;
@ -11,6 +13,7 @@ import com.qiniu.android.storage.UpCompletionHandler;
import com.qiniu.android.storage.UploadManager; import com.qiniu.android.storage.UploadManager;
import com.yunbao.common.http.CommonHttpUtil; import com.yunbao.common.http.CommonHttpUtil;
import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.L; import com.yunbao.common.utils.L;
import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.StringUtil;
@ -18,7 +21,10 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.File; import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale;
import top.zibin.luban.Luban; import top.zibin.luban.Luban;
@ -72,6 +78,8 @@ public class UploadQnImpl implements UploadStrategy {
compressedFile.delete(); compressedFile.delete();
} }
} }
} else if (uploadBean.getType() == UploadBean.LOG) {
uploadBean.getOriginFile().delete();
} }
mIndex++; mIndex++;
if (mIndex < mList.size()) { if (mIndex < mList.size()) {
@ -90,6 +98,10 @@ public class UploadQnImpl implements UploadStrategy {
@Override @Override
public void upload(List<UploadBean> list, boolean needCompress, UploadCallback callback, boolean isImg) { public void upload(List<UploadBean> list, boolean needCompress, UploadCallback callback, boolean isImg) {
upload(list, needCompress, callback, isImg, false);
}
public void upload(List<UploadBean> list, boolean needCompress, UploadCallback callback, boolean isImg, boolean isLog) {
System.err.println("-------upload------>" + list.size()); System.err.println("-------upload------>" + list.size());
if (callback == null) { if (callback == null) {
return; return;
@ -127,8 +139,12 @@ public class UploadQnImpl implements UploadStrategy {
} }
}; };
} }
if (isLog) {
CommonHttpUtil.getUploadQiNiuTokenLog(mGetUploadTokenCallback, list.get(0).getOriginFile().getName());
} else {
CommonHttpUtil.getUploadQiNiuToken(mGetUploadTokenCallback, isImg); CommonHttpUtil.getUploadQiNiuToken(mGetUploadTokenCallback, isImg);
} }
}
@Override @Override
public void cancelUpload() { public void cancelUpload() {
@ -159,8 +175,16 @@ public class UploadQnImpl implements UploadStrategy {
bean.setRemoteFileName(StringUtil.contact(StringUtil.generateFileName(), ".mp4")); bean.setRemoteFileName(StringUtil.contact(StringUtil.generateFileName(), ".mp4"));
} else if (bean.getType() == UploadBean.VOICE) { } else if (bean.getType() == UploadBean.VOICE) {
bean.setRemoteFileName(StringUtil.contact(StringUtil.generateFileName(), ".m4a")); bean.setRemoteFileName(StringUtil.contact(StringUtil.generateFileName(), ".m4a"));
} else if (bean.getType() == UploadBean.LOG) {
bean.setRemoteFileName("logs/"
+ IMLoginManager.get(mContext).getUserInfo().getId()
+ "/"
+ SimpleDateFormat.getDateInstance(DEFAULT, Locale.CHINA).format(new Date())
+ "/"
+ bean.getOriginFile().getName()
);
} }
System.err.println("-------mIndex >= bean.getType() == UploadBean.IMG------>" + bean); System.err.println("-------mIndex >= bean.getType() == " + bean.getType() + "------>" + bean);
upload(bean); upload(bean);
/*if (bean.getType() == UploadBean.IMG && mNeedCompress) { /*if (bean.getType() == UploadBean.IMG && mNeedCompress) {
System.err.println("-------UploadBean.IMG && mNeedCompress------>" + bean + "UploadBean.IMG:" + UploadBean.IMG + "__mNeedCompress" + mNeedCompress); System.err.println("-------UploadBean.IMG && mNeedCompress------>" + bean + "UploadBean.IMG:" + UploadBean.IMG + "__mNeedCompress" + mNeedCompress);

View File

@ -2,6 +2,11 @@ package com.yunbao.common.utils;
import android.util.Log; import android.util.Log;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.UUID;
/** /**
* Created by cxf on 2017/8/3. * Created by cxf on 2017/8/3.
*/ */
@ -24,13 +29,19 @@ public class L {
} }
} }
final static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
public static void e(String tag, String s) { public static void e(String tag, String s) {
if (sDeBug) { if (sDeBug) {
Log.e(tag, s); Log.e(tag, s);
} else {
String uuid = UUID.randomUUID().toString();
Log.e(tag, uuid);
LogUtils.addSafeLog(dateFormat.format(new Date()) + " [" + uuid + "|" + tag + "] " + s);
} }
} }
public static void setDeBug(boolean deBug) { public static void setDeBug(boolean deBug) {
sDeBug = deBug; sDeBug = false;
} }
} }

View File

@ -24,28 +24,25 @@ import com.lzy.okgo.request.PostRequest;
import com.lzy.okserver.OkUpload; import com.lzy.okserver.OkUpload;
import com.lzy.okserver.upload.UploadListener; import com.lzy.okserver.upload.UploadListener;
import com.lzy.okserver.upload.UploadTask; import com.lzy.okserver.upload.UploadTask;
import com.yunbao.common.BuildConfig;
import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.upload.UploadBean;
import com.yunbao.common.upload.UploadCallback;
import com.yunbao.common.upload.UploadQnImpl;
import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.WritableByteChannel;
import java.nio.file.Files; import java.nio.file.Files;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import okhttp3.Call; import okhttp3.Call;
import okhttp3.Callback; import okhttp3.Callback;
@ -149,61 +146,95 @@ public class LogUtil {
public static void shareFile(Context context) { public static void shareFile(Context context) {
try {
IMLoginModel bean = IMLoginManager.get(context).getUserInfo();
boolean isAnchor = false;
if (bean != null) {
isAnchor = bean.anchorUserType();
}
//有debug文件或主播才允许
if (!new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "pdlive.debug").exists() && !isAnchor) {
return;
}
} catch (Exception e) {
return;
}
/* if (PermissionChecker.checkCallingOrSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PERMISSION_GRANTED) {
ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 100);
return;
}*/
String title = "[PDLIVE]" + CommonAppConfig.getInstance().getUid() + "_"; String title = "[PDLIVE]" + CommonAppConfig.getInstance().getUid() + "_";
String today = title + SimpleDateFormat.getDateInstance(DEFAULT, Locale.CHINA).format(new Date()); String today = title + SimpleDateFormat.getDateInstance(DEFAULT, Locale.CHINA).format(new Date());
File dir = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator); File dir = new File("/data/data/" + context.getPackageName() + File.separator);
File zip = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator + today + ".zip"); File zip = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator + today + ".zip");
try { try {
ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zip))); List<String> filters = getFiltersList(context.getPackageName());
FileInputStream fis = null; filters.add(context.getPackageName() + File.separator + "app_files" + File.separator + today + ".zip");
WritableByteChannel writableByteChannel = Channels.newChannel(zos); List<String> srcList = new ArrayList<>();
if (dir.listFiles() != null) { srcList.add(dir.getAbsolutePath());
for (File file : dir.listFiles()) { srcList.add(context.getExternalFilesDir("").getAbsolutePath());
if (file.getName().endsWith(".log")) { LogUtils.endSafeLog();
ZipEntry entry = new ZipEntry(file.getName()); ZipUtils.zipFolder(srcList, zip.getAbsolutePath(), filters, new Runnable() {
zos.putNextEntry(entry); @Override
fis = new FileInputStream(file); public void run() {
FileChannel channel = fis.getChannel(); System.out.println("!!!!!!!!!!!!!!!!!!!");
channel.transferTo(0, file.length() - 1, writableByteChannel); if (BuildConfig.DEBUG) {
fis.close(); return;
} }
UploadQnImpl mUploadStrategy = new UploadQnImpl(context);
List<UploadBean> list = new ArrayList<>();
list.add(new UploadBean(zip, UploadBean.LOG));
mUploadStrategy.upload(list, false, new UploadCallback() {
@Override
public void onFinish(List<UploadBean> list, boolean success) {
if (success) {
LiveNetManager.get(context).getLogUpdateStatus("3", null);
} }
LogUtils.startSafeLog(context);
} }
zos.close(); }, false, true);
writableByteChannel.close(); }
});
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
if (zip.exists()) {
DialogUitl.showSimpleDialog(context, "上报日志", new DialogUitl.SimpleCallback() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
new Thread(new Runnable() {
@Override
public void run() {
uploadLog(zip);
} }
}).start();
dialog.dismiss(); private static @NonNull List<String> getFiltersList(String packageName) {
ToastUtil.show("OK"); List<String> filters = new ArrayList<>();
filters.add(packageName + File.separator + "files" + File.separator + "gif");
filters.add(packageName + File.separator + "app_textures");
filters.add(packageName + File.separator + "app_webview");
filters.add(packageName + File.separator + "code_cache");
filters.add(packageName + File.separator + "databases");
filters.add(packageName + File.separator + "cache" + File.separator + "https");
filters.add(packageName + File.separator + "cache" + File.separator + "image");
filters.add(packageName + File.separator + "cache" + File.separator + "jtechCache");
filters.add(packageName + File.separator + "cache" + File.separator + "picasso-cache");
filters.add(packageName + File.separator + "cache" + File.separator + "svga");
filters.add(packageName + File.separator + "cache" + File.separator + "WebView");
return filters;
}
private static String TAG = "Upload";
private static void uploadLog(File log) {
JSONObject body = new JSONObject();
MultipartBody requestBody = new MultipartBody.Builder().addFormDataPart("uid", CommonAppConfig.getInstance().getUid()).addFormDataPart("time", new SimpleDateFormat("yyyy-DD-mm HH:mm:ss", Locale.getDefault()).format(new Date())).addFormDataPart("isGoogle", CommonAppConfig.IS_GOOGLE_PLAY + "").addFormDataPart("appVersion", CommonAppConfig.getInstance().getVersion()).addFormDataPart("file", "file", RequestBody.create(MediaType.parse("application/octet-stream"), log)) //上报日志文件
.build();
body.put("uid", CommonAppConfig.getInstance().getUid());
body.put("time", new SimpleDateFormat("yyyy-DD-mm HH:mm:ss", Locale.getDefault()).format(new Date()));
body.put("isGoogle", CommonAppConfig.IS_GOOGLE_PLAY);
body.put("appVersion", CommonAppConfig.getInstance().getVersion());
OkHttpClient client = new OkHttpClient.Builder().connectTimeout(3, TimeUnit.SECONDS).build();
Request request = new Request.Builder()
.url("https://tools.yutou233.cn/public/file/request.do")//临时上报地址可接受文件
//.url("https://newht.yaoulive.com/index.php/api/error_log/report") //无法接受文件
.post(requestBody).build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(@NonNull Call call, @NonNull IOException e) {
Log.e(TAG, "error", e);
}
@Override
public void onResponse(Call call, okhttp3.Response response) throws IOException {
String body = response.body().string();
Log.i(TAG, "onResponse: " + body);
}
});
}
private static void openShareDialog(Context context, File zip) {
Intent share = new Intent(Intent.ACTION_SEND); Intent share = new Intent(Intent.ACTION_SEND);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", zip); Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", zip);
@ -231,43 +262,4 @@ public class LogUtil {
e.printStackTrace(); e.printStackTrace();
} }
} }
});
}
}
private static String TAG = "Upload";
private static void uploadLog(File log) {
JSONObject body = new JSONObject();
MultipartBody requestBody = new MultipartBody.Builder().addFormDataPart("uid", CommonAppConfig.getInstance().getUid()).addFormDataPart("time", new SimpleDateFormat("yyyy-DD-mm HH:mm:ss", Locale.getDefault()).format(new Date())).addFormDataPart("isGoogle", CommonAppConfig.IS_GOOGLE_PLAY + "").addFormDataPart("appVersion", CommonAppConfig.getInstance().getVersion()).addFormDataPart("file", "file", RequestBody.create(MediaType.parse("application/octet-stream"), log)) //上报日志文件
.build();
body.put("uid", CommonAppConfig.getInstance().getUid());
body.put("time", new SimpleDateFormat("yyyy-DD-mm HH:mm:ss", Locale.getDefault()).format(new Date()));
body.put("isGoogle", CommonAppConfig.IS_GOOGLE_PLAY);
body.put("appVersion", CommonAppConfig.getInstance().getVersion());
OkHttpClient client = new OkHttpClient.Builder().connectTimeout(3, TimeUnit.SECONDS).build();
Request request = new Request.Builder().url("https://newht.yaoulive.com/index.php/api/error_log/report") //无法接受文件
.post(requestBody).build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(@NonNull Call call, @NonNull IOException e) {
Log.e(TAG, "error", e);
}
@Override
public void onResponse(Call call, okhttp3.Response response) throws IOException {
String body = response.body().string();
Log.i(TAG, "onResponse: " + body);
}
});
}
} }

View File

@ -1,4 +1,4 @@
package com.shayu.phonelive.utils; package com.yunbao.common.utils;
import static java.text.DateFormat.DEFAULT; import static java.text.DateFormat.DEFAULT;
@ -17,8 +17,11 @@ import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.LinkedBlockingQueue;
public class LogUtils { public class LogUtils {
private static final LinkedBlockingQueue<String> QUEUE = new LinkedBlockingQueue<>();
/** /**
* 采集所有日志 * 采集所有日志
*/ */
@ -68,7 +71,58 @@ public class LogUtils {
} }
} }
}).start(); }).start();
startSafeLog(context);
}
private static Thread safeThread;
private static boolean writerSafeLog = true;
public static void startSafeLog(Context context) {
if (safeThread != null && safeThread.isAlive()) {
return;
}
safeThread = new Thread(new Runnable() {
@Override
public void run() {
try {
String title = CommonAppConfig.getInstance().getUid() + "_";
String today = title + SimpleDateFormat.getDateInstance(DEFAULT, Locale.CHINA).format(new Date());
File saveFile = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator + today + ".safe");
saveFile.createNewFile();
FileOutputStream os = new FileOutputStream(saveFile, true);
PrintWriter writer = new PrintWriter(os);
while (writerSafeLog) {
if (!QUEUE.isEmpty()) {
writer.append(QUEUE.poll()).write("\n");
writer.flush();
} else {
Thread.sleep(1000);
}
}
while (!QUEUE.isEmpty()){
writer.append(QUEUE.poll()).write("\n");
writer.flush();
}
writer.flush();
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
});
safeThread.setName("safeLog");
safeThread.start();
}
public static void addSafeLog(String log) {
QUEUE.offer(log);
}
public static void endSafeLog() {
writerSafeLog = false;
while (!QUEUE.isEmpty()){
}
} }
/** /**

View File

@ -1,10 +1,11 @@
package com.yunbao.faceunity.utils; package com.yunbao.common.utils;
import android.util.Log; import android.util.Log;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -151,16 +152,36 @@ public class ZipUtils {
* @param zipFileString 解压完成的Zip路径 * @param zipFileString 解压完成的Zip路径
* @throws Exception * @throws Exception
*/ */
public static void zipFolder(String srcFileString, String zipFileString) throws Exception { public static void zipFolder(List<String> srcFileString, String zipFileString, List<String> filters, Runnable runnable) throws Exception {
if (filters == null) {
filters = new ArrayList<>();
}
filters.add(new File(zipFileString).getAbsolutePath());
final List<String> tmp = new ArrayList<>(filters);
//创建ZIP //创建ZIP
ZipOutputStream outZip = new ZipOutputStream(new FileOutputStream(zipFileString)); ZipOutputStream outZip = new ZipOutputStream(new FileOutputStream(zipFileString));
//创建文件
File file = new File(srcFileString); new Thread(new Runnable() {
@Override
public void run() {
try {
for (String src : srcFileString) {
File file = new File(src);
//压缩 //压缩
zipFiles(file.getParent() + File.separator, file.getName(), outZip); zipFiles(file.getParent() + File.separator, file.getName(), outZip, tmp);
}
//创建文件
//完成和关闭 //完成和关闭
outZip.finish(); outZip.finish();
outZip.close(); outZip.close();
runnable.run();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
} }
/** /**
@ -171,9 +192,15 @@ public class ZipUtils {
* @param zipOutputSteam * @param zipOutputSteam
* @throws Exception * @throws Exception
*/ */
private static void zipFiles(String folderString, String fileString, ZipOutputStream zipOutputSteam) throws Exception { private static void zipFiles(String folderString, String fileString, ZipOutputStream zipOutputSteam, List<String> filters) throws Exception {
if (zipOutputSteam == null) if (zipOutputSteam == null)
return; return;
for (String filter : filters) {
if (fileString.startsWith(filter)) {
return;
}
}
System.out.println("压缩文件:" + folderString + "|" + fileString);
File file = new File(folderString + fileString); File file = new File(folderString + fileString);
if (file.isFile()) { if (file.isFile()) {
ZipEntry zipEntry = new ZipEntry(fileString); ZipEntry zipEntry = new ZipEntry(fileString);
@ -196,7 +223,7 @@ public class ZipUtils {
} }
//子文件和递归 //子文件和递归
for (int i = 0; i < fileList.length; i++) { for (int i = 0; i < fileList.length; i++) {
zipFiles(folderString, fileString + File.separator + fileList[i], zipOutputSteam); zipFiles(folderString, fileString + File.separator + fileList[i], zipOutputSteam, filters);
} }
} }
} }

View File

@ -1 +1 @@
apply plugin: 'com.android.library' apply plugin: 'img-optimizer' apply plugin: 'kotlin-android' apply from: "../package_config.gradle" android { compileSdkVersion rootProject.ext.android.compileSdkVersion buildToolsVersion rootProject.ext.android.buildToolsVersion aaptOptions.cruncherEnabled = false aaptOptions.useNewCruncher = false packagingOptions { pickFirst "lib/armeabi/libyuvutils.so" pickFirst "lib/arm64-v8a/libyuvutils.so" pickFirst "lib/armeabi-v7a/libyuvutils.so" pickFirst "lib/armeabi/libyuvtools.so" pickFirst "lib/arm64-v8a/libyuvtools.so" pickFirst "lib/armeabi-v7a/libyuvtools.so" exclude "lib/arm64-v8a/libmmcv_api_handgesture.so" exclude "lib/arm64-v8a/libmmcv_api_express.so" exclude "lib/arm64-v8a/libMediaEncoder.so" exclude "lib/arm64-v8a/libarcore_sdk_c.so" exclude "lib/arm64-v8a/libmediadecoder.so" exclude "lib/arm64-v8a/libMediaMuxer.so" exclude "lib/arm64-v8a/libarcore_sdk_jni.so" exclude "lib/arm64-v8a/libMediaUtils.so" exclude "lib/arm64-v8a/libcosmosffmpeg.so" } defaultConfig { minSdkVersion rootProject.ext.android.minSdkVersion targetSdkVersion rootProject.ext.android.targetSdkVersion versionCode rootProject.ext.android.versionCode versionName rootProject.ext.android.versionName manifestPlaceholders = rootProject.ext.manifestPlaceholders ndk { abiFilters "armeabi-v7a", "arm64-v8a","x86","x86_64" } javaCompileOptions { annotationProcessorOptions { arguments = [AROUTER_MODULE_NAME: project.getName()] } } } aaptOptions { cruncherEnabled = false useNewCruncher = false } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } kotlinOptions { allWarningsAsErrors = true } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } repositories { flatDir { dirs 'libs', '../libs' } mavenCentral() } dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.0.0' implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) implementation (name:'../libs/beautysdk-202202241203',ext:'aar') implementation (name:'../libs/svgaplayer-release-v1.2.1',ext:'aar') //socket.io implementation('io.socket:socket.io-client:1.0.0') { exclude group: 'org.json', module: 'json' } //common api project(path:':lib_faceunity')//声网-新娱美颜 api project(path:':FaceUnity')//融云-新娱美颜 api project(path:':common')//公共库 api project(':Share')//分享 annotationProcessor rootProject.ext.dependencies["arouter-compiler"] //工具 api rootProject.ext.dependencies["blank-utilcode"] implementation 'com.eightbitlab:blurview:1.6.6' implementation 'com.google.code.gson:gson:2.8.6' implementation "com.getkeepsafe.relinker:relinker:1.4.4" } apply plugin: 'com.android.library' apply plugin: 'img-optimizer' apply plugin: 'kotlin-android' apply from: "../package_config.gradle" android { compileSdkVersion rootProject.ext.android.compileSdkVersion buildToolsVersion rootProject.ext.android.buildToolsVersion aaptOptions.cruncherEnabled = false aaptOptions.useNewCruncher = false packagingOptions { pickFirst "lib/armeabi/libyuvutils.so" pickFirst "lib/arm64-v8a/libyuvutils.so" pickFirst "lib/armeabi-v7a/libyuvutils.so" pickFirst "lib/armeabi/libyuvtools.so" pickFirst "lib/arm64-v8a/libyuvtools.so" pickFirst "lib/armeabi-v7a/libyuvtools.so" exclude "lib/arm64-v8a/libmmcv_api_handgesture.so" exclude "lib/arm64-v8a/libmmcv_api_express.so" exclude "lib/arm64-v8a/libMediaEncoder.so" exclude "lib/arm64-v8a/libarcore_sdk_c.so" exclude "lib/arm64-v8a/libmediadecoder.so" exclude "lib/arm64-v8a/libMediaMuxer.so" exclude "lib/arm64-v8a/libarcore_sdk_jni.so" exclude "lib/arm64-v8a/libMediaUtils.so" exclude "lib/arm64-v8a/libcosmosffmpeg.so" } defaultConfig { minSdkVersion rootProject.ext.android.minSdkVersion targetSdkVersion rootProject.ext.android.targetSdkVersion versionCode rootProject.ext.android.versionCode versionName rootProject.ext.android.versionName manifestPlaceholders = rootProject.ext.manifestPlaceholders ndk { abiFilters "armeabi-v7a", "arm64-v8a","x86","x86_64" } javaCompileOptions { annotationProcessorOptions { arguments = [AROUTER_MODULE_NAME: project.getName()] } } } aaptOptions { cruncherEnabled = false useNewCruncher = false } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } kotlinOptions { allWarningsAsErrors = true } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } repositories { flatDir { dirs 'libs', '../libs' } mavenCentral() } dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.0.0' implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) implementation (name:'../libs/beautysdk-202202241203',ext:'aar') implementation (name:'../libs/svgaplayer-release-v1.2.1',ext:'aar') //socket.io implementation('io.socket:socket.io-client:1.0.0') { exclude group: 'org.json', module: 'json' } //common api project(path:':lib_faceunity')//声网-新娱美颜 api project(path:':FaceUnity')//融云-新娱美颜 api project(path:':common')//公共库 api project(':Share')//分享 annotationProcessor rootProject.ext.dependencies["arouter-compiler"] //工具 implementation 'com.eightbitlab:blurview:1.6.6' implementation 'com.google.code.gson:gson:2.8.6' implementation "com.getkeepsafe.relinker:relinker:1.4.4" }

View File

@ -50,7 +50,9 @@ import com.tencent.imsdk.v2.V2TIMManager;
import com.tencent.imsdk.v2.V2TIMSDKConfig; import com.tencent.imsdk.v2.V2TIMSDKConfig;
import com.tencent.imsdk.v2.V2TIMSDKListener; import com.tencent.imsdk.v2.V2TIMSDKListener;
import com.tencent.imsdk.v2.V2TIMUserFullInfo; import com.tencent.imsdk.v2.V2TIMUserFullInfo;
import com.yunbao.common.bean.QiniuLog;
import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.utils.LogUtil;
import com.yunbao.common.utils.MobclickAgent; import com.yunbao.common.utils.MobclickAgent;
import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.Constants; import com.yunbao.common.Constants;
@ -561,6 +563,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
checkVersion(); checkVersion();
//获取声网Token //获取声网Token
getSwToken(); getSwToken();
initLogUpdate();
} }
private void getSwToken() { private void getSwToken() {
@ -1626,6 +1629,20 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
}); });
} }
private void initLogUpdate(){
LiveNetManager.get(mContext)
.getLogUpdateStatus("1", new com.yunbao.common.http.base.HttpCallback<QiniuLog>() {
@Override
public void onSuccess(QiniuLog data) {
if(data.getLog_type()==1){
LogUtil.shareFile(mContext);
}
}
@Override
public void onError(String error) {
} }
});
}
}

View File

@ -55,7 +55,7 @@ public class SettingAdapter extends RecyclerView.Adapter {
int position = (int) tag; int position = (int) tag;
SettingBean bean = mList.get(position); SettingBean bean = mList.get(position);
if (bean.getId() == 19) { if (bean.getId() == 19) {
LogUtil.shareFile(context);
} }
if (mOnItemClickListener != null) { if (mOnItemClickListener != null) {
mOnItemClickListener.onItemClick(bean, position); mOnItemClickListener.onItemClick(bean, position);