@@ -236,7 +236,6 @@ public void onCallStateChanged(int state, String incomingNumber) {
236
236
switch (state ) {
237
237
case TelephonyManager .CALL_STATE_RINGING :
238
238
// Incoming call is ringing (not used for outgoing call).
239
- Log .i ("onCallStateChanged" , "CALL_STATE_RINGING" );
240
239
break ;
241
240
case TelephonyManager .CALL_STATE_OFFHOOK :
242
241
// Phone call is active -- off the hook.
@@ -245,22 +244,19 @@ public void onCallStateChanged(int state, String incomingNumber) {
245
244
246
245
// Only let the JS side know if there is active app call & active native call
247
246
if (RNCallKeepModule .this .hasActiveCall && isInManagedCall ){
248
- WritableMap args = Arguments .createMap ();
249
- RNCallKeepModule .this .sendEventToJS ("RNCallKeepHasActiveCall" ,args );
247
+ WritableMap args = Arguments .createMap ();
248
+ RNCallKeepModule .this .sendEventToJS ("RNCallKeepHasActiveCall" ,args );
250
249
}else if (VoiceConnectionService .currentConnections .size () > 0 ){
251
250
// Will enter here for the first time to mark the app has active call
252
- RNCallKeepModule .this .hasActiveCall = true ;
251
+ RNCallKeepModule .this .hasActiveCall = true ;
253
252
}
254
- Log .i ("onCallStateChanged" , "CALL_STATE_OFFHOOK" );
255
253
break ;
256
254
case TelephonyManager .CALL_STATE_IDLE :
257
255
// Phone is idle before and after phone call.
258
256
// If running on version older than 19 (KitKat),
259
257
// restart activity when phone call ends.
260
- Log .i ("onCallStateChanged" , "CALL_STATE_IDLE" );
261
258
break ;
262
259
default :
263
- Log .i ("onCallStateChanged" , "default" );
264
260
break ;
265
261
}
266
262
}
@@ -273,7 +269,6 @@ public void onCallStateChanged(int state) {
273
269
switch (state ) {
274
270
case TelephonyManager .CALL_STATE_RINGING :
275
271
// Incoming call is ringing (not used for outgoing call).
276
- Log .i ("onCallStateChanged" , "CALL_STATE_RINGING" );
277
272
break ;
278
273
case TelephonyManager .CALL_STATE_OFFHOOK :
279
274
// Phone call is active -- off the hook.
@@ -289,35 +284,34 @@ public void onCallStateChanged(int state) {
289
284
// Will enter here for the first time to mark the app has active call
290
285
RNCallKeepModule .this .hasActiveCall = true ;
291
286
}
292
- Log .i ("onCallStateChanged" , "CALL_STATE_OFFHOOK" );
293
287
break ;
294
288
case TelephonyManager .CALL_STATE_IDLE :
295
289
// Phone is idle before and after phone call.
296
290
// If running on version older than 19 (KitKat),
297
291
// restart activity when phone call ends.
298
- Log .i ("onCallStateChanged" , "CALL_STATE_IDLE" );
299
292
break ;
300
293
default :
301
- Log .i ("onCallStateChanged" , "default" );
302
294
break ;
303
295
}
304
296
}
305
297
}
306
298
307
299
public void stopListenToNativeCallsState () {
308
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S && callStateListener !=null ){
309
- Log .d (TAG , "[RNCallKeepModule] stopListenToNativeCallsState" );
300
+ Log .d (TAG , "[RNCallKeepModule] stopListenToNativeCallsState" );
301
+
302
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S && callStateListener !=null ){
310
303
telephonyManager .unregisterTelephonyCallback (callStateListener );
311
- }else if (Build .VERSION .SDK_INT < Build .VERSION_CODES .S && legacyCallStateListener != null ){
304
+ } else if (Build .VERSION .SDK_INT < Build .VERSION_CODES .S && legacyCallStateListener != null ){
312
305
telephonyManager .listen (legacyCallStateListener , PhoneStateListener .LISTEN_NONE );
313
306
}
314
307
}
315
308
316
309
public void listenToNativeCallsState () {
310
+ Log .d (TAG , "[RNCallKeepModule] listenToNativeCallsState" );
317
311
Context context = this .getAppContext ();
318
312
int permissionCheck = ContextCompat .checkSelfPermission (context , Manifest .permission .READ_PHONE_STATE );
313
+
319
314
if (permissionCheck == PackageManager .PERMISSION_GRANTED ) {
320
- Log .d (TAG , "[RNCallKeepModule] listenToNativeCallsState" );
321
315
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
322
316
callStateListener = new CallStateListener ();
323
317
telephonyManager .registerTelephonyCallback (context .getMainExecutor (),callStateListener );
@@ -331,14 +325,15 @@ public void listenToNativeCallsState() {
331
325
public boolean checkIsInManagedCall () {
332
326
Context context = this .getAppContext ();
333
327
int permissionCheck = ContextCompat .checkSelfPermission (context , Manifest .permission .READ_PHONE_STATE );
328
+
334
329
if (permissionCheck == PackageManager .PERMISSION_GRANTED ) {
335
330
return telecomManager .isInManagedCall ();
336
331
}
337
- return false ;
332
+ return false ;
338
333
}
339
334
340
335
@ ReactMethod
341
- public void checkIsInManagedCall (Promise promise ) {
336
+ public void checkIsInManagedCall (Promise promise ) {
342
337
boolean isInManagedCall = this .checkIsInManagedCall ();
343
338
promise .resolve (isInManagedCall );
344
339
}
@@ -727,20 +722,20 @@ public void reportEndCallWithUUID(String uuid, int reason) {
727
722
728
723
@ Override
729
724
public void onHostResume () {
730
- Log . d ( TAG , "onResume()" );
725
+
731
726
}
732
727
733
728
@ Override
734
729
public void onHostPause () {
735
- Log . d ( TAG , "onPause()" );
730
+
736
731
}
737
732
738
733
@ Override
739
734
public void onHostDestroy () {
740
- // when activity destroyed end all calls
741
- Log .d (TAG , "onDestroy() " );
735
+ // When activity destroyed end all calls
736
+ Log .d (TAG , "[RNCallKeepModule] onHostDestroy called " );
742
737
if (!isConnectionServiceAvailable () || !hasPhoneAccount ()) {
743
- Log .w (TAG , "[RNCallKeepModule] endAllCalls ignored due to no ConnectionService or no phone account" );
738
+ Log .w (TAG , "[RNCallKeepModule] onHostDestroy ignored due to no ConnectionService or no phone account" );
744
739
return ;
745
740
}
746
741
@@ -751,8 +746,8 @@ public void onHostDestroy() {
751
746
connectionToEnd .onDisconnect ();
752
747
}
753
748
this .stopListenToNativeCallsState ();
754
- Log .d (TAG , "[RNCallKeepModule] endAllCalls executed" );
755
- // this line will kill the android process after ending all calls
749
+ Log .d (TAG , "[RNCallKeepModule] onHostDestroy executed" );
750
+ // This line will kill the android process after ending all calls
756
751
android .os .Process .killProcess (android .os .Process .myPid ());
757
752
}
758
753
0 commit comments