2
2
3
3
import android .app .Activity ;
4
4
import android .content .Context ;
5
- import android .content .Intent ;
6
5
import android .os .AsyncTask ;
7
6
import android .provider .Settings ;
8
7
import android .view .Choreographer ;
9
8
10
9
import com .facebook .react .ReactActivity ;
11
10
import com .facebook .react .ReactInstanceManager ;
11
+ import com .facebook .react .bridge .Arguments ;
12
12
import com .facebook .react .bridge .LifecycleEventListener ;
13
13
import com .facebook .react .bridge .Promise ;
14
14
import com .facebook .react .bridge .ReactApplicationContext ;
15
15
import com .facebook .react .bridge .ReactContextBaseJavaModule ;
16
16
import com .facebook .react .bridge .ReactMethod ;
17
17
import com .facebook .react .bridge .ReadableMap ;
18
18
import com .facebook .react .bridge .WritableMap ;
19
- import com .facebook .react .bridge .WritableNativeMap ;
20
19
import com .facebook .react .modules .core .DeviceEventManagerModule ;
21
20
import com .facebook .react .uimanager .ReactChoreographer ;
22
21
@@ -184,8 +183,8 @@ public void downloadUpdate(final ReadableMap updatePackage, final boolean notify
184
183
@ Override
185
184
protected Void doInBackground (Void ... params ) {
186
185
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 ());
189
188
mUpdateManager .downloadPackage (mutableUpdatePackage , mCodePush .getAssetsBundleFileName (), new DownloadProgressCallback () {
190
189
private boolean hasScheduledNextFrame = false ;
191
190
private DownloadProgress latestDownloadProgress = null ;
@@ -232,14 +231,14 @@ public void dispatchDownloadProgressEvent() {
232
231
}
233
232
});
234
233
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 ) );
237
236
} catch (IOException e ) {
238
237
e .printStackTrace ();
239
238
promise .reject (e );
240
239
} catch (CodePushInvalidUpdateException e ) {
241
240
e .printStackTrace ();
242
- mSettingsManager .saveFailedUpdate (updatePackage );
241
+ mSettingsManager .saveFailedUpdate (CodePushUtils . convertReadableToJsonObject ( updatePackage ) );
243
242
promise .reject (e );
244
243
}
245
244
@@ -252,7 +251,7 @@ public void dispatchDownloadProgressEvent() {
252
251
253
252
@ ReactMethod
254
253
public void getConfiguration (Promise promise ) {
255
- WritableNativeMap configMap = new WritableNativeMap ();
254
+ WritableMap configMap = Arguments . createMap ();
256
255
configMap .putString ("appVersion" , mCodePush .getAppVersion ());
257
256
configMap .putString ("clientUniqueId" , mClientUniqueId );
258
257
configMap .putString ("deploymentKey" , mCodePush .getDeploymentKey ());
@@ -271,7 +270,7 @@ public void getUpdateMetadata(final int updateState, final Promise promise) {
271
270
AsyncTask <Void , Void , Void > asyncTask = new AsyncTask <Void , Void , Void >() {
272
271
@ Override
273
272
protected Void doInBackground (Void ... params ) {
274
- WritableMap currentPackage = mUpdateManager .getCurrentPackage ();
273
+ JSONObject currentPackage = mUpdateManager .getCurrentPackage ();
275
274
276
275
if (currentPackage == null ) {
277
276
promise .resolve ("" );
@@ -280,8 +279,8 @@ protected Void doInBackground(Void... params) {
280
279
281
280
Boolean currentUpdateIsPending = false ;
282
281
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 );
285
284
currentUpdateIsPending = mSettingsManager .isPendingUpdate (currentHash );
286
285
}
287
286
@@ -292,7 +291,7 @@ protected Void doInBackground(Void... params) {
292
291
} else if (updateState == CodePushUpdateState .RUNNING .getValue () && currentUpdateIsPending ) {
293
292
// The caller wants the running update, but the current
294
293
// one is pending, so we need to grab the previous.
295
- promise .resolve (mUpdateManager .getPreviousPackage ());
294
+ promise .resolve (CodePushUtils . convertJsonObjectToWritable ( mUpdateManager .getPreviousPackage () ));
296
295
} else {
297
296
// The current package satisfies the request:
298
297
// 1) Caller wanted a pending, and there is a pending update
@@ -302,12 +301,12 @@ protected Void doInBackground(Void... params) {
302
301
// This only matters in Debug builds. Since we do not clear "outdated" updates,
303
302
// we need to indicate to the JS side that somehow we have a current update on
304
303
// disk that is not actually running.
305
- currentPackage . putBoolean ( "_isDebugOnly" , true );
304
+ CodePushUtils . setJSONValueForKey ( currentPackage , "_isDebugOnly" , true );
306
305
}
307
306
308
307
// 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 ) );
311
310
}
312
311
313
312
return null ;
@@ -339,9 +338,9 @@ protected Void doInBackground(Void... params) {
339
338
}
340
339
}
341
340
} else if (mCodePush .didUpdate ()) {
342
- WritableMap currentPackage = mUpdateManager .getCurrentPackage ();
341
+ JSONObject currentPackage = mUpdateManager .getCurrentPackage ();
343
342
if (currentPackage != null ) {
344
- WritableMap newPackageStatusReport = mTelemetryManager .getUpdateReport (currentPackage );
343
+ WritableMap newPackageStatusReport = mTelemetryManager .getUpdateReport (CodePushUtils . convertJsonObjectToWritable ( currentPackage ) );
345
344
if (newPackageStatusReport != null ) {
346
345
promise .resolve (newPackageStatusReport );
347
346
return null ;
@@ -374,7 +373,7 @@ public void installUpdate(final ReadableMap updatePackage, final int installMode
374
373
AsyncTask <Void , Void , Void > asyncTask = new AsyncTask <Void , Void , Void >() {
375
374
@ Override
376
375
protected Void doInBackground (Void ... params ) {
377
- mUpdateManager .installPackage (updatePackage , mSettingsManager .isPendingUpdate (null ));
376
+ mUpdateManager .installPackage (CodePushUtils . convertReadableToJsonObject ( updatePackage ) , mSettingsManager .isPendingUpdate (null ));
378
377
379
378
String pendingHash = CodePushUtils .tryGetString (updatePackage , CodePushConstants .PACKAGE_HASH_KEY );
380
379
if (pendingHash == null ) {
0 commit comments