Skip to content

Commit 7d73060

Browse files
authored
Merge pull request #34 from grit96/master
Add checkDefault method for addressing #33
2 parents 5722bd5 + 06b0e9b commit 7d73060

File tree

4 files changed

+100
-37
lines changed

4 files changed

+100
-37
lines changed

README.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ RNCallKeep.setup(options);
6969
Cancel button label
7070
- `okButton`: string (required)
7171
Ok button label
72-
72+
7373
## Methods
7474

7575
### setAvailable
7676
_This feature is available only on Android._
7777

78-
Tell _ConnectionService_ that the device is ready to accept outgoing calls.
78+
Tell _ConnectionService_ that the device is ready to accept outgoing calls.
7979
If not the user will be stuck in the build UI screen without any actions.
8080
Eg: Call it with `false` when disconnected from the sip client, when your token expires ...
8181

@@ -207,6 +207,25 @@ _This feature is available only on Android._
207207
await RNCallKeep.hasPhoneAccount();
208208
```
209209

210+
### hasDefaultPhoneAccount
211+
212+
Checks if the user has set a default [phone account](https://developer.android.com/reference/android/telecom/PhoneAccount).
213+
If the user has not set a default they will be prompted to do so with an alert.
214+
215+
This is a workaround for an [issue](https://github.com/wazo-pbx/react-native-callkeep/issues/33) affecting some Samsung devices.
216+
217+
_This feature is available only on Android._
218+
219+
```js
220+
const options = {
221+
alertTitle: 'Default not set',
222+
alertDescription: 'Please set the default phone account'
223+
};
224+
225+
RNCallKeep.hasDefaultPhoneAccount(options);
226+
```
227+
228+
210229
## Events
211230

212231
### didReceiveStartCallAction
@@ -219,7 +238,7 @@ After all works are done, remember to call `RNCallKeep.startCall(uuid, calleeNum
219238

220239
```js
221240
RNCallKeep.addEventListener('didReceiveStartCallAction', ({ handle }) => {
222-
241+
223242
});
224243
```
225244

@@ -283,7 +302,7 @@ A call was muted by the system or the user:
283302

284303
```js
285304
RNCallKeep.addEventListener('didPerformSetMutedCallAction', (muted) => {
286-
305+
287306
});
288307

289308
```
@@ -293,7 +312,7 @@ A call was held or unheld by the current user
293312

294313
```js
295314
RNCallKeep.addEventListener('didToggleHoldCallAction', ({ hold, callUUID }) => {
296-
315+
297316
});
298317
```
299318

@@ -307,7 +326,7 @@ Used type a number on his dialer
307326

308327
```js
309328
RNCallKeep.addEventListener('didPerformDTMFAction', ({ dtmf, callUUID }) => {
310-
329+
311330
});
312331
```
313332

@@ -327,9 +346,9 @@ import uuid from 'uuid';
327346
class RNCallKeepExample extends React.Component {
328347
constructor(props) {
329348
super(props);
330-
349+
331350
this.currentCallId = null;
332-
351+
333352
// Initialise RNCallKeep
334353
const options = {
335354
ios: {
@@ -342,7 +361,7 @@ class RNCallKeepExample extends React.Component {
342361
okButton: 'ok',
343362
}
344363
};
345-
364+
346365

347366
try {
348367
RNCallKeep.setup(options);
@@ -369,13 +388,13 @@ class RNCallKeepExample extends React.Component {
369388
onAnswerCallAction = ({ callUUID }) => {
370389
// called when the user answer the incoming call
371390
};
372-
391+
373392
onEndCallAction = ({ callUUID }) => {
374393
RNCallKeep.endCall(this.getCurrentCallId());
375-
394+
376395
this.currentCallId = null;
377396
};
378-
397+
379398
onIncomingCallDisplayed = error => {
380399
// You will get this event after RNCallKeep finishes showing incoming call UI
381400
// You can check if there was an error while displaying
@@ -389,7 +408,7 @@ class RNCallKeepExample extends React.Component {
389408
// you might want to do following things when receiving this event:
390409
// - Start playing ringback if it is an outgoing call
391410
};
392-
411+
393412
getCurrentCallId = () => {
394413
if (!this.currentCallId) {
395414
this.currentCallId = uuid.v4();

android/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="io.wazo.callkeep">
33

44
<uses-permission android:name="android.permission.CALL_PHONE" />
5+
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
56
</manifest>

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ public void checkPhoneAccountPermission(Promise promise) {
176176
promise.resolve(hasPhoneAccount());
177177
}
178178

179+
@ReactMethod
180+
public void checkDefaultPhoneAccount(Promise promise) {
181+
if (!isConnectionServiceAvailable() || !hasPhoneAccount()) {
182+
promise.resolve(true);
183+
return;
184+
}
185+
186+
if (!Build.MANUFACTURER.equalsIgnoreCase("Samsung")) {
187+
promise.resolve(true);
188+
return;
189+
}
190+
191+
promise.resolve(telecomManager.getDefaultOutgoingPhoneAccount("tel") != null);
192+
}
193+
179194
@ReactMethod
180195
public void hasPhoneAccount(Promise promise) {
181196
promise.resolve(hasPhoneAccount());
@@ -217,6 +232,15 @@ public void openPhoneAccounts() {
217232
return;
218233
}
219234

235+
openPhoneAccountSettings();
236+
}
237+
238+
@ReactMethod
239+
public void openPhoneAccountSettings() {
240+
if (!isConnectionServiceAvailable()) {
241+
return;
242+
}
243+
220244
Intent intent = new Intent(TelecomManager.ACTION_CHANGE_PHONE_ACCOUNTS);
221245
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
222246
this.getAppContext().startActivity(intent);

index.js

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ class RNCallKeep {
3737
return this._setupIOS(options.ios);
3838
};
3939

40+
hasDefaultPhoneAccount = async (options) => {
41+
if (!isIOS) {
42+
return this._hasDefaultPhoneAccount(options);
43+
}
44+
45+
return;
46+
};
47+
4048
displayIncomingCall = (uuid, handle, localizedCallerName, handleType = 'number', hasVideo = false) => {
4149
if (!isIOS) {
4250
RNCallKeepModule.displayIncomingCall(handle, localizedCallerName);
@@ -121,33 +129,44 @@ class RNCallKeep {
121129

122130
_setupAndroid = async (options) => {
123131
const hasAccount = await RNCallKeepModule.checkPhoneAccountPermission();
132+
const shouldOpenAccounts = await this._alert(options, hasAccount);
133+
134+
if (shouldOpenAccounts) {
135+
RNCallKeepModule.openPhoneAccounts();
136+
}
137+
};
138+
139+
_hasDefaultPhoneAccount = async (options) => {
140+
const hasDefault = await RNCallKeepModule.checkDefaultPhoneAccount();
141+
const shouldOpenAccounts = await this._alert(options, hasDefault);
124142

125-
return new Promise((resolve, reject) => {
126-
if (hasAccount) {
127-
return resolve();
128-
}
129-
130-
Alert.alert(
131-
options.alertTitle,
132-
options.alertDescription,
133-
[
134-
{
135-
text: options.cancelButton,
136-
onPress: reject,
137-
style: 'cancel',
138-
},
139-
{ text: options.okButton,
140-
onPress: () => {
141-
RNCallKeepModule.openPhoneAccounts();
142-
resolve();
143-
}
144-
},
145-
],
146-
{ cancelable: true },
147-
);
148-
});
143+
if (shouldOpenAccounts) {
144+
RNCallKeepModule.openPhoneAccountSettings();
145+
}
149146
};
150147

148+
_alert = async (options, condition) => new Promise((resolve, reject) => {
149+
if (condition) {
150+
return resolve(false);
151+
}
152+
153+
Alert.alert(
154+
options.alertTitle,
155+
options.alertDescription,
156+
[
157+
{
158+
text: options.cancelButton,
159+
onPress: reject,
160+
style: 'cancel',
161+
},
162+
{ text: options.okButton,
163+
onPress: () => resolve(true)
164+
},
165+
],
166+
{ cancelable: true },
167+
);
168+
});
169+
151170
backToForeground() {
152171
if (isIOS) {
153172
return;

0 commit comments

Comments
 (0)