Better permission notification (Cheogram)

This commit is contained in:
Arne 2023-05-18 18:05:54 +02:00
parent e43b7eee98
commit 6611f21f6a
3 changed files with 27 additions and 25 deletions

View file

@ -107,7 +107,7 @@ dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'io.michaelrocks:libphonenumber-android:8.12.49'
implementation 'io.github.nishkarsh:android-permissions:2.0.54'
implementation 'io.github.nishkarsh:android-permissions:2.1.6'
}
ext {

View file

@ -33,16 +33,16 @@ import android.os.Parcel;
import android.util.Log;
import com.intentfilter.androidpermissions.PermissionManager;
import com.intentfilter.androidpermissions.NotificationSettings;
import com.intentfilter.androidpermissions.models.DeniedPermissions;
import io.michaelrocks.libphonenumber.android.NumberParseException;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.AppRTCAudioManager;
import eu.siacs.conversations.services.AvatarService;
import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.ui.RtpSessionActivity;
import eu.siacs.conversations.utils.PhoneNumberUtilWrapper;
import eu.siacs.conversations.xmpp.Jid;
import eu.siacs.conversations.xmpp.jingle.JingleRtpConnection;
import eu.siacs.conversations.xmpp.jingle.Media;
@ -71,7 +71,7 @@ public class ConnectionService extends android.telecom.ConnectionService {
try {
startService(intent);
} catch (IllegalStateException e) {
Log.w(".ConnectionService", "unable to start service from " + getClass().getSimpleName());
Log.w("com.cheogram.android.ConnectionService", "unable to start service from " + getClass().getSimpleName());
}
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
@ -91,13 +91,12 @@ public class ConnectionService extends android.telecom.ConnectionService {
String rawTel = request.getAddress().getSchemeSpecificPart();
String postDial = PhoneNumberUtils.extractPostDialPortion(rawTel);
// TODO: jabber:iq:gateway
String tel = PhoneNumberUtils.extractNetworkPortion(rawTel);
try {
tel = PhoneNumberUtilWrapper.normalize(this, tel);
} catch (NumberParseException e) {
return Connection.createFailedConnection(
new DisconnectCause(DisconnectCause.ERROR)
);
if (tel.startsWith("1")) {
tel = "+" + tel;
} else if (!tel.startsWith("+")) {
tel = "+1" + tel;
}
if (xmppConnectionService.getJingleConnectionManager().isBusy()) {
@ -111,6 +110,12 @@ public class ConnectionService extends android.telecom.ConnectionService {
CheogramConnection connection = new CheogramConnection(account, with, postDial);
PermissionManager permissionManager = PermissionManager.getInstance(this);
permissionManager.setNotificationSettings(
new NotificationSettings.Builder()
.withMessage(R.string.microphone_permission_for_call)
.withSmallIcon(R.drawable.ic_notification).build()
);
Set<String> permissions = new HashSet();
permissions.add(Manifest.permission.RECORD_AUDIO);
permissionManager.checkPermissions(permissions, new PermissionManager.PermissionRequestListener() {
@ -129,11 +134,20 @@ public class ConnectionService extends android.telecom.ConnectionService {
}
});
connection.setInitializing();
connection.setAddress(
Uri.fromParts("tel", tel, null), // Normalized tel as tel: URI
TelecomManager.PRESENTATION_ALLOWED
);
connection.setCallerDisplayName(
account.getDisplayName(),
TelecomManager.PRESENTATION_ALLOWED
);
connection.setAudioModeIsVoip(true);
connection.setRingbackRequested(true);
connection.setDialing();
connection.setConnectionCapabilities(
Connection.CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION
);
xmppConnectionService.setOnRtpConnectionUpdateListener(
(XmppConnectionService.OnJingleRtpConnectionUpdate) connection
@ -166,15 +180,6 @@ public class ConnectionService extends android.telecom.ConnectionService {
postDial.push("" + postDialString.charAt(i));
}
}
setCallerDisplayName(
account.getDisplayName(),
TelecomManager.PRESENTATION_ALLOWED
);
setAudioModeIsVoip(true);
setConnectionCapabilities(
Connection.CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION
);
}
public void setSessionId(final String sessionId) {
@ -191,11 +196,7 @@ public class ConnectionService extends android.telecom.ConnectionService {
setStatusHints(new StatusHints(null, gatewayIcon, null));
if (state == RtpEndUserState.FINDING_DEVICE) {
setInitialized();
} else if (state == RtpEndUserState.RINGING) {
setDialing();
} else if (state == RtpEndUserState.CONNECTED) {
if (state == RtpEndUserState.CONNECTED) {
xmppConnectionService.setDiallerIntegrationActive(true);
setActive();

View file

@ -1267,4 +1267,5 @@
<string name="add_anway">Add anyway</string>
<string name="receiving_x_file">Receiving %1$s (%2$d%% completed)</string>
<string name="refresh_feature_discovery">Refresh Feature Discovery</string>
<string name="microphone_permission_for_call">Microphone permission required to complete call</string>
</resources>