Merge pull request #2160 from nextcloud/bugfix/2132/android-build-dependend-bluetooth-permissions-2

Implement comments by PR #2139
This commit is contained in:
Tim Krüger 2022-06-24 17:51:34 +02:00 committed by GitHub
commit a5677872b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 43 deletions

View file

@ -161,14 +161,14 @@ class ChatAndCallMessagingService : FirebaseMessagingService() {
decryptMessage(privateKey, base64DecodedSubject, subject, signature)
}
} catch (e1: NoSuchAlgorithmException) {
Log.d(NotificationWorker.TAG, "No proper algorithm to decrypt the message " + e1.localizedMessage)
Log.e(NotificationWorker.TAG, "No proper algorithm to decrypt the message.", e1)
} catch (e1: NoSuchPaddingException) {
Log.d(NotificationWorker.TAG, "No proper padding to decrypt the message " + e1.localizedMessage)
Log.e(NotificationWorker.TAG, "No proper padding to decrypt the message.", e1)
} catch (e1: InvalidKeyException) {
Log.d(NotificationWorker.TAG, "Invalid private key " + e1.localizedMessage)
Log.e(NotificationWorker.TAG, "Invalid private key.", e1)
}
} catch (exception: Exception) {
Log.d(NotificationWorker.TAG, "Something went very wrong " + exception.localizedMessage, exception)
Log.e(NotificationWorker.TAG, "Something went very wrong!", exception)
}
}
@ -218,7 +218,7 @@ class ChatAndCallMessagingService : FirebaseMessagingService() {
0,
fullScreenIntent,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
} else {
PendingIntent.FLAG_UPDATE_CURRENT
}

View file

