@@ -99,7 +99,7 @@ public CodePush(String deploymentKey, Activity mainActivity, boolean isDebugMode
99
99
appVersion = pInfo .versionName ;
100
100
buildVersion = pInfo .versionCode ;
101
101
} catch (PackageManager .NameNotFoundException e ) {
102
- throw new CodePushUnknownException ("Unable to get package info for " + applicationContext .getPackageName (), e );
102
+ CodePushUtils . logException ("Unable to get package info for " + applicationContext .getPackageName (), e );
103
103
}
104
104
105
105
if (currentInstance != null ) {
@@ -109,6 +109,7 @@ public CodePush(String deploymentKey, Activity mainActivity, boolean isDebugMode
109
109
currentInstance = this ;
110
110
111
111
clearDebugCacheIfNeeded ();
112
+ initializeUpdateAfterRestart ();
112
113
}
113
114
114
115
private void clearDebugCacheIfNeeded () {
@@ -129,13 +130,14 @@ private long getBinaryResourcesModifiedTime() {
129
130
ZipEntry classesDexEntry = applicationFile .getEntry (RESOURCES_BUNDLE );
130
131
return classesDexEntry .getTime ();
131
132
} catch (PackageManager .NameNotFoundException | IOException e ) {
132
- throw new CodePushUnknownException ("Error in getting file information about compiled resources" , e );
133
+ CodePushUtils .logException ("Error in getting file information about compiled resources" , e );
134
+ return -1 ;
133
135
} finally {
134
136
if (applicationFile != null ) {
135
137
try {
136
138
applicationFile .close ();
137
139
} catch (IOException e ) {
138
- throw new CodePushUnknownException ("Error in closing application file." , e );
140
+ CodePushUtils . logException ("Error in closing application file." , e );
139
141
}
140
142
}
141
143
}
@@ -193,7 +195,8 @@ public String getBundleUrlInternal(String assetsBundleFileName) {
193
195
return binaryJsBundleUrl ;
194
196
}
195
197
} catch (NumberFormatException e ) {
196
- throw new CodePushUnknownException ("Error in reading binary modified date from package metadata" , e );
198
+ CodePushUtils .logException ("Error in closing application file." , e );
199
+ return binaryJsBundleUrl ;
197
200
}
198
201
}
199
202
@@ -251,7 +254,7 @@ private void initializeUpdateAfterRestart() {
251
254
}
252
255
} catch (JSONException e ) {
253
256
// Should not happen.
254
- throw new CodePushUnknownException ("Unable to read pending update metadata stored in SharedPreferences" , e );
257
+ CodePushUtils . logException ("Unable to read pending update metadata stored in SharedPreferences" , e );
255
258
}
256
259
}
257
260
}
@@ -267,7 +270,7 @@ private boolean isFailedHash(String packageHash) {
267
270
return true ;
268
271
}
269
272
} catch (JSONException e ) {
270
- throw new CodePushUnknownException ("Unable to read failedUpdates data stored in SharedPreferences." , e );
273
+ CodePushUtils . logException ("Unable to read failedUpdates data stored in SharedPreferences." , e );
271
274
}
272
275
}
273
276
}
@@ -284,7 +287,8 @@ private boolean isPendingUpdate(String packageHash) {
284
287
(packageHash == null || pendingUpdate .getString (PENDING_UPDATE_HASH_KEY ).equals (packageHash ));
285
288
}
286
289
catch (JSONException e ) {
287
- throw new CodePushUnknownException ("Unable to read pending update metadata in isPendingUpdate." , e );
290
+ CodePushUtils .logException ("Unable to read pending update metadata in isPendingUpdate." , e );
291
+ return false ;
288
292
}
289
293
}
290
294
@@ -316,8 +320,9 @@ private void saveFailedUpdate(ReadableMap failedPackage) {
316
320
failedUpdates = new JSONArray (failedUpdatesString );
317
321
} catch (JSONException e ) {
318
322
// Should not happen.
319
- throw new CodePushMalformedDataException ("Unable to parse failed updates information " +
323
+ CodePushUtils . logException ("Unable to parse failed updates information " +
320
324
failedUpdatesString + " stored in SharedPreferences" , e );
325
+ failedUpdates = new JSONArray ();
321
326
}
322
327
}
323
328
@@ -335,7 +340,7 @@ private void savePendingUpdate(String packageHash, boolean isLoading) {
335
340
settings .edit ().putString (PENDING_UPDATE_KEY , pendingUpdate .toString ()).commit ();
336
341
} catch (JSONException e ) {
337
342
// Should not happen.
338
- throw new CodePushUnknownException ("Unable to save pending update." , e );
343
+ CodePushUtils . logException ("Unable to save pending update." , e );
339
344
}
340
345
}
341
346
@@ -382,11 +387,6 @@ public String getName() {
382
387
return "CodePush" ;
383
388
}
384
389
385
- @ Override
386
- public void initialize () {
387
- CodePush .this .initializeUpdateAfterRestart ();
388
- }
389
-
390
390
private void loadBundleLegacy () {
391
391
Intent intent = mainActivity .getIntent ();
392
392
mainActivity .finish ();
@@ -418,6 +418,7 @@ private void loadBundle() {
418
418
public void run () {
419
419
try {
420
420
recreateMethod .invoke (instanceManager );
421
+ initializeUpdateAfterRestart ();
421
422
}
422
423
catch (Exception e ) {
423
424
// The recreation method threw an unknown exception
@@ -558,7 +559,7 @@ protected Void doInBackground(Void... params) {
558
559
return null ;
559
560
}
560
561
} catch (JSONException e ) {
561
- throw new CodePushUnknownException ("Unable to read failed updates information stored in SharedPreferences." , e );
562
+ CodePushUtils . logException ("Unable to read failed updates information stored in SharedPreferences." , e );
562
563
}
563
564
}
564
565
} else if (didUpdate ) {
@@ -595,7 +596,8 @@ protected Void doInBackground(Void... params) {
595
596
596
597
String pendingHash = CodePushUtils .tryGetString (updatePackage , PACKAGE_HASH_KEY );
597
598
if (pendingHash == null ) {
598
- throw new CodePushUnknownException ("Update package to be installed has no hash." );
599
+ CodePushUtils .log ("Update package to be installed has no hash." );
600
+ return null ;
599
601
} else {
600
602
savePendingUpdate (pendingHash , /* isLoading */ false );
601
603
}
@@ -687,7 +689,7 @@ public void downloadAndReplaceCurrentBundle(String remoteBundleUrl) {
687
689
try {
688
690
codePushPackage .downloadAndReplaceCurrentBundle (remoteBundleUrl , assetsBundleFileName );
689
691
} catch (IOException e ) {
690
- throw new CodePushUnknownException ("Unable to replace current bundle" , e );
692
+ CodePushUtils . logException ("Unable to replace current bundle" , e );
691
693
}
692
694
}
693
695
}
0 commit comments