22
33import android .app .Activity ;
44import android .content .Context ;
5- import android .content .Intent ;
65import android .os .AsyncTask ;
76import android .provider .Settings ;
87import android .view .Choreographer ;
98
109import com .facebook .react .ReactActivity ;
1110import com .facebook .react .ReactInstanceManager ;
11+ import com .facebook .react .bridge .Arguments ;
1212import com .facebook .react .bridge .LifecycleEventListener ;
1313import com .facebook .react .bridge .Promise ;
1414import com .facebook .react .bridge .ReactApplicationContext ;
1515import com .facebook .react .bridge .ReactContextBaseJavaModule ;
1616import com .facebook .react .bridge .ReactMethod ;
1717import com .facebook .react .bridge .ReadableMap ;
1818import com .facebook .react .bridge .WritableMap ;
19- import com .facebook .react .bridge .WritableNativeMap ;
2019import com .facebook .react .modules .core .DeviceEventManagerModule ;
2120import com .facebook .react .uimanager .ReactChoreographer ;
2221
@@ -184,8 +183,8 @@ public void downloadUpdate(final ReadableMap updatePackage, final boolean notify
184183 @ Override
185184 protected Void doInBackground (Void ... params ) {
186185 try {
187- WritableMap mutableUpdatePackage = CodePushUtils .convertReadableMapToWritableMap (updatePackage );
188- mutableUpdatePackage . putString ( CodePushConstants .BINARY_MODIFIED_TIME_KEY , "" + mCodePush .getBinaryResourcesModifiedTime ());
186+ JSONObject mutableUpdatePackage = CodePushUtils .convertReadableToJsonObject (updatePackage );
187+ CodePushUtils . setJSONValueForKey ( mutableUpdatePackage , CodePushConstants .BINARY_MODIFIED_TIME_KEY , "" + mCodePush .getBinaryResourcesModifiedTime ());
189188 mUpdateManager .downloadPackage (mutableUpdatePackage , mCodePush .getAssetsBundleFileName (), new DownloadProgressCallback () {
190189 private boolean hasScheduledNextFrame = false ;
191190 private DownloadProgress latestDownloadProgress = null ;
@@ -232,14 +231,14 @@ public void dispatchDownloadProgressEvent() {
232231 }
233232 });
234233
235- WritableMap newPackage = mUpdateManager .getPackage (CodePushUtils .tryGetString (updatePackage , CodePushConstants .PACKAGE_HASH_KEY ));
236- promise .resolve (newPackage );
234+ JSONObject newPackage = mUpdateManager .getPackage (CodePushUtils .tryGetString (updatePackage , CodePushConstants .PACKAGE_HASH_KEY ));
235+ promise .resolve (CodePushUtils . convertJsonObjectToWritable ( newPackage ) );
237236 } catch (IOException e ) {
238237 e .printStackTrace ();
239238 promise .reject (e );
240239 } catch (CodePushInvalidUpdateException e ) {
241240 e .printStackTrace ();
242- mSettingsManager .saveFailedUpdate (updatePackage );
241+ mSettingsManager .saveFailedUpdate (CodePushUtils . convertReadableToJsonObject ( updatePackage ) );
243242 promise .reject (e );
244243 }
245244
@@ -252,7 +251,7 @@ public void dispatchDownloadProgressEvent() {
252251
253252 @ ReactMethod
254253 public void getConfiguration (Promise promise ) {
255- WritableNativeMap configMap = new WritableNativeMap ();
254+ WritableMap configMap = Arguments . createMap ();
256255 configMap .putString ("appVersion" , mCodePush .getAppVersion ());
257256 configMap .putString ("clientUniqueId" , mClientUniqueId );
258257 configMap .putString ("deploymentKey" , mCodePush .getDeploymentKey ());
@@ -271,7 +270,7 @@ public void getUpdateMetadata(final int updateState, final Promise promise) {
271270 AsyncTask <Void , Void , Void > asyncTask = new AsyncTask <Void , Void , Void >() {
272271 @ Override
273272 protected Void doInBackground (Void ... params ) {
274- WritableMap currentPackage = mUpdateManager .getCurrentPackage ();
273+ JSONObject currentPackage = mUpdateManager .getCurrentPackage ();
275274
276275 if (currentPackage == null ) {
277276 promise .resolve ("" );
@@ -280,8 +279,8 @@ protected Void doInBackground(Void... params) {
280279
281280 Boolean currentUpdateIsPending = false ;
282281
283- if (currentPackage .hasKey (CodePushConstants .PACKAGE_HASH_KEY )) {
284- String currentHash = currentPackage .getString (CodePushConstants .PACKAGE_HASH_KEY );
282+ if (currentPackage .has (CodePushConstants .PACKAGE_HASH_KEY )) {
283+ String currentHash = currentPackage .optString (CodePushConstants .PACKAGE_HASH_KEY , null );
285284 currentUpdateIsPending = mSettingsManager .isPendingUpdate (currentHash );
286285 }
287286
@@ -292,7 +291,7 @@ protected Void doInBackground(Void... params) {
292291 } else if (updateState == CodePushUpdateState .RUNNING .getValue () && currentUpdateIsPending ) {
293292 // The caller wants the running update, but the current
294293 // one is pending, so we need to grab the previous.
295- promise .resolve (mUpdateManager .getPreviousPackage ());
294+ promise .resolve (CodePushUtils . convertJsonObjectToWritable ( mUpdateManager .getPreviousPackage () ));
296295 } else {
297296 // The current package satisfies the request:
298297 // 1) Caller wanted a pending, and there is a pending update
@@ -302,12 +301,12 @@ protected Void doInBackground(Void... params) {
302301 // This only matters in Debug builds. Since we do not clear "outdated" updates,
303302 // we need to indicate to the JS side that somehow we have a current update on
304303 // disk that is not actually running.
305- currentPackage . putBoolean ( "_isDebugOnly" , true );
304+ CodePushUtils . setJSONValueForKey ( currentPackage , "_isDebugOnly" , true );
306305 }
307306
308307 // Enable differentiating pending vs. non-pending updates
309- currentPackage . putBoolean ( "isPending" , currentUpdateIsPending );
310- promise .resolve (currentPackage );
308+ CodePushUtils . setJSONValueForKey ( currentPackage , "isPending" , currentUpdateIsPending );
309+ promise .resolve (CodePushUtils . convertJsonObjectToWritable ( currentPackage ) );
311310 }
312311
313312 return null ;
@@ -339,9 +338,9 @@ protected Void doInBackground(Void... params) {
339338 }
340339 }
341340 } else if (mCodePush .didUpdate ()) {
342- WritableMap currentPackage = mUpdateManager .getCurrentPackage ();
341+ JSONObject currentPackage = mUpdateManager .getCurrentPackage ();
343342 if (currentPackage != null ) {
344- WritableMap newPackageStatusReport = mTelemetryManager .getUpdateReport (currentPackage );
343+ WritableMap newPackageStatusReport = mTelemetryManager .getUpdateReport (CodePushUtils . convertJsonObjectToWritable ( currentPackage ) );
345344 if (newPackageStatusReport != null ) {
346345 promise .resolve (newPackageStatusReport );
347346 return null ;
@@ -374,7 +373,7 @@ public void installUpdate(final ReadableMap updatePackage, final int installMode
374373 AsyncTask <Void , Void , Void > asyncTask = new AsyncTask <Void , Void , Void >() {
375374 @ Override
376375 protected Void doInBackground (Void ... params ) {
377- mUpdateManager .installPackage (updatePackage , mSettingsManager .isPendingUpdate (null ));
376+ mUpdateManager .installPackage (CodePushUtils . convertReadableToJsonObject ( updatePackage ) , mSettingsManager .isPendingUpdate (null ));
378377
379378 String pendingHash = CodePushUtils .tryGetString (updatePackage , CodePushConstants .PACKAGE_HASH_KEY );
380379 if (pendingHash == null ) {
0 commit comments