@ -95,10 +95,10 @@ import com.nextcloud.talk.utils.database.user.UserUtils;
import com.nextcloud.talk.utils.power.PowerManagerUtils;
import com.nextcloud.talk.utils.preferences.AppPreferences;
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
import com.nextcloud.talk.webrtc.WebRtcAudioManger;
import com.nextcloud.talk.webrtc.MagicWebRTCUtils;
import com.nextcloud.talk.webrtc.MagicWebSocketInstance;
import com.nextcloud.talk.webrtc.PeerConnectionWrapper;
import com.nextcloud.talk.webrtc.WebRtcAudioManager;
import com.nextcloud.talk.webrtc.WebSocketConnectionHelper;
import com.wooplr.spotlight.SpotlightView;
@ -162,8 +162,7 @@ import me.zhanghai.android.effortlesspermissions.OpenAppDetailsDialogFragment;
import okhttp3.Cache;
import pub.devrel.easypermissions.AfterPermissionGranted;
import static android.app.PendingIntent.FLAG_MUTABLE;
import static android.app.PendingIntent.FLAG_MUTABLE;
import static android.app.PendingIntent.FLAG_IMMUTABLE;
import static com.nextcloud.talk.webrtc.Globals.JOB_ID;
import static com.nextcloud.talk.webrtc.Globals.PARTICIPANTS_UPDATE;
import static com.nextcloud.talk.webrtc.Globals.ROOM_TOKEN;
@ -189,7 +188,7 @@ public class CallActivity extends CallBaseActivity {
public static final String TAG = "CallActivity";
public WebRtcAudioManger audioManager;
public WebRtcAudioManager audioManager;
private static final String[] PERMISSIONS_CALL = {
Manifest.permission.CAMERA,
@ -343,7 +342,6 @@ public class CallActivity extends CallBaseActivity {
updateSelfVideoViewPosition();
}
@SuppressLint("InlinedApi")
@RequiresApi(api = Build.VERSION_CODES.S)
private void requestBluetoothPermission() {
if (ContextCompat.checkSelfPermission(
@ -452,16 +450,16 @@ public class CallActivity extends CallBaseActivity {
// Create and audio manager that will take care of audio routing,
// audio modes, audio device enumeration etc.
audioManager = WebRtcAudioManger.create(getApplicationContext(), isVoiceOnlyCall);
audioManager = WebRtcAudioManager.create(getApplicationContext(), isVoiceOnlyCall);
// Store existing audio settings and change audio mode to
// MODE_IN_COMMUNICATION for best possible VoIP performance.
Log.d(TAG, "Starting the audio manager...");
audioManager.start(this::onAudioManagerDevicesChanged);
if (isVoiceOnlyCall) {
setAudioOutputChannel(WebRtcAudioManger.AudioDevice.EARPIECE);
setAudioOutputChannel(WebRtcAudioManager.AudioDevice.EARPIECE);
} else {
setAudioOutputChannel(WebRtcAudioManger.AudioDevice.SPEAKER_PHONE);
setAudioOutputChannel(WebRtcAudioManager.AudioDevice.SPEAKER_PHONE);
}
iceServers = new ArrayList<>();
@ -495,14 +493,14 @@ public class CallActivity extends CallBaseActivity {
microphoneInitialization();
}
public void setAudioOutputChannel(WebRtcAudioManger.AudioDevice selectedAudioDevice) {
public void setAudioOutputChannel(WebRtcAudioManager.AudioDevice selectedAudioDevice) {
if (audioManager != null) {
audioManager.selectAudioDevice(selectedAudioDevice);
updateAudioOutputButton(audioManager.getCurrentAudioDevice());
}
}
private void updateAudioOutputButton(WebRtcAudioManger.AudioDevice activeAudioDevice) {
private void updateAudioOutputButton(WebRtcAudioManager.AudioDevice activeAudioDevice) {
switch (activeAudioDevice) {
case BLUETOOTH:
binding.audioOutputButton.getHierarchy().setPlaceholderImage(
@ -796,14 +794,14 @@ public class CallActivity extends CallBaseActivity {
}
private void onAudioManagerDevicesChanged(
final WebRtcAudioManger.AudioDevice currentDevice,
final Set<WebRtcAudioManger.AudioDevice> availableDevices) {
final WebRtcAudioManager.AudioDevice currentDevice,
final Set<WebRtcAudioManager.AudioDevice> availableDevices) {
Log.d(TAG, "onAudioManagerDevicesChanged: " + availableDevices + ", "
+ "currentDevice: " + currentDevice);
final boolean shouldDisableProximityLock = (currentDevice.equals(WebRtcAudioManger.AudioDevice.WIRED_HEADSET)
|| currentDevice.equals(WebRtcAudioManger.AudioDevice.SPEAKER_PHONE)
|| currentDevice.equals(WebRtcAudioManger.AudioDevice.BLUETOOTH));
final boolean shouldDisableProximityLock = (currentDevice.equals(WebRtcAudioManager.AudioDevice.WIRED_HEADSET)
|| currentDevice.equals(WebRtcAudioManager.AudioDevice.SPEAKER_PHONE)
|| currentDevice.equals(WebRtcAudioManager.AudioDevice.BLUETOOTH));
if (shouldDisableProximityLock) {
powerManagerUtils.updatePhoneState(PowerManagerUtils.PhoneState.WITHOUT_PROXIMITY_SENSOR_LOCK);
@ -2614,7 +2612,7 @@ public class CallActivity extends CallBaseActivity {
int intentFlag;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
intentFlag = FLAG_MUTABLE;
intentFlag = FLAG_IMMUTABLE;
} else {
intentFlag = 0;
}

View file

@ -30,7 +30,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialog
import com.nextcloud.talk.R
import com.nextcloud.talk.activities.CallActivity
import com.nextcloud.talk.databinding.DialogAudioOutputBinding
import com.nextcloud.talk.webrtc.WebRtcAudioManger
import com.nextcloud.talk.webrtc.WebRtcAudioManager
class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(callActivity) {
@ -47,26 +47,26 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
}
fun updateOutputDeviceList() {
if (callActivity.audioManager?.audioDevices?.contains(WebRtcAudioManger.AudioDevice.BLUETOOTH) == false) {
if (callActivity.audioManager?.audioDevices?.contains(WebRtcAudioManager.AudioDevice.BLUETOOTH) == false) {
dialogAudioOutputBinding.audioOutputBluetooth.visibility = View.GONE
} else {
dialogAudioOutputBinding.audioOutputBluetooth.visibility = View.VISIBLE
}
if (callActivity.audioManager?.audioDevices?.contains(WebRtcAudioManger.AudioDevice.EARPIECE) == false) {
if (callActivity.audioManager?.audioDevices?.contains(WebRtcAudioManager.AudioDevice.EARPIECE) == false) {
dialogAudioOutputBinding.audioOutputEarspeaker.visibility = View.GONE
} else {
dialogAudioOutputBinding.audioOutputEarspeaker.visibility = View.VISIBLE
}
if (callActivity.audioManager?.audioDevices?.contains(WebRtcAudioManger.AudioDevice.SPEAKER_PHONE) == false) {
if (callActivity.audioManager?.audioDevices?.contains(WebRtcAudioManager.AudioDevice.SPEAKER_PHONE) == false) {
dialogAudioOutputBinding.audioOutputSpeaker.visibility = View.GONE
} else {
dialogAudioOutputBinding.audioOutputSpeaker.visibility = View.VISIBLE
}
if (callActivity.audioManager?.currentAudioDevice?.equals(
WebRtcAudioManger.AudioDevice.WIRED_HEADSET
WebRtcAudioManager.AudioDevice.WIRED_HEADSET
) == true
) {
dialogAudioOutputBinding.audioOutputEarspeaker.visibility = View.GONE
@ -81,7 +81,7 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
private fun highlightActiveOutputChannel() {
when (callActivity.audioManager?.currentAudioDevice) {
WebRtcAudioManger.AudioDevice.BLUETOOTH -> {
WebRtcAudioManager.AudioDevice.BLUETOOTH -> {
dialogAudioOutputBinding.audioOutputBluetoothIcon.setColorFilter(
ContextCompat.getColor(
context,
@ -94,7 +94,7 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
)
}
WebRtcAudioManger.AudioDevice.SPEAKER_PHONE -> {
WebRtcAudioManager.AudioDevice.SPEAKER_PHONE -> {
dialogAudioOutputBinding.audioOutputSpeakerIcon.setColorFilter(
ContextCompat.getColor(
context,
@ -107,7 +107,7 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
)
}
WebRtcAudioManger.AudioDevice.EARPIECE -> {
WebRtcAudioManager.AudioDevice.EARPIECE -> {
dialogAudioOutputBinding.audioOutputEarspeakerIcon.setColorFilter(
ContextCompat.getColor(
context,
@ -120,7 +120,7 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
)
}
WebRtcAudioManger.AudioDevice.WIRED_HEADSET -> {
WebRtcAudioManager.AudioDevice.WIRED_HEADSET -> {
dialogAudioOutputBinding.audioOutputWiredHeadsetIcon.setColorFilter(
ContextCompat.getColor(
context,
@ -139,17 +139,17 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
private fun initClickListeners() {
dialogAudioOutputBinding.audioOutputBluetooth.setOnClickListener {
callActivity.setAudioOutputChannel(WebRtcAudioManger.AudioDevice.BLUETOOTH)
callActivity.setAudioOutputChannel(WebRtcAudioManager.AudioDevice.BLUETOOTH)
dismiss()
}
dialogAudioOutputBinding.audioOutputSpeaker.setOnClickListener {
callActivity.setAudioOutputChannel(WebRtcAudioManger.AudioDevice.SPEAKER_PHONE)
callActivity.setAudioOutputChannel(WebRtcAudioManager.AudioDevice.SPEAKER_PHONE)
dismiss()
}
dialogAudioOutputBinding.audioOutputEarspeaker.setOnClickListener {
callActivity.setAudioOutputChannel(WebRtcAudioManger.AudioDevice.EARPIECE)
callActivity.setAudioOutputChannel(WebRtcAudioManager.AudioDevice.EARPIECE)
dismiss()
}
}

View file

@ -54,8 +54,8 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class WebRtcAudioManger {
private static final String TAG = WebRtcAudioManger.class.getCanonicalName();
public class WebRtcAudioManager {
private static final String TAG = WebRtcAudioManager.class.getSimpleName();
private final Context magicContext;
private final WebRtcBluetoothManager bluetoothManager;
private final boolean useProximitySensor;
@ -79,7 +79,7 @@ public class WebRtcAudioManger {
private final PowerManagerUtils powerManagerUtils;
private WebRtcAudioManger(Context context, boolean useProximitySensor) {
private WebRtcAudioManager(Context context, boolean useProximitySensor) {
Log.d(TAG, "ctor");
ThreadUtils.checkIsOnMainThread();
magicContext = context;
@ -110,8 +110,8 @@ public class WebRtcAudioManger {
/**
* Construction.
*/
public static WebRtcAudioManger create(Context context, boolean useProximitySensor) {
return new WebRtcAudioManger(context, useProximitySensor);
public static WebRtcAudioManager create(Context context, boolean useProximitySensor) {
return new WebRtcAudioManager(context, useProximitySensor);
}
public void startBluetoothManager() {
@ -141,7 +141,7 @@ public class WebRtcAudioManger {
.SENSOR_NEAR, null, null, null, null));
} else {
setAudioDeviceInternal(WebRtcAudioManger.AudioDevice.SPEAKER_PHONE);
setAudioDeviceInternal(WebRtcAudioManager.AudioDevice.SPEAKER_PHONE);
Log.d(TAG, "switched to SPEAKER_PHONE because userSelectedAudioDevice was SPEAKER_PHONE and proximity=far");
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType

View file

@ -59,14 +59,14 @@ import java.util.Set;
import androidx.core.app.ActivityCompat;
public class WebRtcBluetoothManager {
private static final String TAG = WebRtcBluetoothManager.class.getCanonicalName();
private static final String TAG = WebRtcBluetoothManager.class.getSimpleName();
// Timeout interval for starting or stopping audio to a Bluetooth SCO device.
private static final int BLUETOOTH_SCO_TIMEOUT_MS = 4000;
// Maximum number of SCO connection attempts.
private static final int MAX_SCO_CONNECTION_ATTEMPTS = 2;
private final Context apprtcContext;
private final WebRtcAudioManger webRtcAudioManager;
private final WebRtcAudioManager webRtcAudioManager;
private final AudioManager audioManager;
private final Handler handler;
private final BluetoothProfile.ServiceListener bluetoothServiceListener;
@ -82,7 +82,7 @@ public class WebRtcBluetoothManager {
private final Runnable bluetoothTimeoutRunnable = this::bluetoothTimeout;
private boolean started = false;
protected WebRtcBluetoothManager(Context context, WebRtcAudioManger audioManager) {
protected WebRtcBluetoothManager(Context context, WebRtcAudioManager audioManager) {
Log.d(TAG, "ctor");
ThreadUtils.checkIsOnMainThread();
apprtcContext = context;
@ -97,7 +97,7 @@ public class WebRtcBluetoothManager {
/**
* Construction.
*/
static WebRtcBluetoothManager create(Context context, WebRtcAudioManger audioManager) {
static WebRtcBluetoothManager create(Context context, WebRtcAudioManager audioManager) {
return new WebRtcBluetoothManager(context, audioManager);
}