Skip to content

Commit 0183469

Browse files
committed
2 parents 1154cc7 + 457f2c4 commit 0183469

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import android.net.Uri;
3636
import android.os.Build;
3737
import android.os.Bundle;
38-
import android.os.Looper;
38+
import android.os.HandlerThread;
3939
import android.view.WindowManager;
4040
import androidx.annotation.NonNull;
4141
import androidx.annotation.Nullable;
@@ -120,6 +120,7 @@ public class RNCallKeepModule extends ReactContextBaseJavaModule implements Life
120120

121121
private static final String TAG = "RNCallKeep";
122122
private static TelecomManager telecomManager;
123+
private HandlerThread handlerThread;
123124
private LegacyCallStateListener legacyCallStateListener;
124125
private CallStateListener callStateListener;
125126
private static TelephonyManager telephonyManager;
@@ -306,6 +307,9 @@ public void stopListenToNativeCallsState() {
306307
telephonyManager.listen(legacyCallStateListener, PhoneStateListener.LISTEN_NONE);
307308
if (Looper.myLooper() != null) {
308309
Looper.myLooper().quit();
310+
if (handlerThread != null) {
311+
handlerThread.quitSafely();
312+
handlerThread = null;
309313
}
310314
}
311315
}
@@ -317,15 +321,16 @@ public void listenToNativeCallsState() {
317321

318322
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
319323
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
320-
callStateListener = new CallStateListener();
321-
telephonyManager.registerTelephonyCallback(context.getMainExecutor(),callStateListener);
324+
callStateListener = new CallStateListener();
325+
telephonyManager.registerTelephonyCallback(context.getMainExecutor(),callStateListener);
322326
} else {
323-
if (Looper.myLooper() == null) {
324-
Looper.prepare();
325-
}
326-
legacyCallStateListener = new LegacyCallStateListener();
327-
telephonyManager.listen(legacyCallStateListener, PhoneStateListener.LISTEN_CALL_STATE);
328-
Looper.loop();
327+
if (handlerThread == null) {
328+
handlerThread = new HandlerThread("TelephonyManager");
329+
handlerThread.start();
330+
}
331+
332+
legacyCallStateListener = new LegacyCallStateListener();
333+
telephonyManager.listen(legacyCallStateListener, PhoneStateListener.LISTEN_CALL_STATE);
329334
}
330335
}
331336
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-callkeep",
3-
"version": "4.3.16",
3+
"version": "4.3.17",
44
"description": "iOS 10 CallKit and Android ConnectionService Framework For React Native",
55
"main": "index.js",
66
"scripts": {},

0 commit comments

Comments
 (0)