34
34
import androidx .annotation .UiThread ;
35
35
import com .facebook .common .logging .FLog ;
36
36
import com .facebook .infer .annotation .Assertions ;
37
+ import com .facebook .infer .annotation .Nullsafe ;
37
38
import com .facebook .react .R ;
38
39
import com .facebook .react .bridge .DefaultJSExceptionHandler ;
39
40
import com .facebook .react .bridge .JSBundleLoader ;
74
75
import java .util .Map ;
75
76
import java .util .Set ;
76
77
78
+ @ Nullsafe (Nullsafe .Mode .LOCAL )
77
79
public abstract class DevSupportManagerBase implements DevSupportManager {
78
80
79
81
public interface CallbackWithBundleLoader {
@@ -222,16 +224,13 @@ private void logJSException(Exception e) {
222
224
223
225
if (e instanceof JavascriptException ) {
224
226
FLog .e (ReactConstants .TAG , "Exception in native call from JS" , e );
225
- showNewError (
226
- // NULLSAFE_FIXME[Nullable Dereference]
227
- e .getMessage ().toString (), new StackFrame [] {}, JSEXCEPTION_ERROR_COOKIE , ErrorType .JS );
227
+ showNewError (e .getMessage (), new StackFrame [] {}, JSEXCEPTION_ERROR_COOKIE , ErrorType .JS );
228
228
} else {
229
229
showNewJavaError (message .toString (), e );
230
230
}
231
231
}
232
232
233
233
@ Override
234
- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
235
234
public void showNewJavaError (@ Nullable String message , Throwable e ) {
236
235
FLog .e (ReactConstants .TAG , "Exception in native call" , e );
237
236
showNewError (
@@ -244,19 +243,17 @@ public void showNewJavaError(@Nullable String message, Throwable e) {
244
243
* called.
245
244
*/
246
245
@ Override
247
- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
248
246
public void addCustomDevOption (String optionName , DevOptionHandler optionHandler ) {
249
247
mCustomDevOptions .put (optionName , optionHandler );
250
248
}
251
249
252
250
@ Override
253
- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
254
- public void showNewJSError ( String message , ReadableArray details , int errorCookie ) {
251
+ public void showNewJSError (
252
+ @ Nullable String message , @ Nullable ReadableArray details , int errorCookie ) {
255
253
showNewError (message , StackTraceHelper .convertJsStackTrace (details ), errorCookie , ErrorType .JS );
256
254
}
257
255
258
256
@ Override
259
- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
260
257
public void registerErrorCustomizer (ErrorCustomizer errorCustomizer ) {
261
258
if (mErrorCustomizers == null ) {
262
259
mErrorCustomizers = new ArrayList <>();
@@ -265,7 +262,6 @@ public void registerErrorCustomizer(ErrorCustomizer errorCustomizer) {
265
262
}
266
263
267
264
@ Override
268
- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
269
265
public Pair <String , StackFrame []> processErrorCustomizers (Pair <String , StackFrame []> errorInfo ) {
270
266
if (mErrorCustomizers != null ) {
271
267
for (ErrorCustomizer errorCustomizer : mErrorCustomizers ) {
@@ -287,14 +283,14 @@ public void hideRedboxDialog() {
287
283
mRedBoxSurfaceDelegate .hide ();
288
284
}
289
285
290
- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
291
286
public @ Nullable View createRootView (String appKey ) {
292
287
return mReactInstanceDevHelper .createRootView (appKey );
293
288
}
294
289
295
- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
296
- public void destroyRootView (View rootView ) {
297
- mReactInstanceDevHelper .destroyRootView (rootView );
290
+ public void destroyRootView (@ Nullable View rootView ) {
291
+ if (rootView != null ) {
292
+ mReactInstanceDevHelper .destroyRootView (rootView );
293
+ }
298
294
}
299
295
300
296
private void hideDevOptionsDialog () {
@@ -526,14 +522,12 @@ public View getView(int position, @Nullable View convertView, ViewGroup parent)
526
522
mDevOptionsDialog =
527
523
new AlertDialog .Builder (context )
528
524
.setCustomTitle (header )
529
- // NULLSAFE_FIXME[Not Vetted Third-Party]
530
525
.setAdapter (
531
526
adapter ,
532
527
(dialog , which ) -> {
533
528
optionHandlers [which ].onOptionSelected ();
534
529
mDevOptionsDialog = null ;
535
530
})
536
- // NULLSAFE_FIXME[Not Vetted Third-Party]
537
531
.setOnCancelListener (dialog -> mDevOptionsDialog = null )
538
532
.create ();
539
533
mDevOptionsDialog .show ();
@@ -544,11 +538,10 @@ public View getView(int position, @Nullable View convertView, ViewGroup parent)
544
538
}
545
539
}
546
540
547
- private String getJSExecutorDescription () {
541
+ private @ Nullable String getJSExecutorDescription () {
548
542
try {
549
543
return getReactInstanceDevHelper ().getJavaScriptExecutorFactory ().toString ();
550
544
} catch (IllegalStateException e ) {
551
- // NULLSAFE_FIXME[Return Not Nullable]
552
545
return null ;
553
546
}
554
547
}
@@ -634,19 +627,20 @@ public boolean hasUpToDateJSBundleInCache() {
634
627
if (mIsDevSupportEnabled && mJSBundleDownloadedFile .exists ()) {
635
628
try {
636
629
String packageName = mApplicationContext .getPackageName ();
637
- PackageInfo thisPackage =
638
- // NULLSAFE_FIXME[Nullable Dereference]
639
- mApplicationContext .getPackageManager ().getPackageInfo (packageName , 0 );
640
- if (mJSBundleDownloadedFile .lastModified () > thisPackage .lastUpdateTime ) {
641
- // Base APK has not been updated since we downloaded JS, but if app is using exopackage
642
- // it may only be a single dex that has been updated. We check for exopackage dir update
643
- // time in that case.
644
- File exopackageDir =
645
- new File (String .format (Locale .US , EXOPACKAGE_LOCATION_FORMAT , packageName ));
646
- if (exopackageDir .exists ()) {
647
- return mJSBundleDownloadedFile .lastModified () > exopackageDir .lastModified ();
630
+ PackageManager packageManager = mApplicationContext .getPackageManager ();
631
+ if (packageManager != null ) {
632
+ PackageInfo thisPackage = packageManager .getPackageInfo (packageName , 0 );
633
+ if (mJSBundleDownloadedFile .lastModified () > thisPackage .lastUpdateTime ) {
634
+ // Base APK has not been updated since we downloaded JS, but if app is using exopackage
635
+ // it may only be a single dex that has been updated. We check for exopackage dir update
636
+ // time in that case.
637
+ File exopackageDir =
638
+ new File (String .format (Locale .US , EXOPACKAGE_LOCATION_FORMAT , packageName ));
639
+ if (exopackageDir .exists ()) {
640
+ return mJSBundleDownloadedFile .lastModified () > exopackageDir .lastModified ();
641
+ }
642
+ return true ;
648
643
}
649
- return true ;
650
644
}
651
645
} catch (PackageManager .NameNotFoundException e ) {
652
646
// Ignore this error and just fallback to loading JS from assets
@@ -675,8 +669,10 @@ private void resetCurrentContext(@Nullable ReactContext reactContext) {
675
669
if (mCurrentReactContext != null ) {
676
670
try {
677
671
URL sourceUrl = new URL (getSourceUrl ());
678
- // NULLSAFE_FIXME[Nullable Dereference]
679
- String path = sourceUrl .getPath ().substring (1 ); // strip initial slash in path
672
+ String path = sourceUrl .getPath ();
673
+ if (path != null ) {
674
+ path = path .substring (1 ); // strip initial slash in path
675
+ }
680
676
String host = sourceUrl .getHost ();
681
677
String scheme = sourceUrl .getProtocol ();
682
678
int port = sourceUrl .getPort () != -1 ? sourceUrl .getPort () : sourceUrl .getDefaultPort ();
@@ -798,7 +794,6 @@ public void onProgress(
798
794
}
799
795
800
796
@ Override
801
- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
802
797
public void onFailure (Exception cause ) {
803
798
UiThreadUtil .runOnUiThread (
804
799
DevSupportManagerBase .this ::hideSplitBundleDevLoadingView );
@@ -807,7 +802,6 @@ public void onFailure(Exception cause) {
807
802
},
808
803
bundleFile ,
809
804
bundleUrl ,
810
- // NULLSAFE_FIXME[Parameter Not Nullable]
811
805
null );
812
806
});
813
807
}
@@ -836,7 +830,6 @@ public void isPackagerRunning(final PackagerStatusCallback callback) {
836
830
}
837
831
838
832
@ Override
839
- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
840
833
public @ Nullable File downloadBundleResourceFromUrlSync (
841
834
final String resourceURL , final File outputFile ) {
842
835
return mDevServerHelper .downloadBundleResourceFromUrlSync (resourceURL , outputFile );
@@ -904,7 +897,6 @@ public void onProgress(
904
897
}
905
898
906
899
@ Override
907
- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
908
900
public void onFailure (final Exception cause ) {
909
901
hideDevLoadingView ();
910
902
if (mBundleDownloadListener != null ) {
@@ -991,10 +983,16 @@ private void reload() {
991
983
992
984
// start shake gesture detector
993
985
if (!mIsShakeDetectorStarted ) {
994
- mShakeDetector .start (
995
- // NULLSAFE_FIXME[Parameter Not Nullable]
996
- (SensorManager ) mApplicationContext .getSystemService (Context .SENSOR_SERVICE ));
997
- mIsShakeDetectorStarted = true ;
986
+ SensorManager sensorManager =
987
+ (SensorManager ) mApplicationContext .getSystemService (Context .SENSOR_SERVICE );
988
+ if (sensorManager != null ) {
989
+ mShakeDetector .start (sensorManager );
990
+ mIsShakeDetectorStarted = true ;
991
+ } else {
992
+ FLog .w (
993
+ ReactConstants .TAG ,
994
+ "Couldn't register shake gesture detector, sensor service is null" );
995
+ }
998
996
}
999
997
1000
998
// register reload app broadcast receiver
@@ -1078,7 +1076,6 @@ private static String getReloadAppAction(Context context) {
1078
1076
}
1079
1077
1080
1078
@ Override
1081
- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
1082
1079
public void setPackagerLocationCustomizer (
1083
1080
DevSupportManager .PackagerLocationCustomizer packagerLocationCustomizer ) {
1084
1081
mPackagerLocationCustomizer = packagerLocationCustomizer ;
@@ -1090,7 +1087,6 @@ public void setPackagerLocationCustomizer(
1090
1087
}
1091
1088
1092
1089
@ Override
1093
- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
1094
1090
public @ Nullable SurfaceDelegate createSurfaceDelegate (String moduleName ) {
1095
1091
if (mSurfaceDelegateFactory == null ) {
1096
1092
return null ;
0 commit comments