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

View file

@ -1981,26 +1981,22 @@ public class ConversationFragment extends XmppFragment
} }
private boolean hasPermissions(int requestCode, List<String> permissions) { private boolean hasPermissions(int requestCode, List<String> permissions) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { final List<String> missingPermissions = new ArrayList<>();
final List<String> missingPermissions = new ArrayList<>(); for (String permission : permissions) {
for (String permission : permissions) { if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU || Config.ONLY_INTERNAL_STORAGE) && permission.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU || Config.ONLY_INTERNAL_STORAGE) && permission.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { continue;
continue;
}
if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
missingPermissions.add(permission);
}
} }
if (missingPermissions.size() == 0) { if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
return true; missingPermissions.add(permission);
} else {
requestPermissions(
missingPermissions.toArray(new String[0]),
requestCode);
return false;
} }
} else { }
if (missingPermissions.size() == 0) {
return true; return true;
} else {
requestPermissions(
missingPermissions.toArray(new String[0]),
requestCode);
return false;
} }
} }

View file

@ -595,6 +595,7 @@
<string name="me">Me</string> <string name="me">Me</string>
<string name="contact_asks_for_presence_subscription">Contact asks for presence subscription</string> <string name="contact_asks_for_presence_subscription">Contact asks for presence subscription</string>
<string name="allow">Allow</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="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_not_found">Remote server not found</string>
<string name="remote_server_timeout">Remote server timeout</string> <string name="remote_server_timeout">Remote server timeout</string>