@@ -771,52 +771,51 @@ void over() {
771
771
}
772
772
}
773
773
774
- private void printNotMatchReasonLog (int status ) {
775
- if (FileDownloadLog .NEED_LOG ) {
776
- FileDownloadLog .d (this , "can't update status change, %d, but the current" +
777
- " status is %d, %d" , status , getStatus (), getDownloadId ());
774
+ boolean updateKeepFlow (final FileDownloadTransferModel transfer ) {
775
+ if (!FileDownloadStatus .isKeepFlow (getStatus (), transfer .getStatus ())) {
776
+ if (FileDownloadLog .NEED_LOG ) {
777
+ FileDownloadLog .d (this , "can't update status change by keep flow, %d, but the" +
778
+ " current status is %d, %d" , status , getStatus (), getDownloadId ());
779
+ }
780
+ return false ;
778
781
}
782
+
783
+ update (transfer );
784
+ return true ;
785
+ }
786
+
787
+ boolean updateKeepAhead (final FileDownloadTransferModel transfer ) {
788
+ if (!FileDownloadStatus .isKeepAhead (getStatus (), transfer .getStatus ())) {
789
+ if (FileDownloadLog .NEED_LOG ) {
790
+ FileDownloadLog .d (this , "can't update status change by keep ahead, %d, but the" +
791
+ " current status is %d, %d" , status , getStatus (), getDownloadId ());
792
+ }
793
+ return false ;
794
+ }
795
+
796
+ update (transfer );
797
+ return true ;
779
798
}
780
799
781
800
/**
782
801
* @param transfer In order to optimize some of the data in some cases is not back
783
802
*/
784
- boolean update (final FileDownloadTransferModel transfer ) {
785
- boolean match = false ;
803
+ private void update (final FileDownloadTransferModel transfer ) {
804
+ setStatus (transfer .getStatus ());
805
+
786
806
switch (transfer .getStatus ()) {
787
807
case FileDownloadStatus .pending :
788
- if (getStatus () != FileDownloadStatus .INVALID_STATUS ) {
789
- printNotMatchReasonLog (transfer .getStatus ());
790
- break ;
791
- }
792
- match = true ;
793
- this .setStatus (transfer .getStatus ());
794
808
this .setSoFarBytes (transfer .getSoFarBytes ());
795
809
this .setTotalBytes (transfer .getTotalBytes ());
796
810
797
811
// notify
798
812
getDriver ().notifyPending ();
799
813
break ;
800
814
case FileDownloadStatus .started :
801
- if (getStatus () != FileDownloadStatus .pending ) {
802
- printNotMatchReasonLog (transfer .getStatus ());
803
- break ;
804
- }
805
- match = true ;
806
- this .setStatus (transfer .getStatus ());
807
-
808
815
// notify
809
816
getDriver ().notifyStarted ();
810
817
break ;
811
818
case FileDownloadStatus .connected :
812
- if (getStatus () != FileDownloadStatus .retry &&
813
- getStatus () != FileDownloadStatus .started ) {
814
- printNotMatchReasonLog (transfer .getStatus ());
815
- break ;
816
- }
817
-
818
- match = true ;
819
- setStatus (transfer .getStatus ());
820
819
setTotalBytes (transfer .getTotalBytes ());
821
820
setSoFarBytes (transfer .getSoFarBytes ());
822
821
this .resuming = transfer .isResuming ();
@@ -826,14 +825,6 @@ boolean update(final FileDownloadTransferModel transfer) {
826
825
getDriver ().notifyConnected ();
827
826
break ;
828
827
case FileDownloadStatus .progress :
829
- if (getStatus () != FileDownloadStatus .progress &&
830
- getStatus () != FileDownloadStatus .connected ) {
831
- printNotMatchReasonLog (transfer .getStatus ());
832
- break ;
833
- }
834
-
835
- match = true ;
836
- setStatus (transfer .getStatus ());
837
828
setSoFarBytes (transfer .getSoFarBytes ());
838
829
839
830
// notify
@@ -845,15 +836,6 @@ boolean update(final FileDownloadTransferModel transfer) {
845
836
*/
846
837
break ;
847
838
case FileDownloadStatus .retry :
848
- if (getStatus () != FileDownloadStatus .progress &&
849
- getStatus () != FileDownloadStatus .pending &&
850
- getStatus () != FileDownloadStatus .connected ) {
851
- printNotMatchReasonLog (transfer .getStatus ());
852
- break ;
853
- }
854
-
855
- match = true ;
856
- setStatus (transfer .getStatus ());
857
839
setSoFarBytes (transfer .getSoFarBytes ());
858
840
setEx (transfer .getThrowable ());
859
841
_setRetryingTimes (transfer .getRetryingTimes ());
@@ -862,14 +844,6 @@ boolean update(final FileDownloadTransferModel transfer) {
862
844
getDriver ().notifyRetry ();
863
845
break ;
864
846
case FileDownloadStatus .error :
865
- if (getStatus () == FileDownloadStatus .error ) {
866
- FileDownloadLog .w (this , "%d already err(%s) , callback by other status same transfer" ,
867
- getDownloadId (), getEx ());
868
- break ;
869
- }
870
-
871
- match = true ;
872
- setStatus (transfer .getStatus ());
873
847
setEx (transfer .getThrowable ());
874
848
setSoFarBytes (transfer .getSoFarBytes ());
875
849
@@ -883,16 +857,7 @@ boolean update(final FileDownloadTransferModel transfer) {
883
857
*/
884
858
break ;
885
859
case FileDownloadStatus .completed :
886
- if (getStatus () != FileDownloadStatus .INVALID_STATUS &&
887
- getStatus () != FileDownloadStatus .connected &&
888
- getStatus () != FileDownloadStatus .progress ) {
889
- printNotMatchReasonLog (transfer .getStatus ());
890
- break ;
891
- }
892
-
893
- match = true ;
894
860
this .isReusedOldFile = transfer .isReusedOldFile ();
895
- setStatus (transfer .getStatus ());
896
861
// only carry total data back
897
862
setSoFarBytes (transfer .getTotalBytes ());
898
863
setTotalBytes (transfer .getTotalBytes ());
@@ -902,12 +867,6 @@ boolean update(final FileDownloadTransferModel transfer) {
902
867
903
868
break ;
904
869
case FileDownloadStatus .warn :
905
- if (getStatus () != FileDownloadStatus .INVALID_STATUS ) {
906
- printNotMatchReasonLog (transfer .getStatus ());
907
- break ;
908
- }
909
-
910
- match = true ;
911
870
final int count = FileDownloadList .getImpl ().count (getDownloadId ());
912
871
if (count <= 1 ) {
913
872
// 1. this progress kill by sys and relive,
@@ -931,14 +890,10 @@ boolean update(final FileDownloadTransferModel transfer) {
931
890
932
891
}
933
892
934
- setStatus (transfer .getStatus ());
935
-
936
893
// to FileDownloadList
937
894
FileDownloadList .getImpl ().removeByWarn (this );
938
895
break ;
939
896
}
940
-
941
- return match ;
942
897
}
943
898
944
899
// why this? thread not safe: update,ready, _start, pause, start which influence of this
@@ -950,7 +905,7 @@ void markAdded2List() {
950
905
isMarkedAdded2List = true ;
951
906
}
952
907
953
- void clearMarkAdded2List (){
908
+ void clearMarkAdded2List () {
954
909
isMarkedAdded2List = false ;
955
910
}
956
911
0 commit comments