FileInfo.java
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.huaheng.download;
import android.net.Uri;
import android.util.Log;
/**
* Created by youjie on 2018/3/30.
*/
public class FileInfo {
public final static int FILE_TYPE_UNKNOWN = 0;
public final static int FILE_TYPE_OTA = FILE_TYPE_UNKNOWN + 1;
public final static int FILE_TYPE_APK = FILE_TYPE_OTA + 1;
public final static int FILE_TYPE_NORMAL = FILE_TYPE_APK + 1;
private final static String SUFFIX_APK = ".apk";
private final static String SUFFIX_OTA = ".zip";
private int fileType;
private String url;
private String fileName;
public String getPkgName() {
return pkgName;
}
public void setPkgName(String pkgName) {
this.pkgName = pkgName;
}
private String pkgName;
private String path;
private int version;
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public int getFileType() {
return fileType;
}
public void setFileType(int fileType) {
this.fileType = fileType;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public boolean check() {
Log.i("WeiPos", "check ");
if (fileName == null || url == null) {
return false;
}
Log.i("WeiPos", "check @@");
try {
Uri.parse(url);
} catch (Exception e) {
e.printStackTrace();
return false;
}
Log.i("WeiPos", "check @@");
if (fileType == FILE_TYPE_APK) {
if (!checkAPK()) {
return false;
}
}
if (fileType == FILE_TYPE_OTA) {
if (!checkOTA()) {
return false;
}
}
return true;
}
public boolean checkAPK() {
Log.i("WeiPos", "checkAPK @@");
if (fileName != null) {
int length = fileName.length();
String suffix = fileName.substring(length - 4, length);
if (suffix != null && suffix.equals(SUFFIX_APK)) {
return true;
}
}
return false;
}
public boolean checkOTA() {
if (fileName != null) {
int length = fileName.length();
String suffix = fileName.substring(length - 4, length);
Log.i("WeiPos", "suffix :" + suffix);
if (suffix != null && suffix.equals(SUFFIX_OTA)) {
Log.i("WeiPos", "checkOTA true");
return true;
}
}
return false;
}
@Override
public String toString() {
return "FileInfo{" +
"fileType=" + fileType +
", url='" + url + '\'' +
", fileName='" + fileName + '\'' +
", path='" + path + '\'' +
", version='" + version + '\'' +
'}';
}
}