2
This commit is contained in:
@@ -368,7 +368,7 @@ public class BindNumberActivity extends BaseActivity implements OnCallBackFromNe
|
|||||||
SharePrefUtil.saveInt(ct, "sex", sex);// 性别(0.男 1.女)
|
SharePrefUtil.saveInt(ct, "sex", sex);// 性别(0.男 1.女)
|
||||||
SharePrefUtil.saveInt(ct, "state", state);// 审核状态( 1.待审核
|
SharePrefUtil.saveInt(ct, "state", state);// 审核状态( 1.待审核
|
||||||
|
|
||||||
|
needreportSimple("login");
|
||||||
addUMToken(PushAgent.getInstance(this).getRegistrationId());
|
addUMToken(PushAgent.getInstance(this).getRegistrationId());
|
||||||
// 2.审核中3.需要补充修改资料
|
// 2.审核中3.需要补充修改资料
|
||||||
// 4.再次提交审核5.拒绝 6.已通过)
|
// 4.再次提交审核5.拒绝 6.已通过)
|
||||||
|
|||||||
@@ -1320,53 +1320,50 @@ public class BookDetailActivity extends BaseActivity implements
|
|||||||
}
|
}
|
||||||
//先判断是否网络下载
|
//先判断是否网络下载
|
||||||
private void isNetWorkDown(){
|
private void isNetWorkDown(){
|
||||||
String message = null;
|
int netType = CommonUtil.isNetworkAvailable(mActivity);
|
||||||
if (CommonUtil.isNetworkAvailable(mActivity) == 1){
|
if (netType == 0){
|
||||||
message = "当前为Wifi网络,您确定下载该篇文章?";
|
|
||||||
}else if (CommonUtil.isNetworkAvailable(mActivity) == 0){
|
|
||||||
ToastUtil.showMessage("无网络,请检查网络连接!");
|
ToastUtil.showMessage("无网络,请检查网络连接!");
|
||||||
}else {
|
return;
|
||||||
message = "当前为移动网络,您确定下载该篇文章?";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (netType == 1){
|
||||||
|
startBookDownload();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String message = "当前为移动网络,您确定下载该篇文章?";
|
||||||
buildAlert = ECAlertDialog.buildAlert(mActivity, message, "取消", "确定",
|
buildAlert = ECAlertDialog.buildAlert(mActivity, message, "取消", "确定",
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
buildAlert.dismiss();
|
buildAlert.dismiss();
|
||||||
}
|
}
|
||||||
}, new DialogInterface.OnClickListener() {
|
}, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
buildAlert.dismiss();
|
||||||
// TODO Auto-generated method stub
|
startBookDownload();
|
||||||
if(mPath!=null&&mPath.contains(Constant.OldfilePath))
|
|
||||||
{
|
|
||||||
new Thread(networkTask3new).start();
|
|
||||||
}
|
|
||||||
else if (hasDownload>0){
|
|
||||||
new Thread(networkTask3).start();
|
|
||||||
buildAlert.dismiss();
|
|
||||||
}else {
|
|
||||||
if (welfareNum>0){
|
|
||||||
useWelfareNum();
|
|
||||||
buildAlert.dismiss();
|
|
||||||
}else {
|
|
||||||
isJifenDown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
buildAlert.setTitle("提示");
|
buildAlert.setTitle("提示");
|
||||||
buildAlert.setTitleColor(mActivity.getResources().getColor(
|
buildAlert.setTitleColor(mActivity.getResources().getColor(
|
||||||
R.color.top_title));
|
R.color.top_title));
|
||||||
buildAlert.show();
|
buildAlert.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startBookDownload() {
|
||||||
|
if(mPath!=null&&mPath.contains(Constant.OldfilePath))
|
||||||
|
{
|
||||||
|
new Thread(networkTask3new).start();
|
||||||
|
}
|
||||||
|
else if (hasDownload>0){
|
||||||
|
new Thread(networkTask3).start();
|
||||||
|
}else {
|
||||||
|
if (welfareNum>0){
|
||||||
|
useWelfareNum();
|
||||||
|
}else {
|
||||||
|
isJifenDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
//使用福利操作
|
//使用福利操作
|
||||||
private void useWelfareNum() {
|
private void useWelfareNum() {
|
||||||
Map<String,String> map = new HashMap<>();
|
Map<String,String> map = new HashMap<>();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cn.shangyu.gdxzExpert.base;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -608,14 +609,18 @@ public abstract class BaseFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
public void startReport(List<reportBean> list)
|
public void startReport(List<reportBean> list)
|
||||||
{
|
{
|
||||||
Intent intent = new Intent(getActivity(), ReportService.class);
|
Context targetContext = getActivity() != null ? getActivity() : UIUtils.getContext();
|
||||||
|
if (targetContext == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Intent intent = new Intent(targetContext, ReportService.class);
|
||||||
if(list!=null)
|
if(list!=null)
|
||||||
{
|
{
|
||||||
intent.putExtra("report_list", (Serializable) list);
|
intent.putExtra("report_list", (Serializable) list);
|
||||||
|
|
||||||
}
|
}
|
||||||
intent.putExtra("report_token", Constant.Repotr_token);
|
intent.putExtra("report_token", Constant.Repotr_token);
|
||||||
getActivity().startService(intent);
|
targetContext.startService(intent);
|
||||||
}
|
}
|
||||||
public void needreportSimple(String name)
|
public void needreportSimple(String name)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,7 +40,9 @@ public class LogoutHelper {
|
|||||||
SharePrefUtil.clear(UIUtils.getContext(), "isLogin");
|
SharePrefUtil.clear(UIUtils.getContext(), "isLogin");
|
||||||
startReport(null);
|
startReport(null);
|
||||||
|
|
||||||
// Constant.Repotr_token="";
|
Constant.Repotr_token = "";
|
||||||
|
Constant.Report_userId = "";
|
||||||
|
Constant.Repotr_app_key = "";
|
||||||
// SharePrefUtil.clear(UIUtils.getContext(), SharePrefUtil.getString(UIUtils.getContext(), Constant.SP_IS_FIRST_NAME,
|
// SharePrefUtil.clear(UIUtils.getContext(), SharePrefUtil.getString(UIUtils.getContext(), Constant.SP_IS_FIRST_NAME,
|
||||||
// Constant.mobile, "") + "my_provinceId");
|
// Constant.mobile, "") + "my_provinceId");
|
||||||
// SharePrefUtil.clear(UIUtils.getContext(), SharePrefUtil.getString(UIUtils.getContext(), Constant.SP_IS_FIRST_NAME,
|
// SharePrefUtil.clear(UIUtils.getContext(), SharePrefUtil.getString(UIUtils.getContext(), Constant.SP_IS_FIRST_NAME,
|
||||||
|
|||||||
+1
-15
@@ -1810,21 +1810,7 @@ public class VideoDetailPolyvPlayerActivity extends FragmentActivity implements
|
|||||||
String netWorkTypeName = getNetWorkTypeName(VideoDetailPolyvPlayerActivity.this);
|
String netWorkTypeName = getNetWorkTypeName(VideoDetailPolyvPlayerActivity.this);
|
||||||
if ("NETWORK_WIFI".equals(netWorkTypeName)){
|
if ("NETWORK_WIFI".equals(netWorkTypeName)){
|
||||||
if ("点击下载".equals(tv_exchange.getText().toString())){
|
if ("点击下载".equals(tv_exchange.getText().toString())){
|
||||||
buildAlert = ECAlertDialog.buildAlert(VideoDetailPolyvPlayerActivity.this,"当前为Wifi网络,确定下载?", "取消", "确定",
|
videoDown();
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
buildAlert.dismiss();
|
|
||||||
}
|
|
||||||
}, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
videoDown();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
buildAlert.setTitle("温馨提示");
|
|
||||||
buildAlert.show();
|
|
||||||
}else if("视频缓存中".equals(tv_exchange.getText().toString())){
|
}else if("视频缓存中".equals(tv_exchange.getText().toString())){
|
||||||
Intent intent1 = new Intent(VideoDetailPolyvPlayerActivity.this, PolyvDownloadActivity.class);
|
Intent intent1 = new Intent(VideoDetailPolyvPlayerActivity.this, PolyvDownloadActivity.class);
|
||||||
intent1.putExtra("isStarting",true);
|
intent1.putExtra("isStarting",true);
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import java.util.zip.ZipEntry;
|
|||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import cn.shangyu.gdxzExpert.BuildConfig;
|
import cn.shangyu.gdxzExpert.BuildConfig;
|
||||||
|
import cn.shangyu.gdxzExpert.utils.Constant;
|
||||||
|
import cn.shangyu.gdxzExpert.utils.StringUtil;
|
||||||
|
|
||||||
public class CommUtil {
|
public class CommUtil {
|
||||||
// public static String userId="";
|
// public static String userId="";
|
||||||
@@ -79,8 +81,20 @@ public class CommUtil {
|
|||||||
Log.d("saveListToFile",file.getAbsolutePath());
|
Log.d("saveListToFile",file.getAbsolutePath());
|
||||||
try {
|
try {
|
||||||
FileOutputStream fos=new FileOutputStream(file,true);//设置为true,继续原文件写入
|
FileOutputStream fos=new FileOutputStream(file,true);//设置为true,继续原文件写入
|
||||||
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos))) {
|
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8"))) {
|
||||||
for (reportBean item : list) {
|
for (reportBean item : list) {
|
||||||
|
if (item == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (StringUtil.isEmpty(item.getUser_id()) && !StringUtil.isEmpty(Constant.Report_userId)) {
|
||||||
|
item.setUser_id(Constant.Report_userId);
|
||||||
|
}
|
||||||
|
if (StringUtil.isEmpty(item.getApp_key()) && !StringUtil.isEmpty(Constant.Repotr_app_key)) {
|
||||||
|
item.setApp_key(Constant.Repotr_app_key);
|
||||||
|
}
|
||||||
|
if (StringUtil.isEmpty(item.getNetwork_carrier()) && !StringUtil.isEmpty(CommUtil.getCarrierName)) {
|
||||||
|
item.setNetwork_carrier(CommUtil.getCarrierName);
|
||||||
|
}
|
||||||
writer.write(gson.toJson(item));
|
writer.write(gson.toJson(item));
|
||||||
writer.newLine(); // 每个布尔值后写入一个新行
|
writer.newLine(); // 每个布尔值后写入一个新行
|
||||||
}
|
}
|
||||||
@@ -106,34 +120,63 @@ public class CommUtil {
|
|||||||
|
|
||||||
try (FileOutputStream fos = new FileOutputStream(zipFile);
|
try (FileOutputStream fos = new FileOutputStream(zipFile);
|
||||||
ZipOutputStream zos = new ZipOutputStream(fos)) {
|
ZipOutputStream zos = new ZipOutputStream(fos)) {
|
||||||
|
zipFolderInternal(folderToZip, zos, basePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
File[] files = folderToZip.listFiles();
|
private static void zipFolderInternal(File currentFolder, ZipOutputStream zos, String basePath) throws IOException {
|
||||||
if (files != null) {
|
File[] files = currentFolder.listFiles();
|
||||||
for (File file : files) {
|
if (files != null) {
|
||||||
String filePath = file.getPath().replace("\\", "/");
|
for (File file : files) {
|
||||||
String entryName = filePath.substring(basePath.length());
|
String filePath = file.getPath().replace("\\", "/");
|
||||||
if (file.isDirectory()) {
|
String entryName = filePath.substring(basePath.length());
|
||||||
// 添加文件夹条目
|
if (file.isDirectory()) {
|
||||||
zos.putNextEntry(new ZipEntry(entryName + "/"));
|
zos.putNextEntry(new ZipEntry(entryName + "/"));
|
||||||
zos.closeEntry();
|
zos.closeEntry();
|
||||||
// 递归地压缩子文件夹
|
zipFolderInternal(file, zos, basePath);
|
||||||
zipFolderCorrected(file, zipFile, basePath);
|
} else {
|
||||||
} else {
|
zos.putNextEntry(new ZipEntry(entryName));
|
||||||
// 添加文件条目并写入文件内容
|
try (FileInputStream fis = new FileInputStream(file)) {
|
||||||
zos.putNextEntry(new ZipEntry(entryName));
|
byte[] buffer = new byte[1024];
|
||||||
try (FileInputStream fis = new FileInputStream(file)) {
|
int length;
|
||||||
byte[] buffer = new byte[1024];
|
while ((length = fis.read(buffer)) >= 0) {
|
||||||
int length;
|
zos.write(buffer, 0, length);
|
||||||
while ((length = fis.read(buffer)) >= 0) {
|
|
||||||
zos.write(buffer, 0, length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
zos.closeEntry();
|
|
||||||
}
|
}
|
||||||
|
zos.closeEntry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将待打包的 upload.txt 合并移动到 uploading/upload.txt 快照目录中,
|
||||||
|
* 避免上传期间产生的新埋点丢失或上传成功后被误删。
|
||||||
|
*/
|
||||||
|
public static void mergeFileToUploading(File srcFile, File destFile) throws IOException {
|
||||||
|
if (srcFile == null || !srcFile.exists() || srcFile.length() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
File parentDir = destFile.getParentFile();
|
||||||
|
if (parentDir != null && !parentDir.exists()) {
|
||||||
|
parentDir.mkdirs();
|
||||||
|
}
|
||||||
|
if (!destFile.exists()) {
|
||||||
|
if (srcFile.renameTo(destFile)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try (FileInputStream fis = new FileInputStream(srcFile);
|
||||||
|
FileOutputStream fos = new FileOutputStream(destFile, true)) {
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
int length;
|
||||||
|
while ((length = fis.read(buffer)) >= 0) {
|
||||||
|
fos.write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
fos.flush();
|
||||||
|
}
|
||||||
|
srcFile.delete();
|
||||||
|
}
|
||||||
public static void deleteFile( String ReportFileZip,String name,String folderPath)
|
public static void deleteFile( String ReportFileZip,String name,String folderPath)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -24,9 +24,12 @@ import java.io.InputStream;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import cn.shangyu.gdxzExpert.bean.TimestampBean;
|
import cn.shangyu.gdxzExpert.bean.TimestampBean;
|
||||||
import cn.shangyu.gdxzExpert.http.HttpHelper;
|
import cn.shangyu.gdxzExpert.http.HttpHelper;
|
||||||
@@ -47,17 +50,24 @@ public class ReportService extends Service {
|
|||||||
|
|
||||||
public ReportService() {
|
public ReportService() {
|
||||||
}
|
}
|
||||||
|
private static final ExecutorService REPORT_EXECUTOR = Executors.newSingleThreadExecutor();
|
||||||
|
private static final List<reportBean> PENDING_BEFORE_TOKEN_LIST = new ArrayList<>();
|
||||||
|
|
||||||
public String ReportFile;
|
public String ReportFile;
|
||||||
|
public String ReportUploadingDir;
|
||||||
public String ReportFileZip;
|
public String ReportFileZip;
|
||||||
public String report_token="";
|
public volatile String report_token = "";
|
||||||
List<reportBean> list;
|
private volatile boolean isFetchingToken = false;
|
||||||
|
|
||||||
// public String FileUrl="https://dev-event.igandan.com/v1/eventLog/upload";//测试环境
|
// public String FileUrl="https://dev-event.igandan.com/v1/eventLog/upload";//测试环境
|
||||||
// public String FileUrl="https://event.igandan.com/v1/eventLog/upload";//正式环境
|
// public String FileUrl="https://event.igandan.com/v1/eventLog/upload";//正式环境
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
ReportFile=getBaseContext().getExternalFilesDir("").getAbsolutePath()+"/gdxz/report/zip";
|
String basePath = getBaseContext().getExternalFilesDir("").getAbsolutePath();
|
||||||
ReportFileZip=getBaseContext().getExternalFilesDir("").getAbsolutePath()+"/gdxz/report/";
|
ReportFile = basePath + "/gdxz/report/zip";
|
||||||
|
ReportUploadingDir = basePath + "/gdxz/report/uploading";
|
||||||
|
ReportFileZip = basePath + "/gdxz/report/";
|
||||||
// if("true".equals(CommUtil.isFirstRun))
|
// if("true".equals(CommUtil.isFirstRun))
|
||||||
// {
|
// {
|
||||||
// CommUtil.isFirstRun="false";
|
// CommUtil.isFirstRun="false";
|
||||||
@@ -102,160 +112,212 @@ public class ReportService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
report_token=intent.getStringExtra("report_token");
|
if (intent == null) {
|
||||||
if(report_token==""||report_token==null)
|
|
||||||
{
|
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
else if(intent.getSerializableExtra("report_list")==null)
|
final String incomingToken = intent.getStringExtra("report_token");
|
||||||
{
|
if (!StringUtil.isEmpty(incomingToken)) {
|
||||||
if(checkReport())
|
report_token = incomingToken;
|
||||||
{
|
} else if (!StringUtil.isEmpty(Constant.Repotr_token)) {
|
||||||
new Thread(new Runnable() {
|
report_token = Constant.Repotr_token;
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
zipFile();
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
return START_NOT_STICKY;
|
|
||||||
}
|
}
|
||||||
list = (List<reportBean>) intent.getSerializableExtra("report_list");
|
final List<reportBean> incomingList = (List<reportBean>) intent.getSerializableExtra("report_list");
|
||||||
CommUtil.totalreport+= list.size();
|
|
||||||
|
|
||||||
// 在新线程或异步任务中执行文件上传
|
REPORT_EXECUTOR.execute(new Runnable() {
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
writeReport();
|
handleReportCommand(incomingList);
|
||||||
// uploadFile(filePath);
|
|
||||||
// // 上传完成后,可以停止服务或发送广播通知其他组件
|
|
||||||
// stopSelf(); // 或者使用广播通知
|
|
||||||
}
|
}
|
||||||
}).start();
|
});
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
public void writeReport()
|
|
||||||
{
|
|
||||||
// if(2>1)
|
|
||||||
// {
|
|
||||||
// CommUtil.deleteFile(ReportFileZip,"output.zip",ReportFile);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
if( "true".equals(CommUtil.isReoprtingNow))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Log.d("okhttp","CommUtil.totalreport "+ CommUtil.totalreport);
|
|
||||||
if(CommUtil.totalreport>99&&checkReport())
|
|
||||||
{
|
|
||||||
|
|
||||||
|
private String getActiveUuid() {
|
||||||
|
String uuid = SharePrefUtil.getString(UIUtils.getContext(), Constant.uuid, "");
|
||||||
|
if (StringUtil.isEmpty(uuid)) {
|
||||||
|
uuid = LogoutHelper.addUMTokenuuid;
|
||||||
|
}
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleReportCommand(List<reportBean> incomingList) {
|
||||||
|
if (!StringUtil.isEmpty(Constant.Repotr_token)) {
|
||||||
|
report_token = Constant.Repotr_token;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Token 尚未就绪时:若用户已登录,先暂存到内存队列并自动请求 Token,避免刚登录/冷启动的埋点丢失
|
||||||
|
if (StringUtil.isEmpty(report_token)) {
|
||||||
|
if (incomingList != null && !incomingList.isEmpty() && !StringUtil.isEmpty(getActiveUuid())) {
|
||||||
|
PENDING_BEFORE_TOKEN_LIST.addAll(incomingList);
|
||||||
|
initReport(false);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Token 已就绪:先把之前暂存的埋点补齐 user_id/app_key 并落盘
|
||||||
|
flushPendingBeforeTokenList();
|
||||||
|
|
||||||
|
if (incomingList == null) {
|
||||||
|
if (checkReport()) {
|
||||||
|
zipFile();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!incomingList.isEmpty()) {
|
||||||
|
writeReport(incomingList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void flushPendingBeforeTokenList() {
|
||||||
|
if (!PENDING_BEFORE_TOKEN_LIST.isEmpty()) {
|
||||||
|
CommUtil.saveListToFile(PENDING_BEFORE_TOKEN_LIST, ReportFile, "upload", ReportFileZip);
|
||||||
|
CommUtil.totalreport += PENDING_BEFORE_TOKEN_LIST.size();
|
||||||
|
PENDING_BEFORE_TOKEN_LIST.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeReport(List<reportBean> currentList) {
|
||||||
|
// 始终先把当前批次写入本地 upload.txt,避免第 100 条埋点丢失或上传期间新埋点丢失
|
||||||
|
CommUtil.saveListToFile(currentList, ReportFile, "upload", ReportFileZip);
|
||||||
|
CommUtil.totalreport += currentList.size();
|
||||||
|
Log.d("okhttp", "CommUtil.totalreport " + CommUtil.totalreport);
|
||||||
|
|
||||||
|
if (CommUtil.totalreport >= 100 && checkReport()) {
|
||||||
zipFile();
|
zipFile();
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
CommUtil.saveListToFile(list,ReportFile,"upload",ReportFileZip);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public void zipFile()
|
|
||||||
{
|
public void zipFile() {
|
||||||
CommUtil.isReoprtingNow="true";
|
if ("true".equals(CommUtil.isReoprtingNow)) {
|
||||||
File folderToZip = new File(ReportFile);
|
return;
|
||||||
File zipFile = new File(ReportFileZip,"outputandroid.zip");
|
}
|
||||||
try {
|
try {
|
||||||
|
File pendingFile = new File(ReportFile, "upload.txt");
|
||||||
|
File uploadingFile = new File(ReportUploadingDir, "upload.txt");
|
||||||
|
// 将待上传的 upload.txt 合并迁移至隔离目录 uploading/upload.txt,避免上传期间新写入的数据被混入或误删
|
||||||
|
CommUtil.mergeFileToUploading(pendingFile, uploadingFile);
|
||||||
|
CommUtil.totalreport = 0;
|
||||||
|
|
||||||
|
if (!uploadingFile.exists() || uploadingFile.length() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommUtil.isReoprtingNow = "true";
|
||||||
|
File folderToZip = new File(ReportUploadingDir);
|
||||||
|
File zipFile = new File(ReportFileZip, "outputandroid.zip");
|
||||||
CommUtil.zipFolderCorrected(folderToZip, zipFile, folderToZip.getPath());
|
CommUtil.zipFolderCorrected(folderToZip, zipFile, folderToZip.getPath());
|
||||||
uploadFile();
|
uploadFile();
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
|
CommUtil.isReoprtingNow = "false";
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void uploadFile() {
|
|
||||||
|
|
||||||
Map<String, String> headers=new HashMap<>();
|
public void uploadFile() {
|
||||||
headers.put("Content-Type","multipart/form-data");
|
Map<String, String> headers = new HashMap<>();
|
||||||
headers.put("Tag-Access",report_token);
|
headers.put("Content-Type", "multipart/form-data");
|
||||||
// Log.d("okhttp","report_token"+report_token);
|
headers.put("Tag-Access", report_token);
|
||||||
File zipFile = new File(ReportFileZip,"outputandroid.zip");
|
File zipFile = new File(ReportFileZip, "outputandroid.zip");
|
||||||
|
if (!zipFile.exists() || zipFile.length() == 0) {
|
||||||
|
CommUtil.isReoprtingNow = "false";
|
||||||
|
return;
|
||||||
|
}
|
||||||
OkHttpUtils
|
OkHttpUtils
|
||||||
.post()
|
.post()
|
||||||
.url(Url.FileUrl)
|
.url(Url.FileUrl)
|
||||||
.headers(headers)
|
.headers(headers)
|
||||||
.addFile("file", "outputandroid.zip", zipFile)//
|
.addFile("file", "outputandroid.zip", zipFile)
|
||||||
|
|
||||||
// .file(zipFile)
|
|
||||||
|
|
||||||
.build()
|
.build()
|
||||||
.execute(new StringCallback() {
|
.execute(new StringCallback() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Call call, Exception e, int id) {
|
public void onError(Call call, Exception e, int id) {
|
||||||
Log.d("okhttp",e+"e");
|
Log.d("okhttp", e + "e");
|
||||||
CommUtil.isReoprtingNow="false";
|
CommUtil.isReoprtingNow = "false";
|
||||||
CommUtil.totalreport=0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(String response, int id) {
|
public void onResponse(String response, int id) {
|
||||||
Log.d("okhttp",response+"responseoutput");
|
Log.d("okhttp", response + "responseoutput");
|
||||||
CommUtil.isReoprtingNow="false";
|
|
||||||
|
|
||||||
JSONObject jsonObject= null;
|
|
||||||
try {
|
try {
|
||||||
jsonObject = new JSONObject(response);
|
JSONObject jsonObject = new JSONObject(response);
|
||||||
if("30007".equals(jsonObject.optString("code")))
|
String code = jsonObject.optString("code");
|
||||||
{
|
if ("30007".equals(code)) {
|
||||||
initReport();
|
initReport(true);
|
||||||
}
|
} else if ("200".equals(code)) {
|
||||||
else if("200".equals(jsonObject.optString("code")))
|
REPORT_EXECUTOR.execute(new Runnable() {
|
||||||
{
|
@Override
|
||||||
CommUtil.deleteFile(ReportFileZip,"outputandroid.zip",ReportFile);
|
public void run() {
|
||||||
// CommUtil.isReoprtingNow="false";
|
// 仅清理已上传成功的快照目录 ReportUploadingDir,保留上传期间新写入 ReportFile 的数据
|
||||||
CommUtil.totalreport=0;
|
CommUtil.deleteFile(ReportFileZip, "outputandroid.zip", ReportUploadingDir);
|
||||||
}
|
CommUtil.isReoprtingNow = "false";
|
||||||
else
|
if (CommUtil.totalreport >= 100 && checkReport()) {
|
||||||
{
|
zipFile();
|
||||||
// CommUtil.isReoprtingNow="false";
|
}
|
||||||
CommUtil.totalreport=0;
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
CommUtil.isReoprtingNow = "false";
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
CommUtil.isReoprtingNow = "false";
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public Boolean checkReport()
|
|
||||||
{
|
public Boolean checkReport() {
|
||||||
File folderToZip = new File(ReportFile);
|
File pendingFile = new File(ReportFile, "upload.txt");
|
||||||
if(folderToZip.exists())
|
File uploadingFile = new File(ReportUploadingDir, "upload.txt");
|
||||||
{
|
return (pendingFile.exists() && pendingFile.length() > 0)
|
||||||
return true;
|
|| (uploadingFile.exists() && uploadingFile.length() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initReport() {
|
||||||
|
initReport(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initReport(final boolean retryUploadAfterToken) {
|
||||||
|
if (isFetchingToken) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return false;
|
String uuid = getActiveUuid();
|
||||||
|
if (StringUtil.isEmpty(uuid)) {
|
||||||
|
if (retryUploadAfterToken) {
|
||||||
|
CommUtil.isReoprtingNow = "false";
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isFetchingToken = true;
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
sendJsonPostParamtoNetSignMD5(Url.getTagToken, map, retryUploadAfterToken);
|
||||||
}
|
}
|
||||||
public void initReport()
|
|
||||||
{
|
|
||||||
|
|
||||||
Map<String,String> map = new HashMap<>();
|
public void sendJsonPostParamtoNetSignMD5(final String postUrl, final Map<String, String> param, final boolean retryUploadAfterToken) {
|
||||||
sendJsonPostParamtoNetSignMD5(Url.getTagToken,map);
|
|
||||||
|
|
||||||
|
HttpHelper.loadData(HttpRequest.HttpMethod.GET, Url.getTimestamp, null, new RequestCallBack<String>() {
|
||||||
}
|
|
||||||
public void sendJsonPostParamtoNetSignMD5(final String postUrl, final Map<String, String> param) {
|
|
||||||
|
|
||||||
HttpHelper.loadData(HttpRequest.HttpMethod.GET, Url.getTimestamp,null, new RequestCallBack<String>() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(ResponseInfo<String> info) {
|
public void onSuccess(ResponseInfo<String> info) {
|
||||||
String uuid = SharePrefUtil.getString(UIUtils.getContext(), Constant.uuid, "");
|
String uuid = getActiveUuid();
|
||||||
if(StringUtil.isEmpty(uuid))
|
if (StringUtil.isEmpty(uuid)) {
|
||||||
{
|
isFetchingToken = false;
|
||||||
uuid= LogoutHelper.addUMTokenuuid;
|
if (retryUploadAfterToken) {
|
||||||
|
CommUtil.isReoprtingNow = "false";
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
param.put("user_uuid", uuid);
|
param.put("user_uuid", uuid);
|
||||||
TimestampBean bean = GsonTools.fromGsonToBean(info.result, TimestampBean.class);
|
TimestampBean bean = GsonTools.fromGsonToBean(info.result, TimestampBean.class);
|
||||||
|
if (bean == null) {
|
||||||
|
isFetchingToken = false;
|
||||||
|
if (retryUploadAfterToken) {
|
||||||
|
CommUtil.isReoprtingNow = "false";
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
param.put("timestamp", bean.getTimestamp());
|
param.put("timestamp", bean.getTimestamp());
|
||||||
param.put("client_type", "A");
|
param.put("client_type", "A");
|
||||||
param.put("version", UpdateVersionUtils.getVersionName());
|
param.put("version", UpdateVersionUtils.getVersionName());
|
||||||
@@ -265,45 +327,58 @@ public class ReportService extends Service {
|
|||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
String params = gson.toJson(param);
|
String params = gson.toJson(param);
|
||||||
byte[] data;
|
byte[] data;
|
||||||
|
boolean tokenRefreshed = false;
|
||||||
try {
|
try {
|
||||||
String sign = SignUtil.getSign(param);
|
String sign = SignUtil.getSign(param);
|
||||||
LogUtil.i("params = "+params.toString());
|
LogUtil.i("params = " + params.toString());
|
||||||
data = params.getBytes(encoding);
|
data = params.getBytes(encoding);
|
||||||
URL url = new URL(postUrl);
|
URL url = new URL(postUrl);
|
||||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
conn.setRequestMethod("POST");
|
conn.setRequestMethod("POST");
|
||||||
conn.setDoOutput(true);
|
conn.setDoOutput(true);
|
||||||
conn.setRequestProperty("Content-Type","application/json");
|
conn.setRequestProperty("Content-Type", "application/json");
|
||||||
conn.setRequestProperty("sign",sign);
|
conn.setRequestProperty("sign", sign);
|
||||||
conn.setRequestProperty("Content-Length",String.valueOf(data.length));
|
conn.setRequestProperty("Content-Length", String.valueOf(data.length));
|
||||||
conn.setConnectTimeout(5 * 1000);
|
conn.setConnectTimeout(5 * 1000);
|
||||||
OutputStream outStream = conn.getOutputStream();
|
OutputStream outStream = conn.getOutputStream();
|
||||||
outStream.write(data);
|
outStream.write(data);
|
||||||
outStream.flush();
|
outStream.flush();
|
||||||
outStream.close();
|
outStream.close();
|
||||||
int ssss=conn.getResponseCode() ;
|
int ssss = conn.getResponseCode();
|
||||||
if (ssss == 200) {
|
if (ssss == 200) {
|
||||||
InputStream inStream = conn.getInputStream();
|
InputStream inStream = conn.getInputStream();
|
||||||
String result = new String(StreamTool.readInputStream(inStream), "UTF-8");
|
String result = new String(StreamTool.readInputStream(inStream), "UTF-8");
|
||||||
String string = new String(result);
|
|
||||||
LogUtil.i("result = " + result);
|
LogUtil.i("result = " + result);
|
||||||
JSONObject jsonObject111 = new JSONObject(string);
|
JSONObject jsonObject111 = new JSONObject(result);
|
||||||
if ("200".equals(jsonObject111.optString("code"))&&!jsonObject111.isNull("data")) {
|
if ("200".equals(jsonObject111.optString("code")) && !jsonObject111.isNull("data")) {
|
||||||
Constant.Report_userId= jsonObject111.optJSONObject("data").optString("userId");
|
Constant.Report_userId = jsonObject111.optJSONObject("data").optString("userId");
|
||||||
Constant.Repotr_token=jsonObject111.optJSONObject("data").optString("token");
|
Constant.Repotr_token = jsonObject111.optJSONObject("data").optString("token");
|
||||||
Constant.Repotr_app_key=jsonObject111.optJSONObject("data").optString("appKey");
|
Constant.Repotr_app_key = jsonObject111.optJSONObject("data").optString("appKey");
|
||||||
report_token=Constant.Repotr_token;
|
report_token = Constant.Repotr_token;
|
||||||
// Log.d("okhttp","report_token666"+report_token);
|
tokenRefreshed = true;
|
||||||
uploadFile();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.e("提交失败,请重试 = "+e.getMessage());
|
LogUtil.e("提交失败,请重试 = " + e.getMessage());
|
||||||
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
|
isFetchingToken = false;
|
||||||
|
if (tokenRefreshed) {
|
||||||
|
if (retryUploadAfterToken) {
|
||||||
|
uploadFile();
|
||||||
|
}
|
||||||
|
REPORT_EXECUTOR.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
flushPendingBeforeTokenList();
|
||||||
|
if (!retryUploadAfterToken && CommUtil.totalreport >= 100 && checkReport()) {
|
||||||
|
zipFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (retryUploadAfterToken) {
|
||||||
|
CommUtil.isReoprtingNow = "false";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
@@ -312,7 +387,10 @@ public class ReportService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(HttpException arg0, String arg1) {
|
public void onFailure(HttpException arg0, String arg1) {
|
||||||
|
isFetchingToken = false;
|
||||||
|
if (retryUploadAfterToken) {
|
||||||
|
CommUtil.isReoprtingNow = "false";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user