Skip to content

Commit 0d8bbd8

Browse files
authored
Merge pull request #817 from react-native-webrtc/fix_telephony_listener
Fix TelephonyManager legacy listener that crashes when no Looper defined
2 parents 08034eb + 7182acc commit 0d8bbd8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import android.net.Uri;
3636
import android.os.Build;
3737
import android.os.Bundle;
38+
import android.os.Looper;
3839
import android.view.WindowManager;
3940
import androidx.annotation.NonNull;
4041
import androidx.annotation.Nullable;
@@ -303,6 +304,7 @@ public void stopListenToNativeCallsState() {
303304
telephonyManager.unregisterTelephonyCallback(callStateListener);
304305
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S && legacyCallStateListener != null){
305306
telephonyManager.listen(legacyCallStateListener, PhoneStateListener.LISTEN_NONE);
307+
Looper.myLooper().quit();
306308
}
307309
}
308310

@@ -316,8 +318,10 @@ public void listenToNativeCallsState() {
316318
callStateListener = new CallStateListener();
317319
telephonyManager.registerTelephonyCallback(context.getMainExecutor(),callStateListener);
318320
} else {
321+
Looper.prepare();
319322
legacyCallStateListener = new LegacyCallStateListener();
320323
telephonyManager.listen(legacyCallStateListener, PhoneStateListener.LISTEN_CALL_STATE);
324+
Looper.loop();
321325
}
322326
}
323327
}

0 commit comments

Comments
 (0)