浏览代码

Set minSdkVersion to 24 + remove checks

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 2 年之前
父节点
当前提交
b1daecac70

+ 1 - 1
app/build.gradle

@@ -82,7 +82,7 @@ android {
 
 
     defaultConfig {
-        minSdkVersion 23
+        minSdkVersion 24
         targetSdkVersion 33
 
         buildConfigField 'boolean', 'CI', ciBuild.toString()

+ 9 - 17
app/src/main/java/com/nextcloud/client/jobs/BackgroundJobFactory.kt

@@ -24,8 +24,6 @@ import android.app.NotificationManager
 import android.content.ContentResolver
 import android.content.Context
 import android.content.res.Resources
-import android.os.Build
-import androidx.annotation.RequiresApi
 import androidx.localbroadcastmanager.content.LocalBroadcastManager
 import androidx.work.ListenableWorker
 import androidx.work.WorkerFactory
@@ -89,8 +87,7 @@ class BackgroundJobFactory @Inject constructor(
             null
         }
 
-        // ContentObserverWork requires N
-        return if (deviceInfo.apiLevel >= Build.VERSION_CODES.N && workerClass == ContentObserverWork::class) {
+        return if (workerClass == ContentObserverWork::class) {
             createContentObserverJob(context, workerParameters)
         } else {
             when (workerClass) {
@@ -127,19 +124,14 @@ class BackgroundJobFactory @Inject constructor(
     private fun createContentObserverJob(
         context: Context,
         workerParameters: WorkerParameters
-    ): ListenableWorker? {
-        @RequiresApi(Build.VERSION_CODES.N)
-        if (deviceInfo.apiLevel >= Build.VERSION_CODES.N) {
-            return ContentObserverWork(
-                context,
-                workerParameters,
-                syncedFolderProvider,
-                powerManagementService,
-                backgroundJobManager.get()
-            )
-        } else {
-            return null
-        }
+    ): ListenableWorker {
+        return ContentObserverWork(
+            context,
+            workerParameters,
+            SyncedFolderProvider(contentResolver, preferences, clock),
+            powerManagementService,
+            backgroundJobManager.get()
+        )
     }
 
     private fun createContactsBackupWork(context: Context, params: WorkerParameters): ContactsBackupWork {

+ 0 - 3
app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt

@@ -19,8 +19,6 @@
  */
 package com.nextcloud.client.jobs
 
-import android.os.Build
-import androidx.annotation.RequiresApi
 import androidx.lifecycle.LiveData
 import com.nextcloud.client.account.User
 import com.owncloud.android.datamodel.OCFile
@@ -44,7 +42,6 @@ interface BackgroundJobManager {
      * This call is idempotent - there will be only one scheduled job
      * regardless of number of calls.
      */
-    @RequiresApi(Build.VERSION_CODES.N)
     fun scheduleContentObserverJob()
 
     /**

+ 0 - 3
app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt

@@ -19,9 +19,7 @@
  */
 package com.nextcloud.client.jobs
 
-import android.os.Build
 import android.provider.MediaStore
-import androidx.annotation.RequiresApi
 import androidx.lifecycle.LiveData
 import androidx.lifecycle.map
 import androidx.work.Constraints
@@ -211,7 +209,6 @@ internal class BackgroundJobManagerImpl(
             return workInfo.map { it -> it.map { fromWorkInfo(it) ?: JobInfo() }.sortedBy { it.started }.reversed() }
         }
 
-    @RequiresApi(Build.VERSION_CODES.N)
     override fun scheduleContentObserverJob() {
         val constrains = Constraints.Builder()
             .addContentUriTrigger(MediaStore.Images.Media.INTERNAL_CONTENT_URI, true)

+ 0 - 3
app/src/main/java/com/nextcloud/client/jobs/ContentObserverWork.kt

@@ -20,8 +20,6 @@
 package com.nextcloud.client.jobs
 
 import android.content.Context
-import android.os.Build
-import androidx.annotation.RequiresApi
 import androidx.work.Worker
 import androidx.work.WorkerParameters
 import com.nextcloud.client.device.PowerManagementService
@@ -34,7 +32,6 @@ import com.owncloud.android.datamodel.SyncedFolderProvider
  *
  * This job must not be started on API < 24.
  */
-@RequiresApi(Build.VERSION_CODES.N)
 class ContentObserverWork(
     appContext: Context,
     private val params: WorkerParameters,

+ 2 - 7
app/src/main/java/com/nextcloud/client/migrations/Migrations.kt

@@ -19,7 +19,6 @@
  */
 package com.nextcloud.client.migrations
 
-import android.os.Build
 import androidx.work.WorkManager
 import com.nextcloud.client.account.UserAccountManager
 import com.nextcloud.client.jobs.BackgroundJobManager
@@ -89,12 +88,8 @@ class Migrations @Inject constructor(
             logger.i(TAG, "${s.description}: cancelling legacy work ${it.id}")
             workManager.cancelWorkById(it.id)
         }
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-            jobManager.scheduleContentObserverJob()
-            logger.i(TAG, "$s: enabled")
-        } else {
-            logger.i(TAG, "$s: disabled")
-        }
+        jobManager.scheduleContentObserverJob()
+        logger.i(TAG, "$s: enabled")
     }
 
     /**

+ 6 - 9
app/src/main/java/com/owncloud/android/MainApp.java

@@ -108,7 +108,6 @@ import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLEngine;
 
 import androidx.annotation.NonNull;
-import androidx.annotation.RequiresApi;
 import androidx.annotation.StringRes;
 import androidx.appcompat.app.AlertDialog;
 import androidx.appcompat.app.AppCompatDelegate;
@@ -325,14 +324,13 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
             Log_OC.d("Debug", "start logging");
         }
 
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-            try {
-                Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
-                m.invoke(null);
-            } catch (Exception e) {
-                Log_OC.d("Debug", "Failed to disable uri exposure");
-            }
+        try {
+            Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
+            m.invoke(null);
+        } catch (Exception e) {
+            Log_OC.d("Debug", "Failed to disable uri exposure");
         }
+
         initSyncOperations(preferences,
                            uploadsStorageManager,
                            accountManager,
@@ -613,7 +611,6 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
         }
     }
 
-    @RequiresApi(api = Build.VERSION_CODES.N)
     private static void createChannel(NotificationManager notificationManager,
                                       String channelId, int channelName,
                                       int channelDescription, Context context) {

+ 2 - 4
app/src/main/java/com/owncloud/android/ui/activity/RichDocumentsEditorWebView.java

@@ -235,10 +235,8 @@ public class RichDocumentsEditorWebView extends EditorWebView {
         @JavascriptInterface
         public void paste() {
             // Javascript cannot do this by itself, so help out.
-            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-                getWebView().dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_PASTE));
-                getWebView().dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_PASTE));
-            }
+            getWebView().dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_PASTE));
+            getWebView().dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_PASTE));
         }
 
         @JavascriptInterface

+ 3 - 8
app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java

@@ -38,7 +38,6 @@ import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.net.Uri;
-import android.os.Build;
 import android.os.Environment;
 import android.os.StatFs;
 import android.provider.MediaStore;
@@ -849,13 +848,9 @@ public class FileOperationsHelper {
                 if (file.isDown()) {
                     File externalFile = new File(file.getStoragePath());
 
-                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-                        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
-                        uri = FileProvider.getUriForFile(context,
-                                                         context.getResources().getString(R.string.file_provider_authority), externalFile);
-                    } else {
-                        uri = Uri.fromFile(externalFile);
-                    }
+                    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+                    uri = FileProvider.getUriForFile(context,
+                                                     context.getResources().getString(R.string.file_provider_authority), externalFile);
                 } else {
                     uri = Uri.parse(UriUtils.URI_CONTENT_SCHEME +
                                         context.getResources().getString(R.string.image_cache_provider_authority) +

+ 1 - 2
app/src/main/java/com/owncloud/android/utils/FilesSyncHelper.java

@@ -28,7 +28,6 @@ import android.content.ContentResolver;
 import android.content.Context;
 import android.database.Cursor;
 import android.net.Uri;
-import android.os.Build;
 import android.provider.MediaStore;
 
 import com.nextcloud.client.account.UserAccountManager;
@@ -243,7 +242,7 @@ public final class FilesSyncHelper {
 
     public static void scheduleFilesSyncIfNeeded(Context context, BackgroundJobManager jobManager) {
         jobManager.schedulePeriodicFilesSyncJob();
-        if (context != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+        if (context != null) {
             jobManager.scheduleContentObserverJob();
         }
     }

+ 2 - 6
app/src/main/java/org/nextcloud/providers/cursors/FileCursor.java

@@ -22,7 +22,6 @@ package org.nextcloud.providers.cursors;
 
 import android.database.MatrixCursor;
 import android.os.AsyncTask;
-import android.os.Build;
 import android.os.Bundle;
 import android.provider.DocumentsContract.Document;
 
@@ -78,11 +77,8 @@ public class FileCursor extends MatrixCursor {
         final String mimeType = file.isFolder() ? Document.MIME_TYPE_DIR : file.getMimeType();
         int flags = Document.FLAG_SUPPORTS_DELETE |
             Document.FLAG_SUPPORTS_WRITE |
-            (MimeTypeUtil.isImage(file) ? Document.FLAG_SUPPORTS_THUMBNAIL : 0);
-
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-            flags = Document.FLAG_SUPPORTS_COPY | Document.FLAG_SUPPORTS_MOVE | Document.FLAG_SUPPORTS_REMOVE | flags;
-        }
+            (MimeTypeUtil.isImage(file) ? Document.FLAG_SUPPORTS_THUMBNAIL : 0) |
+            Document.FLAG_SUPPORTS_COPY | Document.FLAG_SUPPORTS_MOVE | Document.FLAG_SUPPORTS_REMOVE;
 
         if (file.isFolder()) {
             flags = flags | Document.FLAG_DIR_SUPPORTS_CREATE;

+ 0 - 17
app/src/test/java/com/nextcloud/client/jobs/BackgroundJobFactoryTest.kt

@@ -41,7 +41,6 @@ import com.owncloud.android.datamodel.UploadsStorageManager
 import com.owncloud.android.utils.theme.ViewThemeUtils
 import org.greenrobot.eventbus.EventBus
 import org.junit.Assert.assertNotNull
-import org.junit.Assert.assertNull
 import org.junit.Before
 import org.junit.Test
 import org.mockito.Mock
@@ -156,20 +155,4 @@ class BackgroundJobFactoryTest {
         //      factory creates a worker compatible with API level
         assertNotNull(worker)
     }
-
-    @Test
-    fun content_observer_worker_is_not_created_below_api_level_24() {
-        // GIVEN
-        //      api level is < 24
-        //      content URI trigger is not supported
-        whenever(deviceInfo.apiLevel).thenReturn(Build.VERSION_CODES.M)
-
-        // WHEN
-        //      factory is called to create content observer worker
-        val worker = factory.createWorker(context, ContentObserverWork::class.java.name, params)
-
-        // THEN
-        //      factory does not create a worker incompatible with API level
-        assertNull(worker)
-    }
 }