Fix several crashes on lower android

Stephen Paul Weber created

Change summary

src/main/java/eu/siacs/conversations/persistance/FileBackend.java        | 3 
src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 3 
src/main/java/eu/siacs/conversations/ui/ConversationFragment.java        | 6 
3 files changed, 9 insertions(+), 3 deletions(-)

Detailed changes

src/main/java/eu/siacs/conversations/persistance/FileBackend.java 🔗

@@ -607,7 +607,7 @@ public class FileBackend {
         }
 
         try {
-            if (file.exists() && file.toString().startsWith(mXmppConnectionService.getCacheDir().toString())) {
+            if (file.exists() && file.toString().startsWith(mXmppConnectionService.getCacheDir().toString()) && Build.VERSION.SDK_INT >= 26) {
                 java.nio.file.Files.setAttribute(file.toPath(), "lastAccessTime", java.nio.file.attribute.FileTime.fromMillis(System.currentTimeMillis()));
             }
         } catch (final IOException e) {
@@ -1837,6 +1837,7 @@ public class FileBackend {
 
     public File getAvatarFile(String avatar) {
         final var f = new File(mXmppConnectionService.getCacheDir(), "/avatars/" + avatar);
+        if (Build.VERSION.SDK_INT < 26) return f; // Doesn't support file.toPath
         try {
             if (f.exists()) java.nio.file.Files.setAttribute(f.toPath(), "lastAccessTime", java.nio.file.attribute.FileTime.fromMillis(System.currentTimeMillis()));
         } catch (final IOException e) {

src/main/java/eu/siacs/conversations/services/XmppConnectionService.java 🔗

@@ -758,7 +758,8 @@ public class XmppConnectionService extends Service {
     }
 
     protected void cleanupCache() {
-         mStickerScanExecutor.execute(() -> {
+        if (Build.VERSION.SDK_INT < 26) return; // Doesn't support file.toPath
+        mStickerScanExecutor.execute(() -> {
             Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
             final var now = System.currentTimeMillis();
             try {

src/main/java/eu/siacs/conversations/ui/ConversationFragment.java 🔗

@@ -951,7 +951,11 @@ public class ConversationFragment extends XmppFragment
         final Conversation conversation = this.conversation;
         final boolean hasSubject = binding.textinputSubject.getText().length() > 0;
         if (conversation == null || (body.length() == 0 && (conversation.getThread() == null || !hasSubject))) {
-            binding.textSendButton.showContextMenu(0, 0);
+            if (Build.VERSION.SDK_INT >= 24) {
+                binding.textSendButton.showContextMenu(0, 0);
+            } else {
+                binding.textSendButton.showContextMenu();
+            }
             return;
         }
         if (trustKeysIfNeeded(conversation, REQUEST_TRUST_KEYS_TEXT)) {