From ff3dffd0514642be8c47b726244d432f5f69f6b6 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Wed, 28 Dec 2022 11:35:51 +0100 Subject: [PATCH] Spotbugs: literal string comparison Signed-off-by: Andy Scherzinger --- .../nextcloud/talk/activities/CallActivity.java | 2 +- .../talk/adapters/items/ParticipantItem.java | 14 ++++++++++---- .../nextcloud/talk/utils/AuthenticatorService.java | 9 +++------ .../java/com/nextcloud/talk/utils/DeviceUtils.java | 13 ++++++++----- .../preferencestorage/DatabaseStorageModule.java | 14 +++++++------- .../talk/webrtc/PeerConnectionWrapper.java | 9 +++++---- .../talk/webrtc/WebRtcBluetoothManager.java | 12 +++++++----- 7 files changed, 41 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java index f9b90ac04..5b86aa37e 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -367,7 +367,7 @@ public class CallActivity extends CallBaseActivity { powerManagerUtils = new PowerManagerUtils(); - if (extras.getString("state", "").equalsIgnoreCase("resume")) { + if ("resume".equalsIgnoreCase(extras.getString("state", ""))) { setCallState(CallStatus.IN_CONVERSATION); } else { setCallState(CallStatus.CONNECTING); diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/ParticipantItem.java b/app/src/main/java/com/nextcloud/talk/adapters/items/ParticipantItem.java index 6bc572d68..0d2a3cc9e 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/ParticipantItem.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/ParticipantItem.java @@ -154,8 +154,11 @@ public class ParticipantItem extends AbstractFlexibleItem appOpsUtilsClass = Class.forName("android.miui.AppOpsUtils"); if (appOpsUtilsClass != null) { Method setApplicationAutoStartMethod = appOpsUtilsClass.getMethod("setApplicationAutoStart", Context .class, String.class, Boolean.TYPE); if (setApplicationAutoStartMethod != null) { - Context applicationContext = NextcloudTalkApplication.Companion.getSharedApplication().getApplicationContext(); + Context applicationContext = NextcloudTalkApplication + .Companion + .getSharedApplication() + .getApplicationContext(); setApplicationAutoStartMethod.invoke(appOpsUtilsClass, applicationContext, applicationContext .getPackageName(), Boolean.TRUE); } @@ -56,10 +59,10 @@ public class DeviceUtils { } catch (InvocationTargetException e) { Log.e(TAG, "InvocationTargetException"); } - } else if (Build.MANUFACTURER.equalsIgnoreCase("huawei")) { + } else if ("huawei".equalsIgnoreCase(Build.MANUFACTURER)) { try { - @SuppressLint("PrivateApi") Class protectAppControlClass = Class.forName("com.huawei.systemmanager.optimize.process" + - ".ProtectAppControl"); + @SuppressLint("PrivateApi") Class protectAppControlClass = Class.forName( + "com.huawei.systemmanager.optimize.process.ProtectAppControl"); if (protectAppControlClass != null) { Context applicationContext = NextcloudTalkApplication.Companion.getSharedApplication().getApplicationContext(); diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java index 9e891efec..3b4d59cf5 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java +++ b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java @@ -78,7 +78,7 @@ public class DatabaseStorageModule implements StorageModule { @Override public void saveBoolean(String key, boolean value) { - if (key.equals("call_notifications")) { + if ("call_notifications".equals(key)) { int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[]{4}); ncApi.notificationCalls(ApiUtils.getCredentials(conversationUser.getUsername(), conversationUser.getToken()), @@ -112,7 +112,7 @@ public class DatabaseStorageModule implements StorageModule { ); } - if (!key.equals("conversation_lobby")) { + if (!"conversation_lobby".equals(key)) { arbitraryStorageManager.storeStorageSetting(accountIdentifier, key, Boolean.toString(value), @@ -124,7 +124,7 @@ public class DatabaseStorageModule implements StorageModule { @Override public void saveString(String key, String value) { - if (key.equals("message_expire_key")) { + if ("message_expire_key".equals(key)) { int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[]{4}); String trimmedValue = value.replace("expire_", ""); @@ -163,7 +163,7 @@ public class DatabaseStorageModule implements StorageModule { } }); - } else if (key.equals("message_notification_level")) { + } else if ("message_notification_level".equals(key)) { if (CapabilitiesUtilNew.hasSpreedFeatureCapability(conversationUser, "notification-levels")) { if (!TextUtils.isEmpty(messageNotificationLevel) && !messageNotificationLevel.equals(value)) { int intValue; @@ -232,7 +232,7 @@ public class DatabaseStorageModule implements StorageModule { @Override public boolean getBoolean(String key, boolean defaultVal) { - if (key.equals("conversation_lobby")) { + if ("conversation_lobby".equals(key)) { return lobbyValue; } else { return arbitraryStorageManager @@ -244,7 +244,7 @@ public class DatabaseStorageModule implements StorageModule { @Override public String getString(String key, String defaultVal) { - if (key.equals("message_expire_key")) { + if ("message_expire_key".equals(key)) { switch (messageExpiration) { case 2419200: return "expire_2419200"; @@ -259,7 +259,7 @@ public class DatabaseStorageModule implements StorageModule { default: return "expire_0"; } - } else if (key.equals("message_notification_level")) { + } else if ("message_notification_level".equals(key)) { return messageNotificationLevel; } else { return arbitraryStorageManager diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java b/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java index f4a7d6b7e..98ef3ba5d 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java @@ -171,7 +171,7 @@ public class PeerConnectionWrapper { dataChannel.registerObserver(new MagicDataChannelObserver()); if (isMCUPublisher) { peerConnection.createOffer(magicSdpObserver, mediaConstraints); - } else if (hasMCU && this.videoStreamType.equals("video")) { + } else if (hasMCU && "video".equals(this.videoStreamType)) { // If the connection type is "screen" the client sharing the screen will send an // offer; offers should be requested only for videos. // "to" property is not actually needed in the "requestoffer" signaling message, but it is used to @@ -360,8 +360,9 @@ public class PeerConnectionWrapper { @Override public void onStateChange() { - if (dataChannel != null && dataChannel.state() == DataChannel.State.OPEN && - dataChannel.label().equals("status")) { + if (dataChannel != null && + dataChannel.state() == DataChannel.State.OPEN && + "status".equals(dataChannel.label())) { sendInitialMediaStatus(); } } @@ -493,7 +494,7 @@ public class PeerConnectionWrapper { @Override public void onDataChannel(DataChannel dataChannel) { - if (dataChannel.label().equals("status") || dataChannel.label().equals("JanusDataChannel")) { + if ("status".equals(dataChannel.label()) || "JanusDataChannel".equals(dataChannel.label())) { PeerConnectionWrapper.this.dataChannel = dataChannel; PeerConnectionWrapper.this.dataChannel.registerObserver(new MagicDataChannelObserver()); } diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/WebRtcBluetoothManager.java b/app/src/main/java/com/nextcloud/talk/webrtc/WebRtcBluetoothManager.java index 2655f9ba7..65e115af9 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/WebRtcBluetoothManager.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/WebRtcBluetoothManager.java @@ -109,8 +109,6 @@ public class WebRtcBluetoothManager { return bluetoothState; } - ; - /** * Activates components required to detect Bluetooth devices and to enable * BT SCO (audio is routed via BT SCO) for the headset profile. The end @@ -502,8 +500,10 @@ public class WebRtcBluetoothManager { Log.d(TAG, "onServiceConnected done: BT state=" + bluetoothState); } + /** + * Notifies the client when the proxy object has been disconnected from the service. + */ @Override - /** Notifies the client when the proxy object has been disconnected from the service. */ public void onServiceDisconnected(int profile) { if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) { return; @@ -531,7 +531,7 @@ public class WebRtcBluetoothManager { // change does not tell us anything about whether we're streaming // audio to BT over SCO. Typically received when user turns on a BT // headset while audio is active using another audio device. - if (action.equals(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED)) { + if (BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED.equals(action)) { final int state = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE, BluetoothHeadset.STATE_DISCONNECTED); Log.d(TAG, "BluetoothHeadsetBroadcastReceiver.onReceive: " @@ -543,8 +543,10 @@ public class WebRtcBluetoothManager { scoConnectionAttempts = 0; updateAudioDeviceState(); } else if (state == BluetoothHeadset.STATE_CONNECTING) { + Log.d(TAG, "+++ Bluetooth is connecting..."); // No action needed. } else if (state == BluetoothHeadset.STATE_DISCONNECTING) { + Log.d(TAG, "+++ Bluetooth is disconnecting..."); // No action needed. } else if (state == BluetoothHeadset.STATE_DISCONNECTED) { // Bluetooth is probably powered off during the call. @@ -553,7 +555,7 @@ public class WebRtcBluetoothManager { } // Change in the audio (SCO) connection state of the Headset profile. // Typically received after call to startScoAudio() has finalized. - } else if (action.equals(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED)) { + } else if (BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED.equals(action)) { final int state = intent.getIntExtra( BluetoothHeadset.EXTRA_STATE, BluetoothHeadset.STATE_AUDIO_DISCONNECTED); Log.d(TAG, "BluetoothHeadsetBroadcastReceiver.onReceive: "