19
19
import android .content .Context ;
20
20
import android .content .Intent ;
21
21
import android .content .SharedPreferences ;
22
+ import android .content .pm .ApplicationInfo ;
22
23
import android .content .pm .PackageInfo ;
23
24
import android .content .pm .PackageManager ;
24
25
25
26
import org .json .JSONException ;
26
27
import org .json .JSONObject ;
27
28
29
+ import java .io .File ;
28
30
import java .io .IOException ;
29
31
import java .util .ArrayList ;
30
32
import java .util .Calendar ;
34
36
import java .util .Map ;
35
37
import java .util .Timer ;
36
38
import java .util .TimerTask ;
39
+ import java .util .zip .ZipEntry ;
40
+ import java .util .zip .ZipFile ;
37
41
38
42
public class CodePush {
39
43
@@ -51,6 +55,7 @@ public class CodePush {
51
55
private final String ASSETS_BUNDLE_PREFIX = "assets://" ;
52
56
private final String CODE_PUSH_PREFERENCES = "CodePush" ;
53
57
private final String DOWNLOAD_PROGRESS_EVENT_NAME = "CodePushDownloadProgress" ;
58
+ private final String RESOURCES_BUNDLE = "resources.arsc" ;
54
59
55
60
private CodePushPackage codePushPackage ;
56
61
private CodePushReactPackage codePushReactPackage ;
@@ -99,14 +104,34 @@ public String getDocumentsDirectory() {
99
104
public String getBundleUrl (String assetsBundleFileName ) {
100
105
this .assetsBundleFileName = assetsBundleFileName ;
101
106
String binaryJsBundleUrl = ASSETS_BUNDLE_PREFIX + assetsBundleFileName ;
107
+ ZipFile applicationFile ;
108
+ long binaryResourcesModifiedTime = -1 ;
109
+
110
+ ApplicationInfo ai = null ;
111
+ try {
112
+ ai = applicationContext .getPackageManager ().getApplicationInfo (applicationContext .getPackageName (), 0 );
113
+ applicationFile = new ZipFile (ai .sourceDir );
114
+ ZipEntry classesDexEntry = applicationFile .getEntry (RESOURCES_BUNDLE );
115
+ binaryResourcesModifiedTime = classesDexEntry .getTime ();
116
+ applicationFile .close ();
117
+ } catch (PackageManager .NameNotFoundException | IOException e ) {
118
+ throw new CodePushUnknownException ("Error in getting file information about compiled resources" , e );
119
+ }
120
+
102
121
try {
103
- String packageFile = codePushPackage .getCurrentPackageBundlePath ();
104
- if (packageFile == null ) {
122
+ String packageFilePath = codePushPackage .getCurrentPackageBundlePath ();
123
+ if (packageFilePath == null ) {
105
124
// There has not been any downloaded updates.
106
125
return binaryJsBundleUrl ;
107
126
}
108
127
109
- return packageFile ;
128
+ File packageFile = new File (packageFilePath );
129
+ if (packageFile .lastModified () < binaryResourcesModifiedTime ) {
130
+ // The binary version is newer.
131
+ return binaryJsBundleUrl ;
132
+ }
133
+
134
+ return packageFilePath ;
110
135
} catch (IOException e ) {
111
136
throw new CodePushUnknownException ("Error in getting current package bundle path" , e );
112
137
}
0 commit comments