@@ -236,7 +236,6 @@ public void onCallStateChanged(int state, String incomingNumber) {
236236 switch (state ) {
237237 case TelephonyManager .CALL_STATE_RINGING :
238238 // Incoming call is ringing (not used for outgoing call).
239- Log .i ("onCallStateChanged" , "CALL_STATE_RINGING" );
240239 break ;
241240 case TelephonyManager .CALL_STATE_OFFHOOK :
242241 // Phone call is active -- off the hook.
@@ -245,22 +244,19 @@ public void onCallStateChanged(int state, String incomingNumber) {
245244
246245 // Only let the JS side know if there is active app call & active native call
247246 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 );
250249 }else if (VoiceConnectionService .currentConnections .size () > 0 ){
251250 // Will enter here for the first time to mark the app has active call
252- RNCallKeepModule .this .hasActiveCall = true ;
251+ RNCallKeepModule .this .hasActiveCall = true ;
253252 }
254- Log .i ("onCallStateChanged" , "CALL_STATE_OFFHOOK" );
255253 break ;
256254 case TelephonyManager .CALL_STATE_IDLE :
257255 // Phone is idle before and after phone call.
258256 // If running on version older than 19 (KitKat),
259257 // restart activity when phone call ends.
260- Log .i ("onCallStateChanged" , "CALL_STATE_IDLE" );
261258 break ;
262259 default :
263- Log .i ("onCallStateChanged" , "default" );
264260 break ;
265261 }
266262 }
@@ -273,7 +269,6 @@ public void onCallStateChanged(int state) {
273269 switch (state ) {
274270 case TelephonyManager .CALL_STATE_RINGING :
275271 // Incoming call is ringing (not used for outgoing call).
276- Log .i ("onCallStateChanged" , "CALL_STATE_RINGING" );
277272 break ;
278273 case TelephonyManager .CALL_STATE_OFFHOOK :
279274 // Phone call is active -- off the hook.
@@ -289,35 +284,34 @@ public void onCallStateChanged(int state) {
289284 // Will enter here for the first time to mark the app has active call
290285 RNCallKeepModule .this .hasActiveCall = true ;
291286 }
292- Log .i ("onCallStateChanged" , "CALL_STATE_OFFHOOK" );
293287 break ;
294288 case TelephonyManager .CALL_STATE_IDLE :
295289 // Phone is idle before and after phone call.
296290 // If running on version older than 19 (KitKat),
297291 // restart activity when phone call ends.
298- Log .i ("onCallStateChanged" , "CALL_STATE_IDLE" );
299292 break ;
300293 default :
301- Log .i ("onCallStateChanged" , "default" );
302294 break ;
303295 }
304296 }
305297 }
306298
307299 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 ){
310303 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 ){
312305 telephonyManager .listen (legacyCallStateListener , PhoneStateListener .LISTEN_NONE );
313306 }
314307 }
315308
316309 public void listenToNativeCallsState () {
310+ Log .d (TAG , "[RNCallKeepModule] listenToNativeCallsState" );
317311 Context context = this .getAppContext ();
318312 int permissionCheck = ContextCompat .checkSelfPermission (context , Manifest .permission .READ_PHONE_STATE );
313+
319314 if (permissionCheck == PackageManager .PERMISSION_GRANTED ) {
320- Log .d (TAG , "[RNCallKeepModule] listenToNativeCallsState" );
321315 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
322316 callStateListener = new CallStateListener ();
323317 telephonyManager .registerTelephonyCallback (context .getMainExecutor (),callStateListener );
@@ -331,14 +325,15 @@ public void listenToNativeCallsState() {
331325 public boolean checkIsInManagedCall () {
332326 Context context = this .getAppContext ();
333327 int permissionCheck = ContextCompat .checkSelfPermission (context , Manifest .permission .READ_PHONE_STATE );
328+
334329 if (permissionCheck == PackageManager .PERMISSION_GRANTED ) {
335330 return telecomManager .isInManagedCall ();
336331 }
337- return false ;
332+ return false ;
338333 }
339334
340335 @ ReactMethod
341- public void checkIsInManagedCall (Promise promise ) {
336+ public void checkIsInManagedCall (Promise promise ) {
342337 boolean isInManagedCall = this .checkIsInManagedCall ();
343338 promise .resolve (isInManagedCall );
344339 }
@@ -727,20 +722,20 @@ public void reportEndCallWithUUID(String uuid, int reason) {
727722
728723 @ Override
729724 public void onHostResume () {
730- Log . d ( TAG , "onResume()" );
725+
731726 }
732727
733728 @ Override
734729 public void onHostPause () {
735- Log . d ( TAG , "onPause()" );
730+
736731 }
737732
738733 @ Override
739734 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 " );
742737 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" );
744739 return ;
745740 }
746741
@@ -751,8 +746,8 @@ public void onHostDestroy() {
751746 connectionToEnd .onDisconnect ();
752747 }
753748 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
756751 android .os .Process .killProcess (android .os .Process .myPid ());
757752 }
758753
0 commit comments