version:4.4
fix: update:增加截图上传失败重试
This commit is contained in:
@@ -14,7 +14,6 @@ import android.util.Log;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aoleyun.sn.BuildConfig;
|
||||
import com.aoleyun.sn.base.BaseApplication;
|
||||
import com.aoleyun.sn.bean.AppID;
|
||||
import com.aoleyun.sn.bean.AppLimit;
|
||||
import com.aoleyun.sn.bean.AppListInfo;
|
||||
@@ -82,6 +81,7 @@ import com.aoleyun.sn.network.api.post.SendDownloadInfoApi;
|
||||
import com.aoleyun.sn.network.api.post.SendDownloadTimesApi;
|
||||
import com.aoleyun.sn.network.api.post.SendRestoreTimesApi;
|
||||
import com.aoleyun.sn.network.api.post.SendScreenshotApi;
|
||||
import com.aoleyun.sn.network.api.post.SendScreenshotCall;
|
||||
import com.aoleyun.sn.network.api.post.StudentsInfoApi;
|
||||
import com.aoleyun.sn.network.api.post.SystemSettingApi;
|
||||
import com.aoleyun.sn.network.api.post.UpdateDeviceInfoApi;
|
||||
@@ -574,6 +574,10 @@ public class NetInterfaceManager {
|
||||
return mRetrofit.create(SendScreenshotApi.class);
|
||||
}
|
||||
|
||||
public SendScreenshotCall getScreenshotCall() {
|
||||
return mRetrofit.create(SendScreenshotCall.class);
|
||||
}
|
||||
|
||||
public GetUploadLogApi getUploadLogApi() {
|
||||
return mRetrofit.create(GetUploadLogApi.class);
|
||||
}
|
||||
|
||||
92
app/src/main/java/com/aoleyun/sn/network/RetryCallback.java
Normal file
92
app/src/main/java/com/aoleyun/sn/network/RetryCallback.java
Normal file
@@ -0,0 +1,92 @@
|
||||
package com.aoleyun.sn.network;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public abstract class RetryCallback<T> implements Callback<T> {
|
||||
|
||||
private static final String TAG = RetryCallback.class.getSimpleName();
|
||||
|
||||
private int mRetryCount;
|
||||
private long mRetryInterval;
|
||||
|
||||
private int mCurrentRetryCount;
|
||||
|
||||
private boolean isExecuting;
|
||||
|
||||
private Call<T> mCall;
|
||||
|
||||
private Timer timer = new Timer();
|
||||
|
||||
public RetryCallback(Call<T> call, int retryCount, long retryInterval) {
|
||||
isExecuting = true;
|
||||
mCall = call;
|
||||
mRetryCount = retryCount;
|
||||
mRetryInterval = retryInterval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onResponse(@NonNull Call<T> call, @NonNull Response<T> response) {
|
||||
Log.e(TAG, "onResponse");
|
||||
isExecuting = false;
|
||||
if (!response.isSuccessful() && mCurrentRetryCount < mRetryCount) {
|
||||
mCurrentRetryCount++;
|
||||
retryRequest(call);
|
||||
} else {
|
||||
onRequestResponse(call, response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onFailure(@NonNull Call<T> call, @NonNull Throwable t) {
|
||||
Log.e(TAG, "onFailure");
|
||||
isExecuting = false;
|
||||
if (mCurrentRetryCount < mRetryCount) {
|
||||
mCurrentRetryCount++;
|
||||
Log.e(TAG, "onFailure: " + "RetryCount: " + mCurrentRetryCount);
|
||||
Log.e(TAG, "onFailure: " + "RetryResponse: " + call.request());
|
||||
retryRequest(call);
|
||||
} else {
|
||||
onRequestFail(call, t);
|
||||
}
|
||||
}
|
||||
|
||||
private void retryRequest(final Call<T> call) {
|
||||
Log.e(TAG, "retryRequest");
|
||||
onStartRetry();
|
||||
TimerTask timerTask = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (RetryCallback.this) {
|
||||
mCall = call.clone();
|
||||
mCall.enqueue(RetryCallback.this);
|
||||
isExecuting = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
timer.schedule(timerTask, mRetryInterval);
|
||||
}
|
||||
|
||||
public void cancelCall() {
|
||||
synchronized (this) {
|
||||
if (!isExecuting) {
|
||||
timer.cancel();
|
||||
} else {
|
||||
mCall.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void onRequestResponse(Call call, Response response);
|
||||
|
||||
public abstract void onRequestFail(Call call, Throwable t);
|
||||
|
||||
public abstract void onStartRetry();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.aoleyun.sn.network.api.post;
|
||||
|
||||
import com.aoleyun.sn.bean.BaseResponse;
|
||||
import com.aoleyun.sn.network.UrlAddress;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import okhttp3.MultipartBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Multipart;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Part;
|
||||
import retrofit2.http.QueryMap;
|
||||
|
||||
public interface SendScreenshotCall {
|
||||
@Multipart
|
||||
@POST(UrlAddress.SEND_SCREENSHOT)
|
||||
Call<BaseResponse> sendScreenshot(
|
||||
@QueryMap Map<String, String> params,
|
||||
@Part MultipartBody.Part body
|
||||
);
|
||||
}
|
||||
@@ -245,7 +245,7 @@ public class GuardService extends Service {
|
||||
aMapLocationClient.stopLocation();
|
||||
aMapLocationClient.startLocation();
|
||||
getLockState("2", String.valueOf(time));
|
||||
sendScreenStatus(1);
|
||||
// sendScreenStatus(1);
|
||||
}
|
||||
break;
|
||||
case Intent.ACTION_SCREEN_OFF: {
|
||||
@@ -255,7 +255,7 @@ public class GuardService extends Service {
|
||||
JGYUtils.getInstance().wakeUpAoleyunAPP();
|
||||
JGYUtils.getInstance().deleteScreenshots();
|
||||
}
|
||||
sendScreenStatus(2);
|
||||
// sendScreenStatus(2);
|
||||
}
|
||||
break;
|
||||
case Intent.ACTION_SHUTDOWN:
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.aoleyun.sn.comm.JGYActions;
|
||||
import com.aoleyun.sn.disklrucache.CacheHelper;
|
||||
import com.aoleyun.sn.manager.AmapManager;
|
||||
import com.aoleyun.sn.network.NetInterfaceManager;
|
||||
import com.aoleyun.sn.network.RetryCallback;
|
||||
import com.aoleyun.sn.network.UrlAddress;
|
||||
import com.aoleyun.sn.service.main.MainService;
|
||||
import com.aoleyun.sn.tpush.common.NotificationService;
|
||||
@@ -80,7 +81,8 @@ import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class MessageReceiver extends XGPushBaseReceiver {
|
||||
private static final String TAG = MessageReceiver.class.getSimpleName();
|
||||
@@ -946,11 +948,17 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
public void screenshot(String s) {
|
||||
JSONObject jSONObject = JSON.parseObject(s);
|
||||
long createTime = jSONObject.getLong("createTime");
|
||||
PowerManager.WakeLock mWakeLock = JGYUtils.acquireWakeLock(mContext, 2 * 60 * 1000);
|
||||
|
||||
PowerManager.WakeLock mWakeLock = JGYUtils.acquireWakeLock(mContext, 60 * 1000);
|
||||
JGYUtils.release(mWakeLock);
|
||||
if (createTime != 0) {
|
||||
Log.e("createTime", String.valueOf(createTime));
|
||||
doscreenshot(createTime);
|
||||
Handler.getMain().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doscreenshot(createTime);
|
||||
}
|
||||
}, 1234);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1011,31 +1019,49 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("sn", Utils.getSerial(mContext));
|
||||
params.put("createtime", String.valueOf(time));
|
||||
NetInterfaceManager.getInstance().getScreenshotApi()
|
||||
.sendScreenshot(params, body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("uplaodImage", "onSubscribe: ");
|
||||
}
|
||||
Call<BaseResponse> call = NetInterfaceManager.getInstance().getScreenshotCall().sendScreenshot(params, body);
|
||||
call.enqueue(new RetryCallback<BaseResponse>(call, 10, 30 * 1000) {
|
||||
@Override
|
||||
public void onRequestResponse(Call call, Response response) {
|
||||
Log.e(TAG, "onRequestResponse: " + response.body().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
Log.e("uplaodImage", "onNext: " + baseResponse.msg);
|
||||
}
|
||||
@Override
|
||||
public void onRequestFail(Call call, Throwable t) {
|
||||
Log.e(TAG, "onRequestFail: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("uplaodImage", "onError: " + e.getMessage());
|
||||
}
|
||||
@Override
|
||||
public void onStartRetry() {
|
||||
Log.e(TAG, "onStartRetry: ");
|
||||
}
|
||||
});
|
||||
// NetInterfaceManager.getInstance().getScreenshotApi()
|
||||
// .sendScreenshot(params, body)
|
||||
// .subscribeOn(Schedulers.io())
|
||||
// .observeOn(AndroidSchedulers.mainThread())
|
||||
// .subscribe(new Observer<BaseResponse>() {
|
||||
// @Override
|
||||
// public void onSubscribe(Disposable d) {
|
||||
// Log.e("uplaodImage", "onSubscribe: ");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onNext(BaseResponse baseResponse) {
|
||||
// Log.e("uplaodImage", "onNext: " + baseResponse.msg);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Throwable e) {
|
||||
// Log.e("uplaodImage", "onError: " + e.getMessage());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onComplete() {
|
||||
// Log.e("uplaodImage", "onComplete: ");
|
||||
// }
|
||||
// });
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("uplaodImage", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getTimeControl(String extras) {
|
||||
|
||||
Reference in New Issue
Block a user