add permission check to placeCall method

This commit is contained in:
Daniel Gultsch 2024-01-17 09:32:49 +01:00
parent 0ffc295888
commit 66cd50e163
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
3 changed files with 24 additions and 18 deletions

View file

@ -1,9 +1,11 @@
package eu.siacs.conversations.services;
import android.Manifest;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@ -17,6 +19,7 @@ import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telecom.VideoProfile;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.NonNull;
@ -25,6 +28,7 @@ import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.ui.RtpSessionActivity;
import eu.siacs.conversations.xmpp.Jid;
@ -221,7 +225,6 @@ public class CallIntegrationConnectionService extends ConnectionService {
final Account account,
final Jid with,
final Set<Media> media) {
Log.d(Config.LOGTAG, "place call media=" + media);
if (CallIntegration.selfManaged()) {
final var extras = new Bundle();
extras.putParcelable(
@ -231,6 +234,12 @@ public class CallIntegrationConnectionService extends ConnectionService {
Media.audioOnly(media)
? VideoProfile.STATE_AUDIO_ONLY
: VideoProfile.STATE_BIDIRECTIONAL);
if (service.checkSelfPermission(Manifest.permission.MANAGE_OWN_CALLS)
!= PackageManager.PERMISSION_GRANTED) {
Toast.makeText(service, R.string.no_permission_to_place_call, Toast.LENGTH_SHORT)
.show();
return;
}
service.getSystemService(TelecomManager.class)
.placeCall(CallIntegration.address(with), extras);
} else {

View file

@ -1981,7 +1981,6 @@ public class ConversationFragment extends XmppFragment
}
private boolean hasPermissions(int requestCode, List<String> permissions) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final List<String> missingPermissions = new ArrayList<>();
for (String permission : permissions) {
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU || Config.ONLY_INTERNAL_STORAGE) && permission.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
@ -1999,9 +1998,6 @@ public class ConversationFragment extends XmppFragment
requestCode);
return false;
}
} else {
return true;
}
}
private boolean hasPermissions(int requestCode, String... permissions) {

View file

@ -595,6 +595,7 @@
<string name="me">Me</string>
<string name="contact_asks_for_presence_subscription">Contact asks for presence subscription</string>
<string name="allow">Allow</string>
<string name="no_permission_to_place_call">No permission to place phone call</string>
<string name="no_permission_to_access_x">No permission to access %s</string>
<string name="remote_server_not_found">Remote server not found</string>
<string name="remote_server_timeout">Remote server timeout</string>