3434import androidx .annotation .UiThread ;
3535import com .facebook .common .logging .FLog ;
3636import com .facebook .infer .annotation .Assertions ;
37+ import com .facebook .infer .annotation .Nullsafe ;
3738import com .facebook .react .R ;
3839import com .facebook .react .bridge .DefaultJSExceptionHandler ;
3940import com .facebook .react .bridge .JSBundleLoader ;
7475import java .util .Map ;
7576import java .util .Set ;
7677
78+ @ Nullsafe (Nullsafe .Mode .LOCAL )
7779public abstract class DevSupportManagerBase implements DevSupportManager {
7880
7981 public interface CallbackWithBundleLoader {
@@ -222,16 +224,13 @@ private void logJSException(Exception e) {
222224
223225 if (e instanceof JavascriptException ) {
224226 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 );
228228 } else {
229229 showNewJavaError (message .toString (), e );
230230 }
231231 }
232232
233233 @ Override
234- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
235234 public void showNewJavaError (@ Nullable String message , Throwable e ) {
236235 FLog .e (ReactConstants .TAG , "Exception in native call" , e );
237236 showNewError (
@@ -244,19 +243,17 @@ public void showNewJavaError(@Nullable String message, Throwable e) {
244243 * called.
245244 */
246245 @ Override
247- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
248246 public void addCustomDevOption (String optionName , DevOptionHandler optionHandler ) {
249247 mCustomDevOptions .put (optionName , optionHandler );
250248 }
251249
252250 @ 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 ) {
255253 showNewError (message , StackTraceHelper .convertJsStackTrace (details ), errorCookie , ErrorType .JS );
256254 }
257255
258256 @ Override
259- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
260257 public void registerErrorCustomizer (ErrorCustomizer errorCustomizer ) {
261258 if (mErrorCustomizers == null ) {
262259 mErrorCustomizers = new ArrayList <>();
@@ -265,7 +262,6 @@ public void registerErrorCustomizer(ErrorCustomizer errorCustomizer) {
265262 }
266263
267264 @ Override
268- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
269265 public Pair <String , StackFrame []> processErrorCustomizers (Pair <String , StackFrame []> errorInfo ) {
270266 if (mErrorCustomizers != null ) {
271267 for (ErrorCustomizer errorCustomizer : mErrorCustomizers ) {
@@ -287,14 +283,14 @@ public void hideRedboxDialog() {
287283 mRedBoxSurfaceDelegate .hide ();
288284 }
289285
290- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
291286 public @ Nullable View createRootView (String appKey ) {
292287 return mReactInstanceDevHelper .createRootView (appKey );
293288 }
294289
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+ }
298294 }
299295
300296 private void hideDevOptionsDialog () {
@@ -526,14 +522,12 @@ public View getView(int position, @Nullable View convertView, ViewGroup parent)
526522 mDevOptionsDialog =
527523 new AlertDialog .Builder (context )
528524 .setCustomTitle (header )
529- // NULLSAFE_FIXME[Not Vetted Third-Party]
530525 .setAdapter (
531526 adapter ,
532527 (dialog , which ) -> {
533528 optionHandlers [which ].onOptionSelected ();
534529 mDevOptionsDialog = null ;
535530 })
536- // NULLSAFE_FIXME[Not Vetted Third-Party]
537531 .setOnCancelListener (dialog -> mDevOptionsDialog = null )
538532 .create ();
539533 mDevOptionsDialog .show ();
@@ -544,11 +538,10 @@ public View getView(int position, @Nullable View convertView, ViewGroup parent)
544538 }
545539 }
546540
547- private String getJSExecutorDescription () {
541+ private @ Nullable String getJSExecutorDescription () {
548542 try {
549543 return getReactInstanceDevHelper ().getJavaScriptExecutorFactory ().toString ();
550544 } catch (IllegalStateException e ) {
551- // NULLSAFE_FIXME[Return Not Nullable]
552545 return null ;
553546 }
554547 }
@@ -634,19 +627,20 @@ public boolean hasUpToDateJSBundleInCache() {
634627 if (mIsDevSupportEnabled && mJSBundleDownloadedFile .exists ()) {
635628 try {
636629 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 ;
648643 }
649- return true ;
650644 }
651645 } catch (PackageManager .NameNotFoundException e ) {
652646 // Ignore this error and just fallback to loading JS from assets
@@ -675,8 +669,10 @@ private void resetCurrentContext(@Nullable ReactContext reactContext) {
675669 if (mCurrentReactContext != null ) {
676670 try {
677671 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+ }
680676 String host = sourceUrl .getHost ();
681677 String scheme = sourceUrl .getProtocol ();
682678 int port = sourceUrl .getPort () != -1 ? sourceUrl .getPort () : sourceUrl .getDefaultPort ();
@@ -798,7 +794,6 @@ public void onProgress(
798794 }
799795
800796 @ Override
801- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
802797 public void onFailure (Exception cause ) {
803798 UiThreadUtil .runOnUiThread (
804799 DevSupportManagerBase .this ::hideSplitBundleDevLoadingView );
@@ -807,7 +802,6 @@ public void onFailure(Exception cause) {
807802 },
808803 bundleFile ,
809804 bundleUrl ,
810- // NULLSAFE_FIXME[Parameter Not Nullable]
811805 null );
812806 });
813807 }
@@ -836,7 +830,6 @@ public void isPackagerRunning(final PackagerStatusCallback callback) {
836830 }
837831
838832 @ Override
839- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
840833 public @ Nullable File downloadBundleResourceFromUrlSync (
841834 final String resourceURL , final File outputFile ) {
842835 return mDevServerHelper .downloadBundleResourceFromUrlSync (resourceURL , outputFile );
@@ -904,7 +897,6 @@ public void onProgress(
904897 }
905898
906899 @ Override
907- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
908900 public void onFailure (final Exception cause ) {
909901 hideDevLoadingView ();
910902 if (mBundleDownloadListener != null ) {
@@ -991,10 +983,16 @@ private void reload() {
991983
992984 // start shake gesture detector
993985 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+ }
998996 }
999997
1000998 // register reload app broadcast receiver
@@ -1078,7 +1076,6 @@ private static String getReloadAppAction(Context context) {
10781076 }
10791077
10801078 @ Override
1081- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
10821079 public void setPackagerLocationCustomizer (
10831080 DevSupportManager .PackagerLocationCustomizer packagerLocationCustomizer ) {
10841081 mPackagerLocationCustomizer = packagerLocationCustomizer ;
@@ -1090,7 +1087,6 @@ public void setPackagerLocationCustomizer(
10901087 }
10911088
10921089 @ Override
1093- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
10941090 public @ Nullable SurfaceDelegate createSurfaceDelegate (String moduleName ) {
10951091 if (mSurfaceDelegateFactory == null ) {
10961092 return null ;
0 commit comments