新增全量日志采集系统

This commit is contained in:
zlzw 2022-11-11 17:47:28 +08:00
parent 042f53e134
commit 834170e272
4 changed files with 164 additions and 91 deletions

View File

@ -1,14 +1,19 @@
package com.shayu.phonelive.utils; package com.shayu.phonelive.utils;
import static java.text.DateFormat.DEFAULT;
import android.content.Context; import android.content.Context;
import com.yunbao.common.utils.FileUtil; import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.utils.ToastUtil;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URLEncoder; import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class LogUtils { public class LogUtils {
public static void start(Context context) { public static void start(Context context) {
@ -31,18 +36,26 @@ public class LogUtils {
}; };
Process process = Runtime.getRuntime().exec(exec); Process process = Runtime.getRuntime().exec(exec);
StringBuilder builder = new StringBuilder(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()), 1024);
String line; String line;
File saveFile = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath()); PrintWriter writer = null;
while ((line = bufferedReader.readLine()) != null) { String today ="[PDLIVE]"+CommonAppConfig.getInstance().getUid()+"_"+ SimpleDateFormat.getDateInstance(DEFAULT, Locale.CHINA).format(new Date());
builder.append(line).append("\n"); File dir = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator);
if (builder.length() > 65500) { if (dir.listFiles() != null) {
FileUtil.saveAddStringToFile(saveFile, builder.toString(), "logcat.log"); for (File file : dir.listFiles()) {
builder.setLength(0); if (!file.getName().endsWith(today+".log") && !file.getName().endsWith("error.log")) {
file.delete();
}
} }
} }
File saveFile = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator + today + ".log");
FileOutputStream os = new FileOutputStream(saveFile);
writer = new PrintWriter(os);
while ((line = bufferedReader.readLine()) != null) {
writer.append(line).write("\n");
}
writer.flush();
writer.close();
exec = new String[]{ exec = new String[]{
"logcat", "logcat",
"-c" "-c"
@ -52,10 +65,10 @@ public class LogUtils {
start(context); start(context);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
ToastUtil.show("");
} }
} }
}).start(); }).start();
} }
} }

View File

@ -1,9 +1,22 @@
package com.yunbao.common.utils; package com.yunbao.common.utils;
import static androidx.core.content.PermissionChecker.PERMISSION_GRANTED;
import static java.text.DateFormat.DEFAULT;
import android.Manifest;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import androidx.core.app.ActivityCompat;
import androidx.core.content.FileProvider;
import androidx.core.content.PermissionChecker;
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.Progress; import com.lzy.okgo.model.Progress;
@ -16,6 +29,9 @@ import com.yunbao.common.CommonAppConfig;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -119,4 +135,30 @@ public class LogUtil {
} }
return null; return null;
} }
public static void shareFile(Context context) {
if(PermissionChecker.checkCallingOrSelfPermission(context,"android.permission.WRITE_EXTERNAL_STORAGE")!= PERMISSION_GRANTED){
ActivityCompat.requestPermissions((Activity) context,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},100);
return;
}
String today ="[PDLIVE]"+CommonAppConfig.getInstance().getUid()+"_"+ SimpleDateFormat.getDateInstance(DEFAULT, Locale.CHINA).format(new Date());
File file = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator + today + ".log");
file.renameTo(new File(Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+file.getName()));
if (file.exists()) {
Intent share = new Intent(Intent.ACTION_SEND);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", file);
share.putExtra(Intent.EXTRA_STREAM, contentUri);
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
}
share.setType("application/vnd.ms-excel");
share.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(Intent.createChooser(share, "分享文件"));
}
}
} }

View File

