@@ -79,10 +79,12 @@ public CodePush(String deploymentKey, Context context, boolean isDebugMode) {
7979 mCurrentInstance = this ;
8080
8181 String publicKeyFromStrings = getCustomPropertyFromStringsIfExist ("PublicKey" );
82- if (publicKeyFromStrings != null ) mPublicKey = publicKeyFromStrings ;
82+ if (publicKeyFromStrings != null )
83+ mPublicKey = publicKeyFromStrings ;
8384
8485 String serverUrlFromStrings = getCustomPropertyFromStringsIfExist ("ServerUrl" );
85- if (serverUrlFromStrings != null ) mServerUrl = serverUrlFromStrings ;
86+ if (serverUrlFromStrings != null )
87+ mServerUrl = serverUrlFromStrings ;
8688
8789 clearDebugCacheIfNeeded (null );
8890 initializeUpdateAfterRestart ();
@@ -99,7 +101,8 @@ public CodePush(String deploymentKey, Context context, boolean isDebugMode, int
99101 mPublicKey = getPublicKeyByResourceDescriptor (publicKeyResourceDescriptor );
100102 }
101103
102- public CodePush (String deploymentKey , Context context , boolean isDebugMode , String serverUrl , Integer publicKeyResourceDescriptor ) {
104+ public CodePush (String deploymentKey , Context context , boolean isDebugMode , String serverUrl ,
105+ Integer publicKeyResourceDescriptor ) {
103106 this (deploymentKey , context , isDebugMode );
104107
105108 if (publicKeyResourceDescriptor != null ) {
@@ -109,16 +112,16 @@ public CodePush(String deploymentKey, Context context, boolean isDebugMode, Stri
109112 mServerUrl = serverUrl ;
110113 }
111114
112- private String getPublicKeyByResourceDescriptor (int publicKeyResourceDescriptor ){
115+ private String getPublicKeyByResourceDescriptor (int publicKeyResourceDescriptor ) {
113116 String publicKey ;
114117 try {
115118 publicKey = mContext .getString (publicKeyResourceDescriptor );
116119 } catch (Resources .NotFoundException e ) {
117120 throw new CodePushInvalidPublicKeyException (
118121 "Unable to get public key, related resource descriptor " +
119122 publicKeyResourceDescriptor +
120- " can not be found" , e
121- );
123+ " can not be found" ,
124+ e );
122125 }
123126
124127 if (publicKey .isEmpty ()) {
@@ -129,26 +132,28 @@ private String getPublicKeyByResourceDescriptor(int publicKeyResourceDescriptor)
129132
130133 private String getCustomPropertyFromStringsIfExist (String propertyName ) {
131134 String property ;
132-
135+
133136 String packageName = mContext .getPackageName ();
134137 int resId = mContext .getResources ().getIdentifier ("CodePush" + propertyName , "string" , packageName );
135-
138+
136139 if (resId != 0 ) {
137140 property = mContext .getString (resId );
138141
139142 if (!property .isEmpty ()) {
140143 return property ;
141144 } else {
142145 CodePushUtils .log ("Specified " + propertyName + " is empty" );
143- }
146+ }
144147 }
145148
146149 return null ;
147150 }
148151
149152 private boolean isLiveReloadEnabled (ReactInstanceManager instanceManager ) {
150- // Use instanceManager for checking if we use LiveReload mode. In this case we should not remove ReactNativeDevBundle.js file
151- // because we get error with trying to get this after reloading. Issue: https://github.com/microsoft/react-native-code-push/issues/1272
153+ // Use instanceManager for checking if we use LiveReload mode. In this case we
154+ // should not remove ReactNativeDevBundle.js file
155+ // because we get error with trying to get this after reloading. Issue:
156+ // https://github.com/microsoft/react-native-code-push/issues/1272
152157 if (instanceManager != null ) {
153158 DevSupportManager devSupportManager = instanceManager .getDevSupportManager ();
154159 if (devSupportManager != null ) {
@@ -171,7 +176,8 @@ private boolean isLiveReloadEnabled(ReactInstanceManager instanceManager) {
171176
172177 public void clearDebugCacheIfNeeded (ReactInstanceManager instanceManager ) {
173178 if (mIsDebugMode && mSettingsManager .isPendingUpdate (null ) && !isLiveReloadEnabled (instanceManager )) {
174- // This needs to be kept in sync with https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManager.java#L78
179+ // This needs to be kept in sync with
180+ // https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManager.java#L78
175181 File cachedDevBundle = new File (mContext .getFilesDir (), "ReactNativeDevBundle.js" );
176182 if (cachedDevBundle .exists ()) {
177183 cachedDevBundle .delete ();
@@ -198,10 +204,13 @@ public String getPublicKey() {
198204 long getBinaryResourcesModifiedTime () {
199205 try {
200206 String packageName = this .mContext .getPackageName ();
201- int codePushApkBuildTimeId = this .mContext .getResources ().getIdentifier (CodePushConstants .CODE_PUSH_APK_BUILD_TIME_KEY , "string" , packageName );
202- // replace double quotes needed for correct restoration of long value from strings.xml
207+ int codePushApkBuildTimeId = this .mContext .getResources ()
208+ .getIdentifier (CodePushConstants .CODE_PUSH_APK_BUILD_TIME_KEY , "string" , packageName );
209+ // replace double quotes needed for correct restoration of long value from
210+ // strings.xml
203211 // https://github.com/microsoft/cordova-plugin-code-push/issues/264
204- String codePushApkBuildTime = this .mContext .getResources ().getString (codePushApkBuildTimeId ).replaceAll ("\" " ,"" );
212+ String codePushApkBuildTime = this .mContext .getResources ().getString (codePushApkBuildTimeId )
213+ .replaceAll ("\" " , "" );
205214 return Long .parseLong (codePushApkBuildTime );
206215 } catch (Exception e ) {
207216 throw new CodePushUnknownException ("Error in getting binary resources modified time" , e );
@@ -240,7 +249,8 @@ public static String getJSBundleFile() {
240249
241250 public static String getJSBundleFile (String assetsBundleFileName ) {
242251 if (mCurrentInstance == null ) {
243- throw new CodePushNotInitializedException ("A CodePush instance has not been created yet. Have you added it to your app's list of ReactPackages?" );
252+ throw new CodePushNotInitializedException (
253+ "A CodePush instance has not been created yet. Have you added it to your app's list of ReactPackages?" );
244254 }
245255
246256 return mCurrentInstance .getJSBundleFileInternal (assetsBundleFileName );
@@ -305,35 +315,40 @@ void initializeUpdateAfterRestart() {
305315 clearUpdates ();
306316 return ;
307317 }
308- if (packageMetadata == null || !isPackageBundleLatest (packageMetadata ) && hasBinaryVersionChanged (packageMetadata )) {
318+ if (packageMetadata == null
319+ || !isPackageBundleLatest (packageMetadata ) && hasBinaryVersionChanged (packageMetadata )) {
309320 CodePushUtils .log ("Skipping initializeUpdateAfterRestart(), binary version is newer" );
310321 return ;
311322 }
312323
313324 try {
314325 /*
315- * This check is not needed as of now. Will only comment out the code, in case we need it later
316- * */
317- //boolean updateIsLoading = pendingUpdate.getBoolean(CodePushConstants.PENDING_UPDATE_IS_LOADING_KEY);
318- //if (updateIsLoading) {
319- // Pending update was initialized, but notifyApplicationReady was not called.
320- // Therefore, deduce that it is a broken update and rollback.
321- //CodePushUtils.log("Update did not finish loading the last time, rolling back to a previous version.");
322- //sNeedToReportRollback = true;
323- //rollbackPackage();
324- //} else {
325- // There is in fact a new update running for the first
326- // time, so update the local state to ensure the client knows.
327- mDidUpdate = true ;
328-
329- // Mark that we tried to initialize the new update, so that if it crashes,
330- // we will know that we need to rollback when the app next starts.
331- mSettingsManager .savePendingUpdate (pendingUpdate .getString (CodePushConstants .PENDING_UPDATE_HASH_KEY ),
332- /* isLoading */ true );
333- //}
326+ * This check is not needed as of now. Will only comment out the code, in case
327+ * we need it later
328+ */
329+ // boolean updateIsLoading =
330+ // pendingUpdate.getBoolean(CodePushConstants.PENDING_UPDATE_IS_LOADING_KEY);
331+ // if (updateIsLoading) {
332+ // Pending update was initialized, but notifyApplicationReady was not called.
333+ // Therefore, deduce that it is a broken update and rollback.
334+ // CodePushUtils.log("Update did not finish loading the last time, rolling back
335+ // to a previous version.");
336+ // sNeedToReportRollback = true;
337+ // rollbackPackage();
338+ // } else {
339+ // There is in fact a new update running for the first
340+ // time, so update the local state to ensure the client knows.
341+ mDidUpdate = true ;
342+
343+ // Mark that we tried to initialize the new update, so that if it crashes,
344+ // we will know that we need to rollback when the app next starts.
345+ mSettingsManager .savePendingUpdate (pendingUpdate .getString (CodePushConstants .PENDING_UPDATE_HASH_KEY ),
346+ /* isLoading */ true );
347+ // }
334348 } catch (JSONException e ) {
335349 // Should not happen.
336- throw new CodePushUnknownException ("Unable to read pending update metadata stored in SharedPreferences" , e );
350+ throw new CodePushUnknownException ("Unable to read pending update metadata stored in SharedPreferences" ,
351+ e );
337352 }
338353 }
339354 }
@@ -353,18 +368,20 @@ boolean isRunningBinaryVersion() {
353368 private boolean isPackageBundleLatest (JSONObject packageMetadata ) {
354369 try {
355370 Long binaryModifiedDateDuringPackageInstall = null ;
356- String binaryModifiedDateDuringPackageInstallString = packageMetadata .optString (CodePushConstants .BINARY_MODIFIED_TIME_KEY , null );
371+ String binaryModifiedDateDuringPackageInstallString = packageMetadata
372+ .optString (CodePushConstants .BINARY_MODIFIED_TIME_KEY , null );
357373 if (binaryModifiedDateDuringPackageInstallString != null ) {
358374 binaryModifiedDateDuringPackageInstall = Long .parseLong (binaryModifiedDateDuringPackageInstallString );
359375 }
360376 String packageAppVersion = packageMetadata .optString ("appVersion" , null );
361377 long binaryResourcesModifiedTime = this .getBinaryResourcesModifiedTime ();
362378 /*
363- * If packageAppVersion is not sent, DO NOT do a equality check
379+ * If packageAppVersion is not sent, DO NOT do a equality check
364380 */
365381 return binaryModifiedDateDuringPackageInstall != null &&
366382 binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime &&
367- (isUsingTestConfiguration () || (packageAppVersion != null ? sAppVersion .equals (packageAppVersion ) : true ));
383+ (isUsingTestConfiguration ()
384+ || (packageAppVersion != null ? sAppVersion .equals (packageAppVersion ) : true ));
368385 } catch (NumberFormatException e ) {
369386 throw new CodePushUnknownException ("Error in reading binary modified date from package metadata" , e );
370387 }
@@ -394,7 +411,7 @@ public void setNeedToReportRollback(boolean needToReportRollback) {
394411 CodePush .sNeedToReportRollback = needToReportRollback ;
395412 }
396413
397- /* The below 3 methods are used for running tests.*/
414+ /* The below 3 methods are used for running tests. */
398415 public static boolean isUsingTestConfiguration () {
399416 return sTestConfigurationFlag ;
400417 }
@@ -426,7 +443,8 @@ static ReactInstanceManager getReactInstanceManager() {
426443
427444 @ Override
428445 public List <NativeModule > createNativeModules (ReactApplicationContext reactApplicationContext ) {
429- CodePushNativeModule codePushModule = new CodePushNativeModule (reactApplicationContext , this , mUpdateManager , mTelemetryManager , mSettingsManager );
446+ CodePushNativeModule codePushModule = new CodePushNativeModule (reactApplicationContext , this , mUpdateManager ,
447+ mTelemetryManager , mSettingsManager );
430448 CodePushDialog dialogModule = new CodePushDialog (reactApplicationContext );
431449
432450 List <NativeModule > nativeModules = new ArrayList <>();
0 commit comments