Skip to content

Commit

Permalink
[FIX] Duplicated call onAnswer. New open method. (flutter-webrtc#111)
Browse files Browse the repository at this point in the history
* feature: open method openPhoneAccounts

* feature: fixed duplicated call onAnswer on VoiceConnection

* feature: added support for drawables in notification icon in foreground service
  • Loading branch information
efraespada authored Sep 8, 2021
1 parent 5bb6385 commit dd1c872
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final callSetup = <String, dynamic>{
'channelId': 'com.company.my',
'channelName': 'Foreground service for my app',
'notificationTitle': 'My app is running on background',
'notificationIcon': 'Path to the resource icon of the notification',
'notificationIcon': 'mipmap/ic_notification_launcher',
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBindin

@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
if (!callKeep.HandleMethodCall(call, result)) {
if (!callKeep.handleMethodCall(call, result)) {
result.notImplemented();
}
}
Expand Down
8 changes: 6 additions & 2 deletions android/src/main/java/io/wazo/callkeep/CallKeepModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ public void setActivity(Activity activity) {
}

public void dispose(){
if (voiceBroadcastReceiver == null || this._context == null) return;
LocalBroadcastManager.getInstance(this._context).unregisterReceiver(voiceBroadcastReceiver);
VoiceConnectionService.setPhoneAccountHandle(null);
isReceiverRegistered = false;
}

public boolean HandleMethodCall(@NonNull MethodCall call, @NonNull Result result) {
public boolean handleMethodCall(@NonNull MethodCall call, @NonNull Result result) {
switch(call.method) {
case "setup": {
setup(new ConstraintsMap((Map<String, Object>)call.argument("options")));
Expand Down Expand Up @@ -219,6 +221,9 @@ public boolean HandleMethodCall(@NonNull MethodCall call, @NonNull Result result
}

public void setup(ConstraintsMap options) {
if (isReceiverRegistered) {
return;
}
VoiceConnectionService.setAvailable(false);
this._settings = options;
if (isConnectionServiceAvailable()) {
Expand All @@ -243,7 +248,6 @@ public void registerEvents() {
if (!isConnectionServiceAvailable()) {
return;
}

voiceBroadcastReceiver = new VoiceBroadcastReceiver();
registerReceiver();
VoiceConnectionService.setPhoneAccountHandle(handle);
Expand Down
13 changes: 3 additions & 10 deletions android/src/main/java/io/wazo/callkeep/VoiceConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,20 @@ public void onCallAudioStateChanged(CallAudioState state) {
public void onAnswer() {
super.onAnswer();
Log.d(TAG, "onAnswer called");

setConnectionCapabilities(getConnectionCapabilities() | Connection.CAPABILITY_HOLD);
setAudioModeIsVoip(true);

sendCallRequestToActivity(ACTION_ANSWER_CALL, handle);
sendCallRequestToActivity(ACTION_AUDIO_SESSION, handle);
Log.d(TAG, "onAnswer executed");
Log.d(TAG, "onAnswer ignored");
}


@Override
public void onAnswer(int videoState) {
super.onAnswer(videoState);
Log.d(TAG, "onAnswer called");
Log.d(TAG, "onAnswer videoState called: " + videoState);

setConnectionCapabilities(getConnectionCapabilities() | Connection.CAPABILITY_HOLD);
setAudioModeIsVoip(true);

sendCallRequestToActivity(ACTION_ANSWER_CALL, handle);
sendCallRequestToActivity(ACTION_AUDIO_SESSION, handle);
Log.d(TAG, "onAnswer executed");
Log.d(TAG, "onAnswer videoState executed");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,17 @@ private void startForegroundService() {
Context context = this.getApplicationContext();
Resources res = context.getResources();
String smallIcon = foregroundSettings.getString("notificationIcon");
notificationBuilder.setSmallIcon(res.getIdentifier(smallIcon, "mipmap", context.getPackageName()));
String mipmap = "mipmap/";
String drawable = "drawable/";
if (smallIcon.contains(mipmap)) {
notificationBuilder.setSmallIcon(
res.getIdentifier(smallIcon.replace(mipmap, ""),
"mipmap", context.getPackageName()));
} else if (smallIcon.contains(drawable)) {
notificationBuilder.setSmallIcon(
res.getIdentifier(smallIcon.replace(drawable, ""),
"drawable", context.getPackageName()));
}
}

Log.d(TAG, "[VoiceConnectionService] Starting foreground service");
Expand Down
4 changes: 4 additions & 0 deletions lib/src/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ class FlutterCallkeep extends EventManager {
return false;
}

Future<void> openPhoneAccounts() async {
_openPhoneAccounts();
}

Future<void> _openPhoneAccounts() async {
if (!Platform.isAndroid) {
return;
Expand Down

0 comments on commit dd1c872

Please sign in to comment.