Merge remote-tracking branch 'refs/remotes/origin/master'
This commit is contained in:
commit
198319b8ad
|
|
@ -16,7 +16,6 @@ import android.widget.ImageView
|
|||
import android.widget.LinearLayout
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.core.view.GravityCompat
|
||||
import androidx.drawerlayout.widget.DrawerLayout
|
||||
|
|
@ -28,15 +27,6 @@ import com.afollestad.materialdialogs.MaterialDialog
|
|||
import com.afollestad.materialdialogs.customview.customView
|
||||
import com.afollestad.materialdialogs.customview.getCustomView
|
||||
import com.airbnb.lottie.LottieAnimationView
|
||||
import com.alibaba.sdk.android.oss.ClientException
|
||||
import com.alibaba.sdk.android.oss.OSSClient
|
||||
import com.alibaba.sdk.android.oss.ServiceException
|
||||
import com.alibaba.sdk.android.oss.callback.OSSCompletedCallback
|
||||
import com.alibaba.sdk.android.oss.callback.OSSProgressCallback
|
||||
import com.alibaba.sdk.android.oss.common.auth.OSSStsTokenCredentialProvider
|
||||
import com.alibaba.sdk.android.oss.internal.OSSAsyncTask
|
||||
import com.alibaba.sdk.android.oss.model.PutObjectRequest
|
||||
import com.alibaba.sdk.android.oss.model.PutObjectResult
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonObject
|
||||
|
|
@ -62,10 +52,8 @@ import com.yingmao.clash.net.http.NetService
|
|||
import com.yingmao.clash.net.http.entity.AppVersionCheckRsp
|
||||
import com.yingmao.clash.net.http.entity.GetActivityRsp
|
||||
import com.yingmao.clash.net.http.entity.HeartBeatRsp
|
||||
import com.yingmao.clash.net.http.entity.ParamData
|
||||
import com.yingmao.clash.net.http.entity.PhDownloadUrlRsp
|
||||
import com.yingmao.clash.net.http.entity.SubscriptionRsp
|
||||
import com.yingmao.clash.net.http.entity.UploadParamData
|
||||
import com.yingmao.clash.net.http.entity.VipSignRsp
|
||||
import com.yingmao.clash.remote.Remote
|
||||
import com.yingmao.clash.service.ClashManager
|
||||
|
|
@ -77,8 +65,6 @@ import com.yingmao.clash.service.remote.IProfileManager
|
|||
import com.yingmao.clash.service.remote.wrap
|
||||
import com.yingmao.clash.util.AESUtil
|
||||
import com.yingmao.clash.util.CommonUtils
|
||||
import com.yingmao.clash.util.DataUtils
|
||||
import com.yingmao.clash.util.DataUtils.getAllFilePath
|
||||
import com.yingmao.clash.util.Utils
|
||||
import com.yingmao.clash.view.RxToast
|
||||
import com.yingmao.clash.view.adapter.MainVPAdapter
|
||||
|
|
@ -88,7 +74,6 @@ import com.yingmao.clash.view.dialog.DialogAppVersion
|
|||
import com.yingmao.clash.view.dialog.DialogBandChoose
|
||||
import com.yingmao.clash.view.dialog.DialogNotice
|
||||
import com.yingmao.clash.view.dialog.RxDialogShapeLoading
|
||||
import com.yingmao.clash.view.permissions.PermissionX
|
||||
import com.yingmao.clash.vm.MainAtyVM
|
||||
import com.yingmao.clash.webview.BZYWebViewKeFu
|
||||
import com.yingmao.clash.webview.BZYWebViewNormal
|
||||
|
|
@ -102,7 +87,6 @@ import okhttp3.RequestBody
|
|||
import java.io.File
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import java.util.Timer
|
||||
import java.util.TimerTask
|
||||
import java.util.UUID
|
||||
|
|
@ -263,7 +247,6 @@ class NewMainActivity : BaseActivity() {
|
|||
startLog()
|
||||
// showBindAccount()
|
||||
firstEntry()
|
||||
checkPermission()
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -557,32 +540,6 @@ class NewMainActivity : BaseActivity() {
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if (httpStatus.reqType == HttpReqType.UploadParameters) {
|
||||
val upLoadData = httpStatus.rsp as UploadParamData
|
||||
if (upLoadData.code == 1000) {
|
||||
val directory: File? = this.getExternalFilesDir("CrashLog")
|
||||
//多文件上传
|
||||
if (directory != null) {
|
||||
val allFilePath = getAllFilePath(directory.path)
|
||||
if (upLoadData.data != null) {
|
||||
if (allFilePath.isNotEmpty()) {
|
||||
val username =
|
||||
MMKV.defaultMMKV()
|
||||
.decodeString(BZYConstants.MMKV_KEY_REMEMBER_USERNAME, "")!!
|
||||
val nowTime = SimpleDateFormat(
|
||||
"yyyyMMddkkmmss",
|
||||
Locale.getDefault()
|
||||
).format(Date())
|
||||
uploadForAliOss(
|
||||
upLoadData.data,
|
||||
allFilePath,
|
||||
"app/errlog/" + username + "_" + nowTime + ".txt"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1126,88 +1083,4 @@ class NewMainActivity : BaseActivity() {
|
|||
stopUploadTimer()
|
||||
}
|
||||
|
||||
private fun uploadForAliOss(data: ParamData, filePath: List<String>, dirStr: String) {
|
||||
val endpoint = "oss-cn-hongkong.aliyuncs.com"
|
||||
val accessKeyId = data.credentials?.accessKeyId
|
||||
val accessKeySecret = data.credentials?.accessKeySecret
|
||||
// 从STS服务获取的安全令牌(SecurityToken)。
|
||||
val securityToken = data.credentials?.securityToken
|
||||
val credentialProvider =
|
||||
OSSStsTokenCredentialProvider(accessKeyId, accessKeySecret, securityToken)
|
||||
val oss = OSSClient(applicationContext, endpoint, credentialProvider)
|
||||
|
||||
android.util.Log.i("uploadForAliOss", "filePath::::${filePath[0]}")
|
||||
val put = PutObjectRequest("yingmao", dirStr, filePath[0])
|
||||
// 异步上传时可以设置进度回调。
|
||||
put.progressCallback =
|
||||
OSSProgressCallback { request, currentSize, totalSize ->
|
||||
android.util.Log.d(
|
||||
"PutObject",
|
||||
"currentSize: $currentSize totalSize: $totalSize"
|
||||
)
|
||||
}
|
||||
|
||||
val task: OSSAsyncTask<*> = oss.asyncPutObject(put,
|
||||
object : OSSCompletedCallback<PutObjectRequest?, PutObjectResult> {
|
||||
override fun onSuccess(request: PutObjectRequest?, result: PutObjectResult) {
|
||||
if (result.statusCode == 200) {
|
||||
//删除文件
|
||||
DataUtils.deleteFile(filePath[0])
|
||||
}
|
||||
android.util.Log.d("PutObjectRequest", "$request")
|
||||
android.util.Log.d("PutObjectResult", "$result")
|
||||
android.util.Log.d("PutObject", "UploadSuccess")
|
||||
android.util.Log.d("ETag", result.eTag)
|
||||
android.util.Log.d("RequestId", result.requestId)
|
||||
}
|
||||
|
||||
override fun onFailure(
|
||||
request: PutObjectRequest?,
|
||||
clientExcepion: ClientException,
|
||||
serviceException: ServiceException
|
||||
) {
|
||||
// 请求异常。
|
||||
if (clientExcepion != null) {
|
||||
// 本地异常,如网络异常等。
|
||||
clientExcepion.printStackTrace()
|
||||
}
|
||||
if (serviceException != null) {
|
||||
// 服务异常。
|
||||
android.util.Log.e("ErrorCode", serviceException.errorCode)
|
||||
android.util.Log.e("RequestId", serviceException.requestId)
|
||||
android.util.Log.e("HostId", serviceException.hostId)
|
||||
android.util.Log.e("RawMessage", serviceException.rawMessage)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
private fun checkPermission() {
|
||||
PermissionX.request(
|
||||
this,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
) { allGranted, deniedList ->
|
||||
if (allGranted) {
|
||||
android.util.Log.i("checkPermission", "checkPermission::所有申请的权限都已通过")
|
||||
val directory: File? = this.getExternalFilesDir("CrashLog")
|
||||
if (directory != null) {
|
||||
val allFilePath = getAllFilePath(directory.path)
|
||||
if (allFilePath.isNotEmpty()) {
|
||||
mainAtyVM.getUploadParameters()
|
||||
} else {
|
||||
android.util.Log.i("checkPermission", "allFilePath is empty")
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(this, "You denied $deniedList", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,10 +1,23 @@
|
|||
package com.yingmao.clash.act
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.alibaba.sdk.android.oss.ClientException
|
||||
import com.alibaba.sdk.android.oss.OSSClient
|
||||
import com.alibaba.sdk.android.oss.ServiceException
|
||||
import com.alibaba.sdk.android.oss.callback.OSSCompletedCallback
|
||||
import com.alibaba.sdk.android.oss.callback.OSSProgressCallback
|
||||
import com.alibaba.sdk.android.oss.common.auth.OSSStsTokenCredentialProvider
|
||||
import com.alibaba.sdk.android.oss.internal.OSSAsyncTask
|
||||
import com.alibaba.sdk.android.oss.model.PutObjectRequest
|
||||
import com.alibaba.sdk.android.oss.model.PutObjectResult
|
||||
import com.google.gson.Gson
|
||||
|
||||
import com.tencent.mmkv.MMKV
|
||||
|
|
@ -17,24 +30,42 @@ import com.yingmao.clash.base.BaseActivity
|
|||
import com.yingmao.clash.common.log.Log
|
||||
import com.yingmao.clash.conf.BZYConstants
|
||||
import com.yingmao.clash.conf.Conf
|
||||
import com.yingmao.clash.net.http.HttpReqType
|
||||
import com.yingmao.clash.net.http.HttpStatus
|
||||
import com.yingmao.clash.net.http.entity.ParamData
|
||||
import com.yingmao.clash.net.http.entity.UploadParamData
|
||||
import com.yingmao.clash.service.model.Profile
|
||||
import com.yingmao.clash.service.remote.IProfileManager
|
||||
import com.yingmao.clash.util.DataUtils
|
||||
import com.yingmao.clash.util.DataUtils.getAllFilePath
|
||||
import com.yingmao.clash.view.RxToast
|
||||
import com.yingmao.clash.view.dialog.RxDialogShapeLoading
|
||||
import com.yingmao.clash.view.permissions.PermissionX
|
||||
import com.yingmao.clash.vm.MainAtyVM
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.File
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import java.util.UUID
|
||||
|
||||
class SettingActivity : BaseActivity() {
|
||||
|
||||
lateinit var tv_proxy_model: TextView
|
||||
private lateinit var llUpErrorLog:LinearLayout
|
||||
private lateinit var mainAtyVM: MainAtyVM
|
||||
var upErrorLogLoading: RxDialogShapeLoading? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_setting)
|
||||
showTitleBar("设置")
|
||||
initView()
|
||||
mainAtyVM = ViewModelProvider(this)[MainAtyVM::class.java]
|
||||
observe(this, mainAtyVM)
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
|
|
@ -79,8 +110,72 @@ class SettingActivity : BaseActivity() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
llUpErrorLog=findViewById(R.id.llUpErrorLog)
|
||||
llUpErrorLog.setOnClickListener {
|
||||
showLoading("正在上传中...", this@SettingActivity)
|
||||
checkPermission()
|
||||
}
|
||||
}
|
||||
|
||||
override fun httpSuccess(httpStatus: HttpStatus.Success) {
|
||||
if (httpStatus.reqType == HttpReqType.UploadParameters) {
|
||||
val upLoadData = httpStatus.rsp as UploadParamData
|
||||
if (upLoadData.code == 1000) {
|
||||
val directory: File? = this.getExternalFilesDir("CrashLog")
|
||||
//多文件上传
|
||||
if (directory != null) {
|
||||
val allFilePath = getAllFilePath(directory.path)
|
||||
if (upLoadData.data != null) {
|
||||
if (allFilePath.isNotEmpty()) {
|
||||
val username =
|
||||
MMKV.defaultMMKV()
|
||||
.decodeString(BZYConstants.MMKV_KEY_REMEMBER_USERNAME, "")!!
|
||||
val nowTime = SimpleDateFormat(
|
||||
"yyyyMMddkkmmss",
|
||||
Locale.getDefault()
|
||||
).format(Date())
|
||||
uploadForAliOss(
|
||||
upLoadData.data,
|
||||
allFilePath,
|
||||
"app/errlog/" + username + "_" + nowTime + ".txt"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
hideLoading()
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun checkPermission() {
|
||||
PermissionX.request(
|
||||
this,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
) { allGranted, deniedList ->
|
||||
if (allGranted) {
|
||||
android.util.Log.i("checkPermission", "checkPermission::所有申请的权限都已通过")
|
||||
val directory: File? = this.getExternalFilesDir("CrashLog")
|
||||
if (directory != null) {
|
||||
val allFilePath = getAllFilePath(directory.path)
|
||||
if (allFilePath.isNotEmpty()) {
|
||||
mainAtyVM.getUploadParameters()
|
||||
} else {
|
||||
android.util.Log.i("checkPermission", "allFilePath is empty")
|
||||
hideLoading()
|
||||
RxToast.info("暂未收集到错误日志!")
|
||||
}
|
||||
} else {
|
||||
hideLoading()
|
||||
RxToast.error("读写权限被拒绝,请开启相关权限")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
val isGlobal = MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
|
||||
|
|
@ -169,8 +264,74 @@ class SettingActivity : BaseActivity() {
|
|||
Log.d("GetNodeTimeOutNum==>$GetNodeTimeOutNum")
|
||||
delay(1000)
|
||||
}
|
||||
|
||||
errInit()
|
||||
}
|
||||
}
|
||||
private fun uploadForAliOss(data: ParamData, filePath: List<String>, dirStr: String) {
|
||||
val endpoint = "oss-cn-hongkong.aliyuncs.com"
|
||||
val accessKeyId = data.credentials?.accessKeyId
|
||||
val accessKeySecret = data.credentials?.accessKeySecret
|
||||
// 从STS服务获取的安全令牌(SecurityToken)。
|
||||
val securityToken = data.credentials?.securityToken
|
||||
val credentialProvider =
|
||||
OSSStsTokenCredentialProvider(accessKeyId, accessKeySecret, securityToken)
|
||||
val oss = OSSClient(applicationContext, endpoint, credentialProvider)
|
||||
|
||||
android.util.Log.i("uploadForAliOss", "filePath::::${filePath[0]}")
|
||||
val put = PutObjectRequest("yingmao", dirStr, filePath[0])
|
||||
// 异步上传时可以设置进度回调。
|
||||
put.progressCallback =
|
||||
OSSProgressCallback { request, currentSize, totalSize ->
|
||||
android.util.Log.d(
|
||||
"PutObject",
|
||||
"currentSize: $currentSize totalSize: $totalSize"
|
||||
)
|
||||
}
|
||||
|
||||
val task: OSSAsyncTask<*> = oss.asyncPutObject(put,
|
||||
object : OSSCompletedCallback<PutObjectRequest?, PutObjectResult> {
|
||||
override fun onSuccess(request: PutObjectRequest?, result: PutObjectResult) {
|
||||
if (result.statusCode == 200) {
|
||||
//删除文件
|
||||
DataUtils.deleteFile(filePath[0])
|
||||
}
|
||||
|
||||
runOnUiThread {
|
||||
hideLoading()
|
||||
RxToast.info("错误日志上传成功!")
|
||||
}
|
||||
|
||||
android.util.Log.d("PutObjectRequest", "$request")
|
||||
android.util.Log.d("PutObjectResult", "$result")
|
||||
android.util.Log.d("PutObject", "UploadSuccess")
|
||||
android.util.Log.d("ETag", result.eTag)
|
||||
android.util.Log.d("RequestId", result.requestId)
|
||||
}
|
||||
|
||||
override fun onFailure(
|
||||
request: PutObjectRequest?,
|
||||
clientExcepion: ClientException,
|
||||
serviceException: ServiceException
|
||||
) {
|
||||
runOnUiThread {
|
||||
hideLoading()
|
||||
RxToast.error("错误日志上传失败!")
|
||||
}
|
||||
// 请求异常。
|
||||
if (clientExcepion != null) {
|
||||
// 本地异常,如网络异常等。
|
||||
clientExcepion.printStackTrace()
|
||||
}
|
||||
if (serviceException != null) {
|
||||
// 服务异常。
|
||||
android.util.Log.e("ErrorCode", serviceException.errorCode)
|
||||
android.util.Log.e("RequestId", serviceException.requestId)
|
||||
android.util.Log.e("HostId", serviceException.hostId)
|
||||
android.util.Log.e("RawMessage", serviceException.rawMessage)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -191,6 +191,40 @@
|
|||
android:textStyle="bold" />
|
||||
|
||||
|
||||
<ImageView
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_marginLeft="@dimen/dp_10"
|
||||
android:src="@drawable/ic_s_arrow_right" />
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:background="@color/white_50"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"/>
|
||||
<LinearLayout
|
||||
android:id="@+id/llUpErrorLog"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:paddingRight="30dp"
|
||||
android:paddingLeft="30dp"
|
||||
android:paddingTop="@dimen/dp_10"
|
||||
android:paddingBottom="@dimen/dp_10">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/UploadErrorLog"
|
||||
android:textColor="@color/text_yellow"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
|
||||
<ImageView
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
|
|
|
|||
|
|
@ -395,4 +395,6 @@
|
|||
<string name="firstEntry">免费时长已赠送,如果出现初始化,请等待一分钟后关闭app重新打开.</string>
|
||||
<string name="determine">确定</string>
|
||||
<string name="reminder">温馨提示</string>
|
||||
<string name="UploadErrorLog">上传错误日志</string>
|
||||
UpErrorLog
|
||||
</resources>
|
||||
Loading…
Reference in New Issue