From 07f8f46f1f4af29d3731e7441ced7b64a7bbc89a Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Fri, 17 Mar 2023 09:50:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E9=83=A8=E5=88=86?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=97=A0=E6=B3=95=E4=B8=8A=E9=BA=A6=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20=E4=BC=98=E5=8C=96=EF=BC=9A=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E4=B8=8A=E6=8A=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yunbao/common/utils/LogUtil.java | 129 +++++++++++++----- .../live/views/LivePlayRyViewHolder.java | 27 ++-- 2 files changed, 112 insertions(+), 44 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/utils/LogUtil.java b/common/src/main/java/com/yunbao/common/utils/LogUtil.java index e05b249c5..66d0c75d7 100644 --- a/common/src/main/java/com/yunbao/common/utils/LogUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/LogUtil.java @@ -1,11 +1,9 @@ package com.yunbao.common.utils; import static android.provider.Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION; -import static androidx.core.content.PermissionChecker.PERMISSION_GRANTED; import static java.text.DateFormat.DEFAULT; -import android.Manifest; -import android.app.Activity; +import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.net.Uri; @@ -14,10 +12,10 @@ import android.os.Environment; import android.text.TextUtils; import android.util.Log; -import androidx.core.app.ActivityCompat; +import androidx.annotation.NonNull; import androidx.core.content.FileProvider; -import androidx.core.content.PermissionChecker; +import com.alibaba.fastjson.JSONObject; import com.lzy.okgo.OkGo; import com.lzy.okgo.callback.StringCallback; import com.lzy.okgo.model.Progress; @@ -31,7 +29,6 @@ import com.yunbao.common.CommonAppConfig; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; @@ -42,11 +39,20 @@ import java.nio.file.Files; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.MediaType; +import okhttp3.MultipartBody; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; + /** * Created by cxf on 2019/6/20. */ @@ -157,10 +163,10 @@ public class LogUtil { } catch (Exception e) { return; } - if (PermissionChecker.checkCallingOrSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PERMISSION_GRANTED) { + /* 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 today = title + SimpleDateFormat.getDateInstance(DEFAULT, Locale.CHINA).format(new Date()); File dir = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator); @@ -188,33 +194,90 @@ public class LogUtil { e.printStackTrace(); } if (zip.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", zip); - share.putExtra(Intent.EXTRA_STREAM, contentUri); - share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - } else { - share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(zip)); - } - 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, "分享文件")); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !CommonAppConfig.IS_GOOGLE_PLAY) { - if (!Environment.isExternalStorageManager()) { - Intent intent = new Intent(ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION); - context.startActivity(intent); + 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(); + ToastUtil.show("OK"); + Intent share = new Intent(Intent.ACTION_SEND); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", zip); + share.putExtra(Intent.EXTRA_STREAM, contentUri); + share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + } else { + share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(zip)); + } + 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, "分享文件")); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !CommonAppConfig.IS_GOOGLE_PLAY) { + if (!Environment.isExternalStorageManager()) { + Intent intent = new Intent(ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION); + context.startActivity(intent); + } + } + File out = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + zip.getName()); + try { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + Files.copy(zip.toPath(), out.toPath()); + } + } catch (Exception e) { + e.printStackTrace(); + } } - } - File out = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + zip.getName()); - try { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - Files.copy(zip.toPath(), out.toPath()); - } - } catch (Exception e) { - 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") //无法接受文件 + .url("https://tools.yutou233.cn/public/file/request.do")//临时上报地址,可接受文件 + .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); + } + + + }); + } + } diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index 643bbf1c0..0267d522b 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -732,6 +732,19 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { Log.e("ry", "下麦成功"); // 该用户切换为观众成功,可以以观众身份进行音视频 //退出rtc播放 + leaveRoom(); + } + + /** + * 当切换失败且不影响当前角色继续音视频时回调 + * @param errorCode 失败错误码 + */ + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "下麦失败" + errorCode); + leaveRoom(); + } + private void leaveRoom(){ RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { @Override public void onSuccess() { @@ -761,21 +774,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @Override public void onFailed(RTCErrorCode errorCode) { Log.e("ry", errorCode + "退出多人房间成功"); - + userJoinLinkMic = false; } }); } - - /** - * 当切换失败且不影响当前角色继续音视频时回调 - * @param errorCode 失败错误码 - */ - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "下麦失败" + errorCode); - - } }); } } else if ("Debug".equals(str)) { @@ -938,7 +941,9 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { public void run() { RCRTCEngine.getInstance().enableSpeaker(true); //遍历远端用户发布的资源列表 + Log.i(TAG, "软件资源数量:"+data.getLiveStreams().size()); for (RCRTCInputStream stream : data.getLiveStreams()) { + Log.i(TAG, "资源流 type: "+stream.getMediaType()); if (stream.getMediaType() == RCRTCMediaType.VIDEO) { //暂停播放 mPlayer.stop();