@@ -1000,14 +1000,34 @@ private void unregisterBtReceiver() {
1000
1000
1001
1001
private boolean isPhoneStateListenerRegistered ;
1002
1002
1003
+ //Phone state permissions are required to from Api 31. Adding this check to avoid crash.
1004
+ private boolean hasPhoneStatePermission () {
1005
+ if (Build .VERSION .SDK_INT >= 31 ) {
1006
+ if (context .checkSelfPermission (Manifest .permission .READ_PHONE_STATE )
1007
+ != PackageManager .PERMISSION_GRANTED ) {
1008
+ log .e ("Some features may not be available unless the phone permissions has been granted explicitly " +
1009
+ "in the App settings." );
1010
+ return false ;
1011
+ }
1012
+ }
1013
+ return true ;
1014
+ }
1015
+
1003
1016
private void registerPhoneStateListener () {
1004
1017
Log .d (TAG , "registerPhoneStateListener() called" );
1005
1018
1006
1019
if (isPhoneStateListenerRegistered ) {
1007
1020
return ;
1008
1021
}
1009
1022
1023
+ if (!hasPhoneStatePermission ()) {
1024
+ log .d ("No Phone State permissions. Register phoneStateListener cannot " +
1025
+ "be completed." );
1026
+ return ;
1027
+ }
1028
+
1010
1029
if (telephonyManager != null ) {
1030
+ // add snippet code from Jint
1011
1031
telephonyManager .listen (phoneStateListener , PhoneStateListener .LISTEN_CALL_STATE );
1012
1032
isPhoneStateListenerRegistered = true ;
1013
1033
}
@@ -1020,6 +1040,12 @@ private void unRegisterPhoneStateListener() {
1020
1040
return ;
1021
1041
}
1022
1042
1043
+ if (!hasPhoneStatePermission ()) {
1044
+ log .d ("No Phone State permissions. Register phoneStateListener cannot " +
1045
+ "be completed." );
1046
+ return ;
1047
+ }
1048
+
1023
1049
if (telephonyManager != null ) {
1024
1050
telephonyManager .listen (phoneStateListener , PhoneStateListener .LISTEN_NONE );
1025
1051
isPhoneStateListenerRegistered = false ;
0 commit comments