85
85
import static io .wazo .callkeep .Constants .ACTION_AUDIO_SESSION ;
86
86
import static io .wazo .callkeep .Constants .ACTION_CHECK_REACHABILITY ;
87
87
import static io .wazo .callkeep .Constants .ACTION_WAKE_APP ;
88
+ import static io .wazo .callkeep .Constants .ACTION_SHOW_INCOMING_CALL_UI ;
88
89
89
90
// @see https://github.com/kbagchiGWC/voice-quickstart-android/blob/9a2aff7fbe0d0a5ae9457b48e9ad408740dfb968/exampleConnectionService/src/main/java/com/twilio/voice/examples/connectionservice/VoiceConnectionServiceActivity.java
90
91
public class RNCallKeepModule extends ReactContextBaseJavaModule {
@@ -93,7 +94,7 @@ public class RNCallKeepModule extends ReactContextBaseJavaModule {
93
94
94
95
private static final String E_ACTIVITY_DOES_NOT_EXIST = "E_ACTIVITY_DOES_NOT_EXIST" ;
95
96
private static final String REACT_NATIVE_MODULE_NAME = "RNCallKeep" ;
96
- private static final String [] permissions = {
97
+ private static String [] permissions = {
97
98
Build .VERSION .SDK_INT < 30 ? Manifest .permission .READ_PHONE_STATE : Manifest .permission .READ_PHONE_NUMBERS ,
98
99
Manifest .permission .CALL_PHONE ,
99
100
Manifest .permission .RECORD_AUDIO
@@ -115,6 +116,10 @@ public RNCallKeepModule(ReactApplicationContext reactContext) {
115
116
this .reactContext = reactContext ;
116
117
}
117
118
119
+ private boolean isSelfManaged () {
120
+ return Build .VERSION .SDK_INT >= Build .VERSION_CODES .O && _settings .hasKey ("selfManaged" ) && _settings .getBoolean ("selfManaged" );
121
+ }
122
+
118
123
@ Override
119
124
public String getName () {
120
125
return REACT_NATIVE_MODULE_NAME ;
@@ -127,6 +132,20 @@ public void setup(ReadableMap options) {
127
132
VoiceConnectionService .setInitialized (true );
128
133
this ._settings = options ;
129
134
135
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
136
+ if (isSelfManaged ()) {
137
+ Log .d (TAG , "API Version supports self managed, and is enabled in setup" );
138
+ }
139
+ else {
140
+ Log .d (TAG , "API Version supports self managed, but it is not enabled in setup" );
141
+ }
142
+ }
143
+
144
+ //If we're running in self managed mode we need fewer permissions.
145
+ if (isSelfManaged ()) {
146
+ permissions = new String []{ Manifest .permission .RECORD_AUDIO };
147
+ }
148
+
130
149
if (isConnectionServiceAvailable ()) {
131
150
this .registerPhoneAccount ();
132
151
this .registerEvents ();
@@ -196,6 +215,7 @@ public void startCall(String uuid, String number, String callerName) {
196
215
Log .d (TAG , "startCall called, uuid: " + uuid + ", number: " + number + ", callerName: " + callerName );
197
216
198
217
if (!isConnectionServiceAvailable () || !hasPhoneAccount () || !hasPermissions () || number == null ) {
218
+ Log .d (TAG , "startCall ignored: " + isConnectionServiceAvailable () + ", " + hasPhoneAccount () + ", " + hasPermissions () + ", " + number );
199
219
return ;
200
220
}
201
221
@@ -341,7 +361,7 @@ public void reject(String message) {
341
361
hasPhoneAccountPromise .resolve (false );
342
362
}
343
363
});
344
- return ;
364
+ return ;
345
365
}
346
366
347
367
promise .resolve (!hasPhoneAccount ());
@@ -606,8 +626,13 @@ private void registerPhoneAccount(Context appContext) {
606
626
this .initializeTelecomManager ();
607
627
String appName = this .getApplicationName (this .getAppContext ());
608
628
609
- PhoneAccount .Builder builder = new PhoneAccount .Builder (handle , appName )
610
- .setCapabilities (PhoneAccount .CAPABILITY_CALL_PROVIDER );
629
+ PhoneAccount .Builder builder = new PhoneAccount .Builder (handle , appName );
630
+ if (isSelfManaged ()) {
631
+ builder .setCapabilities (PhoneAccount .CAPABILITY_SELF_MANAGED );
632
+ }
633
+ else {
634
+ builder .setCapabilities (PhoneAccount .CAPABILITY_CALL_PROVIDER );
635
+ }
611
636
612
637
if (_settings != null && _settings .hasKey ("imageName" )) {
613
638
int identifier = appContext .getResources ().getIdentifier (_settings .getString ("imageName" ), "drawable" , appContext .getPackageName ());
@@ -669,6 +694,7 @@ private void registerReceiver() {
669
694
intentFilter .addAction (ACTION_ONGOING_CALL );
670
695
intentFilter .addAction (ACTION_AUDIO_SESSION );
671
696
intentFilter .addAction (ACTION_CHECK_REACHABILITY );
697
+ intentFilter .addAction (ACTION_SHOW_INCOMING_CALL_UI );
672
698
LocalBroadcastManager .getInstance (this .reactContext ).registerReceiver (voiceBroadcastReceiver , intentFilter );
673
699
isReceiverRegistered = true ;
674
700
}
@@ -743,6 +769,12 @@ public void onReceive(Context context, Intent intent) {
743
769
case ACTION_CHECK_REACHABILITY :
744
770
sendEventToJS ("RNCallKeepCheckReachability" , null );
745
771
break ;
772
+ case ACTION_SHOW_INCOMING_CALL_UI :
773
+ args .putString ("handle" , attributeMap .get (EXTRA_CALL_NUMBER ));
774
+ args .putString ("callUUID" , attributeMap .get (EXTRA_CALL_UUID ));
775
+ args .putString ("name" , attributeMap .get (EXTRA_CALLER_NAME ));
776
+ sendEventToJS ("RNCallKeepShowIncomingCallUi" , args );
777
+ break ;
746
778
case ACTION_WAKE_APP :
747
779
Intent headlessIntent = new Intent (reactContext , RNCallKeepBackgroundMessagingService .class );
748
780
headlessIntent .putExtra ("callUUID" , attributeMap .get (EXTRA_CALL_UUID ));
0 commit comments