@ -1062,7 +1062,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
return bitmap; return bitmap;
} }
private String TAG="多人PK";
private String TAG = "多人PK";
/** /**
* 退出多人PK * 退出多人PK
*/ */
@ -1186,101 +1188,113 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
@Override @Override
public void onSuccess(int code, String msgs, String[] info) { public void onSuccess(int code, String msgs, String[] info) {
if (code == 0) { if (code == 0) {
Log.i("多人PK","1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info)+" mApplyUid = "+mApplyUid); Log.i("多人PK", "1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info) + " mApplyUid = " + mApplyUid);
if (info.length == 0) { HttpClient.getInstance().get("live.getdrnum", "live.getdrnum")
ToastUtil.show("多人PK次数已用完"); .execute(new HttpCallback() {
return;
}
rtcRoom.getLocalUser().responseJoinOtherRoom(mApplyUid, mApplyUid, true, true, SOCKET_LIVE_DRPK, new IRCRTCResultCallback() {
@Override
public void onSuccess() {
HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom")
.params("uid", CommonAppConfig.getInstance().getUid())
.params("roomid", u.getId())
.execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
Log.i(TAG, "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info));
boolean agree=true;
if (code != 0) {
ToastUtil.show("多人PK次数已用完");
agree=false;
}
rtcRoom.getLocalUser().responseJoinOtherRoom(mApplyUid, mApplyUid, agree, true, SOCKET_LIVE_DRPK, new IRCRTCResultCallback() {
@Override @Override
public void onSuccess(int code, String msg, String[] info) { public void onSuccess() {
Log.i("多人PK","code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom")
.params("uid", CommonAppConfig.getInstance().getUid())
.params("roomid", u.getId())
.execute(new HttpCallback() {
final SocketSendBean msg1 = new SocketSendBean() @Override
.param("_method_", SOCKET_LIVE_DRPK) public void onSuccess(int code, String msg, String[] info) {
.param("action", 10) Log.i("多人PK","code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info));
.param("uid", CommonAppConfig.getInstance().getUid());
msg1.create();
String targetId = "g" + CommonAppConfig.getInstance().getUid();
Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM;
TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString());
io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent);
RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { final SocketSendBean msg1 = new SocketSendBean()
@Override .param("_method_", SOCKET_LIVE_DRPK)
public void onAttached(io.rong.imlib.model.Message message) { .param("action", 10)
.param("uid", CommonAppConfig.getInstance().getUid());
msg1.create();
String targetId = "g" + CommonAppConfig.getInstance().getUid();
Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM;
TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString());
io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent);
} RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() {
@Override
public void onAttached(io.rong.imlib.model.Message message) {
@Override }
public void onSuccess(io.rong.imlib.model.Message message) {
Log.e("ry", "发送成功");
if (SocketRyClient.mSocketHandler != null) {
SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + "");
}
}
@Override @Override
public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { public void onSuccess(io.rong.imlib.model.Message message) {
Log.e("ry", "发送失敗"); Log.e("ry", "发送成功");
} if (SocketRyClient.mSocketHandler != null) {
}); SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + "");
}
}
JSONObject obj = JSONObject.parseObject(info[0]); @Override
JSONArray users = obj.getJSONArray("userlist"); public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) {
Log.e("ry", "发送失敗");
}
});
if(info.length==0){
return;
}
JSONObject obj = JSONObject.parseObject(info[0]);
JSONArray users = obj.getJSONArray("userlist");
//添加水印 //添加水印
// RCRTCRect rect = new RCRTCRect(0.5f, 0.5f, 0.2f); // RCRTCRect rect = new RCRTCRect(0.5f, 0.5f, 0.2f);
// RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(fromText(50, mNameText), rect); // RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(fromText(50, mNameText), rect);
dRjoinOtherRoom(u.getId(), 1); dRjoinOtherRoom(u.getId(), 1);
for (int i = 0; i < users.size(); i++) { for (int i = 0; i < users.size(); i++) {
JSONObject user = users.getJSONObject(i); JSONObject user = users.getJSONObject(i);
Log.e("ry", mApplyUid + "VS" + user.getString("id") + "列表"); Log.e("ry", mApplyUid + "VS" + user.getString("id") + "列表");
if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid())) { if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid())) {
if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid()) && !user.getString("id").equals(u.getId())) { if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid()) && !user.getString("id").equals(u.getId())) {
/** /**
* 向指定用户发送跨房间连麦请求 * 向指定用户发送跨房间连麦请求
* <P> * <P>
* 1: inviterAutoMix为true时 * 1: inviterAutoMix为true时
* *
* 1.1如果被邀请方在加入邀请方房间之前发布了资源当被邀请方加入邀请者房间成功后服务器会把被邀请方流资源合并到邀请方视图 ·默认仅悬浮布局合流 * 1.1如果被邀请方在加入邀请方房间之前发布了资源当被邀请方加入邀请者房间成功后服务器会把被邀请方流资源合并到邀请方视图 ·默认仅悬浮布局合流
* *
* 1.2如果被邀请方在加入邀请方房间之前没有发布过资源将会在被邀请方发布资源成功后服务器会把被邀请方流资源合并到邀请方视图默认仅悬浮布局合流 * 1.2如果被邀请方在加入邀请方房间之前没有发布过资源将会在被邀请方发布资源成功后服务器会把被邀请方流资源合并到邀请方视图默认仅悬浮布局合流
* *
* 2:无论为true或false双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局一旦主动设置过合流布局后续音视频直播过程中设置的自动合流参数将失效 * 2:无论为true或false双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局一旦主动设置过合流布局后续音视频直播过程中设置的自动合流参数将失效
* <P/> * <P/>
*/ */
rtcRoom.getLocalUser().requestJoinOtherRoom(user.getString("id"), user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { rtcRoom.getLocalUser().requestJoinOtherRoom(user.getString("id"), user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() {
@Override @Override
public void onSuccess() { public void onSuccess() {
}
@Override
public void onFailed(RTCErrorCode errorCode) {
}
});
}
}
} }
}
});
@Override }
public void onFailed(RTCErrorCode errorCode) {
} @Override
}); public void onFailed(RTCErrorCode errorCode) {
} ToastUtil.show("接受失败");
}
}
} }
}); });
}
});
}
@Override
public void onFailed(RTCErrorCode errorCode) {
ToastUtil.show("接受失败");
}
});
} }
} }

View File

@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.yunbao.common.Constants; import com.yunbao.common.Constants;
import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.interfaces.OnItemClickListener;
import com.yunbao.common.utils.DeviceUtils; import com.yunbao.common.utils.DeviceUtils;
import com.yunbao.common.utils.LogUtil;
import com.yunbao.common.views.weight.ViewClicksAntiShake; import com.yunbao.common.views.weight.ViewClicksAntiShake;
import com.yunbao.main.BuildConfig; import com.yunbao.main.BuildConfig;
import com.yunbao.main.R; import com.yunbao.main.R;
@ -50,6 +51,9 @@ public class SettingAdapter extends RecyclerView.Adapter {
if (tag != null) { if (tag != null) {
int position = (int) tag; int position = (int) tag;
SettingBean bean = mList.get(position); SettingBean bean = mList.get(position);
if(bean.getId()==19){
LogUtil.shareFile(context);
}
if (mOnItemClickListener != null) { if (mOnItemClickListener != null) {
mOnItemClickListener.onItemClick(bean, position); mOnItemClickListener.onItemClick(bean, position);
} }