@@ -146,7 +146,7 @@ private void acquireProximityWakeLock() {
146146 }
147147 }
148148
149- private void releaseProximityWakeLock (boolean waitForNoProximity ) {
149+ private void releaseProximityWakeLock (final boolean waitForNoProximity ) {
150150 if (!isProximityWakeLockSupported ()) {
151151 return ;
152152 }
@@ -509,7 +509,7 @@ public void test_deviceCallback() {
509509 // -- TODO: bluetooth support
510510 */
511511
512- private static void sendEvent (String eventName , @ Nullable WritableMap params ) {
512+ private static void sendEvent (final String eventName , @ Nullable WritableMap params ) {
513513 try {
514514 reactContext
515515 .getJSModule (DeviceEventManagerModule .RCTDeviceEventEmitter .class )
@@ -520,26 +520,21 @@ private static void sendEvent(String eventName, @Nullable WritableMap params) {
520520 }
521521
522522 @ ReactMethod
523- public void start (String media , boolean auto ) {
524- if (media == "video" ) {
523+ public void start (final String media , final boolean auto ) {
524+ if (media . equals ( "video" ) ) {
525525 defaultSpeakerOn = true ;
526526 } else {
527527 defaultSpeakerOn = false ;
528528 }
529529 automatic = auto ;
530530 if (!audioManagerInitialized ) {
531531 Log .d (TAG , "start audioRouteManager" );
532- requestAudioFocus ();
533- // TODO: even if not acquired focus, we can still play sounds. but need figure out which is better.
534532 storeOriginalAudioSetup ();
533+ startEvents ();
534+ // TODO: even if not acquired focus, we can still play sounds. but need figure out which is better.
535535 setMicrophoneMute (false );
536536 audioManager .setMode (defaultAudioMode );
537537 updateAudioRoute ();
538- startWiredHeadsetEvent ();
539- startNoisyAudioEvent ();
540- startMediaButtonEvent ();
541- startProximitySensor ();
542- setKeepScreenOn (true );
543538 audioManagerInitialized = true ;
544539 }
545540 }
@@ -548,39 +543,45 @@ public void start(String media, boolean auto) {
548543 public void stop () {
549544 if (audioManagerInitialized ) {
550545 Log .d (TAG , "stop audioRouteManager" );
551- stopWiredHeadsetEvent ();
552- stopNoisyAudioEvent ();
553- stopMediaButtonEvent ();
554- stopProximitySensor ();
546+ stopEvents ();
555547 restoreOriginalAudioSetup ();
556- releaseAudioFocus ();
557- setKeepScreenOn (false );
558548 audioManagerInitialized = false ;
559549 }
560550 }
561551
562552 private void pause () {
563553 if (audioManagerInitialized ) {
564554 Log .d (TAG , "pause audioRouteManager" );
565- releaseAudioFocus ();
566- stopWiredHeadsetEvent ();
567- stopNoisyAudioEvent ();
568- stopMediaButtonEvent ();
569- stopProximitySensor ();
570- setKeepScreenOn (false );
555+ stopEvents ();
571556 }
572557 }
573558
574559 private void resume () {
575560 if (audioManagerInitialized ) {
576561 Log .d (TAG , "resume audioRouteManager" );
577- requestAudioFocus ();
578- startWiredHeadsetEvent ();
579- startNoisyAudioEvent ();
580- startMediaButtonEvent ();
562+ startEvents ();
563+ }
564+ }
565+
566+ private void startEvents () {
567+ requestAudioFocus ();
568+ startWiredHeadsetEvent ();
569+ startNoisyAudioEvent ();
570+ startMediaButtonEvent ();
571+ if (!defaultSpeakerOn ) {
572+ // video, default disable proximity
581573 startProximitySensor ();
582- setKeepScreenOn (true );
583574 }
575+ setKeepScreenOn (true );
576+ }
577+
578+ private void stopEvents () {
579+ stopWiredHeadsetEvent ();
580+ stopNoisyAudioEvent ();
581+ stopMediaButtonEvent ();
582+ stopProximitySensor ();
583+ setKeepScreenOn (false );
584+ releaseAudioFocus ();
584585 }
585586
586587 private void requestAudioFocus () {
@@ -664,15 +665,15 @@ public void run() {
664665 }
665666
666667 @ ReactMethod
667- public void setSpeakerphoneOn (boolean enable ) {
668+ public void setSpeakerphoneOn (final boolean enable ) {
668669 if (enable != audioManager .isSpeakerphoneOn ()) {
669670 Log .d (TAG , "setSpeakerphoneOn(): " + enable );
670671 audioManager .setSpeakerphoneOn (enable );
671672 }
672673 }
673674
674675 @ ReactMethod
675- public void setForceSpeakerphoneOn (boolean enable ) {
676+ public void setForceSpeakerphoneOn (final boolean enable ) {
676677 forceSpeakerOn = enable ;
677678 if (forceSpeakerOn ) {
678679 Log .d (TAG , "setForceSpeakerphoneOn()" );
@@ -681,7 +682,7 @@ public void setForceSpeakerphoneOn(boolean enable) {
681682 }
682683
683684 @ ReactMethod
684- public void setMicrophoneMute (boolean enable ) {
685+ public void setMicrophoneMute (final boolean enable ) {
685686 if (enable != audioManager .isMicrophoneMute ()) {
686687 Log .d (TAG , "setMicrophoneMute(): " + enable );
687688 audioManager .setMicrophoneMute (enable );
0 commit comments