Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace android.os.Looper by android.os.HandleThread to prevent blocking main thread #825

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Looper;
import android.os.HandlerThread;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -120,6 +120,7 @@ public class RNCallKeepModule extends ReactContextBaseJavaModule implements Life

private static final String TAG = "RNCallKeep";
private static TelecomManager telecomManager;
private HandlerThread handlerThread;
private LegacyCallStateListener legacyCallStateListener;
private CallStateListener callStateListener;
private static TelephonyManager telephonyManager;
Expand Down Expand Up @@ -304,7 +305,11 @@ public void stopListenToNativeCallsState() {
telephonyManager.unregisterTelephonyCallback(callStateListener);
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S && legacyCallStateListener != null){
telephonyManager.listen(legacyCallStateListener, PhoneStateListener.LISTEN_NONE);
Looper.myLooper().quit();

if (handlerThread != null) {
handlerThread.quitSafely();
handlerThread = null;
}
}
}

Expand All @@ -315,15 +320,16 @@ public void listenToNativeCallsState() {

if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
callStateListener = new CallStateListener();
telephonyManager.registerTelephonyCallback(context.getMainExecutor(),callStateListener);
callStateListener = new CallStateListener();
telephonyManager.registerTelephonyCallback(context.getMainExecutor(),callStateListener);
} else {
if (Looper.myLooper() == null) {
Looper.prepare();
}
legacyCallStateListener = new LegacyCallStateListener();
telephonyManager.listen(legacyCallStateListener, PhoneStateListener.LISTEN_CALL_STATE);
Looper.loop();
if (handlerThread == null) {
handlerThread = new HandlerThread("TelephonyManager");
handlerThread.start();
}

legacyCallStateListener = new LegacyCallStateListener();
telephonyManager.listen(legacyCallStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-callkeep",
"version": "4.3.16",
"version": "4.3.17",
"description": "iOS 10 CallKit and Android ConnectionService Framework For React Native",
"main": "index.js",
"scripts": {},
Expand Down